1 16 package org.apache.coyote.http11; 17 18 import org.apache.tomcat.util.buf.MessageBytes; 19 import org.apache.tomcat.util.buf.ByteChunk; 20 import org.apache.tomcat.util.http.MimeHeaders; 21 22 import org.apache.coyote.ActionCode; 23 import org.apache.coyote.Adapter; 24 import org.apache.coyote.Request; 25 import org.apache.coyote.Response; 26 27 32 public class TestAdapter 33 implements Adapter { 34 35 36 public static final String CRLF = "\r\n"; 37 38 39 42 public void service(Request req, Response res) 43 throws Exception { 44 45 StringBuffer buf = new StringBuffer (); 46 buf.append("Request dump:"); 47 buf.append(CRLF); 48 buf.append(req.method()); 49 buf.append(" "); 50 buf.append(req.unparsedURI()); 51 buf.append(" "); 52 buf.append(req.protocol()); 53 buf.append(CRLF); 54 55 MimeHeaders headers = req.getMimeHeaders(); 56 int size = headers.size(); 57 for (int i = 0; i < size; i++) { 58 buf.append(headers.getName(i) + ": "); 59 buf.append(headers.getValue(i).toString()); 60 buf.append(CRLF); 61 } 62 63 buf.append("Request body:"); 64 buf.append(CRLF); 65 66 res.action(ActionCode.ACTION_ACK, null); 67 68 ByteChunk bc = new ByteChunk(); 69 byte[] b = buf.toString().getBytes(); 70 bc.setBytes(b, 0, b.length); 71 res.doWrite(bc); 72 73 int nRead = 0; 74 75 while (nRead >= 0) { 76 nRead = req.doRead(bc); 77 if (nRead > 0) 78 res.doWrite(bc); 79 } 80 81 } 82 83 84 } 85 | Popular Tags |