@Test public void encodeContentGzipped() 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, false, false, true); encoder.encode(session, httpContent, encoderOut); encoderOut.mergeAll(); IoBufferEx buf = (IoBufferEx) session.getEncoderOutputQueue().poll(); IoBufferEx expected = allocator.wrap(allocator.allocate(17)); expected.put(new byte[] { 0, (byte)12, 0, (byte)~12, (byte)~0 }); expected.put("Hello, world".getBytes()); expected.flip(); assertEquals(expected, buf); }
@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);   }