1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.stomp;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.channel.ChannelHandler;
20 import io.netty.channel.ChannelPipeline;
21 import io.netty.handler.codec.MessageAggregator;
22 import io.netty.handler.codec.TooLongFrameException;
23
24
25
26
27
28
29
30 public class StompSubframeAggregator
31 extends MessageAggregator<StompSubframe, StompHeadersSubframe, StompContentSubframe, StompFrame> {
32
33
34
35
36
37
38
39
40
41 public StompSubframeAggregator(int maxContentLength) {
42 super(maxContentLength);
43 }
44
45 @Override
46 protected boolean isStartMessage(StompSubframe msg) throws Exception {
47 return msg instanceof StompHeadersSubframe;
48 }
49
50 @Override
51 protected boolean isContentMessage(StompSubframe msg) throws Exception {
52 return msg instanceof StompContentSubframe;
53 }
54
55 @Override
56 protected boolean isLastContentMessage(StompContentSubframe msg) throws Exception {
57 return msg instanceof LastStompContentSubframe;
58 }
59
60 @Override
61 protected boolean isAggregated(StompSubframe msg) throws Exception {
62 return msg instanceof StompFrame;
63 }
64
65 @Override
66 protected boolean isContentLengthInvalid(StompHeadersSubframe start, int maxContentLength) {
67 return (int) Math.min(Integer.MAX_VALUE, start.headers().getLong(StompHeaders.CONTENT_LENGTH, -1)) >
68 maxContentLength;
69 }
70
71 @Override
72 protected Object newContinueResponse(StompHeadersSubframe start, int maxContentLength, ChannelPipeline pipeline) {
73 return null;
74 }
75
76 @Override
77 protected boolean closeAfterContinueResponse(Object msg) throws Exception {
78 throw new UnsupportedOperationException();
79 }
80
81 @Override
82 protected boolean ignoreContentAfterContinueResponse(Object msg) throws Exception {
83 throw new UnsupportedOperationException();
84 }
85
86 @Override
87 protected StompFrame beginAggregation(StompHeadersSubframe start, ByteBuf content) throws Exception {
88 StompFrame ret = new DefaultStompFrame(start.command(), content);
89 ret.headers().set(start.headers());
90 return ret;
91 }
92 }