Search in sources :

Example 1 with OptionalParameter

use of org.jsmpp.bean.OptionalParameter in project camel by apache.

the class SmppDataSmCommand method createOptionalParameterByName.

protected Map<String, String> createOptionalParameterByName(OptionalParameter[] optionalParameters) {
    if (optionalParameters == null) {
        return null;
    }
    Map<String, String> optParams = new HashMap<String, String>();
    for (OptionalParameter optionalParameter : optionalParameters) {
        String value = null;
        if (optionalParameter instanceof COctetString) {
            value = ((COctetString) optionalParameter).getValueAsString();
        } else if (optionalParameter instanceof OctetString) {
            value = ((OctetString) optionalParameter).getValueAsString();
        } else if (optionalParameter instanceof Int) {
            value = String.valueOf(((Int) optionalParameter).getValue());
        } else if (optionalParameter instanceof Short) {
            value = String.valueOf(((Short) optionalParameter).getValue());
        } else if (optionalParameter instanceof Byte) {
            value = String.valueOf(((Byte) optionalParameter).getValue());
        } else if (optionalParameter instanceof Null) {
            value = null;
        }
        optParams.put(Tag.valueOf(optionalParameter.tag).name(), value);
    }
    return optParams;
}
Also used : OptionalParameter(org.jsmpp.bean.OptionalParameter) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) Null(org.jsmpp.bean.OptionalParameter.Null) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) HashMap(java.util.HashMap) Byte(org.jsmpp.bean.OptionalParameter.Byte) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) Int(org.jsmpp.bean.OptionalParameter.Int) Short(org.jsmpp.bean.OptionalParameter.Short)

Example 2 with OptionalParameter

use of org.jsmpp.bean.OptionalParameter in project camel by apache.

the class SmppDataSmCommandTest method executeWithOptionalParameter.

@SuppressWarnings("unchecked")
@Test
public void executeWithOptionalParameter() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
    Map<String, String> optionalParameters = new LinkedHashMap<String, String>();
    optionalParameters.put("SOURCE_SUBADDRESS", "1292");
    optionalParameters.put("ADDITIONAL_STATUS_INFO_TEXT", "urgent");
    optionalParameters.put("DEST_ADDR_SUBUNIT", "4");
    optionalParameters.put("DEST_TELEMATICS_ID", "2");
    optionalParameters.put("QOS_TIME_TO_LIVE", "3600000");
    optionalParameters.put("ALERT_ON_MESSAGE_DELIVERY", null);
    // fall back test for vendor specific optional parameter 
    optionalParameters.put("0x2150", "0815");
    optionalParameters.put("0x2151", "0816");
    optionalParameters.put("0x2152", "6");
    optionalParameters.put("0x2153", "9");
    optionalParameters.put("0x2154", "7400000");
    optionalParameters.put("0x2155", null);
    exchange.getIn().setHeader(SmppConstants.OPTIONAL_PARAMETERS, 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.Source_subaddress("1292".getBytes())), eq(new OptionalParameter.Additional_status_info_text("urgent")), eq(new OptionalParameter.Dest_addr_subunit((byte) 4)), eq(new OptionalParameter.Dest_telematics_id((short) 2)), eq(new OptionalParameter.Qos_time_to_live(3600000)), eq(new OptionalParameter.Alert_on_message_delivery((byte) 0)))).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)));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) ESMClass(org.jsmpp.bean.ESMClass) DataSmResult(org.jsmpp.session.DataSmResult) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) LinkedHashMap(java.util.LinkedHashMap) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) OptionalParameter(org.jsmpp.bean.OptionalParameter) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) MessageId(org.jsmpp.util.MessageId) Test(org.junit.Test)

Example 3 with OptionalParameter

use of org.jsmpp.bean.OptionalParameter in project camel by apache.

the class SmppBindingTest method createSmppMessageFromDeliveryReceiptWithoutShortMessageShouldNotThrowException.

