• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Detecting browser proxy settings

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I need to get the proxy setting details before accessing any url using URL class (java net package).

In jdk 1.5 there is a class called ProxySelector, which is supposed to do the job. But it is failing.

Below is source code iam trying

package com.httpclient;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

public class testURL {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedInputStream in;

HttpURLConnection conn;
BufferedReader bin;
URL u;
String fileContents="";
try {
ProxySelector ps = ProxySelector.getDefault();
URL url = new URL("http://google.com");
URLConnection connection = url.openConnection();
List proxyList = ps.select(connection.getURL().toURI());


int len = proxyList.size();
System.out.println("size : "+ len);
for (int i = 0; i < len; i++) {
Proxy p = (Proxy) proxyList.get(i);
InetSocketAddress addr = (InetSocketAddress) p.address();
if (addr == null) {
System.out.println("MANUAL");
}

else {
InetAddress ip_addr = addr.getAddress();

int tcp_port = addr.getPort();
// Use the specified IP and port number as the proxy

System.out.println("IP ADDR " + ip_addr + "tcp_port " + tcp_port);
}
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

Please help on solving this issue. Immediate response will be of very useful.

thanks in advance.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try adding the system property, like this

[ November 15, 2005: Message edited by: Simon Havenith ]
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is this not working (JDK-1.5 option)?

How to detect Proxy Settings for Internet Connection
http://www.java-tips.org/content/view/546/2/
 
Simon Havenith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works for me. What issues are you having?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic