Webservice client in client scope OK but Exception in gateway scope

I develop a module which use apache.cxf for a client webservices SOAP 1.2 (with authentification)

When I create the client connexion in the module client scope and use it, everything is OK.

public final static QName SERVICE_NAME = new QName("http://www.onvif.org/ver20/ptz/wsdl", "PTZService");
public final static QName PORT_NAME = new QName("http://www.onvif.org/ver20/ptz/wsdl", "PTZPort");

...
String user = "ONVIFClient1";
String password = "ONVIFClient1";
String endpointAddress = "http://10.60.21.10:580/onvif/ptz_service";
service = Service.create(SERVICE_NAME);
service.addPort(PORT_NAME, SOAPBinding.SOAP12HTTP_BINDING, endpointAddress);
port = service.getPort(PTZ.class);
client = ClientProxy.getClient(port);  <======== EXCEPTION
endpoint = client.getEndpoint();
...
some code to add authentification in SOAP envelop

When I try to create the client connexion in the module gateway scope, with the same code, I have the following Exception :
(Note : both client and gateway are launched on the same machine)

java.lang.ClassCastException: com.sun.xml.internal.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy
at org.apache.cxf.frontend.ClientProxy.getClient(ClientProxy.java:127)

Both client and gateway .pom have the dependency to common.pom which contain the right dependency to apache-cxf :

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-security</artifactId>
            <version>3.2.1</version>
        </dependency>

Any Idea about the source of this exception ???
I doesn’t figure out why the behaviour is different in the client and the gateway scope.

I’d guess the behavior is different because the ClassLoader structure is different. In the client all code runs under a single ClassLoader. In the gateway, each module gets its own ClassLoader.

You appear to be generating a dynamic client from a WSDL at runtime, which likely entails some code generation and might be the cause of your issues. This page mentions something about generated classes being created under a new ClassLoader.

I don’t know enough about CXF to really help any further.

Thanks @Kevin.Herron for the clarification about classloader which make sense for the different behavior between client and gateway scope.

I solve my problem by creating the webservice client endpoint with

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(PTZ.class);
factory.setAddress("http://10.60.21.10:580/onvif/ptz_service");
port = (PTZ) factory.create();
client = ClientProxy.getClient(port);
endpoint = client.getEndpoint();

I didn’t khow exactly why, but it works.