Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java
r1561 r1563 443 443 assertNotNull(exchange.getResponse().getContent().getData()); 444 444 } 445 446 @Test 447 public void test_LargeRequest_Local() throws Exception { 448 proxy = new HttpMonitoringProxy 449 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", "localhost:" + DUMMY_SERVER_PORT, 450 "local" }); 451 452 proxy.init(); 453 proxy.start(); 454 455 StringBuffer message = new StringBuffer(); 456 StringBuffer expectedResponse = new StringBuffer(); 457 458 for (int i = 0; i < 1000; i++) { 459 message.append(" # " + i + " test request data"); 460 expectedResponse.append(" # " + i + " test response data"); 461 } 462 463 String response = sendDummyMessage("POST", message.toString(), expectedResponse.toString()); 464 465 assertEquals(expectedResponse.toString(), response); 466 467 proxy.stop(); 468 proxy = null; 469 470 File logFile = new File(LOG_FILE_DIR + File.separator + "httpmonitor_000.log"); 471 472 assertTrue(logFile.exists()); 473 474 HTTPLogParser parser = new HTTPLogParser(); 475 476 parser.parseFile(logFile); 477 478 // check the sequences 479 Collection<List<Event>> sequences = parser.getSequences(); 480 481 assertNotNull(sequences); 482 483 Iterator<List<Event>> iterator = sequences.iterator(); 484 assertTrue(iterator.hasNext()); 485 486 List<Event> sequence = iterator.next(); 487 assertFalse(iterator.hasNext()); 488 489 assertNotNull(sequence); 490 assertEquals(1, sequence.size()); 491 492 assertEvent(sequence.get(0), "POST", message.toString(), expectedResponse.toString()); 493 } 494 495 @Test 496 public void test_LargeRequest_Remote() throws Exception { 497 proxy = new HttpMonitoringProxy 498 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 499 "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 500 501 proxy.init(); 502 proxy.start(); 503 504 505 StringBuffer message = new StringBuffer(); 506 StringBuffer expectedResponse = new StringBuffer(); 507 508 for (int i = 0; i < 1000; i++) { 509 message.append(" # " + i + " test request data"); 510 expectedResponse.append(" # " + i + " test response data"); 511 } 512 513 String response = sendDummyMessage("POST", message.toString(), expectedResponse.toString()); 514 515 assertEquals(expectedResponse.toString(), response); 516 517 // give the proxy some time to send the copy of the message 518 while(messages.size() < 1) { 519 Thread.sleep(1000); 520 } 521 522 assertEquals(1, messages.size()); 523 524 JAXBContext jaxbContext = JAXBContext.newInstance(HttpExchange.class.getPackage().getName()); 525 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 526 527 @SuppressWarnings("unchecked") 528 JAXBElement<HttpExchange> jaxObject = 529 (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 530 531 HttpExchange exchange = jaxObject.getValue(); 532 533 assertEquals(message.toString(), exchange.getRequest().getContent().getData()); 534 assertEquals(response.toString(), exchange.getResponse().getContent().getData()); 535 } 445 536 446 537 /** -
trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxyServlet.java
r1561 r1563 23 23 import java.nio.charset.UnsupportedCharsetException; 24 24 import java.util.Iterator; 25 import java.util.LinkedList;26 import java.util.List;27 25 28 26 import javax.servlet.http.HttpServletRequest; … … 258 256 @Override 259 257 public ByteBuffer next() { 260 List<ByteBuffer> buffers = new LinkedList<ByteBuffer>();258 ByteBuffer next = delegate.next(); 261 259 262 int size = 0; 263 while (delegate.hasNext()) { 264 ByteBuffer next = delegate.next(); 265 exchangeListenerManager.onRequestContent(request, next.duplicate()); 266 267 ByteBuffer copy = ByteBuffer.allocate(next.limit()); 268 copy.put(next); 269 copy.position(0); 270 buffers.add(copy); 271 272 size += next.limit(); 273 } 260 ByteBuffer clone = ByteBuffer.allocate(next.capacity()); 261 next.rewind(); 262 clone.put(next); 263 next.rewind(); 264 clone.flip(); 265 266 exchangeListenerManager.onRequestContent(request, clone); 274 267 275 ByteBuffer buffer = ByteBuffer.allocate(size); 276 277 for (ByteBuffer orig : buffers) { 278 buffer.put(orig); 279 } 280 281 buffer.position(0); 282 283 return buffer; 268 return next; 284 269 } 285 270
Note: See TracChangeset
for help on using the changeset viewer.