• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing URL through java from behind a fire wall:

 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am a newbie to java.net packages and am facing a problem

Let me explain my environment before describing my problem

I have to access a URL from behind my fire wall

I am able to access the URL from my Web browser. So I assume I am authorized to do so

I know my proxy settings

This is the code I use



The above code throws an exception
java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.javaranch.com/

First question response code 407 means authorisation needed then why am I able to access the URL through browser without any authentication, so I guess it is something to do with code.

Now I modify the code a bit and add



Where PasswordAuthenticator is an subclass of Authenticator overridding its protected PasswordAuthentication getPasswordAuthentication()method returning the user-id and password I use to log on to windows

Now I get a different error

java.net.ProtocolException: Server redirected too many times (20)

I really can't think of anything else to access this URL through java. Any pointers will be greatly appreciated

Thanks in advance,
Rajagopal
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just pinging to see if any one could help me with this problem

Thanks,
Rajagopal
 
Manuel Moons
Ranch Hand
Posts: 229
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you fill in the proxy settings in the code correctly? Because in your code sample you have filled in :


System.getProperties().put("proxyHost", "proxyname");
System.getProperties().put("proxyPort", "proxyyport");


Maybe you should take a look at:
http://www.rgagnon.com/javadetails/java-0085.html
 
Andrew Moore
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had this exact same problem.
The issue lies around the authentiction. I tried the follwoing:
System.getProperties().put("http.proxyUser", "myuser");
System.getProperties().put("http.proxyPassword", "mypass");
but it didn't work.

I eventually found the fix whilst polling through forums.
Create a new class along the lines of teh following:
//0------------------------------
import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class httpAuthProxy extends Authenticator {

protected PasswordAuthentication setAuthentication() {
return new PasswordAuthentication("myUser","myPass".toCharArray());
}
}
//0------------------------------

Then, in your code add the following:

System.getProperties().put("http.proxyHost", "myHost");
System.getProperties().put("http.proxyPort", "8080");
Authenticator.setDefault( new httpAuthProxy() );

Hope this helps
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic