Search in sources :

Example 1 with ESMClass

use of org.jsmpp.bean.ESMClass 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()));
}
Also used : DataSm(org.jsmpp.bean.DataSm) Message(org.apache.camel.Message) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) ESMClass(org.jsmpp.bean.ESMClass) DataSmResult(org.jsmpp.session.DataSmResult)

Example 2 with ESMClass

use of org.jsmpp.bean.ESMClass 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 ESMClass

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

the class SmppDataSmCommandTest method execute.

@Test
public void execute() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
    exchange.getIn().setHeader(SmppConstants.SERVICE_TYPE, "XXX");
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR, "1919");
    exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
    expect(session.dataShortMessage(eq("XXX"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"), eq(TypeOfNumber.INTERNATIONAL), eq(NumberingPlanIndicator.INTERNET), eq("1919"), eq(new ESMClass()), eq(new RegisteredDelivery((byte) 2)), eq(DataCodings.newInstance((byte) 0)))).andReturn(new DataSmResult(new MessageId("1"), null));
    replay(session);
    command.execute(exchange);
    verify(session);
    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
    assertNull(exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) ESMClass(org.jsmpp.bean.ESMClass) DataSmResult(org.jsmpp.session.DataSmResult) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) MessageId(org.jsmpp.util.MessageId) Test(org.junit.Test)

Example 4 with ESMClass

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

the class SmppSubmitMultiCommandTest method bodyWithSmscDefaultDataCodingNarrowedToCharset.

@Test
public void bodyWithSmscDefaultDataCodingNarrowedToCharset() throws Exception {
    final byte dataCoding = (byte) 0x00;
    /* SMSC-default */
    byte[] body = { (byte) 0xFF, 'A', 'B', (byte) 0x00, (byte) 0xFF, (byte) 0x7F, 'C', (byte) 0xFF };
    byte[] bodyNarrowed = { '?', 'A', 'B', '\0', '?', (byte) 0x7F, 'C', '?' };
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
    exchange.getIn().setHeader(SmppConstants.DATA_CODING, dataCoding);
    exchange.getIn().setBody(body);
    Address[] destAddrs = new Address[] { new Address(TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1717") };
    expect(session.submitMultiple(eq("CMT"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1616"), aryEq(destAddrs), eq(new ESMClass()), eq((byte) 0), eq((byte) 1), (String) isNull(), (String) isNull(), eq(new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE)), eq(ReplaceIfPresentFlag.DEFAULT), eq(DataCodings.newInstance(dataCoding)), eq((byte) 0), aryEq(bodyNarrowed))).andReturn(new SubmitMultiResult("1"));
    replay(session);
    command.execute(exchange);
    verify(session);
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Address(org.jsmpp.bean.Address) SubmitMultiResult(org.jsmpp.bean.SubmitMultiResult) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) ESMClass(org.jsmpp.bean.ESMClass) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 5 with ESMClass

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

the class SmppSubmitMultiCommandTest method bodyWithLatin1DataCodingNarrowedToCharset.

@Test
public void bodyWithLatin1DataCodingNarrowedToCharset() throws Exception {
    final byte dataCoding = (byte) 0x03;
    /* ISO-8859-1 (Latin1) */
    byte[] body = { (byte) 0xFF, 'A', 'B', (byte) 0x00, (byte) 0xFF, (byte) 0x7F, 'C', (byte) 0xFF };
    byte[] bodyNarrowed = { '?', 'A', 'B', '\0', '?', (byte) 0x7F, 'C', '?' };
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
    exchange.getIn().setHeader(SmppConstants.DATA_CODING, dataCoding);
    exchange.getIn().setBody(body);
    Address[] destAddrs = new Address[] { new Address(TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1717") };
    expect(session.submitMultiple(eq("CMT"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1616"), aryEq(destAddrs), eq(new ESMClass()), eq((byte) 0), eq((byte) 1), (String) isNull(), (String) isNull(), eq(new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE)), eq(ReplaceIfPresentFlag.DEFAULT), eq(DataCodings.newInstance(dataCoding)), eq((byte) 0), aryEq(bodyNarrowed))).andReturn(new SubmitMultiResult("1"));
    replay(session);
    command.execute(exchange);
    verify(session);
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Address(org.jsmpp.bean.Address) SubmitMultiResult(org.jsmpp.bean.SubmitMultiResult) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) ESMClass(org.jsmpp.bean.ESMClass) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

ESMClass (org.jsmpp.bean.ESMClass)36 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)33 Exchange (org.apache.camel.Exchange)30 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)30 DefaultExchange (org.apache.camel.impl.DefaultExchange)30 Test (org.junit.Test)30 SubmitMultiResult (org.jsmpp.bean.SubmitMultiResult)12 Address (org.jsmpp.bean.Address)11 Date (java.util.Date)9 LinkedHashMap (java.util.LinkedHashMap)6 DataSmResult (org.jsmpp.session.DataSmResult)5 Message (org.apache.camel.Message)4 MessageId (org.jsmpp.util.MessageId)4 OptionalParameter (org.jsmpp.bean.OptionalParameter)3 SubmitSm (org.jsmpp.bean.SubmitSm)3 ArrayList (java.util.ArrayList)2 EasyMock.isNull (org.easymock.EasyMock.isNull)2 SubmitMulti (org.jsmpp.bean.SubmitMulti)2 UnsuccessDelivery (org.jsmpp.bean.UnsuccessDelivery)2 Assert.assertNull (org.junit.Assert.assertNull)2