use of org.jsmpp.bean.OptionalParameter in project camel by apache.
the class SmppSubmitMultiCommand method createSubmitMultiTemplate.
@SuppressWarnings({ "unchecked" })
protected SubmitMulti createSubmitMultiTemplate(Exchange exchange) {
Message in = exchange.getIn();
SubmitMulti submitMulti = new SubmitMulti();
if (in.getHeaders().containsKey(SmppConstants.DATA_CODING)) {
submitMulti.setDataCoding(in.getHeader(SmppConstants.DATA_CODING, Byte.class));
} else if (in.getHeaders().containsKey(SmppConstants.ALPHABET)) {
submitMulti.setDataCoding(in.getHeader(SmppConstants.ALPHABET, Byte.class));
} else {
submitMulti.setDataCoding(config.getDataCoding());
}
byte destAddrTon;
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_TON)) {
destAddrTon = in.getHeader(SmppConstants.DEST_ADDR_TON, Byte.class);
} else {
destAddrTon = config.getDestAddrTon();
}
byte destAddrNpi;
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_NPI)) {
destAddrNpi = in.getHeader(SmppConstants.DEST_ADDR_NPI, Byte.class);
} else {
destAddrNpi = config.getDestAddrNpi();
}
List<String> destAddresses;
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR)) {
destAddresses = in.getHeader(SmppConstants.DEST_ADDR, List.class);
} else {
destAddresses = Arrays.asList(config.getDestAddr());
}
Address[] addresses = new Address[destAddresses.size()];
int addrNum = 0;
for (String destAddr : destAddresses) {
Address addr = new Address(destAddrTon, destAddrNpi, destAddr);
addresses[addrNum++] = addr;
}
submitMulti.setDestAddresses(addresses);
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
submitMulti.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
} else {
submitMulti.setSourceAddr(config.getSourceAddr());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
submitMulti.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
} else {
submitMulti.setSourceAddrTon(config.getSourceAddrTon());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
submitMulti.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
} else {
submitMulti.setSourceAddrNpi(config.getSourceAddrNpi());
}
if (in.getHeaders().containsKey(SmppConstants.SERVICE_TYPE)) {
submitMulti.setServiceType(in.getHeader(SmppConstants.SERVICE_TYPE, String.class));
} else {
submitMulti.setServiceType(config.getServiceType());
}
if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
submitMulti.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, Byte.class));
} else {
submitMulti.setRegisteredDelivery(config.getRegisteredDelivery());
}
if (in.getHeaders().containsKey(SmppConstants.PROTOCOL_ID)) {
submitMulti.setProtocolId(in.getHeader(SmppConstants.PROTOCOL_ID, Byte.class));
} else {
submitMulti.setProtocolId(config.getProtocolId());
}
if (in.getHeaders().containsKey(SmppConstants.PRIORITY_FLAG)) {
submitMulti.setPriorityFlag(in.getHeader(SmppConstants.PRIORITY_FLAG, Byte.class));
} else {
submitMulti.setPriorityFlag(config.getPriorityFlag());
}
if (in.getHeaders().containsKey(SmppConstants.SCHEDULE_DELIVERY_TIME)) {
submitMulti.setScheduleDeliveryTime(SmppUtils.formatTime(in.getHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, Date.class)));
}
if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
Object validityPeriod = in.getHeader(SmppConstants.VALIDITY_PERIOD);
if (validityPeriod instanceof String) {
submitMulti.setValidityPeriod((String) validityPeriod);
} else if (validityPeriod instanceof Date) {
submitMulti.setValidityPeriod(SmppUtils.formatTime((Date) validityPeriod));
}
}
if (in.getHeaders().containsKey(SmppConstants.REPLACE_IF_PRESENT_FLAG)) {
submitMulti.setReplaceIfPresentFlag(in.getHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, Byte.class));
} else {
submitMulti.setReplaceIfPresentFlag(config.getReplaceIfPresentFlag());
}
Map<java.lang.Short, Object> optinalParamater = in.getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
if (optinalParamater != null) {
List<OptionalParameter> optParams = createOptionalParametersByCode(optinalParamater);
submitMulti.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);
submitMulti.setOptionalParameters(optParams.toArray(new OptionalParameter[optParams.size()]));
} else {
submitMulti.setOptionalParameters(new OptionalParameter[] {});
}
}
return submitMulti;
}
use of org.jsmpp.bean.OptionalParameter in project camel by apache.
the class SmppSubmitSmCommand method createSubmitSmTemplate.
@SuppressWarnings({ "unchecked" })
protected SubmitSm createSubmitSmTemplate(Exchange exchange) {
Message in = exchange.getIn();
SubmitSm submitSm = new SubmitSm();
if (in.getHeaders().containsKey(SmppConstants.DATA_CODING)) {
submitSm.setDataCoding(in.getHeader(SmppConstants.DATA_CODING, Byte.class));
} else if (in.getHeaders().containsKey(SmppConstants.ALPHABET)) {
submitSm.setDataCoding(in.getHeader(SmppConstants.ALPHABET, Byte.class));
} else {
submitSm.setDataCoding(config.getDataCoding());
}
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR)) {
submitSm.setDestAddress(in.getHeader(SmppConstants.DEST_ADDR, String.class));
} else {
submitSm.setDestAddress(config.getDestAddr());
}
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_TON)) {
submitSm.setDestAddrTon(in.getHeader(SmppConstants.DEST_ADDR_TON, Byte.class));
} else {
submitSm.setDestAddrTon(config.getDestAddrTon());
}
if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_NPI)) {
submitSm.setDestAddrNpi(in.getHeader(SmppConstants.DEST_ADDR_NPI, Byte.class));
} else {
submitSm.setDestAddrNpi(config.getDestAddrNpi());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
submitSm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
} else {
submitSm.setSourceAddr(config.getSourceAddr());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
submitSm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
} else {
submitSm.setSourceAddrTon(config.getSourceAddrTon());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
submitSm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
} else {
submitSm.setSourceAddrNpi(config.getSourceAddrNpi());
}
if (in.getHeaders().containsKey(SmppConstants.SERVICE_TYPE)) {
submitSm.setServiceType(in.getHeader(SmppConstants.SERVICE_TYPE, String.class));
} else {
submitSm.setServiceType(config.getServiceType());
}
if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
submitSm.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, Byte.class));
} else {
submitSm.setRegisteredDelivery(config.getRegisteredDelivery());
}
if (in.getHeaders().containsKey(SmppConstants.PROTOCOL_ID)) {
submitSm.setProtocolId(in.getHeader(SmppConstants.PROTOCOL_ID, Byte.class));
} else {
submitSm.setProtocolId(config.getProtocolId());
}
if (in.getHeaders().containsKey(SmppConstants.PRIORITY_FLAG)) {
submitSm.setPriorityFlag(in.getHeader(SmppConstants.PRIORITY_FLAG, Byte.class));
} else {
submitSm.setPriorityFlag(config.getPriorityFlag());
}
if (in.getHeaders().containsKey(SmppConstants.SCHEDULE_DELIVERY_TIME)) {
submitSm.setScheduleDeliveryTime(SmppUtils.formatTime(in.getHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, Date.class)));
}
if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
Object validityPeriod = in.getHeader(SmppConstants.VALIDITY_PERIOD);
if (validityPeriod instanceof String) {
submitSm.setValidityPeriod((String) validityPeriod);
} else if (validityPeriod instanceof Date) {
submitSm.setValidityPeriod(SmppUtils.formatTime((Date) validityPeriod));
}
}
if (in.getHeaders().containsKey(SmppConstants.REPLACE_IF_PRESENT_FLAG)) {
submitSm.setReplaceIfPresent(in.getHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, Byte.class));
} else {
submitSm.setReplaceIfPresent(config.getReplaceIfPresentFlag());
}
submitSm.setEsmClass(new ESMClass().value());
Map<java.lang.Short, Object> optinalParamater = in.getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
if (optinalParamater != null) {
List<OptionalParameter> optParams = createOptionalParametersByCode(optinalParamater);
submitSm.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);
submitSm.setOptionalParameters(optParams.toArray(new OptionalParameter[optParams.size()]));
} else {
submitSm.setOptionalParameters();
}
}
return submitSm;
}
use of org.jsmpp.bean.OptionalParameter 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.OptionalParameter in project camel by apache.
the class MessageReceiverListenerImplTest method onAcceptDataSmSuccess.
@Test
public void onAcceptDataSmSuccess() throws Exception {
SMPPSession session = createMock(SMPPSession.class);
DataSm dataSm = createMock(DataSm.class);
Exchange exchange = createMock(Exchange.class);
OptionalParameter[] optionalParameters = new OptionalParameter[] {};
expect(endpoint.createOnAcceptDataSm(dataSm, "1")).andReturn(exchange);
processor.process(exchange);
expect(exchange.getException()).andReturn(null);
expect(dataSm.getOptionalParameters()).andReturn(optionalParameters);
replay(endpoint, processor, exceptionHandler, session, dataSm, exchange);
DataSmResult result = listener.onAcceptDataSm(dataSm, session);
verify(endpoint, processor, exceptionHandler, session, dataSm, exchange);
assertEquals("1", result.getMessageId());
assertSame(optionalParameters, result.getOptionalParameters());
}
use of org.jsmpp.bean.OptionalParameter in project camel by apache.
the class SmppDataSmCommandTest method executeWithOptionalParameterNewStyle.
@SuppressWarnings("unchecked")
@Test
public void executeWithOptionalParameterNewStyle() throws Exception {
Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
Map<Short, Object> optionalParameters = new LinkedHashMap<Short, Object>();
// standard optional parameter
optionalParameters.put(Short.valueOf((short) 0x0202), "1292".getBytes("UTF-8"));
optionalParameters.put(Short.valueOf((short) 0x001D), "urgent");
optionalParameters.put(Short.valueOf((short) 0x0005), Byte.valueOf("4"));
optionalParameters.put(Short.valueOf((short) 0x0008), Short.valueOf((short) 2));
optionalParameters.put(Short.valueOf((short) 0x0017), Integer.valueOf(3600000));
optionalParameters.put(Short.valueOf((short) 0x130C), null);
// vendor specific optional parameter
optionalParameters.put(Short.valueOf((short) 0x2150), "0815".getBytes("UTF-8"));
optionalParameters.put(Short.valueOf((short) 0x2151), "0816");
optionalParameters.put(Short.valueOf((short) 0x2152), Byte.valueOf("6"));
optionalParameters.put(Short.valueOf((short) 0x2153), Short.valueOf((short) 9));
optionalParameters.put(Short.valueOf((short) 0x2154), Integer.valueOf(7400000));
optionalParameters.put(Short.valueOf((short) 0x2155), null);
exchange.getIn().setHeader(SmppConstants.OPTIONAL_PARAMETER, optionalParameters);
expect(session.dataShortMessage(eq("CMT"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1616"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1717"), eq(new ESMClass()), eq(new RegisteredDelivery((byte) 1)), eq(DataCodings.newInstance((byte) 0)), eq(new OptionalParameter.OctetString(Tag.SOURCE_SUBADDRESS, "1292")), eq(new OptionalParameter.COctetString(Tag.ADDITIONAL_STATUS_INFO_TEXT.code(), "urgent")), eq(new OptionalParameter.Byte(Tag.DEST_ADDR_SUBUNIT, (byte) 4)), eq(new OptionalParameter.Short(Tag.DEST_TELEMATICS_ID.code(), (short) 2)), eq(new OptionalParameter.Int(Tag.QOS_TIME_TO_LIVE, 3600000)), eq(new OptionalParameter.Null(Tag.ALERT_ON_MESSAGE_DELIVERY)), eq(new OptionalParameter.OctetString((short) 0x2150, "1292", "UTF-8")), eq(new OptionalParameter.COctetString((short) 0x2151, "0816")), eq(new OptionalParameter.Byte((short) 0x2152, (byte) 6)), eq(new OptionalParameter.Short((short) 0x2153, (short) 9)), eq(new OptionalParameter.Int((short) 0x2154, 7400000)), eq(new OptionalParameter.Null((short) 0x2155)))).andReturn(new DataSmResult(new MessageId("1"), new OptionalParameter[] { new OptionalParameter.Source_subaddress("1292".getBytes()), new OptionalParameter.Additional_status_info_text("urgent"), new OptionalParameter.Dest_addr_subunit((byte) 4), new OptionalParameter.Dest_telematics_id((short) 2), new OptionalParameter.Qos_time_to_live(3600000), new OptionalParameter.Alert_on_message_delivery((byte) 0) }));
replay(session);
command.execute(exchange);
verify(session);
assertEquals(3, exchange.getOut().getHeaders().size());
assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
Map<String, String> optParamMap = exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
assertEquals(6, optParamMap.size());
assertEquals("1292", optParamMap.get("SOURCE_SUBADDRESS"));
assertEquals("urgent", optParamMap.get("ADDITIONAL_STATUS_INFO_TEXT"));
assertEquals("4", optParamMap.get("DEST_ADDR_SUBUNIT"));
assertEquals("2", optParamMap.get("DEST_TELEMATICS_ID"));
assertEquals("3600000", optParamMap.get("QOS_TIME_TO_LIVE"));
assertEquals("0", optParamMap.get("ALERT_ON_MESSAGE_DELIVERY"));
Map<Short, Object> optionalResultParameter = exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
assertEquals(6, optionalResultParameter.size());
assertArrayEquals("1292".getBytes("UTF-8"), (byte[]) optionalResultParameter.get(Short.valueOf((short) 0x0202)));
assertEquals("urgent", optionalResultParameter.get(Short.valueOf((short) 0x001D)));
assertEquals(Byte.valueOf((byte) 4), optionalResultParameter.get(Short.valueOf((short) 0x0005)));
assertEquals(Short.valueOf((short) 2), optionalResultParameter.get(Short.valueOf((short) 0x0008)));
assertEquals(Integer.valueOf(3600000), optionalResultParameter.get(Short.valueOf((short) 0x0017)));
assertEquals((byte) 0, optionalResultParameter.get(Short.valueOf((short) 0x130C)));
}
Aggregations