Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding submit_multy operation into master branch #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/main/java/com/cloudhopper/smpp/SmppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public class SmppConstants {
//
// SUBMIT_MULTI destination type flags
//
//public static final int SME_ADDRESS = 1;
//public static final int DISTRIBUTION_LIST_NAME = 2;
public static final int SME_ADDRESS = 1;
public static final int DISTRIBUTION_LIST_NAME = 2;

//
// SMPP Command ID (Requests)
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/cloudhopper/smpp/pdu/BaseSm.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public abstract class BaseSm<R extends PduResponse> extends PduRequest<R> {
protected Address sourceAddress;
protected Address destAddress;
protected byte esmClass;
private byte protocolId; // not present in data_sm
private byte priority; // not present in data_sm
private String scheduleDeliveryTime; // not present in data_sm
private String validityPeriod; // not present in data_sm
protected byte protocolId; // not present in data_sm
protected byte priority; // not present in data_sm
protected String scheduleDeliveryTime; // not present in data_sm
protected String validityPeriod; // not present in data_sm
protected byte registeredDelivery;
private byte replaceIfPresent; // not present in data_sm
protected byte replaceIfPresent; // not present in data_sm
protected byte dataCoding;
private byte defaultMsgId; // not present in data_sm, not used in deliver_sm
private byte[] shortMessage; // not present in data_sm
protected byte defaultMsgId; // not present in data_sm, not used in deliver_sm
protected byte[] shortMessage; // not present in data_sm

public BaseSm(int commandId, String name) {
super(commandId, name);
Expand Down Expand Up @@ -243,4 +243,4 @@ public void appendBodyToString(StringBuilder buffer) {
HexUtil.appendHexString(buffer, this.shortMessage);
buffer.append("])");
}
}
}
205 changes: 205 additions & 0 deletions src/main/java/com/cloudhopper/smpp/pdu/SubmitMulti.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/**
*
*/
package com.cloudhopper.smpp.pdu;

