提交 3bbbc1d0 authored 作者: david varnes's avatar david varnes

Re-instate the 'treatUnknownHeadersAsBody' mode/hack which makes outbound work at all

上级 093fd801
......@@ -46,7 +46,8 @@ public abstract class AbstractOutboundClientHandler extends AbstractEslClientHan
log.debug( "Received new connection from server, sending connect message" );
EslMessage response = sendSyncSingleLineCommand( ctx.getChannel(), "connect" );
// A hack in the message decoder treats most of this incoming message as an event so parse now
// The message decoder for outbound, treats most of this incoming message as an 'event' in
// message body, so it parse now
EslEvent channelDataEvent = new EslEvent( response, true );
// Let implementing sub classes choose what to do next
handleConnectResponse( ctx, channelDataEvent );
......
......@@ -35,7 +35,8 @@ public abstract class AbstractOutboundPipelineFactory implements ChannelPipeline
ChannelPipeline pipeline = Channels.pipeline();
// Add the text line codec combination first
pipeline.addLast( "encoder", new StringEncoder() );
pipeline.addLast( "decoder", new EslFrameDecoder( 8092 ) );
// Note that outbound mode requires the decoder to treat many 'headers' as body lines
pipeline.addLast( "decoder", new EslFrameDecoder( 8092, true ) );
// Add an executor to ensure separate thread for each upstream message from here
pipeline.addLast( "executor", new ExecutionHandler(
new OrderedMemoryAwareThreadPoolExecutor( 16, 1048576, 1048576 ) ) );
......
......@@ -62,6 +62,7 @@ public class EslFrameDecoder extends ReplayingDecoder<EslFrameDecoder.State>
private final Logger log = LoggerFactory.getLogger( this.getClass() );
private final int maxHeaderSize;
private EslMessage currentMessage;
private boolean treatUnknownHeadersAsBody = false;
public EslFrameDecoder( int maxHeaderSize )
{
......@@ -75,6 +76,12 @@ public class EslFrameDecoder extends ReplayingDecoder<EslFrameDecoder.State>
this.maxHeaderSize = maxHeaderSize;
}
public EslFrameDecoder( int maxHeaderSize, boolean treatUnknownHeadersAsBody )
{
this( maxHeaderSize );
this.treatUnknownHeadersAsBody = treatUnknownHeadersAsBody;
}
@Override
protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer,
State state ) throws Exception
......@@ -103,7 +110,15 @@ public class EslFrameDecoder extends ReplayingDecoder<EslFrameDecoder.State>
Name headerName = Name.fromLiteral( headerParts[0] );
if ( headerName == null )
{
throw new IllegalStateException( "Unhandled ESL header [" + headerParts[0] + ']' );
if ( treatUnknownHeadersAsBody )
{
// cache this 'header' as a body line <-- useful for Outbound client mode
currentMessage.addBodyLine( headerLine );
}
else
{
throw new IllegalStateException( "Unhandled ESL header [" + headerParts[0] + ']' );
}
}
currentMessage.addHeader( headerName, headerParts[1] );
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论