CXF - ClassCastException(SEIStub/ClientProxy)

发布于 2024-11-01 19:11:37 字数 2408 浏览 0 评论 0 原文

我正在尝试构建一个客户端 jar 文件来访问网络服务。我将 jar 包含在进行客户端 Web 服务调用的 servlet/war 中。我收到以下错误:

INFO: 2011 Apr 14 14:57:32,780 MDT [http-thread-pool-8181(4)] ERROR     my.package.ClientServlet - Caught 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.package.Client.<init>(Client.java:54)
at my.package.ClientServlet.testService(TestServlet.java:118)

我遇到了这篇文章 http://yaytay.wordpress.com/2010/03/06/lsned-29-persuading-jdk-6-to-use-cxf-classes-rather-than-its-own-avoiding- seistub/ 表示要解决问题,您需要将 cxf-rt-frontend-jaxws 包含为依赖项,我就是这样做的。所以,这不是我的问题/解决方案。

我的客户端 jar pom 具有以下依赖项:

<properties>
    <cxf.version>2.3.3</cxf.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <version>${cxf.version}</version>
    </dependency>
</dependencies>

servlet war 在其 lib 中包含以下内容:

asm-3.3.jar
bcprov-jdk15-1.45.jar
commons-logging-1.1.1.jar
cxf-api-2.3.3.jar
cxf-common-schemas-2.3.3.jar
cxf-common-utilities-2.3.3.jar
cxf-rt-bindings-soap-2.3.3.jar
cxf-rt-bindings-xml-2.3.3.jar
cxf-rt-core-2.3.3.jar
cxf-rt-databinding-jaxb-2.3.3.jar
cxf-rt-frontend-jaxws-2.3.3.jar
cxf-rt-frontend-simple-2.3.3.jar
cxf-rt-ws-addr-2.3.3.jar
cxf-rt-ws-security-2.3.3.jar
cxf-tools-common-2.3.3.jar
geronimo-javamail_1.4_spec-1.7.1.jar
jaxb-impl-2.1.13.jar
log4j-1.2.14.jar
neethi-2.0.4.jar
my-client-cxf-1.0.jar
serializer-2.7.1.jar
slf4j-api-1.4.2.jar
slf4j-log4j12-1.4.2.jar
stax2-api-3.0.2.jar
woodstox-core-asl-4.0.8.jar
wsdl4j-1.6.2.jar
wss4j-1.5.11.jar
xalan-2.7.1.jar
xml-resolver-1.2.jar
XmlSchema-1.4.7.jar
xmlsec-1.4.4.jar

我还阅读了一些讨论 javax.xml.ws.spi.Provider 文件的帖子,但还没有'无法找到任何详细说明其应命名、包含和放置内容的参考资料。

有人能指出我正确的方向吗?

I'm trying to build a client jar file to access a webservice. I'm including the jar in a servlet/war that makes the client webservice calls. I'm getting the following error:

INFO: 2011 Apr 14 14:57:32,780 MDT [http-thread-pool-8181(4)] ERROR     my.package.ClientServlet - Caught 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.package.Client.<init>(Client.java:54)
at my.package.ClientServlet.testService(TestServlet.java:118)

I came across this post http://yaytay.wordpress.com/2010/03/06/lsned-29-persuading-jdk-6-to-use-cxf-classes-rather-than-its-own-avoiding-seistub/ which says to fix the problem you need to include cxf-rt-frontend-jaxws as a dependency, which I do. So, that isn't the problem/solution in my case.

My client jar pom has these dependencies:

<properties>
    <cxf.version>2.3.3</cxf.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <version>${cxf.version}</version>
    </dependency>
</dependencies>

The servlet war contains the following in its lib:

