如何在 Glassfish 上选择 CXF 而不是 Metro

发布于 2024-08-18 00:50:34 字数 786 浏览 9 评论 0原文

我在运行我的程序时遇到以下问题(由其他人报告) Glassfish 下的企业应用程序。在 Jetty 下工作正常。

javax/xml/ws/spi/Provider 提到创建 META-INF/services/javax.xml.ws.spi.Provider 资源,但是 CXF 已经提供了该资源,并且创建额外的资源文件并不能解决 Glassfish 下的此问题。

有谁知道如何确保 CXF 在 GlassFish 下被拾取?
(我正在使用具有 CXF 依赖项 2.2.5 的 Maven 多模块项目)

谢谢!
Tim


编辑 #1

现在跳过这个问题,只使用 Metro,但我真的很想知道如何使用 CXF(如果有人有任何指示的话)。如果没有任何效果,我可能不得不切换Web 应用程序容器(或查看 Metro 来满足我的要求)


编辑 #2

一些解决方案通过添加 详细说明了对战争的修复 到 sun-web.xml 文件。但是,这不适用于非战争应用程序。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

肩上的翅膀 2024-08-25 00:50:34

添加 sun-web.xml 并将 delegate=false 设置为类加载器:

<?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> 

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> 
小忆控 2024-08-25 00:50:34

Metro(Glassfish 的 JAX-WS 实现)jar 可能包含在 Glassfish 中,您可以将它们从类路径中排除吗?由于您使用的是 Maven,因此您应该分析 glassfish 依赖项并使用 Metro jar 的排除项。


看来您需要在 Metro jar 之前将 CXF jar 放在应用程序类路径上。您可能无法修改系统类加载器/类路径,但可以更改 Thread.currentThread().getContextClassLoader() 以便它首先加载 CXF。您还可以修改 Glassfish 中的类路径设置

查看 javax.xml.ws.spi.FactoryFinder#find() 查看提供程序实际是如何加载的

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

猫性小仙女 2024-08-25 00:50:34

我想出的(并且不满意的)解决方案是使用 JaxWsProxyFactoryBean。 此处有一个示例。

这是你必须做的事情的要点:

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);

}

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

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);

}
狼亦尘 2024-08-25 00:50:34

对于 SpringBoot 应用程序,我需要添加以下文件:

src/main/resources/META-INF/services/javax.xml.ws.spi.Provider

内容为:

org.apache.cxf。 jaxws.spi.ProviderImpl

For SpringBoot application I needed to add following file:

src/main/resources/META-INF/services/javax.xml.ws.spi.Provider

with content:

org.apache.cxf.jaxws.spi.ProviderImpl

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文