dcsimg
SSL socket connection for HTTPS using Java
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ranvir_Singh
Posted On:   Friday, May 22, 2009 09:30 AM

I 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&q   More>>

I 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 = "" +
" "
" " +
" " +
" 1.0 " +
" 431867 " +
" " +
" NOTSET " +
" 71.124.177.781 " +
" TPS " +
" CAM " +
" " +
" " +
" " +
" " +
" ABM234 " +
" " +
" " +
" " +
" " +
" ";

// 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" + "
");

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




   <<Less
About | Sitemap | Contact