Sunday 15 August 2010

java - Netty, Strings and flushing -


I'm using an example to optimize Native Proxy, to modify some of the contents of the content .

I am proxying between an FTP client and server, so the end of lines in the CRLF - this is important. I am not doing anything with FTP data port yet, so this is not a factor.

I started with this example code:

... which sets a pipeline like this:.

  ch.pipeline () addLast (New LoggingHandler (LogLevel.INFO), New HexDumpProxyFrontendHandler (remoteHost, remotePort));  

... and it works fine.

If I add a new linebasedFrameDecoder (maxLen) then the FTP client is waiting for the server, because the proxy has snatched the CRLF, and the server still waiting Used to be. .. I can fix it by telling the frame decoder not to remove the delimiter: New LineBasedFrameDecoder (maxLen, false, incorrect)

  ch.pipeline () AddLast New LoggingHandler (LogLevel.INFO), New LineBasedFrameDecoder (maxLen, False False), New HexDumpProxyFrontendHandler (remoteHost, remotePort)); So far, if I add a string decoder, I get the same hanging symptom, this time because the StringDecoder after the pipeline step is not applied.  
  ch.pipeline (). AddLast (New LoggingHandler), New LineBasedFrameDecoder (MaxLen, False False), New StringDecoder (StandardCharsets.UTF_8), // Objective rewriter your own string here New StringEncoder (StandardCharsets.UTF_8), New HexDumpProxyFrontendHandler (remoteHost, remotePort ), Is to go,  

In a debugger, the breakpoint in StringEncoder.encode () is not triggered.

itemprop = "text">

string encoder is an outbound channel adapter. I write this to the ByteBuf when it is converted from string to intro Is, so I do not expect the encoded data is called on.

, you will need to replace StringEncoder with an in-channel channel in order to work your code in the adapter which converts the string when reading the bytebook, I doubt that any such codec Netty is present in the library because decoders generally convert from a lower level format to a higher level format, not the other way around.

By LineBasedFrameDecoder emits ByteBuf and HexDumpProxyFrontendHandler Consumption ByteBufs I would recommend that you remove both StringDecoder and StringEncoder and write your client again. But .. it made a bytebook a bytebuilder decoder. Within your decoder you can convert the incoming bytefuff into a string, do your job, then convert it back to the bytefuge and pass it down the pipeline.


No comments:

Post a Comment