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.channel.ChannelHandlerContext;
17 import org.jboss.netty.channel.MessageEvent;
18 import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
19
20 import ch.mimo.netty.handler.codec.icap.DefaultIcapResponse;
21 import ch.mimo.netty.handler.codec.icap.IcapChunk;
22 import ch.mimo.netty.handler.codec.icap.IcapChunkTrailer;
23 import ch.mimo.netty.handler.codec.icap.IcapRequest;
24 import ch.mimo.netty.handler.codec.icap.IcapResponse;
25 import ch.mimo.netty.handler.codec.icap.IcapResponseStatus;
26 import ch.mimo.netty.handler.codec.icap.IcapVersion;
27
28 public class IcapServerHandler extends SimpleChannelUpstreamHandler {
29
30 private boolean continueWasSent;
31
32 @Override
33 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
34 Object msg = e.getMessage();
35 if(msg instanceof IcapRequest) {
36 IcapRequest request = (IcapRequest)e.getMessage();
37 System.out.println(request.toString());
38 } else if(msg instanceof IcapChunkTrailer) {
39 System.out.println(msg.toString());
40 if(!continueWasSent) {
41 continueWasSent = true;
42
43 IcapResponse response = new DefaultIcapResponse(IcapVersion.ICAP_1_0,IcapResponseStatus.CONTINUE);
44 ctx.getChannel().write(response);
45 } else {
46
47 IcapResponse response = new DefaultIcapResponse(IcapVersion.ICAP_1_0,IcapResponseStatus.NO_CONTENT);
48 ctx.getChannel().write(response);
49 }
50 } else if(msg instanceof IcapChunk) {
51 System.out.println(msg);
52 }
53 }
54
55 }