Connect to a URL through a proxy using a java agent

Hi There,

i am trying to establish a connection to a certain url using a notes java agent. I have managed to write some code that works as a standalone app but as soon as I introduce the code in a notes agent I get the following error:

java.net.UnknownHostException: www.ibm.com

java.net.UnknownHostException: www.ibm.com

 at java.net.InetAddress.getAllByName0(InetAddress.java:472)

 at java.net.InetAddress.getByName(InetAddress.java:347)

 at java.net.Socket.<init>(Socket.java:89)

 at sun.net.NetworkClient.doConnect(NetworkClient.java:54)

 at

sun.net.www.http.HttpClient.openServer(HttpClient.java:263)

 at

sun.net.www.http.HttpClient.openServer(HttpClient.java:328)

 at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)

 at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)

 at sun.net.www.http.HttpClient.New(HttpClient.java:222)

 at

sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:318)

 at JavaAgent.NotesMain(JavaAgent.java:43)

 at lotus.domino.AgentBase.runNotes(AgentBase.java:160)

 at lotus.domino.NotesThread.run(NotesThread.java:203)

The code used is below:

import java.util.Properties;

import java.util.Date;

import java.net.*;

import java.io.*;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {



	try {

		Session session = getSession();

		AgentContext agentContext = session.getAgentContext();



	// Enable the properties used for proxy support

	System.getProperties().put( "proxySet", "true" );

	System.getProperties().put( "http.proxyHost", "proxyname" );

	System.getProperties().put( "http.proxyPort", "8080" );



	URL url = new URL("http://www.ibm.com/");

	URLConnection connection = url.openConnection();



	// enter the username and password for the proxy

	//String login = "username:password";

	String login = "username:password";

	String encoded = Base64Converter.encode (login.getBytes());  



	System.out.println("Encoded : "+encoded);



	connection.setRequestProperty("Proxy-Authorization", "Basic "+ encoded);



	// Set up the connection so it knows you are sending

	// proxy user information

	connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");

	connection.setRequestProperty("Accept", "text/html, image/*"); 



	// Set up the connection so you can do read and writes 

	//connection.setDoInput( true );

	connection.setDoOutput( true );

	connection.setUseCaches( false );

	System.out.println("debugg1");

	connection.connect();

	// get ready to read the response from the cgi script

  	InputStream input = connection.getInputStream(); 

// read in each character until end-of-stream is detected

// StreamCopier.copy(input, new FileOutputStream(“index.html”));

    // read in each character until end-of-stream is detected

        for( int c = input.read(); c != -1; c = input.read() )

        {

            System.out.print( (char)c );

        }

        	input.close();

		input.close();



	} catch(Exception e) {

		System.out.println( "Something bad just happened." );

		System.out.println( e );

		e.printStackTrace();

	}

}

}

/*********************************************************************

  * BASE 64 encoding of a String or an array of bytes.

  *



  *********************************************************************/



 public class  Base64Converter

  //////////////////////////////////////////////////////////////////////

  //////////////////////////////////////////////////////////////////////

  {



  public static final char [ ]  alphabet = {

     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',   //  0 to  7

     'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',   //  8 to 15

     'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',   // 16 to 23

     'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',   // 24 to 31

     'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',   // 32 to 39

     'o', 'p', 'q', 'r', 's', 't', 'u', 'v',   // 40 to 47

     'w', 'x', 'y', 'z', '0', '1', '2', '3',   // 48 to 55

     '4', '5', '6', '7', '8', '9', '+', '/' }; // 56 to 63



   //////////////////////////////////////////////////////////////////////

    //////////////////////////////////////////////////////////////////////



  public static String  encode ( String  s )

   //////////////////////////////////////////////////////////////////////

   {

      return encode ( s.getBytes ( ) );

   }



  public static String  encode ( byte [ ]  octetString )

   //////////////////////////////////////////////////////////////////////

   {

     int  bits24;

      int  bits6;



   char [ ]  out = new char [ ( ( octetString.length - 1 ) / 3 + 1 ) * 4 ];



   int outIndex = 0;

      int i        = 0;

while ( ( i + 3 ) <= octetString.length )

      {

        // store the octets

        bits24  = ( octetString [ i++ ] & 0xFF ) << 16; 

        bits24 |= ( octetString [ i++ ] & 0xFF ) <<  8; 

        bits24 |= ( octetString [ i++ ] & 0xFF ) <<  0;



bits6 = ( bits24 & 0x00FC0000 ) >> 18; 

out [ outIndex++ ] = alphabet [ bits6 ];

bits6 = ( bits24 & 0x0003F000 ) >> 12; 

out [ outIndex++ ] = alphabet [ bits6 ];

bits6 = ( bits24 & 0x00000FC0 ) >> 6; 

out [ outIndex++ ] = alphabet [ bits6 ];

bits6 = ( bits24 & 0x0000003F );

out [ outIndex++ ] = alphabet [ bits6 ]; 

      }



     if ( octetString.length - i == 2 )

      {

        // store the octets 

        bits24  = ( octetString [ i     ] & 0xFF ) << 16; 

        bits24 |= ( octetString [ i + 1 ] & 0xFF ) <<  8;



        bits6 = ( bits24 & 0x00FC0000 ) >> 18;

        out [ outIndex++ ] = alphabet [ bits6 ]; 

        bits6 = ( bits24 & 0x0003F000 ) >> 12; 

        out [ outIndex++ ] = alphabet [ bits6 ]; 

        bits6 = ( bits24 & 0x00000FC0 ) >> 6; 

        out [ outIndex++ ] = alphabet [ bits6 ];



        // padding

        out [ outIndex++ ] = '='; 

      }

      else if ( octetString.length - i == 1 )

      {

        // store the octets 

        bits24 = ( octetString [ i ] & 0xFF ) << 16;



        bits6 = ( bits24 & 0x00FC0000 ) >> 18;

        out [ outIndex++ ] = alphabet [ bits6 ];

        bits6 = ( bits24 & 0x0003F000 ) >> 12; 

        out [ outIndex++ ] = alphabet [ bits6 ];



        // padding

        out [ outIndex++ ] = '='; 

        out [ outIndex++ ] = '='; 

      }



     return new String ( out );

   }



 //////////////////////////////////////////////////////////////////////

  //////////////////////////////////////////////////////////////////////

  }

Thanks for any help

Bertso