我有以下例外情况
org.apache.olingo.client.api.http.HttpClientException: java.net.SocketException: Software caused connection abort: recv failed
网址=> https://tp-test.itgr.net:4433/mytest/V4/testCorporate.svc
使用上述Postman工具,URL可以很好地进行get操作,但是相同的URL可以使用DefaultHttpClient提供上述异常。
public DefaultHttpClient create(HttpMethod method, URI uri)
{
Logger.logMessage(LogLevel.LEVEL_DEBUG, ODATAstepAdaptor.ODATA_CLIENT_LOG_MODULE, "In side:create(HttpMethod method, URI uri)");
DefaultHttpClient client=null;
String[] tlsProtocols=null;
String[] cipherSuites=null;
try {
String filepath=System.getProperty("com.test.ilt.home");
Logger.logMessage(LogLevel.LEVEL_DEBUG, ODATAstepAdaptor.ODATA_CLIENT_LOG_MODULE, "FilePath=>"+filepath+"/java/conf/tlsProtocols.dat");
BufferedReader in = new BufferedReader(new FileReader(filepath+"/java/conf/tlsProtocols.dat"));
String str=null;
ArrayList<String> lines = new ArrayList<String>();
while((str = in.readLine()) != null){
lines.add(str);
}
in.close();
tlsProtocols = lines.toArray(new String[lines.size()]);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
//SSLSocketFactory sf = new SSLSocketFactory(sslContext);
SSLSocketFactory sf = new CustomizedSSLSocketFactory(sslContext,null,tlsProtocols,cipherSuites);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
client=new DefaultHttpClient(ccm, params);
client.getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(this.username, this.password));
} catch (Exception e) {
Logger.logMessage(LogLevel.LEVEL_ERROR, ODATAstepAdaptor.ODATA_CLIENT_LOG_MODULE,e.getMessage());
}
return client;
}