Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

fix (and test) for encoding submit_sm_resp messages with no message_id #31

Merged
merged 1 commit into from
Oct 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/com/cloudhopper/smpp/pdu/BaseSmResp.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ public int calculateByteSizeOfBody() {

@Override
public void writeBody(ChannelBuffer buffer) throws UnrecoverablePduException, RecoverablePduException {
ChannelBufferUtil.writeNullTerminatedString(buffer, this.messageId);
// when this PDU was parsed, it's possible it was missing the messageId instead
// of having a NULL messageId. If that's the case, the commandLength will be just
// enough for the headers (and theoretically any optional TLVs). Don't try to
// write the NULL byte for that case.
// See special note in 4.4.2 of SMPP 3.4 spec
if (!((buffer.writableBytes() == 0) && (this.messageId == null))) {
ChannelBufferUtil.writeNullTerminatedString(buffer, this.messageId);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,25 @@ public void encodeSubmitSmResp() throws Exception {
}

@Test
public void encodeSubmitSmRespWithNoMessageId() throws Exception {
public void encodeSubmitSmRespWithNullMessageId() throws Exception {
SubmitSmResp pdu0 = new SubmitSmResp();
pdu0.setSequenceNumber(171192033);

ChannelBuffer buffer = transcoder.encode(pdu0);
Assert.assertArrayEquals(HexUtil.toByteArray("0000001180000004000000000a342ee100"), BufferHelper.createByteArray(buffer));
}

@Test
public void encodeSubmitSmRespWithOmittedMesageId() throws Exception {
SubmitSmResp pdu0 = new SubmitSmResp();
pdu0.setSequenceNumber(171192033);
pdu0.setCommandStatus(0x30);
pdu0.setCommandLength(16);

ChannelBuffer buffer = transcoder.encode(pdu0);
Assert.assertArrayEquals(HexUtil.toByteArray("0000001080000004000000300a342ee1"), BufferHelper.createByteArray(buffer));
}

@Test
public void encodeDeliverSmResp() throws Exception {
DeliverSmResp pdu0 = new DeliverSmResp();
Expand Down