I am trying to get the InputStream from a URLConnection object. The connection must be established with the Internet through a proxy.
My code stops at the following line: line = reader.readLine();
I already asked my security guys if I could tunnel through and they change the setting on the proxy server to allow for HTTP tunelling and they said no because it is a security risk.
Here is my environment:
IBM WebSphere Application Developer 4.03 w/ JDK 1.3.1
Proxy Server: Novell Border Manager
I have jecert.jar, jnet.jar and jsse.jar in my classpath and they are located here: C:\Program Files\IBM\Application Developer\jre\lib\ext
(I was told I need to use the SUN classes and not the IBM ones)
From my java.security file:
security.provider.1=sun.security.provider.Sun
security.provider.2=com.sun.net.ssl.internal.ssl.Provider
security.provider.3=com.ibm.crypto.provider.IBMJCA
Here is my code:
Code:
package com.MattSidesinger.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.Security;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
public class ProxyConnectionTester
{
public static void main(String[] args)
{
try
{
// Set the system and security properties
System.setProperty("javax.net.ssl.trustStore", "C:\\cacerts1");
System.setProperty("javax.net.ssl.trustStorePassword", "password");
// Keystore location and password
System.setProperty("javax.net.ssl.keyStore", "C:\\cacerts1");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
System.setProperty("proxyHost","bmserver");
System.setProperty("proxyPort","8080");
System.setProperty("proxyUserName","username");
System.setProperty("proxyPassword","password");
System.setProperty("proxySet","true");
System.setProperty("http.proxyHost","bmserver");
System.setProperty("http.proxyPort","8080");
System.setProperty("http.proxyUserName","username");
System.setProperty("http.proxyPassword","password");
System.setProperty("http.proxySet","true");
System.setProperty("https.proxyHost","bmserver");
System.setProperty("https.proxyPort","8080");
System.setProperty("https.proxyUserName","username");
System.setProperty("https.proxyPassword","password");
System.setProperty("https.proxySet","true");
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// connect to get the web page
URL url = new URL("http://www.google.com");
URLConnection connection = url.openConnection();
// get the contents of the web page
InputStream stream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
// read in the entire web page
StringBuffer webPage = new StringBuffer();
String line = null;
while(true)
{
line = reader.readLine(); // STOPS HERE
if (line == null)
{
break;
}
webPage = webPage.append(line);
}
// close all resources that we do not need
// now that the web page has been obtained
stream.close();
reader.close();
}
catch (MalformedURLException e)
{
System.out.println("MalformedURLException");
}
catch (IOException e)
{
System.out.println(e.toString());
}
}
}
There were no errors when I installed the certificates to the keystore using the keytool.
I will keep you updated if I have any further advances.