Search in sources :

Example 11 with Address

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

the class SmppSubmitMultiCommandTest method execute.

@Test
public void execute() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
    exchange.getIn().setHeader(SmppConstants.ID, "1");
    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, Arrays.asList("1919"));
    exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
    exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
    exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
    exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
    exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
    exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
    exchange.getIn().setBody("short message body");
    expect(session.submitMultiple(eq("CMT"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"), aryEq(new Address[] { new Address(TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.INTERNET, "1919") }), eq(new ESMClass()), eq((byte) 1), eq((byte) 2), eq("-300101001831100+"), eq("-300101003702200+"), eq(new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE)), eq(ReplaceIfPresentFlag.REPLACE), eq(DataCodings.newInstance((byte) 0)), eq((byte) 0), aryEq("short message body".getBytes()))).andReturn(new SubmitMultiResult("1"));
    replay(session);
    command.execute(exchange);
    verify(session);
    assertEquals(Arrays.asList("1"), exchange.getOut().getHeader(SmppConstants.ID));
    assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
    assertNull(exchange.getOut().getHeader(SmppConstants.ERROR));
}
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) Date(java.util.Date) Test(org.junit.Test)

Example 12 with Address

use of org.jsmpp.bean.Address 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;
}
Also used : Message(org.apache.camel.Message) Address(org.jsmpp.bean.Address) Date(java.util.Date) OptionalParameter(org.jsmpp.bean.OptionalParameter) ArrayList(java.util.ArrayList) List(java.util.List) SubmitMulti(org.jsmpp.bean.SubmitMulti)

Aggregations

Address (org.jsmpp.bean.Address)12 Exchange (org.apache.camel.Exchange)11 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)11 DefaultExchange (org.apache.camel.impl.DefaultExchange)11 ESMClass (org.jsmpp.bean.ESMClass)11 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)11 SubmitMultiResult (org.jsmpp.bean.SubmitMultiResult)11 Test (org.junit.Test)11 Date (java.util.Date)5 LinkedHashMap (java.util.LinkedHashMap)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Message (org.apache.camel.Message)1 EasyMock.isNull (org.easymock.EasyMock.isNull)1 OptionalParameter (org.jsmpp.bean.OptionalParameter)1 SubmitMulti (org.jsmpp.bean.SubmitMulti)1 UnsuccessDelivery (org.jsmpp.bean.UnsuccessDelivery)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1