CXF - ClassCastException(SEIStub / ClientProxy)

时间:2011-04-14 22:13:46

标签: java cxf classcastexception

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

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文件的帖子,但未能找到任何详细说明应该命名,包含和放置的文章。

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

7 个答案:

答案 0 :(得分:7)

解决方案是在战争WEB-INF中包含sun-web.xml(或glassfish-web.xml)文件。见How to pick CXF over Metro on Glassfish

修改

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> 

答案 1 :(得分:2)

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

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

答案 2 :(得分:1)

我过去尝试过CXF,遇到过像这样的奇怪例外。我假设您已经尝试CXF mailing list

我会试着放慢速度:从CFX发行版的一个工作示例开始,一次进行一次更改,直到遇到问题为止。

答案 3 :(得分:1)

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

答案 4 :(得分:0)

将应用程序升级到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迁移中使用此线程:Replacements for deprecated JPMS modules with Java EE APIs

答案 5 :(得分:0)

代替使用构造函数

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

答案 6 :(得分:0)

在使用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"