这是我第一次使用CXF。我正在编写一个客户端来使用Web服务。我的要求是编写一个客户端,并添加一个日志拦截器。很遗憾,服务提供商未通过WSDL
提供URL?wsdl
。我从服务提供商处获得了所有必需的WSDLs and XSDs
zip文件,我必须使用此版本的文件来构建我的客户端。到目前为止,我已经关注了几个例子并且阅读了很多关于CXF
个客户端的内容。似乎以下方法让客户端运行是正确的。但是,它在这里不起作用。我需要帮助解决这个问题。
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(<SERVICE_CLASS_NAME>.class); <<I have the ".class for service here>>
QName SERVICE_NAME = new QName(<<namespaceURI>>, <<ServiceName>>);
factory.setServiceName(SERVICE_NAME);
factory.setAddress(SERVICE_URL);
factory.setWsdlLocation(localWSDLAddress);
portType = factory.create();
这是一个独立的客户端程序,我尝试了几种jar文件组合来运行这个程序(详情如下)。该程序不会超出上面代码段中提到的最后一行。异常跟踪如下。
Exception in thread "main" java.lang.AbstractMethodError: org.apache.cxf.binding.soap.SoapTransportFactory.createEndpointInfo(Lorg/apache/cxf/service/model/ServiceInfo;Lorg/apache/cxf/service/model/BindingInfo;Ljava/util/List;)Lorg/apache/cxf/service/model/EndpointInfo;
at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildEndpoint(WSDLServiceBuilder.java:459)
at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:356)
at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:203)
at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:175)
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:408)
用于运行包含上述代码段的客户端程序的命令行。我通过反复试验到达了这个jar文件列表。
java -cp %CLASSPATH%;.;./cxf-core-3.0.2.jar;./cxf-rt-bindings-soap-3.0.2.jar;./cxf-rt-bindings-xml-3.0.2.jar;./cxf-rt-core-2.7.11.jar;./cxf-rt-frontend-simple-3.0.2.jar;./cxf-rt-ws-addr-3.0.2.jar;./cxf-rt-ws-policy-3.0.2.jar;./neethi-3.0.2.jar;./wsdl4j-1.6.3.jar;./xmlschema-core-2.1.0.jar;./cxf-rt-frontend-jaxws-3.0.2.jar;./cxf-bundle-3.0.0-milestone2.jar;./cxf-bundle-jaxrs-2.7.12.jar;./woodstox-core-asl-4.4.1.jar;./stax2-api-3.1.4.jar;./cxf-rt-databinding-jaxb-3.0.2.jar;./cxf-common-utilities-2.5.11.jar;./cxf-rt-transports-http-3.0.2.jar javaclass
答案 0 :(得分:0)
将WSDL作为项目的一部分包含在内,并生成客户端/服务器的java代码。
使用cxf maven插件生成代码:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/ws/booking-v1.wsdl</wsdl>
<wsdlLocation>classpath:ws/booking-v1.wsdl</wsdlLocation>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/bindings.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>