asm-3.3.jar
bcprov-jdk15-1.45.jar
commons-logging-1.1.1.jar
cxf-api-2.3.3.jar
cxf-common-schemas-2.3.3.jar
cxf-common-utilities-2.3.3.jar
cxf-rt-bindings-soap-2.3.3.jar
cxf-rt-bindings-xml-2.3.3.jar
cxf-rt-core-2.3.3.jar
cxf-rt-databinding-jaxb-2.3.3.jar
cxf-rt-frontend-jaxws-2.3.3.jar
cxf-rt-frontend-simple-2.3.3.jar
cxf-rt-ws-addr-2.3.3.jar
cxf-rt-ws-security-2.3.3.jar
cxf-tools-common-2.3.3.jar
geronimo-javamail_1.4_spec-1.7.1.jar
jaxb-impl-2.1.13.jar
log4j-1.2.14.jar
neethi-2.0.4.jar
my-client-cxf-1.0.jar
serializer-2.7.1.jar
slf4j-api-1.4.2.jar
slf4j-log4j12-1.4.2.jar
stax2-api-3.0.2.jar
woodstox-core-asl-4.0.8.jar
wsdl4j-1.6.2.jar
wss4j-1.5.11.jar
xalan-2.7.1.jar
xml-resolver-1.2.jar
XmlSchema-1.4.7.jar
xmlsec-1.4.4.jar

I've also read some posts that talk about a javax.xml.ws.spi.Provider file, but haven't been able to find any references that detail what it should be named, contain and placed.

Can anybody point me in the right direction?

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

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

发布评论

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

