bodtx bodtx - 5 months ago 49
Java Question

Using JAX-WS stub even if Apache CXF is in dependency

WS client, it works when I call my WS
when I create my stub, I get an SEIStub impl.

Then here is a new client for another WS in Apache CXF. We put the dependency in our pom, then bad things happen:
When I call my first WS with my JAX-WS stub I get now a

JaxWSClientProxy
, Apache CXF seems to become the default implmentation. and I cannot use my special header function that was done for WSBindingProvider instead of
JaxWsClientProxy


Generation of client with jaxws:

<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>${jaxws.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>fr.xxxx.commons.client.stub.y</packageName>
<sourceDestDir>${ws.java.target}</sourceDestDir>
<extension>true</extension>
<wsdlDirectory>${project.parent.basedir}/src/main/wsdl/v2.1/</wsdlDirectory>
<wsdlFiles>
<wsdlFile>XXXXWebServices_v2.1.wsdl</wsdlFile>
</wsdlFiles>
<xnocompile>false</xnocompile>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
</execution>
</executions>
</plugin>


the JAX-WS instanciation where the error is (on the cast)

xStub = new XWebServicesV21(url, qnameXWebServices);

xGetPort.set(xStub.getAutogenerate());

generateHeader(aApplicationID, aUserId, (WSBindingProvider) xGetPort.get(), xUrl);


How to force JAXWS impl? I use JDK8 and Apache CXF 2.3.11 .

Answer

Sun's jaxws use com.sun.xml.ws.developer.WSBindingProvider, but CXF does not use it. org.apache.cxf.jaxws.JaxWsClientProxy implements javax.xml.ws.BindingProvider

Therefore you can not cast xGetPort.get() to WSBindingProvider. In order to add soap headers with CXF in a similar way that WSBindingProvider.setOutboundHeaders check documentation or use CXF WS-Security support to generate the standard authentication headers for SOAP messages

If you want to use Sun's jaxws, make sure the jars are in the classpath before, or remove cxfjaxws dependencies.