/*
* #%L
* ch-smpp
* %%
* Copyright (C) 2009 - 2013 Cloudhopper by Twitter
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import java.util.ArrayList;
import java.util.List;

import org.jboss.netty.buffer.ChannelBuffer;

import com.cloudhopper.smpp.SmppConstants;
import com.cloudhopper.smpp.type.Address;
import com.cloudhopper.smpp.type.RecoverablePduException;
import com.cloudhopper.smpp.type.SmppInvalidArgumentException;
import com.cloudhopper.smpp.type.UnrecoverablePduException;
import com.cloudhopper.smpp.util.ChannelBufferUtil;
import com.cloudhopper.smpp.util.PduUtil;

/**
* @author Amit Bhayani
*
*/
public class SubmitMulti extends BaseSm<SubmitMultiResp> {

private int numberOfDest;

private List<Address> destAddresses = new ArrayList<Address>();
private List<String> destDistributionList = new ArrayList<String>();

/**
* @param commandId
* @param name
*/
public SubmitMulti() {
super(SmppConstants.CMD_ID_SUBMIT_MULTI, "submit_multi");
}

/*
* (non-Javadoc)
*
* @see com.cloudhopper.smpp.pdu.PduRequest#createResponse()
*/
@Override
public SubmitMultiResp createResponse() {
SubmitMultiResp resp = new SubmitMultiResp();
resp.setSequenceNumber(this.getSequenceNumber());
return resp;
}

/*
* (non-Javadoc)
*
* @see com.cloudhopper.smpp.pdu.PduRequest#getResponseClass()
*/
@Override
public Class<SubmitMultiResp> getResponseClass() {
return SubmitMultiResp.class;
}

@Override
public Address getDestAddress() {
return null;
}

@Override
public void setDestAddress(Address value) {

}

public void addDestAddresses(Address address)
throws SmppInvalidArgumentException {
this.numberOfDest++;
this.destAddresses.add(address);
}

public void addDestDestributionListName(String name) {
this.numberOfDest++;
this.destDistributionList.add(name);
}

public List<Address> getDestAddresses() {
return this.destAddresses;
}

public List<String> getDestDestributionListName() {
return this.destDistributionList;
}

public int getNumberOfDest(){
return this.numberOfDest;
}

@Override
public void readBody(ChannelBuffer buffer) throws UnrecoverablePduException, RecoverablePduException {
this.serviceType = ChannelBufferUtil.readNullTerminatedString(buffer);
this.sourceAddress = ChannelBufferUtil.readAddress(buffer);

this.numberOfDest = buffer.readByte() & 0xFF;

for(int count=0;count<this.numberOfDest; count++){
byte flag = buffer.readByte();
if(flag==SmppConstants.SME_ADDRESS){
this.destAddresses.add(ChannelBufferUtil.readAddress(buffer));
} else if(flag==SmppConstants.DISTRIBUTION_LIST_NAME){
this.destDistributionList.add(ChannelBufferUtil.readNullTerminatedString(buffer));
}
}

this.esmClass = buffer.readByte();
this.protocolId = buffer.readByte();
this.priority = buffer.readByte();
this.scheduleDeliveryTime = ChannelBufferUtil.readNullTerminatedString(buffer);
this.validityPeriod = ChannelBufferUtil.readNullTerminatedString(buffer);
this.registeredDelivery = buffer.readByte();
this.replaceIfPresent = buffer.readByte();
this.dataCoding = buffer.readByte();
this.defaultMsgId = buffer.readByte();
// this is always an unsigned version of the short message length
short shortMessageLength = buffer.readUnsignedByte();
this.shortMessage = new byte[shortMessageLength];
buffer.readBytes(this.shortMessage);
}

@Override
public void writeBody(ChannelBuffer buffer)
throws UnrecoverablePduException, RecoverablePduException {
ChannelBufferUtil.writeNullTerminatedString(buffer, this.serviceType);
ChannelBufferUtil.writeAddress(buffer, this.sourceAddress);

buffer.writeByte(this.numberOfDest);

for(Address adress : this.destAddresses){
buffer.writeByte(SmppConstants.SME_ADDRESS);
ChannelBufferUtil.writeAddress(buffer, adress);
}

for(String s : this.destDistributionList){
buffer.writeByte(SmppConstants.DISTRIBUTION_LIST_NAME);
ChannelBufferUtil.writeNullTerminatedString(buffer, s);

}

buffer.writeByte(this.esmClass);
buffer.writeByte(this.protocolId);
buffer.writeByte(this.priority);
ChannelBufferUtil.writeNullTerminatedString(buffer,
this.scheduleDeliveryTime);
ChannelBufferUtil
.writeNullTerminatedString(buffer, this.validityPeriod);
buffer.writeByte(this.registeredDelivery);
buffer.writeByte(this.replaceIfPresent);
buffer.writeByte(this.dataCoding);
buffer.writeByte(this.defaultMsgId);
buffer.writeByte((byte) getShortMessageLength());
if (this.shortMessage != null) {
buffer.writeBytes(this.shortMessage);
}
}

@Override
public int calculateByteSizeOfBody() {
int bodyLength = 0;
bodyLength += PduUtil.calculateByteSizeOfNullTerminatedString(this.serviceType);
bodyLength += PduUtil.calculateByteSizeOfAddress(this.sourceAddress);

bodyLength +=1; //number_of_dests

for(Address adress : this.destAddresses){
bodyLength += 1;//Flag
bodyLength += PduUtil.calculateByteSizeOfAddress(adress);
}

for(String s : this.destDistributionList){
bodyLength += 1;//Flag
bodyLength += PduUtil.calculateByteSizeOfNullTerminatedString(s);
}

bodyLength += 3; // esmClass, priority, protocolId
bodyLength += PduUtil.calculateByteSizeOfNullTerminatedString(this.scheduleDeliveryTime);
bodyLength += PduUtil.calculateByteSizeOfNullTerminatedString(this.validityPeriod);
bodyLength += 5; // regDelivery, replace, dataCoding, defaultMsgId, messageLength bytes
bodyLength += getShortMessageLength();
return bodyLength;
}
}
119 changes: 119 additions & 0 deletions src/main/java/com/cloudhopper/smpp/pdu/SubmitMultiResp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
*
*/
package com.cloudhopper.smpp.pdu;

