强制AXIS客户端使用TLS [英] Force AXIS client to use TLS
本文介绍了强制AXIS客户端使用TLS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何强制SOAP Axis客户端使用TLS而不是SSL?我有这段代码:
How can I force a SOAP Axis client to use TLS instead of SSL? I have this code:
SOAPMessage soapMessage = MessageFactory.newInstance()
.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
javax.xml.soap.SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationStyle(org.apache.axis.constants.Style.DOCUMENT);
call.setSOAPActionURI("urn:processDocument");
call.setUsername(user);
call.setPassword(password);
call.setTimeout(10000);
call.invoke(new Message(soapEnvelope.toString()));
执行时的错误是:
javax.net.ssl.SSLException: Received fatal alert: unexpected_message
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:1870)
at TestTLSConnect.main(TestTLSConnect.java:100)
我也激活了SSL记录,我可以看到:
Also I activated SSL logging and I can see this:
main, WRITE: SSLv3 Handshake, length = 79
main, READ: TLSv1 Alert, length = 2
main, RECV TLSv1 ALERT: fatal, unexpected_message
我尝试使用System.setProperty(https.protocols,TLSv1);设置协议,但我收到相同的错误和相同的日志消息。
I tried setting the protocol with System.setProperty("https.protocols", "TLSv1");, but I get the same error and the same log message.
推荐答案
try {
SSLContext ctx = SSLContext.getInstance("TLSv1.2");
ctx.init(null, null, null);
SSLContext.setDefault(ctx);
} catch (Exception e) {
System.out.println(e.getMessage());
}
您可以使用此代码将SSL的默认协议设置为TLS 1.2和然后写下你的其他陈述。
You can use this code the set the default protocol for SSL to TLS 1.2 and then write your other statements.
这篇关于强制AXIS客户端使用TLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文