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
Axis2 1.7.0除了不支持Apache HttpClient 4.x维护时间更长的Commons HttpClient3.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不兼容
提前感谢。
我正在将Apache Httpclient 3.1替换为4.5版本,我们的应用程序使用的是AXIS 2 SOAP Web服务存根,其下面使用的是HTTPClient 3.1 TransportSender。我需要迁移...