public void testXmlHandler() throws Exception {
final byte[] contents = "<myxml><msg>hello xml</msg></myxml>".getBytes();
final Mongrel2Handler handler = new Mongrel2Handler(UUID.randomUUID().toString(), XML_RECV, XML_SEND);
// handler.setLevel(Level.DEBUG);
handler.setActive(true);
final Socket s = new Socket(SERVER_ADDR.getAddress(), SERVER_ADDR.getPort());
final InputStream in = s.getInputStream();
final OutputStream out = s.getOutputStream();
// send message
// out.write("<myxml>".getBytes());
out.write(contents);
out.write(0);
out.flush();
// wait to receive message at handler
final Request req = new Request();
handler.takeRequest(req);
// verify correctness
Assert.assertEquals("server content length unequal", contents.length, req.getContent().length);
Assert.assertTrue("server contents do not match", Arrays.equals(contents, req.getContent()));
// echo message back to client
final Response rsp = new Response();
rsp.setPayload(contents);
Assert.assertTrue(Arrays.equals(contents, rsp.getPayload()));
handler.sendResponse(rsp, req);
// handler.sendResponse(rsp, req);
// read out message at client
final byte[] msg1 = readInputStream(in, true);
Assert.assertTrue("zero-length message", msg1.length > 0);