Changeset 19


Ignore:
Timestamp:
Aug 14, 2012 8:54:59 PM (5 years ago)
Author:
psaiteja
Message:

made minor changes to the comments and removed some unnecessary code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • VSNClient/appClientModule/jProxy.java

    r17 r19  
    1 /* <!-- in case someone opens this in a browser... --> <pre> */ 
    2 /* 
    3  * This is a simple multi-threaded Java proxy server 
    4  * for HTTP requests (HTTPS doesn't seem to work, because 
    5  * the CONNECT requests aren't always handled properly). 
    6  * I implemented the class as a thread so you can call it  
    7  * from other programs and kill it, if necessary (by using  
    8  * the closeSocket() method). 
    9  * 
    10  * We'll call this the 1.1 version of this class. All I  
    11  * changed was to separate the HTTP header elements with 
    12  * \r\n instead of just \n, to comply with the official 
    13  * HTTP specification. 
    14  *   
    15  * This can be used either as a direct proxy to other 
    16  * servers, or as a forwarding proxy to another proxy 
    17  * server. This makes it useful if you want to monitor 
    18  * traffic going to and from a proxy server (for example, 
    19  * you can run this on your local machine and set the 
    20  * fwdServer and fwdPort to a real proxy server, and then 
    21  * tell your browser to use "localhost" as the proxy, and 
    22  * you can watch the browser traffic going in and out). 
    23  * 
    24  * One limitation of this implementation is that it doesn't  
    25  * close the ProxyThread socket if the client disconnects 
    26  * or the server never responds, so you could end up with 
    27  * a bunch of loose threads running amuck and waiting for 
    28  * connections. As a band-aid, you can set the server socket 
    29  * to timeout after a certain amount of time (use the 
    30  * setTimeout() method in the ProxyThread class), although 
    31  * this can cause false timeouts if a remote server is simply 
    32  * slow to respond. 
    33  * 
    34  * Another thing is that it doesn't limit the number of 
    35  * socket threads it will create, so if you use this on a 
    36  * really busy machine that processed a bunch of requests, 
    37  * you may have problems. You should use thread pools if 
    38  * you're going to try something like this in a "real" 
    39  * application. 
    40  * 
    41  * Note that if you're using the "main" method to run this 
    42  * by itself and you don't need the debug output, it will 
    43  * run a bit faster if you pipe the std output to 'nul'. 
    44  * 
    45  * You may use this code as you wish, just don't pretend  
    46  * that you wrote it yourself, and don't hold me liable for  
    47  * anything that it does or doesn't do. If you're feeling  
    48  * especially honest, please include a link to nsftools.com 
    49  * along with the code. Thanks, and good luck. 
    50  * 
    51  * Julian Robichaux -- http://www.nsftools.com 
    52  */ 
    531import java.io.*; 
    542import java.net.*; 
     
    415363                                                rs.close(); 
    416364 
    417                                         } catch (Exception e) { 
     365                                        } catch (SQLException e) { 
    418366                                                e.printStackTrace(); 
    419367                                        } 
     
    422370                                // tell the client there was an error 
    423371                                System.out.println("Error connecting to the server"); 
    424                                 String errMsg = "HTTP/1.0 503 Service Unavailable\r\nContent Type: text/plain\r\n" +  
    425                                                                 "<html><body>Error connecting to the server:\n" + e + "\n</body></html>\r\n"; 
     372                                String errMsg_body = "<html><head><title>503 Service Temporarily Unavailable</title></head>"+ 
     373                                        "<body><h1>VSN ERROR MESSAGE: Service Temporarily Unavailable</h1>"+ 
     374                                        "<p>The server("+hostName+") is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.</p>"+ 
     375                                        "</body></html>\r\n"; 
     376                                String errMsg_header = "HTTP/1.1 503 Service Unavailable\r\n"+ 
     377                                "Content-Type: text/html\r\n"+ 
     378                                                "Content-Length: "+errMsg_body.length()+"\r\n"+ 
     379                                        "Connection: close\r\n\r\n"; 
     380                                String errMsg = errMsg_header+errMsg_body; 
     381                                 
    426382                                clientOut.write(errMsg.getBytes(), 0, errMsg.length()); 
    427383                        } 
     
    684640                                        contentLength = Integer.parseInt(data.substring(pos + 15) 
    685641                                                        .trim()); 
    686                         } 
     642                        }                        
    687643                         
    688644                        if(url.toString().startsWith(host.toString()) || url.toString().startsWith("http://"+host.toString())){ 
Note: See TracChangeset for help on using the changeset viewer.