Ignore:
Timestamp:
02/13/14 11:28:18 (11 years ago)
Author:
pharms
Message:
Location:
trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListener.java

    r1374 r1382  
    4444/** 
    4545 * <p> 
    46  * TODO comment 
     46 * recording an exchange can not be done in one step. This is due to the fact, that the proxy 
     47 * servlet notifies different processing states for requests and response. An exchange listener 
     48 * records all these event. On the occurrence of the final event, it compiles an 
     49 * {@link HttpExchange} and forwards it to the exchange handler. 
    4750 * </p> 
    4851 *  
     
    5255     
    5356    /** 
    54      *  
     57     * <p> 
     58     * the exchange handler to forward compiles exchanges to 
     59     * </p> 
    5560     */ 
    5661    private HttpMonitorExchangeHandler exchangeHandler; 
    5762     
    5863    /** 
    59      *  
     64     * <p> 
     65     * the request of compiled exchange 
     66     * </p> 
    6067     */ 
    6168    private HttpServletRequest request; 
    6269 
    6370    /** 
    64      *  
     71     * <p> 
     72     * the content of the request of compiled exchange 
     73     * </p> 
    6574     */ 
    6675    private List<ByteBuffer> requestData = new LinkedList<ByteBuffer>(); 
    6776     
    6877    /** 
    69      *  
     78     * <p> 
     79     * the response of compiled exchange 
     80     * </p> 
    7081     */ 
    7182    private HttpServletResponse response; 
    7283 
    7384    /** 
    74      *  
     85     * <p> 
     86     * the content of the response of compiled exchange 
     87     * </p> 
    7588     */ 
    7689    private List<ByteBuffer> responseData = new LinkedList<ByteBuffer>(); 
    7790     
    7891    /** 
    79      *  
     92     * <p> 
     93     * the last time an event for the exchange was received (used for supporting timeouts) 
     94     * </p> 
    8095     */ 
    8196    private long lastUpdate = System.currentTimeMillis(); 
    8297     
    8398    /** 
    84      * 
     99     * <p> 
     100     * initialized the exchange listener with the exchange handler to forward compiled exchanges to 
     101     * </p> 
     102     *  
     103     * @param exchangeHandler the exchange handler to forward compiled exchanges to 
    85104     */ 
    86105    ExchangeListener(HttpMonitorExchangeHandler exchangeHandler) { 
     
    89108 
    90109    /** 
    91      *  
     110     * <p> 
     111     * called, when the request was received by the proxy 
     112     * </p> 
     113     *  
     114     * @param request the request of the exchange 
    92115     */ 
    93116    public void onRequest(HttpServletRequest request) throws IllegalStateException { 
     
    103126 
    104127    /** 
    105      *  
     128     * <p> 
     129     * called, when some content of the request was processed by the proxy 
     130     * </p> 
     131     *  
     132     * @param data the processed content of the request of the exchange 
    106133     */ 
    107134    public void onRequestContent(ByteBuffer data) { 
     
    117144     
    118145    /** 
    119      *  
     146     * <p> 
     147     * called, when the response is to be returned by the proxy 
     148     * </p> 
     149     *  
     150     * @param response the response of the exchange 
    120151     */ 
    121152    public void onResponse(HttpServletResponse response) { 
     
    131162     
    132163    /** 
    133      *  
     164     * <p> 
     165     * called, when some content of the response was processed by the proxy 
     166     * </p> 
     167     *  
     168     * @param data the processed content of the response of the exchange 
    134169     */ 
    135170    public void onResponseContent(ByteBuffer data) { 
     
    145180     
    146181    /** 
    147      *  
     182     * <p> 
     183     * called, when proxy finished proxying a request 
     184     * </p> 
     185     *  
     186     * @param status the status of the proxying after finalization 
    148187     */ 
    149188    public void onFinish(Status status) { 
     
    159198     
    160199    /** 
    161      * @return the request 
     200     * @return the request of the exchange 
    162201     */ 
    163202    HttpServletRequest getRequest() { 
     
    166205 
    167206    /** 
    168      * 
     207     * @return the last time this listener received an event 
    169208     */ 
    170209    long getLastUpdate() { 
     
    173212 
    174213    /** 
    175      * 
     214     * <p> 
     215     * convenience method to compile an {@link HttpExchange} and send it to the exchange handler 
     216     * after finalization of the exchange. 
     217     * </p> 
     218     *  
     219     * @param status the status of the proxying after finalization 
    176220     */ 
    177221    private void sendToExchangeHandler(Status status) { 
     
    202246 
    203247    /** 
    204      * 
     248     * <p> 
     249     * convenience method to map an {@link HttpServletRequest} to an {@link HttpRequest} 
     250     * </p> 
    205251     */ 
    206252    private HttpRequest map(HttpServletRequest request, ObjectFactory eventObjectFactory) { 
     
    261307 
    262308    /** 
    263      * 
     309     * <p> 
     310     * convenience method to map an {@link HttpServletResponse} to an {@link HttpResponse} 
     311     * </p> 
    264312     */ 
    265313    private HttpResponse map(HttpServletResponse response, ObjectFactory eventObjectFactory) { 
     
    297345 
    298346    /** 
    299      * 
     347     * <p> 
     348     * convenience method to create a string out of recorded request or response content 
     349     * </p> 
    300350     */ 
    301351    private String createString(List<ByteBuffer> bufferList) { 
  • trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListenerManager.java

    r1381 r1382  
    3535/** 
    3636 * <p> 
    37  * TODO update comment 
    38  * The log manager handles different {@link HttpMonitorOutputWriter}s to perform the logging 
    39  * of recorded messages. It initializes a new writer if the first message for a specific 
    40  * client is received and it closes a writer if for a specific period of time no further message 
    41  * of the same client was received. The writers themselves consider log rotation. For handling 
    42  * messages, the {@link HttpMonitorExchangeHandler} mechanism provided by the 
    43  * {@link HttpMonitorServer} is used. 
     37 * {@link ExchangeListener}s need to be managed, as there is one instantiated for each proxied 
     38 * request/response. They need to be timed out, if for a longer time, no update is received. All 
     39 * this is done by the ExchangeListenerManager. 
    4440 * </p> 
    4541 *  
     
    5248 
    5349    /** 
     50     * <p> 
    5451     * the timeout after which a writer of an inactive client is closed 
     52     * </p> 
    5553     */ 
    5654    private static final int SESSION_TIMEOUT = 10 * 60 * 1000; 
    5755     
    5856    /** 
    59      *  
     57     * <p> 
     58     * the exchange handler forwarded to the exchange listeners 
     59     * </p> 
    6060     */ 
    6161    private HttpMonitorExchangeHandler exchangeHandler; 
    6262     
    6363    /** 
    64      * the mapping of client ids to the respective writers. 
     64     * <p> 
     65     * the mapping of requests handled by the proxy to the respective exchange listeners 
     66     * </p> 
    6567     */ 
    6668    private Map<HttpServletRequest, ExchangeListener> listeners; 
    6769 
    6870    /** 
    69      * a timer used to detect exchange timeouts 
     71     * <p> 
     72     * a timer used to detect exchange listener timeouts 
     73     * </p> 
    7074     */ 
    7175    private Timer listenerTimer; 
    7276 
    7377    /** 
    74      * 
    75      * 
     78     * <p> 
     79     * creates the exchange listener manager with the exchange handler to be forwarded to the 
     80     * exchange listeners 
     81     * </p> 
     82     *  
     83     * @param exchangeHandler the exchange handler to be forwarded to the exchange listeners 
    7684     */ 
    7785    ExchangeListenerManager(HttpMonitorExchangeHandler exchangeHandler) { 
     
    130138 
    131139    /** 
    132      *  
     140     * <p> 
     141     * called, when the request was received by the proxy. Calls the appropriate method on 
     142     * the exchange listener. 
     143     * </p> 
     144     *  
     145     * @param request the request of the exchange 
    133146     */ 
    134147    public void onRequest(HttpServletRequest request) throws IllegalStateException { 
     
    137150 
    138151    /** 
    139      *  
     152     * <p> 
     153     * called, when some content of the request was processed by the proxy. Calls the appropriate 
     154     * method on the exchange listener. 
     155     * </p> 
     156     *  
     157     * @param request the request of the exchange 
     158     * @param data    the processed content of the request of the exchange 
    140159     */ 
    141160    public void onRequestContent(HttpServletRequest request, ByteBuffer data) 
     
    146165 
    147166    /** 
    148      *  
     167     * <p> 
     168     * called, when the response is to be returned by the proxy. Calls the appropriate 
     169     * method on the exchange listener. 
     170     * </p> 
     171     *  
     172     * @param request  the request of the exchange 
     173     * @param response the response of the exchange 
    149174     */ 
    150175    public void onResponse(HttpServletRequest request, HttpServletResponse response) 
     
    155180 
    156181    /** 
    157      *  
     182     * <p> 
     183     * called, when some content of the response was processed by the proxy. Calls the appropriate 
     184     * method on the exchange listener. 
     185     * </p> 
     186     *  
     187     * @param request the request of the exchange 
     188     * @param data    the processed content of the response of the exchange 
    158189     */ 
    159190    public void onResponseContent(HttpServletRequest request, ByteBuffer data) 
     
    164195 
    165196    /** 
    166      *  
     197     * <p> 
     198     * called, when proxy finished proxying a request. Calls the appropriate method on the 
     199     * exchange listener and afterwards cleans up the listener. 
     200     * </p> 
     201     *  
     202     * @param request the request of the exchange 
     203     * @param status  the status of the proxying after finalization 
    167204     */ 
    168205    public void onFinish(HttpServletRequest request, Status status) throws IllegalStateException { 
     
    173210 
    174211    /** 
    175      * 
     212     * <p> 
     213     * convenience method to ensure a listener for a specific HTTP servlet request to be handled. 
     214     * </p> 
    176215     */ 
    177216    private ExchangeListener ensureListener(HttpServletRequest request) { 
     
    194233    /** 
    195234     * <p> 
    196      * internal timer task used for detecting session timeouts of clients 
     235     * internal timer task used for detecting exchange timeouts 
    197236     * </p> 
    198237     *  
  • trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java

    r1381 r1382  
    3434import org.eclipse.jetty.util.thread.QueuedThreadPool; 
    3535 
     36import de.ugoe.cs.autoquest.httpmonitor.HttpMonitor; 
    3637import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent; 
    3738import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorException; 
     
    4344/** 
    4445 * <p> 
    45  * TODO comment 
     46 * If the exchanges recorded by the proxy are to be transmitted to a central {@link HttpMonitor}, 
     47 * this exchanges handler is used. It is called by the exchange listener on completion of a proxied 
     48 * request/response. It then creates an HTTP request to the central monitor and sends it there. 
     49 * It is initialized with the name of the server and the port on which the central monitor runs. 
     50 * If the exchanges can not be forwarded to the central server, they are discarded. 
    4651 * </p> 
    4752 *  
     
    5560    private static final long serialVersionUID = 1L; 
    5661 
    57     /** */ 
     62    /** 
     63     * <p> 
     64     * the HTTP client used internally to send data to the central server 
     65     * </p> 
     66     */ 
    5867    private HttpClient httpClient; 
    5968     
    60     /** */ 
     69    /** 
     70     * <p> 
     71     * the host name of the central server 
     72     * </p> 
     73     */ 
    6174    private String httpMonitorServer; 
    6275     
    63     /** */ 
     76    /** 
     77     * <p> 
     78     * the port of the central server 
     79     * </p> 
     80     */ 
    6481    private int httpMonitorPort; 
    6582 
    66     /** */ 
     83    /** 
     84     * <p> 
     85     * a set of requests send to the central server for which the response was not received yet 
     86     * </p> 
     87     */ 
    6788    private Set<Request> openRequests = new HashSet<Request>(); 
    6889     
    6990    /** 
    7091     * <p> 
    71      * TODO: comment 
     92     * initializes the exchange handler with the host and port of the central server 
    7293     * </p> 
    7394     * 
    74      * @param httpMonitorServer2 
    75      * @param httpMonitorPort2 
     95     * @param httpMonitorServer the host name of the central server 
     96     * @param httpMonitorPort   the port of the central server 
    7697     */ 
    7798    public HttpMonitorRemoteExchangeHandler(String httpMonitorServer, int httpMonitorPort) { 
     
    187208 
    188209    /** 
    189      *  
     210     * <p> 
     211     * convenience method to create an initialize the utilized HTTP client 
     212     * </p> 
    190213     */ 
    191214    private HttpClient createHttpClient() { 
  • trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxy.java

    r1381 r1382  
    2828/** 
    2929 * <p> 
    30  * TODO comment 
    31  * The HTML monitor starts a web server ({@link HttpMonitorServer}) that receives log messages 
    32  * of the HTML monitor java script. These messages are logged using the 
    33  * {@link ExchangeListenerManager}. The class assures that on shutdown e.g. caused by CTRL-C the 
    34  * server and the log manager are stopped correctly. 
     30 * The HTTP monitory proxy monitor starts a web server ({@link HttpMonitorServer}) that receives 
     31 * proxies HTTP messages and response. Each exchange of a request and a response is forwarded to 
     32 * an exchange handler. The exchange handler is either a local log manager 
     33 * ({@link HttpMonitorLogManager}) or a connection to an external and central HTTP monitor via 
     34 * an {@link HttpMonitorRemoteExchangeHandler}. The class ensures that on shutdown e.g. caused 
     35 * by CTRL-C the server and all other requied components are stopped correctly. 
    3536 * </p> 
    3637 *  
     
    4849     
    4950    /** 
    50      * the web server receiving the log messages 
     51     * the web server receiving the HTTP requests to be proxied 
    5152     */ 
    5253    private HttpMonitorServer server; 
    5354     
    5455    /** 
    55      * the web server receiving the log messages 
     56     * the manager for all currently recorded exchanges 
    5657     */ 
    5758    private ExchangeListenerManager exchangeListenerManager; 
    5859     
    5960    /** 
    60      *  
     61     *  the exchange handler to handle are request/response combinations, i.e., exchanges 
    6162     */ 
    6263    private HttpMonitorExchangeHandler exchangeHandler; 
     
    7273    private Thread shutdownHook; 
    7374 
    74     /** */ 
     75    /** 
     76     * the name of the proxied server 
     77     */ 
    7578    private String proxiedServer; 
    7679     
    77     /** */ 
     80    /** 
     81     * the port of the proxied server 
     82     */ 
    7883    private int proxiedPort; 
    7984     
    80     /** */ 
     85    /** 
     86     * the name of the server where the HTTP monitor runs if the exchanges are not logged locally 
     87     */ 
    8188    private String httpMonitorServer; 
    8289     
    83     /** */ 
     90    /** 
     91     * the port of the server where the HTTP monitor runs if the exchanges are not logged locally 
     92     */ 
    8493    private int httpMonitorPort; 
    8594     
    8695    /** 
    8796     * <p> 
    88      * initializes the monitor with the command line arguments. Those may be the log directory 
    89      * as first argument and the port to listen on as second 
     97     * initializes the proxy with the command line arguments. Those are the log directory 
     98     * as first argument, the port to listen to as second argument, the proxied server and port 
     99     * as third argument, and either the server and port of the HTTP monitor or the term local as 
     100     * fourth argument. If the term local is provided as fourth argument, logging of exchanges 
     101     * takes place locally. 
    90102     * </p> 
    91103     * 
  • trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxyServlet.java

    r1374 r1382  
    3434/** 
    3535 * <p> 
    36  * TODO document 
    37  * the servlet deployed in the web server that receives all client messages and returns the client 
    38  * java script. The messages are parsed, validated, and forwarded to the provided message listener. 
    39  * If a message is not valid, it is discarded. If an event in a message is not valid, it is 
    40  * discarded. Messages are only received via the POST HTTP method. The GET HTTP method is only 
    41  * implemented for returning the client java script. 
     36 * the servlet deployed in the web server of the proxy that proxies all incoming messages and 
     37 * forwards a copy of recorded exchanges to the exchange listener manager. It is based on the 
     38 * proxy servlet provided by jetty. It extends the servlet and implements all hooks required to  
     39 * get access to the exchanged requests and responses. Each hook forwards the tracked data to the 
     40 * exchange listener. On exchange completion, the exchange listener ensures a logging of the 
     41 * recorded exchange. 
    4242 * </p> 
    4343 *  
     
    4949    private static final long serialVersionUID = 1L; 
    5050 
    51     /** */ 
     51    /** 
     52     * the proxied server 
     53     */ 
    5254    private String proxiedServer; 
    5355     
    54     /** */ 
     56    /** 
     57     * the port of the proxied server 
     58     */ 
    5559    private int proxiedPort; 
    5660 
    57     /** */ 
     61    /** 
     62     * the exchange listener to handle the different events happening when an exchange is proxied 
     63     */ 
    5864    private ExchangeListenerManager exchangeListenerManager; 
    5965     
    6066    /** 
    6167     * <p> 
    62      * initializes the servlet with the message listener to which all events shall be forwarded 
     68     * initializes the servlet with the proxied server and the exchange listener 
    6369     * </p> 
    6470     * 
    65      * @param messageListener the message listener that shall receive all client events 
     71     * @param proxiedServer           the proxied server 
     72     * @param proxiedPort             the port of the proxied server 
     73     * @param exchangeListenerManager the exchange listener to handle the different events 
     74     *                                happening when an exchange is proxied 
    6675     */ 
    6776    HttpMonitoringProxyServlet(String                  proxiedServer, 
     
    7584 
    7685    /* (non-Javadoc) 
    77      * @see org.eclipse.jetty.proxy.ProxyServlet#rewriteURI(javax.servlet.http.HttpServletRequest) 
     86     * @see org.eclipse.jetty.proxy.ProxyServlet#rewriteURI(HttpServletRequest) 
    7887     */ 
    7988    @Override 
     
    91100 
    92101    /* (non-Javadoc) 
    93      * @see org.eclipse.jetty.proxy.ProxyServlet#customizeProxyRequest(org.eclipse.jetty.client.api.Request, javax.servlet.http.HttpServletRequest) 
     102     * @see org.eclipse.jetty.proxy.ProxyServlet#customizeProxyRequest(Request, HttpServletRequest) 
    94103     */ 
    95104    @Override 
     
    102111 
    103112    /* (non-Javadoc) 
    104      * @see org.eclipse.jetty.proxy.ProxyServlet#onResponseContent(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.eclipse.jetty.client.api.Response, byte[], int, int) 
     113     * @see ProxyServlet#onResponseContent(HttpServletRequest, HttpServletResponse, Response, byte[], int, int) 
    105114     */ 
    106115    @Override 
     
    119128 
    120129    /* (non-Javadoc) 
    121      * @see org.eclipse.jetty.proxy.ProxyServlet#onResponseSuccess(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.eclipse.jetty.client.api.Response) 
     130     * @see ProxyServlet#onResponseSuccess(HttpServletRequest, HttpServletResponse, Response) 
    122131     */ 
    123132    @Override 
     
    133142 
    134143    /* (non-Javadoc) 
    135      * @see org.eclipse.jetty.proxy.ProxyServlet#onResponseFailure(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.eclipse.jetty.client.api.Response, java.lang.Throwable) 
     144     * @see ProxyServlet#onResponseFailure(HttpServletRequest, HttpServletResponse, Response, Throwable) 
    136145     */ 
    137146    @Override 
     
    148157 
    149158    /** 
    150      * 
     159     * This content provided is required to copy the content of a proxied request. It uses 
     160     * delegation to wrap the original content provided but to also copy the data and forward 
     161     * it to the exchange listener manager. 
    151162     */ 
    152163    private class DubbingContentProvider implements ContentProvider { 
    153164 
    154         /** */ 
     165        /** 
     166         * the dubbed request 
     167         */ 
    155168        private HttpServletRequest request; 
    156169         
    157         /** */ 
     170        /** 
     171         * the original content provider of which the data is copied  
     172         */ 
    158173        private ContentProvider delegate; 
    159174 
    160175        /** 
    161          * 
     176         * initializes this content provider with the copied request and the delegate. 
    162177         */ 
    163178        public DubbingContentProvider(HttpServletRequest request, ContentProvider delegate) { 
     
    185200 
    186201    /** 
    187      * 
     202     * This iterator is used to implement the {@link DubbingContentProvider}. It works in the  
     203     * same manner and uses delegation for wrapping the original iterator and forwards all copied 
     204     * data to the exchange listener manager. 
    188205     */ 
    189206    public class DubbingByteBufferIterator implements Iterator<ByteBuffer> { 
    190207 
    191         /** */ 
     208        /** 
     209         * the dubbed request 
     210         */ 
    192211        private HttpServletRequest request; 
    193212         
    194         /** */ 
     213        /** 
     214         * the original iterator of which the data is copied  
     215         */ 
    195216        private Iterator<ByteBuffer> delegate; 
    196217         
    197218        /** 
    198          * 
     219         * initializes this iterator with the copied request and the delegate. 
    199220         */ 
    200221        public DubbingByteBufferIterator(HttpServletRequest request, Iterator<ByteBuffer> delegate) { 
Note: See TracChangeset for help on using the changeset viewer.