1 17 18 package org.apache.coyote.memory; 19 20 import java.io.IOException ; 21 import java.util.Iterator ; 22 import org.apache.tomcat.util.buf.ByteChunk; 23 24 import org.apache.coyote.Adapter; 25 import org.apache.coyote.InputBuffer; 26 import org.apache.coyote.OutputBuffer; 27 import org.apache.coyote.ProtocolHandler; 28 import org.apache.coyote.Request; 29 import org.apache.coyote.Response; 30 31 32 39 public class MemoryProtocolHandler 40 implements ProtocolHandler { 41 42 43 45 46 49 public void setAttribute(String name, Object value) { 50 } 51 52 public Object getAttribute(String name) { 53 return null; 54 } 55 56 public Iterator getAttributeNames() { return null ; } 57 60 protected Adapter adapter = null; 61 62 65 public void setAdapter(Adapter adapter) { 66 this.adapter = adapter; 67 } 68 69 public Adapter getAdapter() { 70 return (adapter); 71 } 72 73 74 76 77 80 public void init() 81 throws Exception { 82 } 83 84 85 88 public void start() 89 throws Exception { 90 } 91 92 93 public void pause() 94 throws Exception { 95 } 96 97 public void resume() 98 throws Exception { 99 } 100 101 public void destroy() 102 throws Exception { 103 } 104 105 106 108 109 112 public void process(Request request, ByteChunk input, 113 Response response, ByteChunk output) 114 throws Exception { 115 116 InputBuffer inputBuffer = new ByteChunkInputBuffer(input); 117 OutputBuffer outputBuffer = new ByteChunkOutputBuffer(output); 118 request.setInputBuffer(inputBuffer); 119 response.setOutputBuffer(outputBuffer); 120 121 adapter.service(request, response); 122 123 } 124 125 126 128 129 protected class ByteChunkInputBuffer 130 implements InputBuffer { 131 132 protected ByteChunk input = null; 133 134 public ByteChunkInputBuffer(ByteChunk input) { 135 this.input = input; 136 } 137 138 public int doRead(ByteChunk chunk, Request request) 139 throws IOException { 140 return input.substract(chunk); 141 } 142 143 } 144 145 146 148 149 protected class ByteChunkOutputBuffer 150 implements OutputBuffer { 151 152 protected ByteChunk output = null; 153 154 public ByteChunkOutputBuffer(ByteChunk output) { 155 this.output = output; 156 } 157 158 public int doWrite(ByteChunk chunk, Response response) 159 throws IOException { 160 output.append(chunk); 161 return chunk.getLength(); 162 } 163 164 } 165 166 167 } 168 | Popular Tags |