File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes SSL Connection ....doesnt send response back in jdk1.4!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "SSL Connection ....doesnt send response back in jdk1.4!!!" Watch "SSL Connection ....doesnt send response back in jdk1.4!!!" New topic

SSL Connection ....doesnt send response back in jdk1.4!!!

lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
I am including my test code which establishes a ssl connection to a server and posts an HTTP Post request .which then sends the response back.
This code works fine with jdk1.3.1_01.
But when i try to run the same code sample on j2sdk1.4.2_02, i get Socket Exception. Unexcpected end of file error just after the System.out.println(hello....10)statement. On searching the net i found there is a bug in URLConnection's getContent Method of j2sdk1.4.2_02....which has been fixed in i downladed the same.....and tried to run the same....but now it gives
what could be the reason??
pl. throw some light..
Thanks and Regards

import javax.servlet.*;import javax.servlet.http.*;import java.util.*;import*;import*;import;public class BTServlet extends HttpServlet {public void init(){// Setting proxy server hostSystem.setProperty("https.proxyHost", "3.123.456.209");// Setting proxy server portSystem.setProperty("https.proxyPort", "80");Security.addProvider(new;System.setProperty("java.protocol.handler.pkgs","");// Setting security certicicate locationSystem.setProperty("","C:\\j2sdk1.4.2_03\\jre\\lib\\security\\cacerts");//System.setProperty("","ssl,handshake,data,trustmanager");System.setProperty("security.SSL.ignoreHostnameVerification", "true" );}public void service(HttpServletRequest req,HttpServletResponse res){int c;URL url = null;Reader reader = null;Writer writer = null;StringBuffer sb = new StringBuffer("");try{String reqType = req.getParameter("reqType");if(reqType == null){reqType = "ping.xml";}String prefix = getServletContext().getRealPath("/");System.out.println("#### path="+prefix);url = new URL("");reader = new FileReader(prefix+"\\WEB-INF\\req\\"+reqType);// set an Authenticator to generate username/passwordAuthenticator auth = new Authenticator() {protected PasswordAuthentication getPasswordAuthentication(){String username = "qgdw8gi5zPVN";String password = "vazpCrQjkBVM";return new PasswordAuthentication( username,password.toCharArray() );}};Authenticator.setDefault( auth ); connection = ( url.openConnection();connection.setRequestMethod( "POST" );connection.setDoOutput( true );connection.setRequestProperty( "Content-Type", "text/xml" );// connect and open the writer for POST bodyconnection.connect(); connWriter = new connection.getOutputStream() );// write the post bodywhile ( (c = != -1 )connWriter.write( c );connWriter.flush();// close the POST bodySystem.out.printlnconnection.getOutputStream().close();System.out.println("hello....10");

String str = connection.getContentType();
// get the response body reader
java.lang.Object response = connection.getContent(); connReader = new ( response );
// read the response to the output
while ( (c = != -1 )
req.setAttribute("RESP_XML", sb.toString());
catch (Exception e)
req.setAttribute("RESP_XML", e.toString());
if(reader != null)
if(writer != null)
RequestDispatcher dispatcher;
dispatcher = getServletContext().getRequestDispatcher("/abcd.jsp");
dispatcher.forward(req, res);
catch (Exception e1) {
jQuery in Action, 3rd edition
subject: SSL Connection ....doesnt send response back in jdk1.4!!!
It's not a secret anymore!