SSL连接使用java(Axis2)通过代理服务器(mod_proxy)失败

时间:2013-10-04 16:27:51

标签: java ssl proxy axis2

我使用Java(Axis2)连接.net web服务。

我从WSDL2Java Converter创建了存根类。

代理服务器:Apache mod_proxy

以下所有情况都使用C#代码但是使用Java(Axis2)

时出错
(SSL = true, Proxy = false  : Success)
(SSl = false, Proxy = true : Success)
(SSL = true, Proxy = true : Fail (class javax.net.ssl.SSLException))



ServiceStub objStub = new ServiceStub(sWebServiceURL);
      objStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
        objStub._getServiceClient().getOptions().setProperty("customCookieID",DEF_COOKIEID);
        objStub._getServiceClient().getOptions().setManageSession(true);

objConfigSetting = new DCAServiceConfigSetting();
nSocketTimeout = 30000;
objStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.SO_TIMEOUT, new Integer(nSocketTimeout));

//Setting the authentication for web service   

setServiceAuthentication(objStub, objConnSetting.getAuthenticationInfo());

//Setting Proxy properties

if(objConnSetting.getProxySettingStatus() == true)
{
   setProxyProperties(objStub, objConnSetting.getProxySettingInfo());
}

if(objConnSetting.getWebServiceURL().contains("https://"))
{
    if(objConnSetting.getWithoutSSLSerCertificateStatus() == true)
    {
      Protocol objProtocol = new Protocol("https", new MySocketFactory(), 443);
        objStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CUSTOM_PROTOCOL_HANDLER, objProtocol);
}



// command to set proxy setting
objStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.PROXY, objProxyProperties);


// Inside MySocketFactory class ----------------------------------------------

public Socket createSocket(final String host,
                           final int port,
                           final InetAddress localAddress,
                           final int localPort,
                           final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException 

{
if (params == null){
throw new IllegalArgumentException("Parameters may not be null");
}
 int timeout = params.getConnectionTimeout();
 SocketFactory socketfactory = getSSLContext().getSocketFactory();
 if (timeout == 0) 
 {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    }
    else 
    {
        Socket socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
}


   // Also 

 private static SSLContext createEasySSLContext() 
{
    try 
    {
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] {new NaiveTrustManager()}, null);
        return context;
    }
    catch (Exception e) 
    {
        LOG.error(e.getMessage(), e);
        throw new HttpClientError(e.toString());
    }
}

详细错误日志

Exception Message: Unrecognized SSL message, plaintext connection? 
Stack Trace: org.apache.axis2.AxisFault: Unrecognized SSL message, plaintext    connection? 
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) 
at org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:98) 
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499) 
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114) 
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096) 
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398) 
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) 
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) 
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621) 
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193) 
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75) 
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404) 
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231) 
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443) 
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406) 
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) 
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) 
at WebService.ServiceStub.calWebFunction(ServiceStub.java:1892) 
Caused by: 

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? 
at sun.security.ssl.InputRecord.handleUnknownRecord(Unknown Source) 
at sun.security.ssl.InputRecord.read(Unknown Source) 
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) 
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) 
at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source) 
at sun.security.ssl.AppOutputStream.write(Unknown Source) 
at java.io.BufferedOutputStream.flushBuffer(Unknown Source) 
at java.io.BufferedOutputStream.flush(Unknown Source) 
at java.io.FilterOutputStream.flush(Unknown Source) 
at org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:94) ... 20 more


    Apache access.log
10.128.43.60 - - [24/Sep/2013:13:49:02 +0900] "\x16\x03\x01" 501 215

Please reply ASAP

0 个答案:

没有答案