1 package org.kuali.ole.deliver.batch;
2
3 import org.apache.camel.Exchange;
4 import org.apache.camel.ExchangePattern;
5 import org.apache.camel.component.smpp.SmppConfiguration;
6 import org.apache.camel.component.smpp.SmppConstants;
7 import org.apache.camel.component.smpp.SmppSubmitSmCommand;
8 import org.apache.camel.impl.DefaultCamelContext;
9 import org.apache.camel.impl.DefaultExchange;
10 import org.apache.log4j.Logger;
11 import org.jsmpp.bean.*;
12 import org.jsmpp.session.SMPPSession;
13
14 import java.util.Date;
15
16
17
18
19
20
21
22
23 public class OleSms {
24 private SMPPSession session;
25
26 private SmppConfiguration config = new SmppConfiguration();
27 private static final Logger LOG = Logger.getLogger(OleSms.class);
28 private SmppSubmitSmCommand command = new SmppSubmitSmCommand(session, config);
29
30
31 public void sendSms(String from, String to, String message) {
32 Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
33 exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitSm");
34 exchange.getIn().setHeader(SmppConstants.ID, "1");
35 exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
36 exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.ISDN.value());
37 exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, from);
38 exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
39 exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.ISDN.value());
40 exchange.getIn().setHeader(SmppConstants.DEST_ADDR, to);
41 exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
42 exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
43 exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
44 exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
45 exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS).value());
46 exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
47 exchange.getIn().setBody(message);
48
49 try {
50 command.execute(exchange);
51 } catch (Exception e) {
52 LOG.error("Exception while sending sms", e);
53 }
54 }
55
56 }