SSL socket connection error using HTTPS
843811May 25 2009 — edited May 25 2009I am trying to create an SSL socket connection for HTTPS using Java (dont know much of that) and am getting an error. Following is my Java code:
import javax.net.SocketFactory;
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
import java.security.*;
public class SSLPipeClean_again {
public static void main(String args[]) {
System.setProperty("javax.net.ssl.trustStore",args[0]);
System.setProperty("javax.net.ssl.truststorePassword",args[1]);
System.setProperty("javax.net.ssl.keyStore",args[2]);
System.setProperty("javax.net.ssl.keyStorePassword",args[3]);
try {
String xmldata = "" +
"<\SOAP-ENV:Body>"
"<\m:request>" +
"<\m:header>" +
"<\m0:Version>1.0<\/m0:Version>" +
"<\m0:UserIdentifier>431867<\/m0:UserIdentifier>" +
"<\m0:AuditHeader>" +
"<\m0:LocationName>NOTSET<\/m0:LocationName>" +
"<\m0:LocationAddress>71.124.177.781<\/m0:LocationAddress>" +
"<\m0:SourceSystem>TPS<\/m0:SourceSystem>" +
"<m0:SourceSubsystem>CAM<\/m0:SourceSubsystem>" +
"<\/m0:AuditHeader>" +
"<\/m:header>" +
"<\m:body>" +
"<\m:SiS>" +
"<\m1:SiSBody>ABM234<\/m1:SiSBody>" +
"<\/m:SiS>" +
"<\/m:body>" +
"<\/m:request>" +
"<\/SOAP-ENV:Body>" +
"<\/SOAP-ENV:Envelope>";
// Please excuse the "\"s in the "xmldata"
String urlString = args[4];
URL url = new URL(urlString);
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket)factory.createSocket(url.getHost(), url.getPort());
String[] enabled = {"SSL_RSA_WITH_NULL_MD5","SSL_RSA_WITH_NULL_SHA"};
socket.setEnabledCipherSuites(enabled);
PrintWriter out = new PrintWriter(
new OutputStreamWriter(
socket.getOutputStream()));
String userId = "43187267";
String host = "21.451.758.73";
String port = "8080";
out.println("POST " + urlString + " HTTP/1.1" + "\n");
out.println("Content-Length: " + xmldata.length());
out.println("Content-Type" + "text/xml; charset=utf-8");
out.println("Authorization: " + userId);
out.println("SOAPAction: " + "request");
out.println("Host: " + host + ":" + port);
out.println("Connection: " + "Keep-Alive");
out.println(xmldata);
out.flush();
BufferedReader in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
out.close();
in.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
System.out.println("test");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
//System.out.println(e);
e.printStackTrace();
}
}
}
Command used to execute this code:
java SSLPipeClean_again /truststore/truststore.jks default /keystore/keystore.jks default https://71.444.155.28:8080/ABCWebService/services/SearchService
Getting the following error response:
HTTP/1.1 403 Forbidden
Content-Type: text/html;charset=ISO-8859-1
$WSEP:
Content-Language: en-GB
Transfer-Encoding: chunked
Date: Fri, 22 May 2009 07:21:23 GMT
Server: WebSphere Application Server/6.0
30
Error 403: No UserId in request to authenticate
0
HTTP/1.1 400 Bad Request
Connection: Close
Content-Length: 0
Date: Fri, 22 May 2009 07:21:23 GMT
Server: WebSphere Application Server/6.0
Can somebody please suggest what can resolve this issue.
Thanks a lot,
Ranvir