Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java
          +++ new/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java
↓ open down ↓ 25 lines elided ↑ open up ↑
  26   26  
  27   27  import java.io.*;
  28   28  import java.net.*;
  29   29  import java.util.Hashtable;
  30   30  
  31   31  /**
  32   32   * CGIClientException is thrown when an error is detected
  33   33   * in a client's request.
  34   34   */
  35   35  class CGIClientException extends Exception {
       36 +    private static final long serialVersionUID = 8147981687059865216L;
  36   37  
  37   38      public CGIClientException(String s) {
  38   39          super(s);
  39   40      }
  40   41  }
  41   42  
  42   43  /**
  43   44   * CGIServerException is thrown when an error occurs here on the server.
  44   45   */
  45   46  class CGIServerException extends Exception {
  46   47  
       48 +    private static final long serialVersionUID = 6928425456704527017L;
       49 +
  47   50      public CGIServerException(String s) {
  48   51          super(s);
  49   52      }
  50   53  }
  51   54  
  52   55  /**
  53   56   * CGICommandHandler is the interface to an object that handles a
  54   57   * particular supported command.
  55   58   */
  56   59  interface CGICommandHandler {
↓ open down ↓ 47 lines elided ↑ open up ↑
 104  107  
 105  108      /* list of handlers for supported commands */
 106  109      private static CGICommandHandler commands[] = {
 107  110          new CGIForwardCommand(),
 108  111          new CGIGethostnameCommand(),
 109  112          new CGIPingCommand(),
 110  113          new CGITryHostnameCommand()
 111  114      };
 112  115  
 113  116      /* construct table mapping command strings to handlers */
 114      -    private static Hashtable commandLookup;
      117 +    private static Hashtable<String, CGICommandHandler> commandLookup;
 115  118      static {
 116      -        commandLookup = new Hashtable();
      119 +        commandLookup = new Hashtable<>();
 117  120          for (int i = 0; i < commands.length; ++ i)
 118  121              commandLookup.put(commands[i].getName(), commands[i]);
 119  122      }
 120  123  
 121  124      /* prevent instantiation of this class */
 122  125      private CGIHandler() {}
 123  126  
 124  127      /**
 125  128       * Execute command given in query string on URL.  The string before
 126  129       * the first '=' is interpreted as the command name, and the string
↓ open down ↓ 6 lines elided ↑ open up ↑
 133  136              int delim = QueryString.indexOf("=");
 134  137              if (delim == -1) {
 135  138                  command = QueryString;
 136  139                  param = "";
 137  140              }
 138  141              else {
 139  142                  command = QueryString.substring(0, delim);
 140  143                  param = QueryString.substring(delim + 1);
 141  144              }
 142  145              CGICommandHandler handler =
 143      -                (CGICommandHandler) commandLookup.get(command);
      146 +                commandLookup.get(command);
 144  147              if (handler != null)
 145  148                  try {
 146  149                      handler.execute(param);
 147  150                  } catch (CGIClientException e) {
 148  151                      returnClientError(e.getMessage());
 149  152                  } catch (CGIServerException e) {
 150  153                      returnServerError(e.getMessage());
 151  154                  }
 152  155              else
 153  156                  returnClientError("invalid command: " + command);
↓ open down ↓ 39 lines elided ↑ open up ↑
 193  196          System.out.println("<H1>Java RMI Server Error</H1>");
 194  197          System.out.println("");
 195  198          System.out.println(message);
 196  199          System.out.println("</BODY></HTML>");
 197  200          System.exit(1);
 198  201      }
 199  202  }
 200  203  
 201  204  /**
 202  205   * "forward" command: Forward request body to local port on the server,
 203      - * and send reponse back to client.
      206 + * and send response back to client.
 204  207   */
 205  208  final class CGIForwardCommand implements CGICommandHandler {
 206  209  
 207  210      public String getName() {
 208  211          return "forward";
 209  212      }
      213 +    
      214 +    @SuppressWarnings("deprecation")
      215 +    private String getLine (DataInputStream socketIn) throws IOException {
      216 +        return socketIn.readLine();
      217 +    }
 210  218  
 211  219      public void execute(String param) throws CGIClientException, CGIServerException
 212  220      {
 213  221          if (!CGIHandler.RequestMethod.equals("POST"))
 214  222              throw new CGIClientException("can only forward POST requests");
 215  223  
 216  224          int port;
 217  225          try {
 218  226              port = Integer.parseInt(param);
 219  227          } catch (NumberFormatException e) {
↓ open down ↓ 49 lines elided ↑ open up ↑
 269  277              socketIn = new DataInputStream(socket.getInputStream());
 270  278          } catch (IOException e) {
 271  279              throw new CGIServerException("error reading from server");
 272  280          }
 273  281          String key = "Content-length:".toLowerCase();
 274  282          boolean contentLengthFound = false;
 275  283          String line;
 276  284          int responseContentLength = -1;
 277  285          do {
 278  286              try {
 279      -                line = socketIn.readLine();
      287 +                line = getLine(socketIn);
 280  288              } catch (IOException e) {
 281  289                  throw new CGIServerException("error reading from server");
 282  290              }
 283  291              if (line == null)
 284  292                  throw new CGIServerException(
 285  293                      "unexpected EOF reading server response");
 286  294  
 287  295              if (line.toLowerCase().startsWith(key)) {
 288      -                if (contentLengthFound)
 289      -                    ; // what would we want to do in this case??
      296 +                if (contentLengthFound){
      297 +                    // what would we want to do in this case??
      298 +                }
 290  299                  responseContentLength =
 291  300                      Integer.parseInt(line.substring(key.length()).trim());
 292  301                  contentLengthFound = true;
 293  302              }
 294  303          } while ((line.length() != 0) &&
 295  304                   (line.charAt(0) != '\r') && (line.charAt(0) != '\n'));
 296  305  
 297  306          if (!contentLengthFound || responseContentLength < 0)
 298  307              throw new CGIServerException(
 299  308                  "missing or invalid content length in server response");
↓ open down ↓ 102 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX