devxlogo

Implementing a Proxy Selector in the Tiger Release of Tiger

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 select(URI uri)  {        //the proxy servers list    List proxys=new ArrayList();  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...");  } }

devx-admin

Share the Post: