View RSS Feed

My Java Tips

Testing supported protocols

Rate this Entry
by , 11-03-2011 at 12:13 PM (637 Views)
Consider the following scenario: You are asked to test your browser with a list of protocols. So, you can do this by making URL objects for a host with each protocol. If object is created, it means protocol is supported, in other case, it simply means that the browser does not support the particular protocol.




Review the applet code below:

Java Code:
public class ProtocolTesterApplet extends Applet {

  TextArea results = new TextArea( );  

  public void init( ) {

    this.setLayout(new BorderLayout( ));    

    this.add("Center", results);

  }

  public void start( ) {
    String host = "http://content-uk.cricinfo.com";
    String file = "/ci/content/current/story/index.html";

    String[] schemes = {"http", "https", "ftp", "mailto",
                        "telnet", "file",    "ldap", "gopher",
                        "jdbc",   "rmi",     "jndi", "jar",
                        "doc",    "netdoc",  "nfs",  "verbatim",
                        "finger", "daytime", "systemresource"};

    for (int i = 0; i < schemes.length; i++) {
      try {

        URL u = new URL(schemes[i], host, file);
        results.append(schemes[i] + " is supportedrn");
      }

      catch (MalformedURLException ex) {

        results.append(schemes[i] + " is not supportedrn");      

      }
    }
  }

}

Submit "Testing supported protocols" to Facebook Submit "Testing supported protocols" to Digg Submit "Testing supported protocols" to del.icio.us Submit "Testing supported protocols" to StumbleUpon Submit "Testing supported protocols" to Google

Tags: None Add / Edit Tags
Categories
Network Programming

Comments