CXF - ClassCastException (SEIStub/ClientProxy)

2022-09-03 14:00:06

我正在尝试构建一个客户端jar文件来访问Web服务。我将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

任何人都可以给我指出正确的方向吗?


答案 1

解决方案是在战争WEB-INF中包含一个太阳网.xml(或玻璃鱼网.xml)文件。了解如何在玻璃鱼上选择CXF而不是Metro

编辑

玻璃鱼网的内容.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> 

答案 2

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


推荐