Changeset 1382 for trunk/autoquest-httpmonitor
- Timestamp:
- 02/13/14 11:28:18 (11 years ago)
- 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 44 44 /** 45 45 * <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. 47 50 * </p> 48 51 * … … 52 55 53 56 /** 54 * 57 * <p> 58 * the exchange handler to forward compiles exchanges to 59 * </p> 55 60 */ 56 61 private HttpMonitorExchangeHandler exchangeHandler; 57 62 58 63 /** 59 * 64 * <p> 65 * the request of compiled exchange 66 * </p> 60 67 */ 61 68 private HttpServletRequest request; 62 69 63 70 /** 64 * 71 * <p> 72 * the content of the request of compiled exchange 73 * </p> 65 74 */ 66 75 private List<ByteBuffer> requestData = new LinkedList<ByteBuffer>(); 67 76 68 77 /** 69 * 78 * <p> 79 * the response of compiled exchange 80 * </p> 70 81 */ 71 82 private HttpServletResponse response; 72 83 73 84 /** 74 * 85 * <p> 86 * the content of the response of compiled exchange 87 * </p> 75 88 */ 76 89 private List<ByteBuffer> responseData = new LinkedList<ByteBuffer>(); 77 90 78 91 /** 79 * 92 * <p> 93 * the last time an event for the exchange was received (used for supporting timeouts) 94 * </p> 80 95 */ 81 96 private long lastUpdate = System.currentTimeMillis(); 82 97 83 98 /** 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 85 104 */ 86 105 ExchangeListener(HttpMonitorExchangeHandler exchangeHandler) { … … 89 108 90 109 /** 91 * 110 * <p> 111 * called, when the request was received by the proxy 112 * </p> 113 * 114 * @param request the request of the exchange 92 115 */ 93 116 public void onRequest(HttpServletRequest request) throws IllegalStateException { … … 103 126 104 127 /** 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 106 133 */ 107 134 public void onRequestContent(ByteBuffer data) { … … 117 144 118 145 /** 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 120 151 */ 121 152 public void onResponse(HttpServletResponse response) { … … 131 162 132 163 /** 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 134 169 */ 135 170 public void onResponseContent(ByteBuffer data) { … … 145 180 146 181 /** 147 * 182 * <p> 183 * called, when proxy finished proxying a request 184 * </p> 185 * 186 * @param status the status of the proxying after finalization 148 187 */ 149 188 public void onFinish(Status status) { … … 159 198 160 199 /** 161 * @return the request 200 * @return the request of the exchange 162 201 */ 163 202 HttpServletRequest getRequest() { … … 166 205 167 206 /** 168 * 207 * @return the last time this listener received an event 169 208 */ 170 209 long getLastUpdate() { … … 173 212 174 213 /** 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 176 220 */ 177 221 private void sendToExchangeHandler(Status status) { … … 202 246 203 247 /** 204 * 248 * <p> 249 * convenience method to map an {@link HttpServletRequest} to an {@link HttpRequest} 250 * </p> 205 251 */ 206 252 private HttpRequest map(HttpServletRequest request, ObjectFactory eventObjectFactory) { … … 261 307 262 308 /** 263 * 309 * <p> 310 * convenience method to map an {@link HttpServletResponse} to an {@link HttpResponse} 311 * </p> 264 312 */ 265 313 private HttpResponse map(HttpServletResponse response, ObjectFactory eventObjectFactory) { … … 297 345 298 346 /** 299 * 347 * <p> 348 * convenience method to create a string out of recorded request or response content 349 * </p> 300 350 */ 301 351 private String createString(List<ByteBuffer> bufferList) { -
trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListenerManager.java
r1381 r1382 35 35 /** 36 36 * <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. 44 40 * </p> 45 41 * … … 52 48 53 49 /** 50 * <p> 54 51 * the timeout after which a writer of an inactive client is closed 52 * </p> 55 53 */ 56 54 private static final int SESSION_TIMEOUT = 10 * 60 * 1000; 57 55 58 56 /** 59 * 57 * <p> 58 * the exchange handler forwarded to the exchange listeners 59 * </p> 60 60 */ 61 61 private HttpMonitorExchangeHandler exchangeHandler; 62 62 63 63 /** 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> 65 67 */ 66 68 private Map<HttpServletRequest, ExchangeListener> listeners; 67 69 68 70 /** 69 * a timer used to detect exchange timeouts 71 * <p> 72 * a timer used to detect exchange listener timeouts 73 * </p> 70 74 */ 71 75 private Timer listenerTimer; 72 76 73 77 /** 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 76 84 */ 77 85 ExchangeListenerManager(HttpMonitorExchangeHandler exchangeHandler) { … … 130 138 131 139 /** 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 133 146 */ 134 147 public void onRequest(HttpServletRequest request) throws IllegalStateException { … … 137 150 138 151 /** 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 140 159 */ 141 160 public void onRequestContent(HttpServletRequest request, ByteBuffer data) … … 146 165 147 166 /** 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 149 174 */ 150 175 public void onResponse(HttpServletRequest request, HttpServletResponse response) … … 155 180 156 181 /** 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 158 189 */ 159 190 public void onResponseContent(HttpServletRequest request, ByteBuffer data) … … 164 195 165 196 /** 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 167 204 */ 168 205 public void onFinish(HttpServletRequest request, Status status) throws IllegalStateException { … … 173 210 174 211 /** 175 * 212 * <p> 213 * convenience method to ensure a listener for a specific HTTP servlet request to be handled. 214 * </p> 176 215 */ 177 216 private ExchangeListener ensureListener(HttpServletRequest request) { … … 194 233 /** 195 234 * <p> 196 * internal timer task used for detecting session timeouts of clients235 * internal timer task used for detecting exchange timeouts 197 236 * </p> 198 237 * -
trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java
r1381 r1382 34 34 import org.eclipse.jetty.util.thread.QueuedThreadPool; 35 35 36 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitor; 36 37 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent; 37 38 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorException; … … 43 44 /** 44 45 * <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. 46 51 * </p> 47 52 * … … 55 60 private static final long serialVersionUID = 1L; 56 61 57 /** */ 62 /** 63 * <p> 64 * the HTTP client used internally to send data to the central server 65 * </p> 66 */ 58 67 private HttpClient httpClient; 59 68 60 /** */ 69 /** 70 * <p> 71 * the host name of the central server 72 * </p> 73 */ 61 74 private String httpMonitorServer; 62 75 63 /** */ 76 /** 77 * <p> 78 * the port of the central server 79 * </p> 80 */ 64 81 private int httpMonitorPort; 65 82 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 */ 67 88 private Set<Request> openRequests = new HashSet<Request>(); 68 89 69 90 /** 70 91 * <p> 71 * TODO: comment92 * initializes the exchange handler with the host and port of the central server 72 93 * </p> 73 94 * 74 * @param httpMonitorServer 275 * @param httpMonitorPort 295 * @param httpMonitorServer the host name of the central server 96 * @param httpMonitorPort the port of the central server 76 97 */ 77 98 public HttpMonitorRemoteExchangeHandler(String httpMonitorServer, int httpMonitorPort) { … … 187 208 188 209 /** 189 * 210 * <p> 211 * convenience method to create an initialize the utilized HTTP client 212 * </p> 190 213 */ 191 214 private HttpClient createHttpClient() { -
trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxy.java
r1381 r1382 28 28 /** 29 29 * <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. 35 36 * </p> 36 37 * … … 48 49 49 50 /** 50 * the web server receiving the log messages51 * the web server receiving the HTTP requests to be proxied 51 52 */ 52 53 private HttpMonitorServer server; 53 54 54 55 /** 55 * the web server receiving the log messages56 * the manager for all currently recorded exchanges 56 57 */ 57 58 private ExchangeListenerManager exchangeListenerManager; 58 59 59 60 /** 60 * 61 * the exchange handler to handle are request/response combinations, i.e., exchanges 61 62 */ 62 63 private HttpMonitorExchangeHandler exchangeHandler; … … 72 73 private Thread shutdownHook; 73 74 74 /** */ 75 /** 76 * the name of the proxied server 77 */ 75 78 private String proxiedServer; 76 79 77 /** */ 80 /** 81 * the port of the proxied server 82 */ 78 83 private int proxiedPort; 79 84 80 /** */ 85 /** 86 * the name of the server where the HTTP monitor runs if the exchanges are not logged locally 87 */ 81 88 private String httpMonitorServer; 82 89 83 /** */ 90 /** 91 * the port of the server where the HTTP monitor runs if the exchanges are not logged locally 92 */ 84 93 private int httpMonitorPort; 85 94 86 95 /** 87 96 * <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. 90 102 * </p> 91 103 * -
trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxyServlet.java
r1374 r1382 34 34 /** 35 35 * <p> 36 * TODO document37 * the servlet deployed in the web server that receives all client messages and returns the client38 * 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 is40 * discarded. Messages are only received via the POST HTTP method. The GET HTTP method is only41 * 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. 42 42 * </p> 43 43 * … … 49 49 private static final long serialVersionUID = 1L; 50 50 51 /** */ 51 /** 52 * the proxied server 53 */ 52 54 private String proxiedServer; 53 55 54 /** */ 56 /** 57 * the port of the proxied server 58 */ 55 59 private int proxiedPort; 56 60 57 /** */ 61 /** 62 * the exchange listener to handle the different events happening when an exchange is proxied 63 */ 58 64 private ExchangeListenerManager exchangeListenerManager; 59 65 60 66 /** 61 67 * <p> 62 * initializes the servlet with the message listener to which all events shall be forwarded68 * initializes the servlet with the proxied server and the exchange listener 63 69 * </p> 64 70 * 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 66 75 */ 67 76 HttpMonitoringProxyServlet(String proxiedServer, … … 75 84 76 85 /* (non-Javadoc) 77 * @see org.eclipse.jetty.proxy.ProxyServlet#rewriteURI( javax.servlet.http.HttpServletRequest)86 * @see org.eclipse.jetty.proxy.ProxyServlet#rewriteURI(HttpServletRequest) 78 87 */ 79 88 @Override … … 91 100 92 101 /* (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) 94 103 */ 95 104 @Override … … 102 111 103 112 /* (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) 105 114 */ 106 115 @Override … … 119 128 120 129 /* (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) 122 131 */ 123 132 @Override … … 133 142 134 143 /* (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) 136 145 */ 137 146 @Override … … 148 157 149 158 /** 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. 151 162 */ 152 163 private class DubbingContentProvider implements ContentProvider { 153 164 154 /** */ 165 /** 166 * the dubbed request 167 */ 155 168 private HttpServletRequest request; 156 169 157 /** */ 170 /** 171 * the original content provider of which the data is copied 172 */ 158 173 private ContentProvider delegate; 159 174 160 175 /** 161 * 176 * initializes this content provider with the copied request and the delegate. 162 177 */ 163 178 public DubbingContentProvider(HttpServletRequest request, ContentProvider delegate) { … … 185 200 186 201 /** 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. 188 205 */ 189 206 public class DubbingByteBufferIterator implements Iterator<ByteBuffer> { 190 207 191 /** */ 208 /** 209 * the dubbed request 210 */ 192 211 private HttpServletRequest request; 193 212 194 /** */ 213 /** 214 * the original iterator of which the data is copied 215 */ 195 216 private Iterator<ByteBuffer> delegate; 196 217 197 218 /** 198 * 219 * initializes this iterator with the copied request and the delegate. 199 220 */ 200 221 public DubbingByteBufferIterator(HttpServletRequest request, Iterator<ByteBuffer> delegate) {
Note: See TracChangeset
for help on using the changeset viewer.