InternalHttpClient 无法转换为 HttpClient

问题描述 投票:0回答:1

我已经使用 WSDL2Java 命令生成了 axis2 客户端存根并尝试调用第三方 Web 服务。 我在控制台中看到此错误:

java.lang.ClassCastException: class org.apache.http.impl.client.InternalHttpClient cannot be cast to class org.apache.commons.httpclient.HttpClient (org.apache.http.impl.client.InternalHttpClient and org.apache.commons.httpclient.HttpClient are in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @674c583e)
        at org.apache.axis2.transport.http.AbstractHTTPSender.getHttpClient(AbstractHTTPSender.java:529)
        at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:157)
        at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
        at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
        at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
        at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
        at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
        at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)

我们正在像这样设置 CACHED_HTTP_CLIENT 属性(放置两行):

     MyStub stub = new MyStub() ; 

        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, customHttpClient);
            stub._getServiceClient().getServiceContext()
                    .setProperty(HTTPConstants.CACHED_HTTP_CLIENT, customHttpClient);

但是不知何故 AbstractHttpSender.getHttpClient 无法获取我们的 HttpCLient。 这是 AbstractHttpSender 类中抛出 ClassCastException 的行:-

  HttpClient httpClient = (HttpClient) msgContext.getProperty(
                HTTPConstants.CACHED_HTTP_CLIENT);

我是否需要在 MyStub() 构造函数中传递任何内容以确保 HttpClient 在 MessageContext 中正确设置?

提前致谢。

编辑:我可以看到这个问题。上面的 HttpClient 是 org.apache.commons.httpclient.HttpClient 而不是 org.apache.http.client.HttpClient (正如我之前所想的那样)。 现在我该如何解决呢?有没有办法让 axis2 客户端存根不转到 AbstractHttpSender 并转到使用 org.apache.http.client.HttpClient 的类?

soap apache-axis
1个回答
0
投票

你有解决办法吗,我们也面临着同样的问题。

谢谢, 奇拉格

© www.soinside.com 2019 - 2024. All rights reserved.