luthriaajay
Programmer
Folks
I have configured the WAS Websphere 4 with the required Server Certificates (thru the IkeyMan manager) and stored the client and server certificates in the ${WAS_HOME}/etc
directory.
I am testing 2 servlets on WAS.One to send username and pwd
over HTTPS to the receiving servlet.
But in my UserPwd2 Servlet,(which sends Username and password over https)the control is not entering the first try -catch block where the SSL statements are.
Is it becos I have installed Websphere using IBM java toolkit and not the Sun tool Kit?
How do I test the entire https connection if this work or not? I have entered the out.println() statements which arent getting executed.
Please can any body help me on this!!
regards
ajay
ajayluthria@hotmail.com
Servlet : UserPwd2
Send UserName and Password Over https
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.security.*;
// The SSL Package.
import javax.net.*;
import javax.net.ssl.*;
import com.sun.net.ssl.*;
import java.net.*;
public class UserPwd2 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>"
out.println("<head><title>UserPwd</title></head>"
out.println("<body BGCOLOR=\"aliceblue\">"
out.println("<CENTER>"
out.println("<Table>"
out.println("<tr>"
out.println("<td colspan=75 BGCOLOR=Gold></td>"
out.println("</tr>"
out.println("<FORM Method=\"POST\" ACTION=" +
"\"
out.println("<Font Color=Navy Face=Arial size=4 ><B>france tele</B></Font>"
out.println("<Font Color=Gold Face=Arial size=4 ><B>com</B></Font>"
out.println("<BR>"
out.println("<Font Color=Navy Face=Arial size=4 ><B>R&D</B></Font>"
out.println("<BR>"
out.println("<BR>"
out.println("<Font Color=Red Face=Arial size=3 >Pulsar Application</Font>"
out.println("<TR>"
out.println("<TD><Font face=\"Arial\" size=3 Color=\"Blue\">User </Font></TD>"
out.println("<TD><INPUT TYPE=\"text\" name=\"userName\"> </TD>"
out.println("</TR>"
out.println("<TR>"
out.println("<TD><Font face=\"Arial\" size=3 Color=\"Blue\">Password :</TD>"
out.println("<TD><INPUT TYPE=\"password\" name=\"pwd\"></TD>"
out.println("</TR>"
out.println("<TR>"
out.println("<td><INPUT Type=\"SUBMIT\" VALUE=\"SUBMIT\"></td>"
out.println("</TR>"
out.println("<tr>"
out.println("<td colspan=75 BGCOLOR=Gold></td>"
out.println("</tr>"
out.print("</Table>"
out.println("</Form>"
out.println("</body></html>"
} // End of doGet()
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html"
PrintWriter out = response.getWriter();
String name = request.getParameter("userName"
String pwd = request.getParameter("pwd"
out.println("<html>"
out.println("<head><title>Test</title></head>"
out.println("<body>"
out.println("<p>Hello </p>" + name + " " + pwd);
try {
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal. Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// Store the name and password in String line.
String line = name + ":" + pwd;
URL url;
String uri="
url = new URL(uri);
HttpsURLConnection hpCon=null;
try {
SSLContext sslContext = SSLContext.getInstance("SSL"
java.security.SecureRandom());
SSLSocketFactory sslSF = sslContext.getSocketFactory();
hpCon = (HttpsURLConnection)url.openConnection();
hpCon.setSSLSocketFactory(sslSF);
}catch(Exception e){}
hpCon.setDoOutput(true);
hpCon.setDoInput(true);
// Send the user name and password as a Stream to the Receving Servlet
out.println("Sending data over a secured connection ie HTTPS......" + line);
OutputStream output = hpCon.getOutputStream();
output.write(line.getBytes());
output.flush();
output.close();
//Response from the Receiving Servlet.
out.println("Received response from the Server....."
int i;
InputStreamReader input = new InputStreamReader(hpCon.getInputStream());
while((i = input.read())!=-1)
{
// Send a response on the Browser.
out.print((char)i);
}
}catch(IOException e)
{
System.out.println("Error in Client " + e);
}
out.println("Outside"
out.println("</Body></Html>"
} // End of doPost
} // End of Class UserPwd2.
I have configured the WAS Websphere 4 with the required Server Certificates (thru the IkeyMan manager) and stored the client and server certificates in the ${WAS_HOME}/etc
directory.
I am testing 2 servlets on WAS.One to send username and pwd
over HTTPS to the receiving servlet.
But in my UserPwd2 Servlet,(which sends Username and password over https)the control is not entering the first try -catch block where the SSL statements are.
Is it becos I have installed Websphere using IBM java toolkit and not the Sun tool Kit?
How do I test the entire https connection if this work or not? I have entered the out.println() statements which arent getting executed.
Please can any body help me on this!!
regards
ajay
ajayluthria@hotmail.com
Servlet : UserPwd2
Send UserName and Password Over https
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.security.*;
// The SSL Package.
import javax.net.*;
import javax.net.ssl.*;
import com.sun.net.ssl.*;
import java.net.*;
public class UserPwd2 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>"
out.println("<head><title>UserPwd</title></head>"
out.println("<body BGCOLOR=\"aliceblue\">"
out.println("<CENTER>"
out.println("<Table>"
out.println("<tr>"
out.println("<td colspan=75 BGCOLOR=Gold></td>"
out.println("</tr>"
out.println("<FORM Method=\"POST\" ACTION=" +
"\"
out.println("<Font Color=Navy Face=Arial size=4 ><B>france tele</B></Font>"
out.println("<Font Color=Gold Face=Arial size=4 ><B>com</B></Font>"
out.println("<BR>"
out.println("<Font Color=Navy Face=Arial size=4 ><B>R&D</B></Font>"
out.println("<BR>"
out.println("<BR>"
out.println("<Font Color=Red Face=Arial size=3 >Pulsar Application</Font>"
out.println("<TR>"
out.println("<TD><Font face=\"Arial\" size=3 Color=\"Blue\">User </Font></TD>"
out.println("<TD><INPUT TYPE=\"text\" name=\"userName\"> </TD>"
out.println("</TR>"
out.println("<TR>"
out.println("<TD><Font face=\"Arial\" size=3 Color=\"Blue\">Password :</TD>"
out.println("<TD><INPUT TYPE=\"password\" name=\"pwd\"></TD>"
out.println("</TR>"
out.println("<TR>"
out.println("<td><INPUT Type=\"SUBMIT\" VALUE=\"SUBMIT\"></td>"
out.println("</TR>"
out.println("<tr>"
out.println("<td colspan=75 BGCOLOR=Gold></td>"
out.println("</tr>"
out.print("</Table>"
out.println("</Form>"
out.println("</body></html>"
} // End of doGet()
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html"
PrintWriter out = response.getWriter();
String name = request.getParameter("userName"
String pwd = request.getParameter("pwd"
out.println("<html>"
out.println("<head><title>Test</title></head>"
out.println("<body>"
out.println("<p>Hello </p>" + name + " " + pwd);
try {
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal. Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// Store the name and password in String line.
String line = name + ":" + pwd;
URL url;
String uri="
url = new URL(uri);
HttpsURLConnection hpCon=null;
try {
SSLContext sslContext = SSLContext.getInstance("SSL"
java.security.SecureRandom());
SSLSocketFactory sslSF = sslContext.getSocketFactory();
hpCon = (HttpsURLConnection)url.openConnection();
hpCon.setSSLSocketFactory(sslSF);
}catch(Exception e){}
hpCon.setDoOutput(true);
hpCon.setDoInput(true);
// Send the user name and password as a Stream to the Receving Servlet
out.println("Sending data over a secured connection ie HTTPS......" + line);
OutputStream output = hpCon.getOutputStream();
output.write(line.getBytes());
output.flush();
output.close();
//Response from the Receiving Servlet.
out.println("Received response from the Server....."
int i;
InputStreamReader input = new InputStreamReader(hpCon.getInputStream());
while((i = input.read())!=-1)
{
// Send a response on the Browser.
out.print((char)i);
}
}catch(IOException e)
{
System.out.println("Error in Client " + e);
}
out.println("Outside"
out.println("</Body></Html>"
} // End of doPost
} // End of Class UserPwd2.