Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Https Testing on Websphere 4/Apache 1.3.20 NT

Status
Not open for further replies.

luthriaajay

Programmer
Jan 29, 2002
41
FR
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(&quot;<html>&quot;);
out.println(&quot;<head><title>UserPwd</title></head>&quot;);
out.println(&quot;<body BGCOLOR=\&quot;aliceblue\&quot;>&quot;);
out.println(&quot;<CENTER>&quot;);

out.println(&quot;<Table>&quot;);

out.println(&quot;<tr>&quot;);
out.println(&quot;<td colspan=75 BGCOLOR=Gold></td>&quot;);
out.println(&quot;</tr>&quot;);

out.println(&quot;<FORM Method=\&quot;POST\&quot; ACTION=&quot; +
&quot;\&quot;
out.println(&quot;<Font Color=Navy Face=Arial size=4 ><B>france tele</B></Font>&quot;);
out.println(&quot;<Font Color=Gold Face=Arial size=4 ><B>com</B></Font>&quot;);
out.println(&quot;<BR>&quot;);
out.println(&quot;<Font Color=Navy Face=Arial size=4 ><B>R&D</B></Font>&quot;);
out.println(&quot;<BR>&quot;);
out.println(&quot;<BR>&quot;);
out.println(&quot;<Font Color=Red Face=Arial size=3 >Pulsar Application</Font>&quot;);


out.println(&quot;<TR>&quot;);
out.println(&quot;<TD><Font face=\&quot;Arial\&quot; size=3 Color=\&quot;Blue\&quot;>User </Font></TD>&quot;);
out.println(&quot;<TD><INPUT TYPE=\&quot;text\&quot; name=\&quot;userName\&quot;> </TD>&quot;);
out.println(&quot;</TR>&quot;);

out.println(&quot;<TR>&quot;);
out.println(&quot;<TD><Font face=\&quot;Arial\&quot; size=3 Color=\&quot;Blue\&quot;>Password :</TD>&quot;);
out.println(&quot;<TD><INPUT TYPE=\&quot;password\&quot; name=\&quot;pwd\&quot;></TD>&quot;);
out.println(&quot;</TR>&quot;);

out.println(&quot;<TR>&quot;);
out.println(&quot;<td><INPUT Type=\&quot;SUBMIT\&quot; VALUE=\&quot;SUBMIT\&quot;></td>&quot;);
out.println(&quot;</TR>&quot;);

out.println(&quot;<tr>&quot;);
out.println(&quot;<td colspan=75 BGCOLOR=Gold></td>&quot;);
out.println(&quot;</tr>&quot;);

out.print(&quot;</Table>&quot;);
out.println(&quot;</Form>&quot;);
out.println(&quot;</body></html>&quot;);

} // End of doGet()


public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

response.setContentType(&quot;text/html&quot;);
PrintWriter out = response.getWriter();

String name = request.getParameter(&quot;userName&quot;);
String pwd = request.getParameter(&quot;pwd&quot;);

out.println(&quot;<html>&quot;);
out.println(&quot;<head><title>Test</title></head>&quot;);
out.println(&quot;<body>&quot;);
out.println(&quot;<p>Hello </p>&quot; + name + &quot; &quot; + pwd);


try {

System.setProperty(&quot;java.protocol.handler.pkgs&quot;,&quot;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 + &quot;:&quot; + pwd;

URL url;

String uri=&quot;
url = new URL(uri);
HttpsURLConnection hpCon=null;

try {


SSLContext sslContext = SSLContext.getInstance(&quot;SSL&quot;);
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(&quot;Sending data over a secured connection ie HTTPS......&quot; + line);

OutputStream output = hpCon.getOutputStream();
output.write(line.getBytes());
output.flush();
output.close();


//Response from the Receiving Servlet.
out.println(&quot;Received response from the Server.....&quot;);

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(&quot;Error in Client &quot; + e);
}


out.println(&quot;Outside&quot;);
out.println(&quot;</Body></Html>&quot;);

} // End of doPost



} // End of Class UserPwd2.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top