CXF 3.1.8如何关闭模式验证

时间:2018-04-11 11:36:08

标签: apache soap wsdl cxf jax-ws

Apache CXF 3.1.8 Codegen-cxf-plugin禁用验证

我在我的ejb项目中使用Codegen-cxf-plugin作为soap客户端。

当我尝试初始化服务时:

private static WsProviderPortType lkService = null;

                  WsProviderService lk = new WsProviderService(new URL(AppConfig.getConfig().getProperty("lk.service")));
                    lkService = lk.getWsProviderPort();

Cxf下载wsdl和xsd并检查它。我想关掉这个验证。我该怎么做? 有没有办法用注释做到这一点?

这是使用wsdl类生成的:

@WebServiceClient(name = "WsProviderService", 
              wsdlLocation = "file:/C:/src/lklB2B/lkB2B_ejb/src/main/resources/wsdl/test/lk_srv.wsdl",
              targetNamespace = "http://south.rt.ru/WsProvider/") 
public class WsProviderService extends Service {

public final static URL WSDL_LOCATION;

public final static QName SERVICE = new QName("http://south.rt.ru/WsProvider/", "WsProviderService");
public final static QName WsProviderPort = new QName("http://south.rt.ru/WsProvider/", "WsProviderPort");
static {
    URL url = null;
    try {
        url = new URL("file:/C:/src/lklB2B/lkB2B_ejb/src/main/resources/wsdl/test/lk_srv.wsdl");
    } catch (MalformedURLException e) {
        java.util.logging.Logger.getLogger(WsProviderService.class.getName())
            .log(java.util.logging.Level.INFO, 
                 "Can not initialize the default wsdl from {0}", "file:/C:/src/lklB2B/lkB2B_ejb/src/main/resources/wsdl/test/lk_srv.wsdl");
    }
    WSDL_LOCATION = url;
}

public WsProviderService(URL wsdlLocation) {
    super(wsdlLocation, SERVICE);
}

public WsProviderService(URL wsdlLocation, QName serviceName) {
    super(wsdlLocation, serviceName);
}

public WsProviderService() {
    super(WSDL_LOCATION, SERVICE);
}

public WsProviderService(WebServiceFeature ... features) {
    super(WSDL_LOCATION, SERVICE, features);
}

public WsProviderService(URL wsdlLocation, WebServiceFeature ... features) {
    super(wsdlLocation, SERVICE, features);
}

public WsProviderService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
    super(wsdlLocation, serviceName, features);
}    

这是我的wsdl的一部分:

......

