1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.mimo.netty.example.icap.preview;
15
16 import org.jboss.netty.buffer.ChannelBuffers;
17 import org.jboss.netty.channel.ChannelHandlerContext;
18 import org.jboss.netty.channel.MessageEvent;
19 import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
20
21 import ch.mimo.netty.handler.codec.icap.DefaultIcapChunk;
22 import ch.mimo.netty.handler.codec.icap.DefaultIcapChunkTrailer;
23 import ch.mimo.netty.handler.codec.icap.IcapChunk;
24 import ch.mimo.netty.handler.codec.icap.IcapChunkTrailer;
25 import ch.mimo.netty.handler.codec.icap.IcapResponse;
26 import ch.mimo.netty.handler.codec.icap.IcapResponseStatus;
27
28 public class IcapClientHandler extends SimpleChannelUpstreamHandler {
29
30 @Override
31 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
32 IcapResponse response = (IcapResponse)e.getMessage();
33 if(response.getStatus().equals(IcapResponseStatus.CONTINUE)) {
34 System.out.println(response.toString());
35 IcapChunk chunk = new DefaultIcapChunk(ChannelBuffers.copiedBuffer("ns why and how we can avoid such a desaster next time...".getBytes()));
36 IcapChunkTrailer trailer = new DefaultIcapChunkTrailer(true,false);
37 ctx.getChannel().write(chunk);
38 ctx.getChannel().write(trailer);
39 } else if(response.getStatus().equals(IcapResponseStatus.NO_CONTENT)) {
40 System.out.println(response.toString());
41 }
42 }
43 }