Sure; but before doing so I am wondering what will happen if the client
sends a message and disconnects while I was intending to send
acknowledgement back, will I receive the same null pointer exception?
Because in the past whenever I had a problem in the response encoder, I used
to see it in the stack trace(like exception at line25 responseencoder.java
etc). I don't feel that message even gets to the encode method in the
encoder.
My encoder is as follows: It simply creates a byte array from getter methods
of the object.
public void encode(IoSession session, Object message, ProtocolEncoderOutput
out) throws Exception {
int capacity = 1;
//log.warn("encoding the response");
IoBuffer buffer = IoBuffer.allocate(capacity, false);
buffer.setAutoExpand(true);
if(message instanceof ResponseMessage)
{
...
}
else if (message instanceof AckMessage)
{
AckMessage msg = (AckMessage) message;
buffer.put((byte)1);
int tmpMod = msg.getModuloCounter();
byte[] modData = new byte[3];
modData[2] = (byte)(tmpMod & 255);
tmpMod = tmpMod >> 8;
modData[1] = (byte)(tmpMod & 255);
tmpMod = tmpMod >> 8;
modData[0] = (byte)(tmpMod & 255);
buffer.put(modData[0]);
buffer.put(modData[1]);
buffer.put(modData[2]);
buffer.put(msg.getPriority());
buffer.put(msg.getStatus());
buffer.put(msg.getPacketNumber());
buffer.put((byte)msg.getMdtId().length());
buffer.putString(msg.getMdtId(),Charset.forName("ASCII").newEncoder());
buffer.put(msg.getFleetIdLength());
buffer.putString(msg.getFleetId(),Charset.forName("ASCII").newEncoder());
buffer.put(msg.getCmtTokenLength());
buffer.putString(msg.getCmtToken(),Charset.forName("ASCII").newEncoder());
buffer.putChar((char) 0);
buffer.put((byte)4);
buffer.flip();
}
try
{
byte[] byteArray = TrimArray(buffer.array());
int tmpCrc = CRCCalculation(byteArray);
byte[] crcData = new byte[2];
crcData[1] = (byte)(tmpCrc & 255);
tmpCrc = tmpCrc >> 8;
crcData[0] = (byte)(tmpCrc & 255);
byteArray[byteArray.length-3] = crcData[0];
byteArray[byteArray.length-2] = crcData[1];
buffer = IoBuffer.wrap(Stuff(byteArray));
out.write(buffer);
}
catch(Exception e)
{
log.error(e.getMessage());
}
}
On Tue, Mar 23, 2010 at 7:30 PM, Emmanuel Lecharny <[email protected]>wrote:
> On 3/24/10 12:08 AM, Erinc Arikan wrote:
>
>> I am using MINA 2.0.0.RC1, I built my own protocol codec filter to deal
>> with
>> messages. All of my tests went fine in test environments and I went live
>> recently. I am processing almost a message every second.
>>
>> The issue that I experienced in the production environment is random null
>> pointer exceptions. I suspect that they are happening when I try to write
>> back an ack message to the session in my custom message handler. Following
>> is the exception trace:
>>
>>
> You most certainly have an issue in your encoder. Now, I agree that it's
> difficult to tell exactly what's going wrong with this stack trace...
>
> Is it possible to see the code of your encoder ?
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.nextury.com
>
>
>