本文介绍了Glassfish 3.1-在同一场战争中部署的CXF和Jersey客户吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向Glassfish 3.1.1部署战争,该战争利用CXF Web服务客户端库和Jersey网络服务客户端库.为了使Glassfish使用CXF而不是Metro作为JAX-WS实现,我包括了一个glassfish-web.xml文件,其内容如下:

I am trying to deploy a war to Glassfish 3.1.1 that makes use of a CXF webservice client library and a Jersey webservice client library. In order to get Glassfish to use CXF instead of Metro as the JAX-WS implementation, I am including a glassfish-web.xml file with the following contents:

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

<glassfish-web-app>
    <!-- Need this to tell Glassfish not to load the JAX-WS RI classes so it will 
        use the CXF ones instead -->
    <class-loader delegate="false" />
</glassfish-web-app> 

这会对我的Jersey客户造成不良影响:

This has the undesirable effect of causing problems for my Jersey client:

2011 Oct 19 15:04:16,994 MDT [http-thread-pool-80(3)] ERROR my.company.MyServlet - Error testing JerseyClient
java.lang.NoSuchMethodError: com.sun.jersey.core.spi.component.ProviderServices.<init>(Ljava/lang/Class;Lcom/sun/jersey/core/spi/component/ProviderFactory;Ljava/util/Set;Ljava/util/Set;)V
        at com.sun.jersey.api.client.Client.init(Client.java:242)
        at com.sun.jersey.api.client.Client.access$000(Client.java:118)
        at com.sun.jersey.api.client.Client$1.f(Client.java:191)
        at com.sun.jersey.api.client.Client$1.f(Client.java:187)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
        at com.sun.jersey.api.client.Client.<init>(Client.java:187)
        at com.sun.jersey.api.client.Client.<init>(Client.java:170)
        at com.sun.jersey.api.client.Client.create(Client.java:679)
        at my.company.MyJerseyClient.<init>(MyJerseyClient.java:93)

由于战争中包括了Jersey图书馆(并且Glassfish预计不会提供),所以我不明白.

Since the Jersey libraries are included in the war (and not expected to be provided in Glassfish), I don't understand this.

如果我不包括glassfish-web.xml文件,则Jersey客户端可以正常工作,但在CXF客户端上出现此错误:

If I don't include the glassfish-web.xml file, the Jersey client works fine, but I get this error on the CXF client:

2011-10-19T15:00:53.993-0600|WARNING|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=32;_ThreadName=Thread-2;|StandardWrapperValve[my-servlet]: PWC1406: Servlet.service() for servlet my-servlet threw exception
java.lang.ClassCastException: com.sun.xml.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy
        at org.apache.cxf.frontend.ClientProxy.getClient(ClientProxy.java:93)
        at my.company.MyCXFClient.<init>(MyCXFClient.java:53)

是否可以让这两个库在同一场战争中进行部署(和工作)?

Is it possible to get these two libraries to deploy (and work) in the same war?

推荐答案

这是不可能的.因为客户端部分依赖jax-rs api,并且除非使用单独的类加载器将它们完全隔离,否则一次战争不能使用两种不同的jax-rs实现,因为jax-rs api本身指向实现(和不能指向某些工厂对象的两个实现.

It is not possible. Because the client part depends on the jax-rs api and you can't have two different jax-rs implementations used by one war unless you completely isolate them with separate class loaders, as the jax-rs api itself points to an implementation (and can't point to two implementations) for some factory objects.

更新:糟糕,我看到您正在将一个用于SOAP,将另一个用于REST.那可能行得通,但我不确定.尝试执行以下操作:

UPDATE: Oops, I see you are using one for SOAP and the other for REST. That may work, but I am not sure. Try to do the following:

  1. 确保在您的war文件中也包括jersey-core.jar
  2. 按照用war文件覆盖Jersey的说明,在GF中设置JVM属性.泽西岛用户指南的章节
  1. Make sure you include jersey-core.jar in your war file as well
  2. Set the JVM property in GF as described in Overriding Jersey with war files chapter of Jersey user guide

这篇关于Glassfish 3.1-在同一场战争中部署的CXF和Jersey客户吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 11:38