<wsdl:portType name="WsProviderPortType">
    <wsdl:operation name="UpdateStatus">
        <wsdl:input name="UpdateStatusRequest" message="tns:UpdateStatusRequest">
        </wsdl:input>
        <wsdl:output name="UpdateStatusResponse" message="tns:UpdateStatusResponse">
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="canCharge">
        <wsdl:input name="canChargeRequest" message="tns:canChargeRequest"/>
        <wsdl:output name="canChargeResponse" message="tns:canChargeResponse"/>
    </wsdl:operation>
    <wsdl:operation name="getOrder">
        <wsdl:input name="getOrderRequest" message="tns:getOrderRequest">
        </wsdl:input>
        <wsdl:output name="getOrderResponse" message="tns:getOrderResponse">
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getAvailableSIMCardsList">
        <wsdl:input name="getAvailableSIMCardsListRequest" message="tns:getAvailableSIMCardsListRequest">
        </wsdl:input>
        <wsdl:output name="getAvailableSIMCardsListResponse" message="tns:getAvailableSIMCardsListResponse">
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="updateOrderStatus">
        <wsdl:input name="updateOrderStatusRequest" message="tns:updateOrderStatusRequest">
        </wsdl:input>
        <wsdl:output name="updateOrderStatusResponse" message="tns:updateOrderStatusResponse">
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="createOrderB2B">
        <wsdl:input name="createOrderB2BRequest" message="tns:createOrderB2BRequest">
        </wsdl:input>
        <wsdl:output name="createOrderB2BResponse" message="tns:createOrderB2BResponse">
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="searchOrder">
        <wsdl:input name="searchOrderRequest" message="tns:searchOrderRequest">
        </wsdl:input>
        <wsdl:output name="searchOrderResponse" message="tns:searchOrderResponse">
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="UpdateStatusLastMileCMS">
        <wsdl:input name="UpdateStatusLastMileCMSRequest" message="tns:UpdateStatusLastMileCMSRequest">
        </wsdl:input>
        <wsdl:output name="UpdateStatusLastMileCMSResponse" message="tns:UpdateStatusLastMileCMSResponse">
        </wsdl:output>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WsProviderServiceSoapBinding" type="tns:WsProviderPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="UpdateStatus">
        <wsdl:input name="UpdateStatusRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="UpdateStatusResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="canCharge">
        <wsdl:input name="canChargeRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="canChargeResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getOrder">
        <wsdl:input name="getOrderRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="getOrderResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getAvailableSIMCardsList">
        <wsdl:input name="getAvailableSIMCardsListRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="getAvailableSIMCardsListResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="updateOrderStatus">
        <wsdl:input name="updateOrderStatusRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="updateOrderStatusResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="createOrderB2B">
        <wsdl:input name="createOrderB2BRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="createOrderB2BResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="searchOrder">
        <wsdl:input name="searchOrderRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="searchOrderResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="UpdateStatusLastMileCMS">
        <wsdl:input name="UpdateStatusLastMileCMSRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="UpdateStatusLastMileCMSResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="WsProviderService">
    <wsdl:port name="WsProviderPort" binding="tns:WsProviderServiceSoapBinding">
        <soap:address location="http://lkdevel2.south.rt.ru/wsp/soap/wsprovider/lk_srv"/>
    </wsdl:port>
</wsdl:service>

这是我的pom:

</dependencies>
<properties>
    <cxf-version>3.1.8</cxf-version>
</properties>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <ejbVersion>3.1</ejbVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<profiles>
    <profile>
        <id>test</id>
        <dependencies>
            <dependency>
                <groupId>ru.rt.mdm</groupId>
                <artifactId>fw_ejb</artifactId>
                <version>${mdm.fw.version}</version>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-codegen-plugin</artifactId>
                    <version>3.1.8</version>
                    <executions>
                        <execution>
                            <id>generate-sources</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                                <wsdlOptions>
                                    <wsdlOption>

                                            ${basedir}/src/main/resources/wsdl/test/newordernotificationb2b_client_ep.wsdl
                                        </wsdl>
                                        <extraargs>
                                            <extraarg>-p</extraarg>
                                            <extraarg>http://result.general.rt.ru=ru.rt.general.result.mrf.center
                                            </extraarg>
                                            <extraarg>-p</extraarg>
                                            <extraarg>
                                                http://problem.result.general.rt.ru=ru.rt.general.result.mrf.center.problem
                                            </extraarg>
                                        </extraargs>
                                    </wsdlOption>

<wsdl>${basedir}/src/main/resources/wsdl/test/wsAttachment.wsdl</wsdl>
                                    </wsdlOption>-->
                                </wsdlOptions>
                            </configuration>
                            <goals>
                                <goal>wsdl2java</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <properties>
            <cxf-version>3.1.8</cxf-version>
            <mdm.fw.version>3.0</mdm.fw.version>
            <mdm.domain.jar>domain-3.0.jar</mdm.domain.jar>
            <service.login>testLogin</service.login>
            <service.password>testPass</service.password>
        </properties>
    </profile>
</profiles>

1 个答案:

答案 0 :(得分:0)

其中一个解决方案是在Service类中添加BindingProvider并在getRequestContext()方法中设置端点设置:

        BindingProvider bp = (BindingProvider) lkService;
        bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, AppConfig.getConfig().getProperty("lk.service"));