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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SSL Socket connection via proxy

Status
Not open for further replies.

fla5h

Programmer
Oct 24, 1999
3
0
0
GB
Visit site
I am trying to connect to a secure web page (https) and read the contents, all sounds simple right?&nbsp;&nbsp;I have to go through a proxy.&nbsp;&nbsp;I am using JSSE 1.01 and basicaly running one of the samples that comes with JSSE.&nbsp;&nbsp;This is the code...<br><br>// set up ssl socket to do tunneling through proxy<br>tunnelHost = System.getProperty(&quot;https.proxyHost&quot;);<br>tunnelPort = Integer.getInteger(&quot;https.proxyPort&quot;).intValue();<br><br>Socket tunnel = new Socket(tunnelHost, tunnelPort);<br>doTunnelHandshake(tunnel, host, port);<br>SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();<br>SSLSocket socket = (SSLSocket)factory.createSocket(tunnel, host, port, true);<br><br>// register a callback for handshaking completion event<br>socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {<br>public void handshakeCompleted(HandshakeCompletedEvent event) {<br>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;Handshake finished!&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;\t CipherSuite:&quot; + event.getCipherSuite());<br>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;\t SessionId &quot; + event.getSession());<br>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;\t PeerHost &quot; + event.getSession().getPeerHost());<br>}<br>});<br><br>// send http request<br>PrintWriter out = new PrintWriter(<br>new BufferedWriter(<br>&nbsp;&nbsp;new OutputStreamWriter(<br>&nbsp;&nbsp;socket.getOutputStream())));<br><br>out.println(&quot;GET <A HREF=" TARGET="_new"> HTTP/1.1&quot;);<br>out.println();<br>out.flush();<br><br>// read response<br>BufferedReader in = new BufferedReader(<br>&nbsp;&nbsp;&nbsp;new InputStreamReader(<br>&nbsp;&nbsp;&nbsp;socket.getInputStream()));<br><br>String inputLine;<br><br>while ((inputLine = in.readLine()) != null)<br>System.out.println(inputLine);<br><br>in.close();<br><br>----------------------------------------------<br>If I run the code Im told that the line:<br>&nbsp;&nbsp;&nbsp;&nbsp;out.flush();<br>Causes exception:<br>java.lang.IllegalArgumentException<br> void java.io.PrintWriter.flush()<br> void SSLSocketClientWithTunneling.doIt(java.lang.String, int)<br> void SSLSocketClientWithTunneling.main(java.lang.String[])<br><br>But, if I run the code in debug mode and add a break point on the out.flush() line and use debug to step over it the code works fine?<br><br>Any help would be well received.<br><br>fl@5h
 
ummm... put it in a try/catch block with nothing in the catch block? what happens then? <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
I should have said, it is in a try catch block.&nbsp;&nbsp;Thats how it catches the<br><br>java.lang.IllegalArgumentException:&nbsp;&nbsp;out.flush();<br>void java.io.PrintWriter.flush()<br>void SSLSocketClientWithTunneling.doIt(java.lang.String, int)<br>void SSLSocketClientWithTunneling.main(java.lang.String[])<br><br>I am thinking the problem might be a timing issue with the proxy?&nbsp;&nbsp;The JSSE code fires off a few threads which is making impossible for me to try and trace for debugging.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top