aspose file tools*
The moose likes Servlets and the fly likes Bypass proxy to access local network URLs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Bypass proxy to access local network URLs" Watch "Bypass proxy to access local network URLs" New topic
Author

Bypass proxy to access local network URLs

Ashraf Fouad
Ranch Hand

Joined: Oct 07, 2001
Posts: 80
Dears,
I have a web application deployed on application server Oracle 9i AppServer -I don't think the application server has

anything to do with my problem-, it calls other web application through HTTP, on the local network, the other application

servers are hosted on windows platform and/or Unix platform.

All these machine can access Internet through proxy server, but there are no proxy or firewalls between them, so everything

is openned between the machines in the local network.

When I try to connect from one machine to another using the following code, I find that it always request proxy

authentication, which I would like to bypass.
The error says: http request returned error code 407


package com.rsw.common.net;

import java.net.*;
import java.io.*;
import java.util.Properties;
public class UrlConnector
{
public void connect(String url,String[] params, String[] values )
{
try
{
URL l_URL = new URL(url);
URLConnection l_URLConnection = l_URL.openConnection();
l_URLConnection.setDoOutput(true);
l_URLConnection.setDoInput(true);
l_URLConnection.setUseCaches(false);
l_URLConnection.setRequestProperty("Method", "POST");
PrintWriter l_PrintWriter = new PrintWriter(l_URLConnection.getOutputStream());
String l_szParams ="";
if(params!=null)
{
if(params.length >=1)
l_szParams=params[0]+"="+URLEncoder.encode(values[0]);

for(int i=1;i<params.length;i++)
l_szParams+="&"+params[i]+"="+URLEncoder.encode(values[i]);

l_PrintWriter.println(l_szParams);
}
l_PrintWriter.close();
BufferedReader l_BufferedReader = new BufferedReader(new InputStreamReader(l_URLConnection.getInputStream()));
String l_szResponseLine = "";
String l_szURLResponse;
for ( l_szURLResponse = "";
(l_szResponseLine = l_BufferedReader.readLine()) != null;
l_szURLResponse = l_szURLResponse + l_szResponseLine );

l_BufferedReader.close();
System.out.println(l_szURLResponse);
}
catch(Exception l_exception)
{
System.out.println(l_exception.getMessage());
}
}
}


I found that what I need is similar to setting in Internet Explorer to bypass proxy for addresses starting with ..... But

I don't know how to apply this to my code? I'm using JDK 1.3.1

Anyone can help, I'm open to use any libary that overcome this problem.

Thanks, in advance


Ashraf Fouad
SCJP 1.2, SCBCD 5
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
I believe the system property you're looking for is http.nonProxyHosts. You can find out more at...

http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html


James Carman, President<br />Carman Consulting, Inc.
Ashraf Fouad
Ranch Hand

Joined: Oct 07, 2001
Posts: 80
Thanks very much it worked great

Thanks for fast reply
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bypass proxy to access local network URLs
 
Similar Threads
Simulating Post in Java code.....
help: need help for post
Imp-How to execute a JSP file from java main
HTML form created by Java
How create URL object with GET parameters?