/*
* #%L
* ch-smpp
* %%
* Copyright (C) 2009 - 2013 Cloudhopper by Twitter
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import java.util.ArrayList;
import java.util.List;

import org.jboss.netty.buffer.ChannelBuffer;

import com.cloudhopper.smpp.SmppConstants;
import com.cloudhopper.smpp.type.Address;
import com.cloudhopper.smpp.type.RecoverablePduException;
import com.cloudhopper.smpp.type.SmppInvalidArgumentException;
import com.cloudhopper.smpp.type.UnrecoverablePduException;
import com.cloudhopper.smpp.type.UnsucessfulSME;
import com.cloudhopper.smpp.util.ChannelBufferUtil;
import com.cloudhopper.smpp.util.PduUtil;

/**
* @author Amit Bhayani
*
*/
public class SubmitMultiResp extends BaseSmResp {

private int numberOfUnsucessfulDest;
private List<UnsucessfulSME> unsucessfulSmes = new ArrayList<UnsucessfulSME>();

/**
* @param commandId
* @param name
*/
public SubmitMultiResp() {
super(SmppConstants.CMD_ID_SUBMIT_MULTI_RESP, "submit_multi_resp");
}

public void addUnsucessfulSME(UnsucessfulSME unsucessfulSME)
throws SmppInvalidArgumentException {
this.numberOfUnsucessfulDest++;
this.unsucessfulSmes.add(unsucessfulSME);
}

public int getNumberOfUnsucessfulDest() {
return numberOfUnsucessfulDest;
}

public List<UnsucessfulSME> getUnsucessfulSmes() {
return unsucessfulSmes;
}

@Override
public void readBody(ChannelBuffer buffer)
throws UnrecoverablePduException, RecoverablePduException {
super.readBody(buffer);

this.numberOfUnsucessfulDest = buffer.readByte() & 0xFF;

for (int count = 0; count < this.numberOfUnsucessfulDest; count++) {
Address address = ChannelBufferUtil.readAddress(buffer);
int errorStatusCode = buffer.readInt();

this.unsucessfulSmes.add(new UnsucessfulSME(errorStatusCode,
address));

}
}

@Override
public int calculateByteSizeOfBody() {
int bodyLength = 0;
bodyLength = super.calculateByteSizeOfBody();

bodyLength += 1; // no_unsuccess

for (int count = 0; count < this.numberOfUnsucessfulDest; count++) {
UnsucessfulSME unsucessfulSME = this.unsucessfulSmes.get(count);
bodyLength += PduUtil.calculateByteSizeOfAddress(unsucessfulSME
.getAddress());
bodyLength += 4; // error_status_code
}

return bodyLength;
}

@Override
public void writeBody(ChannelBuffer buffer)
throws UnrecoverablePduException, RecoverablePduException {
super.writeBody(buffer);

buffer.writeByte(this.numberOfUnsucessfulDest);

for (int count = 0; count < this.numberOfUnsucessfulDest; count++) {
UnsucessfulSME unsucessfulSME = this.unsucessfulSmes.get(count);
ChannelBufferUtil.writeAddress(buffer, unsucessfulSME.getAddress());
buffer.writeInt(unsucessfulSME.getErrorStatusCode());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import com.cloudhopper.smpp.pdu.QuerySmResp;
import com.cloudhopper.smpp.pdu.ReplaceSm;
import com.cloudhopper.smpp.pdu.ReplaceSmResp;
import com.cloudhopper.smpp.pdu.SubmitMulti;
import com.cloudhopper.smpp.pdu.SubmitMultiResp;
import com.cloudhopper.smpp.pdu.SubmitSm;
import com.cloudhopper.smpp.pdu.SubmitSmResp;
import com.cloudhopper.smpp.pdu.Unbind;
Expand Down Expand Up @@ -181,6 +183,8 @@ protected Pdu doDecode(int commandLength, ChannelBuffer buffer) throws Unrecover
pdu = new Unbind();
} else if (commandId == SmppConstants.CMD_ID_ALERT_NOTIFICATION) {
pdu = new AlertNotification();
} else if (commandId == SmppConstants.CMD_ID_SUBMIT_MULTI) {
pdu = new SubmitMulti();
} else {
pdu = new PartialPdu(commandId);
}
Expand Down Expand Up @@ -209,6 +213,8 @@ protected Pdu doDecode(int commandLength, ChannelBuffer buffer) throws Unrecover
pdu = new UnbindResp();
} else if (commandId == SmppConstants.CMD_ID_GENERIC_NACK) {
pdu = new GenericNack();
} else if (commandId == SmppConstants.CMD_ID_SUBMIT_MULTI_RESP) {
pdu = new SubmitMultiResp();
} else {
pdu = new PartialPduResp(commandId);
}
Expand Down
Loading