@@ -62,8 +62,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
62
62
ctx .write (new DefaultFullHttpResponse (HttpVersion .HTTP_1_1 , HttpResponseStatus .CONTINUE ));
63
63
}
64
64
65
- Conversion conversion = connections .get (ctx .channel ().id ().asLongText ());
66
- conversion .parse (msg );
65
+ getConn (ctx ).parse (msg );
67
66
68
67
} catch (Exception ex ) {
69
68
ReferenceCountUtil .release (msg );
@@ -96,13 +95,14 @@ public ResponseWrapper(int code, String message, String info, long generationNan
96
95
@ Override
97
96
public void channelReadComplete (ChannelHandlerContext ctx ) throws Exception {
98
97
99
- Conversion conversion = connections . get (ctx . channel (). id (). asLongText () );
98
+ Conversion conversion = getConn (ctx );
100
99
if (conversion .getRequest ().getHttpDecoder () != null ) {
101
100
if ((conversion .getRequest ().getHttpDecoder ().isMultipart ()) && (!conversion .getRequest ().getHttpDecoder ().hasNext ())) {
102
101
return ;
103
102
}
104
103
}
105
104
process (conversion , ctx );
105
+ connections .remove (ctx .channel ().id ().asLongText ());
106
106
107
107
ctx .flush ();
108
108
}
@@ -193,6 +193,18 @@ public static void process(Conversion conversion, ChannelHandlerContext ctx) thr
193
193
writeJSON (ctx , HttpResponseStatus .valueOf (conversion .getResponse ().getStatus ().getCode ()), bb , conversion .getResponse ());
194
194
195
195
}
196
+
197
+ }
198
+
199
+ public Conversion getConn (ChannelHandlerContext ctx ) {
200
+ String key = ctx .channel ().id ().asLongText ();
201
+ if (connections .containsKey (key )) {
202
+ return connections .get (key );
203
+ } else {
204
+ Conversion c = new Conversion (ctx , server );
205
+ connections .put (key , c );
206
+ return c ;
207
+ }
196
208
}
197
209
198
210
/**
@@ -204,7 +216,7 @@ public static void process(Conversion conversion, ChannelHandlerContext ctx) thr
204
216
public void channelRegistered (ChannelHandlerContext ctx ) throws Exception {
205
217
super .channelRegistered (ctx ); //To change body of generated methods, choose Tools | Templates.
206
218
207
- connections . put (ctx . channel (). id (). asLongText (), new Conversion ( ctx , server ) );
219
+ getConn (ctx );
208
220
}
209
221
210
222
/**
0 commit comments