problem with URLConnection behind a firewall

Discussion in 'Java' started by vj, Nov 15, 2006.

  1. vj

    vj Guest

    Hi,

    I am creating a URLConnection object behind a firewall and facing some
    serious problems.
    The thing goes on smooth untill firewall does not enforces security. As
    soon as user authorization is enforced the thing stops working. The
    firewall is HTTP working on port 8080 of localhost. Here is the code
    that i am using

    /*************************CODE************************/
    Properties systemSettings = System.getProperties();
    System.setProperties(systemSettings);

    URL url=new URL("http://someserver/somepage");
    URLConnection uc = url.openConnection ();
    String encoded = new String
    (Base64.base64Encode(new
    String("username:password").getBytes()));
    uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);

    System.out.println("Connecting...");
    uc.connect();
    InputStream is= uc.getInputStream();
    System.out.println("Connected and retriving data...");

    /***********************************************************/
    the main problem is that as soon as authorization is enforced the
    programs freezes after giving the output "Connecting..." !!!

    Any ideas what really is the problem. I have tried googling and tried
    all sorts of methods that were suggested on the web.


    Thanks,
    VJ
     
    vj, Nov 15, 2006
    #1
    1. Advertising

  2. vj

    Graham Guest

    Hi vj,

    Are you using a firewall
    (http://en.wikipedia.org/wiki/Firewall_(networking)) or a proxy
    (http://en.wikipedia.org/wiki/Proxy_server)? There are some
    differences, so it is worth checking what you are actually working
    with.

    If you are actually using a proxy then you need to look at:
    http://java.sun.com/j2se/1.5.0/docs/api/java/net/Proxy.html

    You can pass the proxy object when you call url.openConnection ()

    Regards,

    Graham
    Lead Senior Developer
    Modern Security Solutions
    http://www.modernsecuritysolutions.com


    vj wrote:

    > Hi,
    >
    > I am creating a URLConnection object behind a firewall and facing some
    > serious problems.
    > The thing goes on smooth untill firewall does not enforces security. As
    > soon as user authorization is enforced the thing stops working. The
    > firewall is HTTP working on port 8080 of localhost. Here is the code
    > that i am using
    >
    > /*************************CODE************************/
    > Properties systemSettings = System.getProperties();
    > System.setProperties(systemSettings);
    >
    > URL url=new URL("http://someserver/somepage");
    > URLConnection uc = url.openConnection ();
    > String encoded = new String
    > (Base64.base64Encode(new
    > String("username:password").getBytes()));
    > uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
    >
    > System.out.println("Connecting...");
    > uc.connect();
    > InputStream is= uc.getInputStream();
    > System.out.println("Connected and retriving data...");
    >
    > /***********************************************************/
    > the main problem is that as soon as authorization is enforced the
    > programs freezes after giving the output "Connecting..." !!!
    >
    > Any ideas what really is the problem. I have tried googling and tried
    > all sorts of methods that were suggested on the web.
    >
    >
    > Thanks,
    > VJ
     
    Graham, Nov 15, 2006
    #2
    1. Advertising

  3. vj

    Real Gagnon Guest

    "vj" <> wrote in news:1163573095.757240.204140
    @f16g2000cwb.googlegroups.com:

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


    You need to set some System properties since a proxy is used :

    Properties systemSettings = System.getProperties();
    systemSettings.put("http.proxyHost","proxy.mydomain.local") ;
    systemSettings.put("http.proxyPort", "80") ;

    see http://www.rgagnon.com/javadetails/java-0085.html

    Bye.
    --
    Real Gagnon from Quebec, Canada
    * Looking for Java or PB code examples ? Visit Real's How-to
    * http://www.rgagnon.com/howto.html
     
    Real Gagnon, Nov 16, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg W via DotNetMonster.com

    problem connecting to my database behind a firewall

    Greg W via DotNetMonster.com, Jul 16, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    546
    Alan Samet
    Jul 19, 2005
  2. Robert Dodier
    Replies:
    6
    Views:
    2,362
    Matthias Kraft
    Sep 14, 2004
  3. Replies:
    2
    Views:
    3,606
  4. Francis Tsui

    Problem with Web service behind firewall

    Francis Tsui, Aug 20, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    139
    Francis Tsui
    Aug 20, 2003
  5. Kumarforg

    Web Service invocation from behind proxy behind firewall

    Kumarforg, Aug 3, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    191
    Kumarforg
    Aug 3, 2004
Loading...

Share This Page