How to pick CXF over Metro on Glassfish

佐手、 提交于 2019-12-21 04:42:35

问题


I'm having the following problem (reported there by someone else) when running my enterprise application under Glassfish. Under Jetty it works fine.

javax/xml/ws/spi/Provider mentions creating a META-INF/services/javax.xml.ws.spi.Provider resource, but this is already supplied with CXF and creating an additional resource file does not solve this problem under Glassfish.

Does anyone know how to ensure that CXF is picked up under GlassFish?
(I'm using a Maven Multi-modules project with CXF dependency 2.2.5)

Thanks!
Tim


EDIT #1

Skipping the problem for now and just working with Metro, but I'd really like to know how to use CXF instead if anyone has any pointers.. If nothing works I might have to switch web application container (or look into Metro to fill my requirements)


EDIT #2

Some of the solutions detail the fix for war's by adding <class-loader delegate="false"/> to the sun-web.xml file. However, this does not work for non-war ee apps.


回答1:


Add a sun-web.xml and set delegate=false to the class-loader:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE sun-web-app PUBLIC '-//Sun Microsystems, Inc.//DTD 
Application Server 9.0 Servlet 2.5//EN' 
'http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd'> 
<sun-web-app> 
    <class-loader delegate="false"/> 
</sun-web-app> 



回答2:


The Metro (Glassfish's JAX-WS implementation) jars are probably being included with Glassfish, can you exclude them from the classpath? Since you're using maven, you should analyze the glassfish dependencies and using an exclusion for the metro jars.


It seems that you need to have the CXF jars on the applications classpath before the Metro jars. You probably can't modify the system classloader/classpath but you can change the Thread.currentThread().getContextClassLoader() such that it loads CXF first. There also might a classpath settings in Glassfish you can modify

Check out the source for javax.xml.ws.spi.FactoryFinder#find() to see how the provider is actually loaded




回答3:


The solution I came up with (and am unsatisfied with) is to use JaxWsProxyFactoryBean. There is an example [here].1.

This is the jist of what you have to do:

public static void main(String args[]) throws Exception {

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

    // I didn't need these next 2 calls, but I doubt they hurt
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());

    factory.setServiceClass(AuthService.class);
    factory.setAddress("http://localhost:7001/authManager/services/cxfAuth");

    // 'AuthService' is whatever your interface type is
    AuthService client = (AuthService) factory.create();

    Employee employee = client.getEmployee("0223938");
    System.out.println("Server said: " + employee.getLastName() + ", " + employee.getFirstName());
    System.exit(0);

}


来源:https://stackoverflow.com/questions/2064068/how-to-pick-cxf-over-metro-on-glassfish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!