Java Secure Socket Extension Package Overview

   

Listing 23.19 is basically the example from Listing 23.15, which just prints out the page found at a given URL. The difference in this example is that it is reading the page from a site that is using SSL. This example does the handshaking with the server and negotiates an encryption algorithm and then gets the text.

Note

You will need to have all three JSSE jar files included in your system CLASSPATH for this example to work correctly.


Listing 23.19 Source Code for PrintHTTPSUrlPage Application
 import javax.net.ssl.*; import java.io.*; import java.net.*; import java.security.*; public class PrintHTTPSUrlPage {   public static void main(String args[]) throws Exception   {    System.setProperty("java.protocol.handler.pkgs", graphics/ccc.gif "com.sun.net.ssl.internal.www.protocol");     Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());     // Notice the https protocol here     URL url = new URL("https://www.verisign.com" );     URLConnection conn = url.openConnection();     conn.connect();     BufferedReader reader = new BufferedReader( new InputStreamReader( graphics/ccc.gif conn.getInputStream() ) );     String data = null;     // Keep reading lines until there are no more to read     while( (data = reader.readLine()) != null )     {       // Just write out the text to the console       System.out.println( data );     }   } } 

Troubleshooting Tip

If your HTTPS connection takes a long time to connect, see "Using JSSE Takes Forever" in the following "Troubleshooting" section.


   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net