• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

SSL Connection fail through Proxy server(mod_proxy) using java(Axis2)

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Java(Axis2 1.6.1 ) to connect .net web service. created stub class from WSDL2Java Converter.
Proxy Server : Apache mod_proxy

Try to access code from C# and Java
below all cases are working with the C#, but getting error with the Java(Axis2)
(SSL = true, Proxy = false : Success)
(SSl = false, Proxy = true : Success)
(SSL = true, Proxy = true : Fail (class javax.net.ssl.SSLException))

code:

ServiceStub objStub = new ServiceStub("https://192.XXX.XX.XX/path/abc.asmx");

//Setting Chunk http data to false and Cookie ID
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);


// set authentication code start-----------------------------------------------------------------------------------------------------------------------------------
HttpTransportProperties.Authenticator objAuthenticator = null;
enAuthType = objAuthSetting.getAuthentication();
sUserID = "";
sPassword = "";
sDomain = "";

//Setting Authenticator properties
switch (enAuthType)
{
case Anonymous:
{
objAuthenticator = null;
break;
}
case Basic:
{
objAuthenticator = new HttpTransportProperties.Authenticator();
objAuthenticator.setUsername(sUserID);
objAuthenticator.setPassword(sPassword);
break;
}
case Digest:
{
objAuthenticator = new HttpTransportProperties.Authenticator();
objAuthenticator.setUsername(sDomain + "\\" + sUserID);
objAuthenticator.setPassword(sPassword);
break;
}
default:
{
}
}

//Setting authenticaiton for web service
if(objAuthenticator != null)
{
objStub._getServiceClient().getOptions().
setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, objAuthenticator);
}

// set authentication code End -----------------------------------------------------------------------------------------------------------------------------------

// In case of Proxy setting (HttpTransportProperties.ProxyProperties) Code Start -------------------------------------------------------------------------
HttpTransportProperties.ProxyProperties objProxyProperties = null;
objProxyAuth = objProxySetting.getAuthenticationInfo();

sProxyAddress = "192.XXX.XX.XX";
nProxyPort = "8080";
enAuthType = objProxyAuth.getAuthenticationFormula();
sProxyUID = "abc";
sProxyPasswd = "xxx");
sProxyDomain = "def";

objProxyProperties = new HttpTransportProperties.ProxyProperties();
objProxyProperties.setProxyName(sProxyAddress);
objProxyProperties.setProxyPort(nProxyPort);

switch (enAuthType)
{
case Anonymous:
{
break;
}
case Basic:
{
objProxyProperties.setUserName(sProxyUID);
objProxyProperties.setPassWord(sProxyPasswd);
break;
}
case Digest:
{
objProxyProperties.setUserName(sProxyDomain + "\\" + sProxyUID);
objProxyProperties.setPassWord(sProxyPasswd);
break;
}
default:
{
}
}

objStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.PROXY,
objProxyProperties);

// In case of Proxy setting (HttpTransportProperties.ProxyProperties) Code End -------------------------------------------------------------------------

// to work without certifcate (ohterwise not using following 2 lines)
objProtocol = new Protocol("https", new MySocketFactory(), 443);
objStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CUSTOM_PROTOCOL_HANDLER, objProtocol);


//----------------------- code start for MySocketFactory--------------------------------------------------------------------------------------------------------
public class MySocketFactory implements ProtocolSocketFactory
{
//contains following two function
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());
}
}

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;
}
}

}

//----------------------- code end for MySocketFactory--------------------------------------------------------------------------------------------------------


while accessing function of the Web Service(.Net Service) getting following error.

Exception Message: Unrecognized SSL message, plaintext connection?
Stack Trace: org.apache.axis2.AxisFault: Unrecognized SSL message, plaintext connection?

Apache access.log
10.128.43.60 - - [24/Sep/2013:13:49:02 +0900] "\x16\x03\x01" 501 215
 
DeveloperSd Vichare
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Detail Error log

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
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic