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