@Test public void encodeContentChunkedComplete() throws Exception { ProtocolCodecSessionEx session = new ProtocolCodecSessionEx(); IoBufferAllocatorEx<?> allocator = session.getBufferAllocator(); ProtocolEncoder encoder = new HttpResponseEncoder(allocator); ProtocolEncoderOutput encoderOut = session.getEncoderOutput(); IoBufferEx data = allocator.wrap(ByteBuffer.wrap("Hello, world".getBytes())); HttpContentMessage httpContent = new HttpContentMessage(data, true, true, false); encoder.encode(session, httpContent, encoderOut); encoderOut.mergeAll(); IoBufferEx buf = (IoBufferEx) session.getEncoderOutputQueue().poll(); assertEquals("c\r\n" + "Hello, world\r\n" + "0\r\n" + "\r\n", buf.getString(Charset.forName("UTF-8").newDecoder())); }
@Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } }
HttpResponseEncoder extends HttpMessageEncoder<HttpResponseMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } }
HttpResponseEncoder extends HttpMessageEncoder<HttpResponseMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpResponseEncoder(IoBufferAllocatorEx<?> allocator);  HttpResponseEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator); }
HttpResponseEncoder extends HttpMessageEncoder<HttpResponseMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpResponseEncoder(IoBufferAllocatorEx<?> allocator);  HttpResponseEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator);  }
HttpResponseEncoder extends HttpMessageEncoder<HttpResponseMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpResponseEncoder(IoBufferAllocatorEx<?> allocator);  HttpResponseEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator);   }