@Test
public void createSmppMessageFromDeliveryReceiptWithoutShortMessageShouldNotThrowException() throws Exception {
    DeliverSm deliverSm = new DeliverSm();
    deliverSm.setSmscDeliveryReceipt();
    deliverSm.setOptionalParameters(new OptionalParameter.Short((short) 0x2153, (short) 0));
    try {
        SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
        Map<Short, Object> optionalParameter = smppMessage.getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
        assertEquals(Short.valueOf((short) 0), optionalParameter.get(Short.valueOf((short) 0x2153)));
    } catch (Exception e) {
        fail("Should not throw exception while creating smppMessage in absence of shortMessage");
    }
}
Also used : OptionalParameter(org.jsmpp.bean.OptionalParameter) DeliverSm(org.jsmpp.bean.DeliverSm) Test(org.junit.Test)

Example 4 with OptionalParameter

use of org.jsmpp.bean.OptionalParameter in project camel by apache.

the class SmppBindingTest method createSmppMessageFromDeliveryReceiptWithOptionalParametersShouldReturnASmppMessage.

@SuppressWarnings("unchecked")
@Test
public void createSmppMessageFromDeliveryReceiptWithOptionalParametersShouldReturnASmppMessage() throws Exception {
    DeliverSm deliverSm = new DeliverSm();
    deliverSm.setSmscDeliveryReceipt();
    deliverSm.setShortMessage("id:2 sub:001 dlvrd:001 submit date:0908312310 done date:0908312311 stat:DELIVRD err:xxx Text:Hello SMPP world!".getBytes());
    deliverSm.setOptionalParameters(new OptionalParameter.OctetString(Tag.SOURCE_SUBADDRESS, "OctetString"), new OptionalParameter.COctetString((short) 0x001D, "COctetString"), new OptionalParameter.Byte(Tag.DEST_ADDR_SUBUNIT, (byte) 0x01), new OptionalParameter.Short(Tag.DEST_TELEMATICS_ID, (short) 1), new OptionalParameter.Int(Tag.QOS_TIME_TO_LIVE, 1), new OptionalParameter.Null(Tag.ALERT_ON_MESSAGE_DELIVERY));
    SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
    assertEquals("Hello SMPP world!", smppMessage.getBody());
    assertEquals(10, smppMessage.getHeaders().size());
    assertEquals("2", smppMessage.getHeader(SmppConstants.ID));
    assertEquals(1, smppMessage.getHeader(SmppConstants.DELIVERED));
    // To avoid the test failure when running in different TimeZone
    //assertEquals(new Date(1251753060000L), smppMessage.getHeader(SmppConstants.DONE_DATE));
    assertEquals("xxx", smppMessage.getHeader(SmppConstants.ERROR));
    //assertEquals(new Date(1251753000000L), smppMessage.getHeader(SmppConstants.SUBMIT_DATE));
    assertEquals(1, smppMessage.getHeader(SmppConstants.SUBMITTED));
    assertEquals(DeliveryReceiptState.DELIVRD, smppMessage.getHeader(SmppConstants.FINAL_STATUS));
    assertEquals(SmppMessageType.DeliveryReceipt.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
    Map<String, Object> optionalParameters = smppMessage.getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
    assertEquals(6, optionalParameters.size());
    assertEquals("OctetString", optionalParameters.get("SOURCE_SUBADDRESS"));
    assertEquals("COctetString", optionalParameters.get("ADDITIONAL_STATUS_INFO_TEXT"));
    assertEquals(Byte.valueOf((byte) 0x01), optionalParameters.get("DEST_ADDR_SUBUNIT"));
    assertEquals(Short.valueOf((short) 1), optionalParameters.get("DEST_TELEMATICS_ID"));
    assertEquals(Integer.valueOf(1), optionalParameters.get("QOS_TIME_TO_LIVE"));
    assertNull("0x00", optionalParameters.get("ALERT_ON_MESSAGE_DELIVERY"));
    Map<Short, Object> optionalParameter = smppMessage.getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
    assertEquals(6, optionalParameter.size());
    assertArrayEquals("OctetString".getBytes("UTF-8"), (byte[]) optionalParameter.get(Short.valueOf((short) 0x0202)));
    assertEquals("COctetString", optionalParameter.get(Short.valueOf((short) 0x001D)));
    assertEquals(Byte.valueOf((byte) 0x01), optionalParameter.get(Short.valueOf((short) 0x0005)));
    assertEquals(Short.valueOf((short) 1), optionalParameter.get(Short.valueOf((short) 0x0008)));
    assertEquals(Integer.valueOf(1), optionalParameter.get(Short.valueOf((short) 0x0017)));
    assertNull("0x00", optionalParameter.get(Short.valueOf((short) 0x130C)));
}
Also used : OctetString(org.jsmpp.bean.OptionalParameter.OctetString) OptionalParameter(org.jsmpp.bean.OptionalParameter) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) DeliverSm(org.jsmpp.bean.DeliverSm) Test(org.junit.Test)

