use of org.jsmpp.bean.DataSm in project camel by apache.
the class SmppDataSmCommand method execute.
@Override
public void execute(Exchange exchange) throws SmppException {
DataSm dataSm = createDataSm(exchange);
if (log.isDebugEnabled()) {
log.debug("Sending a data short message for exchange id '{}'...", exchange.getExchangeId());
}
DataSmResult result;
try {
result = session.dataShortMessage(dataSm.getServiceType(), TypeOfNumber.valueOf(dataSm.getSourceAddrTon()), NumberingPlanIndicator.valueOf(dataSm.getSourceAddrNpi()), dataSm.getSourceAddr(), TypeOfNumber.valueOf(dataSm.getDestAddrTon()), NumberingPlanIndicator.valueOf(dataSm.getDestAddrNpi()), dataSm.getDestAddress(), new ESMClass(dataSm.getEsmClass()), new RegisteredDelivery(dataSm.getRegisteredDelivery()), DataCodings.newInstance(dataSm.getDataCoding()), dataSm.getOptionalParameters());
} catch (Exception e) {
throw new SmppException(e);
}
if (log.isDebugEnabled()) {
log.debug("Sent a data short message for exchange id '{}' and message id '{}'", exchange.getExchangeId(), result.getMessageId());
}
Message message = getResponseMessage(exchange);
message.setHeader(SmppConstants.ID, result.getMessageId());
message.setHeader(SmppConstants.OPTIONAL_PARAMETERS, createOptionalParameterByName(result.getOptionalParameters()));
message.setHeader(SmppConstants.OPTIONAL_PARAMETER, createOptionalParameterByCode(result.getOptionalParameters()));
}
use of org.jsmpp.bean.DataSm in project camel by apache.
the class SmppEndpointTest method createOnAcceptDataSmWithExchangePattern.
@Test
public void createOnAcceptDataSmWithExchangePattern() throws Exception {
DataSm dataSm = createMock(DataSm.class);
SmppMessage message = createMock(SmppMessage.class);
expect(binding.createSmppMessage(eq(dataSm), isA(String.class))).andReturn(message);
message.setExchange(isA(Exchange.class));
replay(dataSm, binding, message);
Exchange exchange = endpoint.createOnAcceptDataSm(ExchangePattern.InOut, dataSm, "1");
verify(dataSm, binding, message);
assertSame(binding, exchange.getProperty(Exchange.BINDING));
assertSame(message, exchange.getIn());
assertSame(ExchangePattern.InOut, exchange.getPattern());
}
use of org.jsmpp.bean.DataSm in project camel by apache.
the class SmppBindingTest method createSmppMessageFromDataSmShouldReturnASmppMessage.
@Test
public void createSmppMessageFromDataSmShouldReturnASmppMessage() throws Exception {
DataSm dataSm = new DataSm();
dataSm.setSequenceNumber(1);
dataSm.setCommandId(1);
dataSm.setCommandStatus(0);
dataSm.setSourceAddr("1818");
dataSm.setSourceAddrNpi(NumberingPlanIndicator.NATIONAL.value());
dataSm.setSourceAddrTon(TypeOfNumber.NATIONAL.value());
dataSm.setDestAddress("1919");
dataSm.setDestAddrNpi(NumberingPlanIndicator.NATIONAL.value());
dataSm.setDestAddrTon(TypeOfNumber.NATIONAL.value());
dataSm.setServiceType("WAP");
dataSm.setRegisteredDelivery((byte) 0);
SmppMessage smppMessage = binding.createSmppMessage(dataSm, "1");
assertNull(smppMessage.getBody());
assertEquals(14, smppMessage.getHeaders().size());
assertEquals("1", smppMessage.getHeader(SmppConstants.ID));
assertEquals(1, smppMessage.getHeader(SmppConstants.SEQUENCE_NUMBER));
assertEquals(1, smppMessage.getHeader(SmppConstants.COMMAND_ID));
assertEquals(0, smppMessage.getHeader(SmppConstants.COMMAND_STATUS));
assertEquals("1818", smppMessage.getHeader(SmppConstants.SOURCE_ADDR));
assertEquals((byte) 8, smppMessage.getHeader(SmppConstants.SOURCE_ADDR_NPI));
assertEquals((byte) 2, smppMessage.getHeader(SmppConstants.SOURCE_ADDR_TON));
assertEquals("1919", smppMessage.getHeader(SmppConstants.DEST_ADDR));
assertEquals((byte) 8, smppMessage.getHeader(SmppConstants.DEST_ADDR_NPI));
assertEquals((byte) 2, smppMessage.getHeader(SmppConstants.DEST_ADDR_TON));
assertEquals("WAP", smppMessage.getHeader(SmppConstants.SERVICE_TYPE));
assertEquals((byte) 0, smppMessage.getHeader(SmppConstants.REGISTERED_DELIVERY));
assertEquals((byte) 0, smppMessage.getHeader(SmppConstants.DATA_CODING));
assertEquals(SmppMessageType.DataSm.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
}
use of org.jsmpp.bean.DataSm in project camel by apache.
the class SmppDataSmCommand method createDataSm.
@SuppressWarnings({ "unchecked" })
protected DataSm createDataSm(Exchange exchange) {
Message in = exchange.getIn();
DataSm dataSm = new DataSm();
if (in.getHeaders().containsKey(SmppConstants.DATA_CODING)) {
dataSm.setDataCoding(in.getHeader(SmppConstants.DATA_CODING, java.lang.Byte.class));
} else if (in.getHeaders().containsKey(SmppConstants.ALPHABET)) {
dataSm.setDataCoding(in.getHeader(SmppConstants.ALPHABET, java.lang.Byte.class));
} else {
dataSm.setDataCoding(config.getDataCoding());
}
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR)) {
dataSm.setDestAddress(in.getHeader(SmppConstants.DEST_ADDR, String.class));
} else {
dataSm.setDestAddress(config.getDestAddr());
}
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_TON)) {
dataSm.setDestAddrTon(in.getHeader(SmppConstants.DEST_ADDR_TON, java.lang.Byte.class));
} else {
dataSm.setDestAddrTon(config.getDestAddrTon());
}
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_NPI)) {
dataSm.setDestAddrNpi(in.getHeader(SmppConstants.DEST_ADDR_NPI, java.lang.Byte.class));
} else {
dataSm.setDestAddrNpi(config.getDestAddrNpi());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
dataSm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
} else {
dataSm.setSourceAddr(config.getSourceAddr());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
dataSm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, java.lang.Byte.class));
} else {
dataSm.setSourceAddrTon(config.getSourceAddrTon());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
dataSm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, java.lang.Byte.class));
} else {
dataSm.setSourceAddrNpi(config.getSourceAddrNpi());
}
if (in.getHeaders().containsKey(SmppConstants.SERVICE_TYPE)) {
dataSm.setServiceType(in.getHeader(SmppConstants.SERVICE_TYPE, String.class));
} else {
dataSm.setServiceType(config.getServiceType());
}
if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
dataSm.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, java.lang.Byte.class));
} else {
dataSm.setRegisteredDelivery(config.getRegisteredDelivery());
}
Map<java.lang.Short, Object> optinalParamater = in.getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
if (optinalParamater != null) {
List<OptionalParameter> optParams = createOptionalParametersByCode(optinalParamater);
dataSm.setOptionalParameters(optParams.toArray(new OptionalParameter[optParams.size()]));
} else {
Map<String, String> optinalParamaters = in.getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
if (optinalParamaters != null) {
List<OptionalParameter> optParams = createOptionalParametersByName(optinalParamaters);
dataSm.setOptionalParameters(optParams.toArray(new OptionalParameter[optParams.size()]));
} else {
dataSm.setOptionalParameters();
}
}
return dataSm;
}
use of org.jsmpp.bean.DataSm in project camel by apache.
the class SmppUtils method copyDataSm.
public static DataSm copyDataSm(DataSm src) {
DataSm dest = new DataSm();
dest.setCommandId(src.getCommandId());
dest.setCommandLength(src.getCommandLength());
dest.setCommandStatus(src.getCommandStatus());
dest.setDataCoding(src.getDataCoding());
dest.setDestAddress(src.getDestAddress());
dest.setDestAddrNpi(src.getDestAddrNpi());
dest.setDestAddrTon(src.getDestAddrTon());
dest.setEsmClass(src.getEsmClass());
dest.setOptionalParameters(src.getOptionalParameters());
dest.setRegisteredDelivery(src.getRegisteredDelivery());
dest.setSequenceNumber(src.getSequenceNumber());
dest.setServiceType(src.getServiceType());
dest.setSourceAddr(src.getSourceAddr());
dest.setSourceAddrNpi(src.getSourceAddrNpi());
dest.setSourceAddrTon(src.getSourceAddrTon());
if (src.isDefaultMessageType()) {
dest.setDefaultMessageType();
}
if (src.isReplyPath()) {
dest.setReplyPath();
}
if (src.isUdhi()) {
dest.setUdhi();
}
if (src.isUdhiAndReplyPath()) {
dest.setUdhiAndReplyPath();
}
return dest;
}
Aggregations