【问题标题】:Configure Apache HttpClient 4.5 as a transport sender in Axis2 stub将 Apache HttpClient 4.5 配置为 Axis2 存根中的传输发送方
【发布时间】:2020-07-22 11:07:35
【问题描述】:

我正在将 Apache Httpclient 3.1 替换为 4.5 版本,我们的应用程序使用的是 AXIS 2 SOAP Web 服务存根,它下面使用的是 HTTPClient 3.1 TransportSender。我需要迁移它以使用 HttpClient 4.5 版本。下面是需要迁移到 HttpClient 4.5 版本的完整代码:

import org.apache.commons.httpclient.protocol.Protocol; // 3.1 version
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; // 3.1 version


final Options clientOptions = stub._getServiceClient().getOptions();
clientOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER, new Protocol("https", new TLSSocketFactory(), 443));




public class TLSSocketFactory extends SSLSocketFactory implements SecureProtocolSocketFactory {
private SSLSocketFactory internalSSLSocketFactory;
public TLSSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
    SSLContext context = SSLContext.getInstance("TLS");
    context.init(null, null, null);
    internalSSLSocketFactory = context.getSocketFactory();
}
@Override
public String[] getDefaultCipherSuites() {
    return internalSSLSocketFactory.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
    return internalSSLSocketFactory.getSupportedCipherSuites();
}
@Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
    return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, host, port, autoClose));
}
@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
    return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
}
@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
    return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port, localHost, localPort));
}

@Override
public Socket createSocket(String s, int i, InetAddress inetAddress, int i1, HttpConnectionParams httpConnectionParams) throws IOException, UnknownHostException, ConnectTimeoutException {
    return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, i, inetAddress, i1));
}

@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
    return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
}
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
    return enableTLSOnSocket(internalSSLSocketFactory.createSocket(address, port, localAddress, localPort));
}
private Socket enableTLSOnSocket(Socket socket) {
    if(socket != null && (socket instanceof SSLSocket)) {
        ((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"});
    }
    return socket;
}

}

我看到了这个 StackOverflow 帖子:How to configure SSL with Axis2 using httpClient4

但在帖子中明确提到它只兼容 httpclient 4.4.1。

Axis2 1.7.0 除了支持 Apache HttpClient 4.x 维护时间更长的 Commons HttpClient 3.x。启用对 HttpClient 4.x,使用 org.apache.axis2.transport.http.impl.httpclient4.HTTPClient4TransportSender 而不是 org.apache.axis2.transport.http.CommonsHTTPTransportSender 在axis2.xml中。请注意,代码是为 HttpClient 编写的 4.2.x 并且应该与 4.3.x 和 4.4.x 一起使用,但与 4.5.x 不兼容。

我们使用的是 HttpClient 4.5,它明确表示它与 4.5.x 不兼容

我真的被困住了,需要帮助来迁移上面的代码以使用 HttpClient 4.5。

提前致谢。

【问题讨论】:

标签: java ssl axis2 apache-httpclient-4.x soap-client


【解决方案1】:

以下 SO Post 中提到的步骤也适用于 HttpClient 4.5.x。

configure SSL with Axis2 using httpClient4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多