private static final String KERBEROS_MESSAGE_CONTAINER = "kerberosMessageContainer";
public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws IOException
{
ByteBuffer buf = in.buf();
KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer ) session.getAttribute( KERBEROS_MESSAGE_CONTAINER );
if ( kerberosMessageContainer == null )
{
kerberosMessageContainer = new KerberosMessageContainer();
session.setAttribute( KERBEROS_MESSAGE_CONTAINER, kerberosMessageContainer );
kerberosMessageContainer.setStream( buf );
kerberosMessageContainer.setGathering( true );
kerberosMessageContainer.setTCP( !session.getTransportMetadata().isConnectionless() );
}
if ( kerberosMessageContainer.isTCP() )
{
if ( buf.remaining() > 4 )
{
kerberosMessageContainer.setTcpLength( buf.getInt() );
buf.mark();
}
else
{
return;
}
}
else
{
buf.mark();
}
while ( buf.hasRemaining() )
{
try
{
asn1Decoder.decode( buf, kerberosMessageContainer );
if ( kerberosMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
{
if ( IS_DEBUG )
{
LOG.debug( "Decoded KerberosMessage : " + kerberosMessageContainer.getMessage() );
buf.mark();
}
out.write( kerberosMessageContainer.getMessage() );
kerberosMessageContainer.clean();
}
}
catch ( DecoderException de )
{
buf.clear();
kerberosMessageContainer.clean();
}
catch ( Exception e )
{
LOG.warn( "error while decoding", e );
}