001: package org.mortbay.jetty.ajp;
002:
003: import java.io.IOException;
004:
005: import org.mortbay.io.Buffer;
006: import org.mortbay.io.Buffers;
007: import org.mortbay.io.ByteArrayBuffer;
008: import org.mortbay.io.ByteArrayEndPoint;
009: import org.mortbay.io.EndPoint;
010: import org.mortbay.io.SimpleBuffers;
011: import org.mortbay.util.TypeUtil;
012:
013: import junit.framework.TestCase;
014:
015: public class TestAjpParser extends TestCase {
016:
017: public void testPacket1() throws Exception {
018: String packet = "123401070202000f77696474683d20485454502f312e300000122f636f6e74726f6c2f70726f647563742f2200000e3230382e32372e3230332e31323800ffff000c7777772e756c74612e636f6d000050000005a006000a6b6565702d616c69766500a00b000c7777772e756c74612e636f6d00a00e002b4d6f7a696c6c612f342e302028636f6d70617469626c653b20426f726465724d616e6167657220332e302900a0010043696d6167652f6769662c20696d6167652f782d786269746d61702c20696d6167652f6a7065672c20696d6167652f706a7065672c20696d6167652f706d672c202a2f2a00a008000130000600067570726f64310008000a4145533235362d53484100ff";
019: byte[] src = TypeUtil.fromHexString(packet);
020:
021: ByteArrayBuffer buffer = new ByteArrayBuffer(
022: Ajp13Packet.MAX_PACKET_SIZE);
023: SimpleBuffers buffers = new SimpleBuffers(
024: new Buffer[] { buffer });
025:
026: EndPoint endp = new ByteArrayEndPoint(src,
027: Ajp13Packet.MAX_PACKET_SIZE);
028:
029: Ajp13Parser parser = new Ajp13Parser(buffers, endp, new EH(),
030: new Ajp13Generator(buffers, endp, 0, 0));
031:
032: parser.parseAvailable();
033:
034: assertTrue(true);
035: }
036:
037: private static class EH implements Ajp13Parser.EventHandler {
038:
039: public void content(Buffer ref) throws IOException {
040: System.err.println(ref);
041: }
042:
043: public void headerComplete() throws IOException {
044: System.err.println();
045: }
046:
047: public void messageComplete(long contextLength)
048: throws IOException {
049: // TODO Auto-generated method stub
050: }
051:
052: public void parsedHeader(Buffer name, Buffer value)
053: throws IOException {
054: System.err.println(name + ": " + value);
055: }
056:
057: public void parsedMethod(Buffer method) throws IOException {
058: System.err.println(method);
059: }
060:
061: public void parsedProtocol(Buffer protocol) throws IOException {
062: System.err.println(protocol);
063:
064: }
065:
066: public void parsedQueryString(Buffer value) throws IOException {
067: System.err.println("?" + value);
068: }
069:
070: public void parsedRemoteAddr(Buffer addr) throws IOException {
071: System.err.println("addr=" + addr);
072:
073: }
074:
075: public void parsedRemoteHost(Buffer host) throws IOException {
076: System.err.println("host=" + host);
077:
078: }
079:
080: public void parsedRequestAttribute(String key, Buffer value)
081: throws IOException {
082: System.err.println(key + ":: " + value);
083:
084: }
085:
086: public void parsedServerName(Buffer name) throws IOException {
087: // TODO Auto-generated method stub
088:
089: }
090:
091: public void parsedServerPort(int port) throws IOException {
092: // TODO Auto-generated method stub
093:
094: }
095:
096: public void parsedSslSecure(boolean secure) throws IOException {
097: // TODO Auto-generated method stub
098:
099: }
100:
101: public void parsedUri(Buffer uri) throws IOException {
102: System.err.println(uri);
103:
104: }
105:
106: public void startForwardRequest() throws IOException {
107: // TODO Auto-generated method stub
108:
109: }
110:
111: }
112:
113: }
|