Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Advanced
Apr 5, 2006

Implementing a Proxy Selector in the Tiger Release of Tiger

Use this code to implement a proxy selector class in the Tiger release of Tiger:

import java.net.*;
import java.util.*;
import java.io.*;

public class MyProxySelector extends ProxySelector{
  
//implement the select method
  public List<java.net.Proxy> select(URI uri)
  {      
  //the proxy servers list  
  List<java.net.Proxy> proxys=new ArrayList<java.net.Proxy>();
  if((uri.getHost()).equals("www.yahoo.com"))
   {
   try{
      InetAddress addr=InetAddress.getLocalHost();
      InetSocketAddress ISA=new InetSocketAddress(addr,808);
      java.net.Proxy proxy=new java.net.Proxy
                                java.net.Proxy.Type.HTTP,ISA);
      proxys.add(proxy);
     }catch(java.net.UnknownHostException e)
            {System.out.println(e.getMessage());}
    }    
    else 
      System.out.println("Unknown address...");
    
    return proxys;    
  }
  
  //the connectFailed method
  public void connectFailed(URI uri, SocketAddress address, IOException ex)
  {
  System.out.println(uri.getHost());
  System.out.println("Fatal error...");
  } 
}
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date