评论(7

暮年 2024-11-08 19:11:37

解决方案是在 war WEB-INF 中包含 sun-web.xml(或 glassfish-web.xml)文件。请参阅如何在 Glassfish 上选择 CXF 而不是 Metro

编辑

glassfish-web.xml 的内容:

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

The solution was to include a sun-web.xml (or glassfish-web.xml) file in the war WEB-INF. See How to pick CXF over Metro on Glassfish

EDIT

Contents of glassfish-web.xml:

<?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> 
触ぅ动初心 2024-11-08 19:11:37

从构建路径中删除 JAX-WS 库,这样可以解决我的问题,即 (ClassCastException) SEIStub 到 ClientProxy。

Remove JAX-WS Libraries from buildpath, so this can resolves my problem that is (ClassCastException) SEIStub to ClientProxy.

椒妓 2024-11-08 19:11:37

如果所有其他方法都失败,您可以使用反射来覆盖服务的委托。

        QName qName = new QName(wsTargetNamespace, wsName);
        service = new YourServiceScheduler(loc, qName);
        Field delegateField = Service.class.getDeclaredField("delegate");
        delegateField.setAccessible(true);
        ServiceDelegate previousDelegate = (ServiceDelegate)delegateField.get(service);
        if(!previousDelegate.getClass().getName().contains("cxf")) {
            ServiceDelegate serviceDelegate = ((Provider) Class.forName("org.apache.cxf.jaxws.spi.ProviderImpl").newInstance())
                .createServiceDelegate(loc, qName, service.getClass());
            log.info("The " + getClass().getSimpleName() + " delegate is changed from " + "[" + previousDelegate + "] to [" +
                serviceDelegate +
                "]");
            delegateField.set(service, serviceDelegate);
        }
        port = service.getYourServiceSoap();

If all else fails, you can use reflection to override the delegate of the service.

        QName qName = new QName(wsTargetNamespace, wsName);
        service = new YourServiceScheduler(loc, qName);
        Field delegateField = Service.class.getDeclaredField("delegate");
        delegateField.setAccessible(true);
        ServiceDelegate previousDelegate = (ServiceDelegate)delegateField.get(service);
        if(!previousDelegate.getClass().getName().contains("cxf")) {
            ServiceDelegate serviceDelegate = ((Provider) Class.forName("org.apache.cxf.jaxws.spi.ProviderImpl").newInstance())
                .createServiceDelegate(loc, qName, service.getClass());
            log.info("The " + getClass().getSimpleName() + " delegate is changed from " + "[" + previousDelegate + "] to [" +
                serviceDelegate +
                "]");
            delegateField.set(service, serviceDelegate);
        }
        port = service.getYourServiceSoap();
离鸿 2024-11-08 19:11:37

我刚刚在将应用程序升级到 Java 11 时遇到了这个问题。最后发现我们有一些奇怪的依赖设置和两个“冲突”的库:

cxf-rt-frontend-simple 与 cxf-rt-frontend-jaxws

所以我删除了所有简单的依赖项并用 jaxws 替换它们,现在一切都很好 ->

<dependency>
 <groupId>org.apache.cxf</groupId>
 <artifactId>cxf-rt-frontend-jaxws</artifactId>
 <version>${cxf.version}</version>
</dependency>

归功于这篇博文 -> http://www.littlebigextra.com/exception-how-to-resolve-com-sun-xml-internal-ws-client-sei-seistub-cannot -be-cast-to-org-apache-cxf-frontend-clientproxy/

为了进一步阅读,我推荐这个关于 Java > 8 迁移的线程:用 Java EE API 替换已弃用的 JPMS 模块

I just had this issue while upgrading our application to Java 11. In the end it turned out that we had some weired dependency setup and two "conflicting" libs:

cxf-rt-frontend-simple vs. cxf-rt-frontend-jaxws

So I removed all the simple dependencies and replaced them with jaxws and now all is fine ->

<dependency>
 <groupId>org.apache.cxf</groupId>
 <artifactId>cxf-rt-frontend-jaxws</artifactId>
 <version>${cxf.version}</version>
</dependency>

Credits to this blog post -> http://www.littlebigextra.com/exception-how-to-resolve-com-sun-xml-internal-ws-client-sei-seistub-cannot-be-cast-to-org-apache-cxf-frontend-clientproxy/

For further reading I recommend this thread on Java >8 migrations: Replacements for deprecated JPMS modules with Java EE APIs

那请放手 2024-11-08 19:11:37

我过去尝试过 CXF,但遇到过像这样的奇怪异常。我假设您已经尝试过 CXF 邮件列表

我会尝试慢慢来:从 CFX 发行版的一个工作示例开始,一次进行一项更改,直到解决问题。

I tried CXF in the past and came across strange exceptions like this one. I assume you already tried CXF mailing list.

I would try to go slow: start with a working example from the CFX distribution and make one change at a time until you get to the problem.

叫思念不要吵 2024-11-08 19:11:37

不使用构造函数

Cebbcws ws = new Cebbcws();
CebbcwsPortType wsport = ws.getCebbcwsPort();

使用 JaxWsProxyFactoryBean 调用服务

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getClientFactoryBean().getServiceFactory().setWsdlURL(Cebbcws.WSDL_LOCATION);
factory.setServiceName(Cebbcws.SERVICE);
factory.setEndpointName(Cebbcws.CebbcwsPort);
CebbcwsPortType wsport = factory.create(CebbcwsPortType.class);

来源:https://stackoverflow.com/a/39251733/ 2686972

Instead of using constructor

Cebbcws ws = new Cebbcws();
CebbcwsPortType wsport = ws.getCebbcwsPort();

Invoke the service using JaxWsProxyFactoryBean

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getClientFactoryBean().getServiceFactory().setWsdlURL(Cebbcws.WSDL_LOCATION);
factory.setServiceName(Cebbcws.SERVICE);
factory.setEndpointName(Cebbcws.CebbcwsPort);
CebbcwsPortType wsport = factory.create(CebbcwsPortType.class);

Source: https://stackoverflow.com/a/39251733/2686972

独夜无伴 2024-11-08 19:11:37

使用 OpenJdk 11 迁移到 sbt 1.3.6 时也会发生此错误。

但实际上我使用的是:

"com.sun.xml.ws" % "jaxws-ri" % "xxx"

并替换为 apache 的 jaxws 修复了错误:

"org.apache.cxf" % "cxf-rt-frontend-jaxrs" % "3.3.0"

This error also happened while migrating to sbt 1.3.6 with OpenJdk 11.

But acually I was using:

"com.sun.xml.ws" % "jaxws-ri" % "xxx"

and replacing with apache's jaxws fixes the error:

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