简体   繁体   中英

Eclipse RCP and Apache CXF

I'm trying to use Apache CXF in an Eclipse RCP application. One plugin (X) would provide an OSGI service which uses CXF. Another plugin (Y) would call this service.

The "X" plugin uses the CXF JAR's I downloaded (CXF 2.7.11) which I added to the MANIFEST.MF. When I run my test cases from withint plugin X everything goes fine ie I can call a webservice and get a response.

When I try to run plugin "Y" it sees the OSGI service which I can call. The OSGI service calls the same code from withint project "X" as in the above case, but now it doesnt work. The exception I get is:

com.sun.xml.internal.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy

in this part:

org.apache.cxf.endpoint.Client client = ClientProxy.getClient(myServicePort);

Now when I run the SAME CODE within this plugin (plugin X) it just runs fine.

So I suspect it has something to do with the JAR's and dependencies etc. but Im not sure. I searched for this exception and this comes up when some JAR's are missing from CXF, but added ALL JAR's to the MANIFEST.MF I found in the CXF distribution.

I'm not even sure what classes of CXF I really need, but the test cases seem to run just fine.

Any ideas what went wrong?

I set the client this way:

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(YourClass.class);
factory.setAddress(endpoint);
YourClass port = (YourClass) factory.create(); 
Client client = ClientProxy.getClient(port);

If you have autogenerated the javas you will have the client class with name_name_client.java and name_name12_client.java, and YourClass is name.java (this java defines the WebMethods), so change this, and set your endpoint. Try it and let us know if it works for you.

I usually switch ClassLoader to cxf plugin before creating Service and Port. When port is created I set context class loader to the original one. This approach assures that classloader of cxf plugin is used and correct client class is loaded, so you will not get casting exception.

// to avoid class loader visibility issue
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 
try {
    Thread.currentThread().setContextClassLoader(ProviderImpl.class.getClassLoader());
    MyService ss = new MyService(wsdlURL, SERVICE_NAME);
    MyPort port = ss.getMyPort();
    Client client = ClientProxy.getClient(port);
    ...
} finally {
    Thread.currentThread().setContextClassLoader(classLoader);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM