我正在努力纠正一些必须能够在Java 1.4应用服务器中运行的旧Java应用程序代码的问题。
该应用程序正在调用SOAP WebService,并且必须传递客户端证书。该应用程序正在与许多其他应用程序共享服务器,因此我尝试使用自定义密钥管理器进行连接。下面的代码适用于较新版本的Java,但“setDefault”在1.6中引入。当我尝试编译时,它导致无法找到符号错误。
javax.net.ssl.SSLContext context = javax.net.ssl.SSLContext.getInstance("SSL");
context.init(getKeyManagers(), (TrustManager[]) getKeyManagers(), null);
SSLContext.setDefault(context);
那么,在Java 1.4中,什么相当于“SSLContext.setDefault(context);”?
谢谢, 道格
以下是我正在尝试做的其他代码:
private org.apache.axis.message.SOAPEnvelope SendSOAP(String SOAPaction,
String EndPointURL, String SOAPmessage) {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
// TODO Auto-generated method stub
return null;
}
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
// TODO Auto-generated method stub
}
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
// TODO Auto-generated method stub
}
} };
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(getKeyManagers(), trustAllCerts, null);
SSLContext.setDefault(context);
} catch (Exception e) {
logger.fatal(e.toString());
}
org.apache.axis.message.SOAPEnvelope resp = null;
try {
InputStream input = new ByteArrayInputStream(SOAPmessage.getBytes());
org.apache.axis.client.Service service = new org.apache.axis.client.Service();
logger.debug(SOAPmessage);
Call call = (Call) service.createCall();
call.setSOAPActionURI(SOAPaction);
call.setTargetEndpointAddress(new URL(EndPointURL));
SOAPEnvelope env = new SOAPEnvelope(input);
resp = call.invoke(env);
} catch (Exception e) {
e.printStackTrace();
logger.fatal("Exception from send soap: " + e.toString());
e.printStackTrace(System.out);
}
return resp;
}