001package org.kuali.ole.deliver.batch;
002
003import org.apache.camel.Exchange;
004import org.apache.camel.ExchangePattern;
005import org.apache.camel.component.smpp.SmppConfiguration;
006import org.apache.camel.component.smpp.SmppConstants;
007import org.apache.camel.component.smpp.SmppSubmitSmCommand;
008import org.apache.camel.impl.DefaultCamelContext;
009import org.apache.camel.impl.DefaultExchange;
010import org.apache.log4j.Logger;
011import org.jsmpp.bean.*;
012import org.jsmpp.session.SMPPSession;
013
014import java.util.Date;
015
016/**
017 * Created with IntelliJ IDEA.
018 * User: ?
019 * Date: 1/16/13
020 * Time: 7:08 PM
021 * To change this template use File | Settings | File Templates.
022 */
023public class OleSms {
024    private SMPPSession session;
025
026    private SmppConfiguration config = new SmppConfiguration();
027    private static final Logger LOG = Logger.getLogger(OleSms.class);
028    private SmppSubmitSmCommand command = new SmppSubmitSmCommand(session, config);
029
030
031    public void sendSms(String from, String to, String message) {
032        Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
033        exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitSm");
034        exchange.getIn().setHeader(SmppConstants.ID, "1");
035        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
036        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.ISDN.value());
037        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, from);
038        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
039        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.ISDN.value());
040        exchange.getIn().setHeader(SmppConstants.DEST_ADDR, to);
041        exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
042        exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
043        exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
044        exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
045        exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS).value());
046        exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
047        exchange.getIn().setBody(message);
048
049        try {
050            command.execute(exchange);
051        } catch (Exception e) {
052            LOG.error("Exception while sending sms", e);
053        }
054    }
055
056}