我正面临SSL异常文件Keystore.jks只在一个环境中找不到环境其他环境正常工作我们有4个环境。
我使用DefaultHttpClient调用rest http url。我已经在java中开发了这个并将jar插入我们的IBM BPM流程。
DefaultHttpClient httpclient = new DefaultHttpClient();
List<String> authpref = new ArrayList<String>();
authpref.add(AuthPolicy.NTLM);
NTCredentials ntlm =new NTCredentials(userName, password, "", "XXXX");
httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
// httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
// UsernamePasswordCredentials creds = new UsernamePasswordCredentials(userName,password);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, ntlm);
String finalURL = baseURL +folderpath;
finalURL = finalURL.replaceAll(" ", "%20");
System.out.println("final URL --->"+finalURL);
HttpGet request2 = new HttpGet(finalURL); // target
request2.addHeader("Accept", "application/json;odata=verbose");
HttpResponse response2 = null;
response2 = httpclient.execute(request2);
我也尝试过使用自定义http客户端。
public class CustomHTTPClient
{
public DefaultHttpClient getNewHttpClient()
{
try
{
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "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);
return new DefaultHttpClient(ccm, params);
}
catch (Exception e) {}
return new DefaultHttpClient();
}
}
public class MySSLSocketFactory
extends org.apache.http.conn.ssl.SSLSocketFactory
{
SSLContext sslContext = SSLContext.getInstance("TLS");
public MySSLSocketFactory(KeyStore truststore)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException
{
super(truststore);
TrustManager tm = new X509TrustManager()
{
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException
{}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException
{}
public X509Certificate[] getAcceptedIssuers()
{
return null;
}
};
this.sslContext.init(null, new TrustManager[] { tm }, null);
}
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
throws IOException, UnknownHostException
{
return this.sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
public Socket createSocket()
throws IOException
{
return this.sslContext.getSocketFactory().createSocket();
}
}
这是一个休息的http网址而不是https。 任何人都可以提出建议