Ignore:
Timestamp:
10/15/12 14:53:44 (12 years ago)
Author:
pharms
Message:
  • changed implementation so that java script is served by server itself and that it determines the servers location through its own URL
Location:
trunk/autoquest-htmlmonitor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-htmlmonitor

    • Property svn:ignore set to
      target
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServlet.java

    r873 r879  
    11package de.ugoe.cs.autoquest.htmlmonitor; 
    22 
     3import java.io.BufferedReader; 
    34import java.io.IOException; 
     5import java.io.InputStream; 
    46import java.io.InputStreamReader; 
     7import java.io.PrintWriter; 
    58import java.net.MalformedURLException; 
    69import java.net.URL; 
     
    2427/** 
    2528 * <p> 
    26  * the servlet deployed in the web server that receives all client messages. The messages are 
    27  * parsed, validated, and forwarded to the provided message listener. If a message is not valid, 
    28  * it is discarded. If an event in a message is not valid, it is discarded. Messages are only 
    29  * received via the POST HTTP method. 
     29 * the servlet deployed in the web server that receives all client messages and returns the client 
     30 * java script. The messages are parsed, validated, and forwarded to the provided message listener. 
     31 * If a message is not valid, it is discarded. If an event in a message is not valid, it is 
     32 * discarded. Messages are only received via the POST HTTP method. The GET HTTP method is only 
     33 * implemented for returning the client java script. 
    3034 * </p> 
    3135 *  
     
    3741    private static final long serialVersionUID = 1L; 
    3842     
     43    /**  */ 
     44    private static final boolean DO_TRACE = false; 
     45     
    3946    /** 
    4047     * the message listener to forward received messages to. 
     
    5158    HtmlMonitorServlet(HtmlMonitorMessageListener messageListener) { 
    5259        this.messageListener = messageListener; 
     60    } 
     61 
     62    /* (non-Javadoc) 
     63     * @see org.mortbay.jetty.servlet.DefaultServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) 
     64     */ 
     65    @Override 
     66    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
     67        throws ServletException, IOException 
     68    { 
     69        if ((request.getPathInfo() != null) && 
     70            (request.getPathInfo().endsWith("/script/autoquest-htmlmonitor.js"))) 
     71        { 
     72            InputStream script = null; 
     73             
     74            try { 
     75                script = this.getClass().getClassLoader().getResourceAsStream 
     76                     ("autoquest-htmlmonitor.js"); 
     77             
     78                if (script == null) { 
     79                    Console.printerrln("could not read autoquest-htmlmonitor.js from classpath"); 
     80                } 
     81                else { 
     82                    BufferedReader reader = new BufferedReader(new InputStreamReader(script)); 
     83                    PrintWriter output = response.getWriter(); 
     84                    String line; 
     85                     
     86                    while ((line = reader.readLine()) != null) { 
     87                        output.println(line); 
     88                    } 
     89                     
     90                    output.close(); 
     91                } 
     92            } 
     93            catch (Exception e) { 
     94                Console.printerrln("could not read autoquest-htmlmonitor.js from classpath: " + e); 
     95                Console.logException(e); 
     96            } 
     97            finally { 
     98                if (script != null) { 
     99                    script.close(); 
     100                } 
     101            } 
     102        } 
    53103    } 
    54104 
     
    87137     */ 
    88138    private void handleJSONObject(JSONObject object) { 
    89         dumpJSONObject(object, ""); 
     139        if (DO_TRACE) { 
     140            dumpJSONObject(object, ""); 
     141        } 
    90142         
    91143        JSONObject message = assertValue(object, "message", JSONObject.class); 
Note: See TracChangeset for help on using the changeset viewer.