Proxy Server

This application is the Java proxy server. It resides in the cgi-bin directory with the script snoopy. It passes a request received from K.class to a specified URL and returns results to K.class and to a file "file.test" which resides in cgi-bin.

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

public class Websnoop
{
   public static String urldecode(String str)
   {
      StringBuffer out = new StringBuffer(str.length());
      for (int i=0 ; i < str.length() ; i++)
      {
         if (str.charAt(i) == '\\') i++;
         out.append(str.charAt(i));
      }
      return new String(out);
   }
      

   public static void getIt(String a)
   {
      PrintStream os;
      URL s;

      System.out.println("Content-type: text/html\n\n");

      try
      {
         s = new URL(a);

         os = new PrintStream(new FileOutputStream("file.test"));
         DataInputStream in = new DataInputStream(s.openStream());

         String str = in.readLine();
         os.print(str);
         os.print("\n");
         System.out.println(str);
         while (str != null)
         {
            str = in.readLine();
            os.print(str);
            os.print("\n");
            System.out.println(str);
         }
      }
      catch(IOException ex)
      {
         System.out.println("Error:"+ex+"\n");
      }
   }

   public static void main(String arg[])
   {
      try
      {
         getIt(urldecode(arg[0]));
         System.out.println("Query1:"+urldecode(arg[0]));
      }
      catch (ArrayIndexOutOfBoundsException e) { System.out.println(e); }
   }
}