This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) {
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!