所以我有一个非常简单的设置,我在我的Web应用程序中有一个wsdl,我使用这个wsdl生成类,然后我实例化并用于调用远程服务器上存在的方法,该方法使用与我所拥有的完全相同的wsdl我的网络应用程序。
直到不久前,我从CXF 2.6.8升级到CXF 3.0.4(更准确地说是JBoss Fuse 6.2.1在JBoss 6.4.0 EAP上运行的版本)。这是我的pom文件的依赖项部分(请注意,我有一个用于版本管理的根pom,默认情况下提供所有依赖项):
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-all-6.0</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cdi</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
以下是wsdl2java maven插件的源代码,也来自pom:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<configuration>
<fork>once</fork>
</configuration>
<executions>
<execution>
<id>Step one</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources/wsdl/pg-sapc</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}/src/main/resources/wsdl/Generic/MyWsdl.wsdl</wsdl>
<wsdlLocation>classpath:wsdl/Generic/MyWsdl.wsdl</wsdlLocation>
<packagenames>
<packagename>my.package</packagename>
</packagenames>
<extraargs>
<extraarg>-exsh</extraarg>
<extraarg>true</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
...
这是使用生成文件的代码,请注意我在调用方法之前将端点更改为远程服务器端点:
private static final GeneratedSource GENERATEDSOURCE = new GeneratedSource();
...
Service destination = GENERATEDSOURCE.getServiceport(); //EXCEPTION TRIGGERED ON THIS LINE!!!
BindingProvider prov = (BindingProvider)destination;
prov.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
try {
destination.methodCall(inputData);
} catch (WebServiceException ex) {
...
我在上面的代码中标记了抛出异常的行。堆栈跟踪是:
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Service class my.package.protocol.session.SessionControl does not implement the logout method.
at org.apache.cxf.jaxws.JAXWSMethodDispatcher.bind(JAXWSMethodDispatcher.java:69) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.bindOperation(JaxWsServiceFactoryBean.java:294) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.initializeWSDLOperation(JaxWsServiceFactoryBean.java:267) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeWSDLOperations(ReflectionServiceFactoryBean.java:665) [cxf-rt-wsdl-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.initializeWSDLOperations(JaxWsServiceFactoryBean.java:303) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:415) [cxf-rt-wsdl-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:525) [cxf-rt-wsdl-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:261) [cxf-rt-wsdl-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102) [cxf-rt-frontend-simple-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91) [cxf-rt-frontend-simple-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157) [cxf-rt-frontend-simple-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.jaxws.ServiceImpl.createPort(ServiceImpl.java:493) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:359) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
... 211 more
Caused by: java.lang.NoSuchMethodException: my.package.protocol.session.SessionControl.logout(my.package.protocol.session.Logout, javax.xml.ws.Holder)
at java.lang.Class.getMethod(Class.java:1670) [rt.jar:1.7.0_71]
at org.apache.cxf.jaxws.JAXWSMethodDispatcher.getImplementationMethod(JAXWSMethodDispatcher.java:89) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
at org.apache.cxf.jaxws.JAXWSMethodDispatcher.bind(JAXWSMethodDispatcher.java:56) [cxf-rt-frontend-jaxws-3.0.4.redhat-621084.jar:3.0.4.redhat-621084]
... 225 more
我非常感谢任何关于我做错事的线索,谢谢!