Changeset 1614 for trunk/autoquest-httpmonitor/src
- Timestamp:
- 07/15/14 13:45:31 (10 years ago)
- Location:
- trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java
r1561 r1614 142 142 */ 143 143 @Override 144 public void handleHttpExchange(HttpExchange httpExchange) {144 public synchronized void handleHttpExchange(HttpExchange httpExchange) { 145 145 // send the exchange to the server and wait for completion 146 synchronized (openRequests) { 147 Request httpMonitorRequest = httpClient.newRequest(httpMonitorServer, httpMonitorPort); 148 httpMonitorRequest.method(HttpMethod.POST); 149 httpMonitorRequest.version(HttpVersion.HTTP_1_1); 150 151 OutputStreamContentProvider out = new OutputStreamContentProvider(); 152 httpMonitorRequest.content(out); 153 httpMonitorRequest.send(this); 154 155 try { 156 JAXBContext jaxbContext = 157 JAXBContext.newInstance(HttpExchange.class.getPackage().getName()); 158 Marshaller marshaller = jaxbContext.createMarshaller(); 159 160 OutputStreamWriter writer = new OutputStreamWriter(out.getOutputStream(), "UTF-8"); 161 marshaller.marshal(new ObjectFactory().createHttpExchange(httpExchange), writer); 162 163 out.getOutputStream().close(); 164 } 165 catch (JAXBException e) { 166 Console.printerrln("could not convert request and response to XML string: " + e); 167 Console.logException(e); 168 } 169 catch (IOException e) { 170 Console.printerrln 146 Request httpMonitorRequest = httpClient.newRequest(httpMonitorServer, httpMonitorPort); 147 httpMonitorRequest.method(HttpMethod.POST); 148 httpMonitorRequest.version(HttpVersion.HTTP_1_1); 149 150 OutputStreamContentProvider out = new OutputStreamContentProvider(); 151 httpMonitorRequest.content(out); 152 153 openRequests.add(httpMonitorRequest); 154 httpMonitorRequest.send(this); 155 156 try { 157 JAXBContext jaxbContext = 158 JAXBContext.newInstance(HttpExchange.class.getPackage().getName()); 159 Marshaller marshaller = jaxbContext.createMarshaller(); 160 161 OutputStreamWriter writer = new OutputStreamWriter(out.getOutputStream(), "UTF-8"); 162 marshaller.marshal(new ObjectFactory().createHttpExchange(httpExchange), writer); 163 164 out.getOutputStream().close(); 165 } 166 catch (JAXBException e) { 167 Console.printerrln("could not convert request and response to XML string: " + e); 168 Console.logException(e); 169 } 170 catch (IOException e) { 171 Console.printerrln 171 172 ("could not close the stream for sending data to the HTML monitor: " + e); 172 Console.logException(e); 173 } 174 175 openRequests.add(httpMonitorRequest); 176 177 try { 178 // wait for the request to be removed fromt the list asynchronously 179 while (openRequests.contains(httpMonitorRequest)) { 180 openRequests.wait(); 173 Console.logException(e); 174 } 175 176 try { 177 // wait for the request to be removed from the list asynchronously 178 int count = 30; 179 while (openRequests.contains(httpMonitorRequest)) { 180 this.wait(1000); 181 182 if (--count == 0) { 183 // after 30 seconds, cancel the sending of the loggin request 184 openRequests.remove(httpMonitorRequest); 185 break; 181 186 } 182 187 } 183 catch (InterruptedException e) {184 // ignore, as this may only happen on system shutdown185 }188 } 189 catch (InterruptedException e) { 190 // ignore, as this may only happen on system shutdown 186 191 } 187 192 } … … 191 196 */ 192 197 @Override 193 public void onComplete(Result result) {198 public synchronized void onComplete(Result result) { 194 199 if (result.isFailed()) { 195 200 Console.traceln … … 198 203 } 199 204 200 synchronized (openRequests) { 201 openRequests.remove(result.getRequest()); 202 openRequests.notify(); 203 } 205 openRequests.remove(result.getRequest()); 206 this.notify(); 204 207 } 205 208 -
trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxyServlet.java
r1567 r1614 19 19 import java.net.URI; 20 20 import java.net.URISyntaxException; 21 import java.net.URLDecoder; 21 22 import java.net.URLEncoder; 22 23 import java.nio.ByteBuffer; … … 99 100 protected URI rewriteURI(HttpServletRequest request) { 100 101 try { 102 String query = request.getQueryString(); 103 104 if (query != null) { 105 query = URLDecoder.decode(query, "UTF-8"); 106 } 107 101 108 return new URI(request.getScheme(), null, proxiedServer, proxiedPort, 102 request.getPathInfo(), request.getQueryString(), null);109 request.getPathInfo(), query, null); 103 110 } 104 111 catch (URISyntaxException e) { 112 Console.printerrln("could not rewrite URI: " + e); 113 Console.logException(e); 114 return null; 115 } 116 catch (UnsupportedEncodingException e) { 105 117 Console.printerrln("could not rewrite URI: " + e); 106 118 Console.logException(e); … … 365 377 } 366 378 } 367 return result.toString(); 379 380 if (result.length() <= 0) { 381 return null; 382 } 383 else { 384 return result.toString(); 385 } 368 386 } 369 387
Note: See TracChangeset
for help on using the changeset viewer.