Example 5 with OptionalParameter

use of org.jsmpp.bean.OptionalParameter in project camel by apache.

the class AbstractSmppCommand method createOptionalParametersByName.

/**
     * @deprecated will be removed in Camel 2.13.0/3.0.0 - use createOptionalParametersByCode instead
     * @param optinalParamaters
     * @return
     */
@Deprecated
@SuppressWarnings({ "rawtypes", "unchecked" })
protected List<OptionalParameter> createOptionalParametersByName(Map<String, String> optinalParamaters) {
    List<OptionalParameter> optParams = new ArrayList<OptionalParameter>();
    for (Entry<String, String> entry : optinalParamaters.entrySet()) {
        OptionalParameter optParam = null;
        String value = entry.getValue();
        try {
            Tag tag = Tag.valueOf(entry.getKey());
            Class type = determineTypeClass(tag);
            Set<Class> ancestorClasses = new HashSet<Class>(2);
            Class superclass = type.getSuperclass();
            ancestorClasses.add(superclass);
            if (superclass != Object.class) {
                ancestorClasses.add(superclass.getSuperclass());
            }
            if (ancestorClasses.contains(OctetString.class)) {
                optParam = (OptionalParameter) type.getConstructor(byte[].class).newInstance(value.getBytes());
            } else if (ancestorClasses.contains(OptionalParameter.Byte.class)) {
                // required because jsmpp 2.1.1 interpreted null as 0
                Byte byteValue = (value == null) ? 0 : Byte.valueOf(value);
                optParam = (OptionalParameter) type.getConstructor(byte.class).newInstance(byteValue);
            } else if (ancestorClasses.contains(OptionalParameter.Int.class)) {
                // required because jsmpp 2.1.1 interpreted null as 0
                Integer intValue = (value == null) ? 0 : Integer.valueOf(value);
                optParam = (OptionalParameter) type.getConstructor(int.class).newInstance(intValue);
            } else if (ancestorClasses.contains(OptionalParameter.Short.class)) {
                // required because jsmpp 2.1.1 interpreted null as 0
                Short shortValue = (value == null) ? 0 : Short.valueOf(value);
                optParam = (OptionalParameter) type.getConstructor(short.class).newInstance(shortValue);
            }
            optParams.add(optParam);
        } catch (Exception e) {
            log.info("Couldn't determine optional parameter for key {} and value {}. Skip this one.", entry.getKey(), value);
        }
    }
    return optParams;
}
Also used : ArrayList(java.util.ArrayList) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) OptionalParameter(org.jsmpp.bean.OptionalParameter) Tag(org.jsmpp.bean.OptionalParameter.Tag) HashSet(java.util.HashSet)

Aggregations

OptionalParameter (org.jsmpp.bean.OptionalParameter)15 OctetString (org.jsmpp.bean.OptionalParameter.OctetString)8 COctetString (org.jsmpp.bean.OptionalParameter.COctetString)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Exchange (org.apache.camel.Exchange)3 Message (org.apache.camel.Message)3 ESMClass (org.jsmpp.bean.ESMClass)3 Null (org.jsmpp.bean.OptionalParameter.Null)3 DataSmResult (org.jsmpp.session.DataSmResult)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 DataSm (org.jsmpp.bean.DataSm)2 DeliverSm (org.jsmpp.bean.DeliverSm)2 Byte (org.jsmpp.bean.OptionalParameter.Byte)2 Short (org.jsmpp.bean.OptionalParameter.Short)2 Tag (org.jsmpp.bean.OptionalParameter.Tag)2