• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

HttpClient: Detect Proxy Settings or Configuration Script from HttpClient

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

We have an intranet link which can be accessed only if the configuration script (http://XXXXX/proxy.pac) is selected in IE. I want to connect to this link using jakarta HttpClient. I am getting connection refused error when tried to connect using proxy server mentioned in .pac file.
-----------
loginURL = "http://login.url.com";
proxyURL = "proxyserver.com";

client = new HttpClient();
hostConfig = client.getHostConfiguration();
hostConfig.setProxy(proxyURL, 8080);
get = new GetMethod(loginURL);
statusCode = client.executeMethod(get);
-------

Is it possible to open this link using configuration script directly from HttpClient?

If so, could someone please provide a sample code to use this configuration script and connet to the link. I have searched for solution in google, but no where available.


Thanks in advance,
Yadu
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From memory, the pac file is a text configuration file. Have you tried reading the file and configuring HttpClient manually?
 
Yadunandan srirama
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have opened the configuration link (http://XXXXX/proxy.pac) in browser. It contains below method in which the proxy server is mentioned for the login url.

function FindProxyForURL (url, host) {
if (shExpMatch(host,"login*.url.com"))
return "PROXY proxyserver.com; PROXY proxyserver1.com;PROXY proxyserver2.com";


if (dnsDomainIs(host, ".aaa.net"))
return "PROXY 123.45.67.8;PROXY 123.45.67.9";
......
......

}

Can we use this configuration script link (http://XXXXX/proxy.pac) directly and connect using HttpClient?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PAC is used by user agents to automatically select the right proxy based on the return values given by the javascript function.

In your case, the HttpClient won't be knowing how to interpret it I guess. You have to write the logic necessary to interpret the response and then connect using the right proxy.

But you state that even though you are hard coding the right proxy within your program, the connection is being refused. So check the parameters you are passing.

Are your proxy credentials correct, if any? Whats the HTTP status code you are getting?

Here are a few programs that work with PAC files. You can use them for testing your problem or analyze the code.

http://code.google.com/p/pacparser/
http://code.google.com/p/pactester/

Hope it helps
[ May 29, 2008: Message edited by: Prakash Subramanian ]
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my pac file

function FindProxyForURL(url, host)
{
var returnValue = "DIRECT";

//Show request
//alert("FindProxyForURL url=" + url + " host=" + host);

// Plain host name (including "localhost")
if (isPlainHostName(host))
returnValue = "DIRECT";


// Return value
return returnValue;
}

function hashProxy(address)
{

var n = URLhash2(address) % 2;

if (n < 1)
return "PROXY 192.168.100.6:8080; " +
"PROXY 192.168.100.62:8080";
if (n < 2)
return "PROXY 192.168.100.62:8080; " +
"PROXY 192.168.100.6:8080";
}

function URLhash2(name)
{
var cnt=0;
var dirptr=0;

var str=name.toLowerCase(name);
if ( str.length ==0) {
return cnt;
}

/* skip filename in directory */
for(var i=str.length - 1;i >=0 ; i--) {
if ( str.substring(i,i +1) == '/' ) {
dirptr = i+1 ;
break;
}
}

for(var i=0;i < dirptr; i++) {
var ch= atoi(str.substring(i,i + 1));
cnt = cnt + ch;
}

return cnt ;
}


function atoi(charstring)
{

if ( charstring == "a" ) return 0x61; if ( charstring == "b" ) return 0x62;
if ( charstring == "c" ) return 0x63; if ( charstring == "d" ) return 0x64;
if ( charstring == "e" ) return 0x65; if ( charstring == "f" ) return 0x66;
if ( charstring == "g" ) return 0x67; if ( charstring == "h" ) return 0x68;
if ( charstring == "i" ) return 0x69; if ( charstring == "j" ) return 0x6a;
if ( charstring == "k" ) return 0x6b; if ( charstring == "l" ) return 0x6c;
if ( charstring == "m" ) return 0x6d; if ( charstring == "n" ) return 0x6e;
if ( charstring == "o" ) return 0x6f; if ( charstring == "p" ) return 0x70;
if ( charstring == "q" ) return 0x71; if ( charstring == "r" ) return 0x72;
if ( charstring == "s" ) return 0x73; if ( charstring == "t" ) return 0x74;
if ( charstring == "u" ) return 0x75; if ( charstring == "v" ) return 0x76;
if ( charstring == "w" ) return 0x77; if ( charstring == "x" ) return 0x78;
if ( charstring == "y" ) return 0x79; if ( charstring == "z" ) return 0x7a;
if ( charstring == "0" ) return 0x30; if ( charstring == "1" ) return 0x31;
if ( charstring == "2" ) return 0x32; if ( charstring == "3" ) return 0x33;
if ( charstring == "4" ) return 0x34; if ( charstring == "5" ) return 0x35;
if ( charstring == "6" ) return 0x36; if ( charstring == "7" ) return 0x37;
if ( charstring == "8" ) return 0x38; if ( charstring == "9" ) return 0x39;
if ( charstring == "." ) return 0x2e;
return 0x20;
}



This is my proxey file when it going to come at point isPlainHostName() it's showing me this function is not avaliable so can any budy help me with this.



can any budy tell me how to read .pac file using java.
 
No holds barred. And no bars holed. Except this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic