Examples of SMPPSession


Examples of org.jsmpp.session.SMPPSession

        assertTrue(command instanceof SmppDataSmCommand);
    }
   
    @Test
    public void createSmppReplaceSmCommand() {
        SMPPSession session = new SMPPSession();
        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
        exchange.getIn().setHeader(SmppConstants.COMMAND, "ReplaceSm");
       
        SmppCommand command = binding.createSmppCommand(session, exchange);
       
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

        assertTrue(command instanceof SmppReplaceSmCommand);
    }
   
    @Test
    public void createSmppQuerySmCommand() {
        SMPPSession session = new SMPPSession();
        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
        exchange.getIn().setHeader(SmppConstants.COMMAND, "QuerySm");
       
        SmppCommand command = binding.createSmppCommand(session, exchange);
       
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

        assertTrue(command instanceof SmppQuerySmCommand);
    }
   
    @Test
    public void createSmppCancelSmCommand() {
        SMPPSession session = new SMPPSession();
        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
        exchange.getIn().setHeader(SmppConstants.COMMAND, "CancelSm");
       
        SmppCommand command = binding.createSmppCommand(session, exchange);
       
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

* @author uudashr
*
*/
public class SendUnicode {
    public static void main(String[] args) throws Exception {
        SMPPSession session = null; // 1. initialize
        // 2. Initiate bind
        // 3. Set message receiver listener if needed
       
        // this is how to write "house" in arabic
        String house = "\u0628" + "\u064e" + "\u064a" +
                        "\u0652" + "\u067a" + "\u064f";
       
        TimeFormatter timeFormatter = new RelativeTimeFormatter();
       
       
        // 4. Specify the data coding using UCS2
        DataCoding dataCoding = new GeneralDataCoding(Alphabet.ALPHA_UCS2, MessageClass.CLASS1, false);
       
        // 5. UTF-16BE is equals to UCS2
        byte[] data = house.getBytes("UTF-16BE");
       
        // 6. Submit the short message
        String messageId = session.submitShortMessage("CMT",
                TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN,
                "1616", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN,
                "628176504657", new ESMClass(), (byte)0, (byte)1
                timeFormatter.format(new Date()), null,
                new RegisteredDelivery(SMSCDeliveryReceipt.DEFAULT), (byte)0,
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

     *
     * @return the {@link SMPPSession}.
     * @throws IOException if the creation of new session failed.
     */
    private SMPPSession newSession() throws IOException {
        SMPPSession tmpSession = new SMPPSession(remoteIpAddress, remotePort, bindParam);
        tmpSession.addSessionStateListener(new SessionStateListenerImpl());
        return tmpSession;
    }
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

    String sourceMsisdn = "1616";
    String destinationMsisdn = "666111222";
    MessageClass messageClass = MessageClass.CLASS1;
    String messageBody = "Lorem ipsum dolor sit amet enim. Etiam ullamcorper. Suspendisse a pellentesque dui, non felis. Maecenas malesuada elit lectus felis, malesuada ultricies. Curabitur et ligula. Ut molestie a, ultricies porta urna.";

    SMPPSession session = new SMPPSession();
    session.addSessionStateListener(new SessionStateListenerImpl());
    session.setMessageReceiverListener(new MessageReceiverListenerImpl());

    try {
      session.connectAndBind("localhost", 2775, new BindParameter(BindType.BIND_TRX, "smppclient", "password",
          "cp", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null));
    } catch (IOException e) {
      System.err.println("Failed connect and bind to host");
      e.printStackTrace();
    }

    // configure variables acording to if message contains national
    // characters
    Alphabet alphabet = null;
    int maximumSingleMessageSize = 0;
    int maximumMultipartMessageSegmentSize = 0;
    byte[] byteSingleMessage = null;
    if (Gsm0338.isEncodeableInGsm0338(messageBody)) {
      byteSingleMessage = messageBody.getBytes();
      alphabet = Alphabet.ALPHA_DEFAULT;
      maximumSingleMessageSize = MAX_SINGLE_MSG_SEGMENT_SIZE_7BIT;
      maximumMultipartMessageSegmentSize = MAX_MULTIPART_MSG_SEGMENT_SIZE_7BIT;
    } else {
      byteSingleMessage = messageBody.getBytes("UTF-16BE");
      alphabet = Alphabet.ALPHA_UCS2;
      maximumSingleMessageSize = MAX_SINGLE_MSG_SEGMENT_SIZE_UCS2;
      maximumMultipartMessageSegmentSize = MAX_MULTIPART_MSG_SEGMENT_SIZE_UCS2;
    }

    // check if message needs splitting and set required sending parameters
    byte[][] byteMessagesArray = null;
    ESMClass esmClass = null;
    if (messageBody.length() > maximumSingleMessageSize) {
      // split message according to the maximum length of a segment
      byteMessagesArray = splitUnicodeMessage(byteSingleMessage, maximumMultipartMessageSegmentSize);
      // set UDHI so PDU will decode the header
      esmClass = new ESMClass(MessageMode.DEFAULT, MessageType.DEFAULT, GSMSpecificFeature.UDHI);
    } else {
      byteMessagesArray = new byte[][] { byteSingleMessage };
      esmClass = new ESMClass();
    }

    System.out.println("Sending message " + messageBody);
    System.out.printf("Message is %d characters long and will be sent as %d messages with params: %s %s ",
        messageBody.length(), byteMessagesArray.length, alphabet, messageClass);
    System.out.println();

    // submit all messages
    for (int i = 0; i < byteMessagesArray.length; i++) {
      String messageId = submitMessage(session, byteMessagesArray[i], sourceMsisdn, destinationMsisdn,
          messageClass, alphabet, esmClass);
      System.out.println("Message submitted, message_id is " + messageId);
    }

    System.out.println("Entering listening mode. Press enter to finish...");

    try {
      System.in.read();
    } catch (IOException e) {
      e.printStackTrace();
    }

    session.unbindAndClose();
  }
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

    private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter();

    public static void main(String[] args) {

        // Create a new SMPP Session
        SMPPSession session = new SMPPSession();
        try {
           
            session.setMessageReceiverListener(new MessageReceiverListenerImpl());
           
            // Bind to the Server
            session.connectAndBind("localhost", 8056,
                                    new BindParameter(BindType.BIND_TRX, "test",
                                                        "test", "cp",
                                                        TypeOfNumber.UNKNOWN,
                                                        NumberingPlanIndicator.UNKNOWN,
                                                        null));
           
        } catch (IOException e) {
            System.err.println("Failed connect and bind to host");
            e.printStackTrace();
        }

        try {
            Address address1 = new Address(TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "628176504657");
            Address address2 = new Address(TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "628176504658");
            Address[] addresses = new Address[] {address1, address2};
            SubmitMultiResult result = session.submitMultiple("CMT", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "1616",
                                                        addresses, new ESMClass(), (byte)0, (byte)1, timeFormatter.format(new Date()), null,
                                                        new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS), ReplaceIfPresentFlag.REPLACE,
                                                        new GeneralDataCoding(Alphabet.ALPHA_DEFAULT, MessageClass.CLASS1, false), (byte)0,
                                                        "jSMPP simplify SMPP on Java platform".getBytes());
            System.out.println("Messages submitted, result is " + result);
            Thread.sleep(2000);
        } catch (PDUException e) {
            // Invalid PDU parameter
            System.err.println("Invalid PDU parameter");
            e.printStackTrace();
        } catch (ResponseTimeoutException e) {
            // Response timeout
            System.err.println("Response timeout");
            e.printStackTrace();
        } catch (InvalidResponseException e) {
            // Invalid response
            System.err.println("Receive invalid respose");
            e.printStackTrace();
        } catch (NegativeResponseException e) {
            // Receiving negative response (non-zero command_status)
            System.err.println("Receive negative response");
            e.printStackTrace();
        } catch (IOException e) {
            System.err.println("IO error occur");
            e.printStackTrace();
        } catch (InterruptedException e) {
            System.err.println("Thread interrupted");
            e.printStackTrace();
        }

        session.unbindAndClose();
    }
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

    private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter();;
    public static void main(String[] args) {
        final AtomicInteger counter = new AtomicInteger();
       
        BasicConfigurator.configure();
        final SMPPSession session = new SMPPSession();
        try {
            session.connectAndBind("localhost", 8056, new BindParameter(BindType.BIND_TRX, "test", "test", "cp", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null));
        } catch (IOException e) {
            System.err.println("Failed connect and bind to host");
            e.printStackTrace();
        }
       
        // Set listener to receive deliver_sm
        session.setMessageReceiverListener(new MessageReceiverListener() {
            public void onAcceptDeliverSm(DeliverSm deliverSm)
                    throws ProcessRequestException {
                if (MessageType.SMSC_DEL_RECEIPT.containedIn(deliverSm.getEsmClass())) {
                    counter.incrementAndGet();
                    // delivery receipt
                    try {
                        DeliveryReceipt delReceipt = deliverSm.getShortMessageAsDeliveryReceipt();
                        long id = Long.parseLong(delReceipt.getId()) & 0xffffffff;
                        String messageId = Long.toString(id, 16).toUpperCase();
                        System.out.println("Receiving delivery receipt for message '" + messageId + "' : " + delReceipt);
                    } catch (InvalidDeliveryReceiptException e) {
                        System.err.println("Failed getting delivery receipt");
                        e.printStackTrace();
                    }
                } else {
                    // regular short message
                    System.out.println("Receiving message : " + new String(deliverSm.getShortMessage()));
                }
            }
           
            public void onAcceptAlertNotification(
                    AlertNotification alertNotification) {
            }
           
            public DataSmResult onAcceptDataSm(DataSm dataSm, Session source)
                    throws ProcessRequestException {
                // TODO Auto-generated method stub
                return null;
            }
        });
       
        // Now we will send 50 message asynchronously with max outstanding messages 10.
        ExecutorService execService = Executors.newFixedThreadPool(10);
       
        // requesting delivery report
        final RegisteredDelivery registeredDelivery = new RegisteredDelivery();
        registeredDelivery.setSMSCDeliveryReceipt(SMSCDeliveryReceipt.SUCCESS_FAILURE);
        final int maxMessage = 50;
        for (int i = 0; i < maxMessage; i++) {
           
            execService.execute(new Runnable() {
                public void run() {
                    try {
                        String messageId = session.submitShortMessage("CMT", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "1616", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN, "628176504657", new ESMClass(), (byte)0, (byte)1,  timeFormatter.format(new Date()), null, registeredDelivery, (byte)0, DataCodings.ZERO, (byte)0, "jSMPP simplify SMPP on Java platform".getBytes());
                        System.out.println("Message submitted, message_id is " + messageId);
                    } catch (PDUException e) {
                        System.err.println("Invalid PDU parameter");
                        e.printStackTrace();
                        counter.incrementAndGet();
                    } catch (ResponseTimeoutException e) {
                        System.err.println("Response timeout");
                        e.printStackTrace();
                        counter.incrementAndGet();
                    } catch (InvalidResponseException e) {
                        // Invalid response
                        System.err.println("Receive invalid respose");
                        e.printStackTrace();
                        counter.incrementAndGet();
                    } catch (NegativeResponseException e) {
                        // Receiving negative response (non-zero command_status)
                        System.err.println("Receive negative response");
                        e.printStackTrace();
                        counter.incrementAndGet();
                    } catch (IOException e) {
                        System.err.println("IO error occur");
                        e.printStackTrace();
                        counter.incrementAndGet();
                    }
                }
            });
        }
       
        while (counter.get() != maxMessage) {
            try { Thread.sleep(1000); } catch (InterruptedException e) { }
        }
        session.unbindAndClose();
        execService.shutdown();
    }
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

*/
public class SubmitLongMessageExample {
    private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter();;
   
    public static void main(String[] args) {
        SMPPSession session = new SMPPSession();
        try {
            session.connectAndBind("localhost", 8056, new BindParameter(BindType.BIND_TX, "test", "test", "cp", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null));
        } catch (IOException e) {
            System.err.println("Failed connect and bind to host");
            e.printStackTrace();
        }
        Random random = new Random();
       
        final int totalSegments = 3;
        OptionalParameter sarMsgRefNum = OptionalParameters.newSarMsgRefNum((short)random.nextInt());
        OptionalParameter sarTotalSegments = OptionalParameters.newSarTotalSegments(totalSegments);
       
        for (int i = 0; i < totalSegments; i++) {
            final int seqNum = i + 1;
            String message = "Message part " + seqNum + " of " + totalSegments + " ";
            OptionalParameter sarSegmentSeqnum = OptionalParameters.newSarSegmentSeqnum(seqNum);
            String messageId = submitMessage(session, message, sarMsgRefNum, sarSegmentSeqnum, sarTotalSegments);
            System.out.println("Message submitted, message_id is " + messageId);
        }
       
        session.unbindAndClose();
    }
View Full Code Here

Examples of org.jsmpp.session.SMPPSession

        String server = "localhost";
        int port = 8056;
        String message = "jSMPP simplify SMPP on Java platform";

        // bind(connect)
        SMPPSession session = new SMPPSession();
        try {
            session.connectAndBind(server, port, new BindParameter(BindType.BIND_TRX, "test", "test", "cp",
                    TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null));
        } catch (IOException e) {
            System.err.println("Failed connect and bind to host");
            e.printStackTrace();
        }

        // send Message
        try {
            // set RegisteredDelivery
            final RegisteredDelivery registeredDelivery = new RegisteredDelivery();
            registeredDelivery.setSMSCDeliveryReceipt(SMSCDeliveryReceipt.SUCCESS_FAILURE);

            String messageId = session.submitShortMessage("CMT", TypeOfNumber.INTERNATIONAL,
                    NumberingPlanIndicator.UNKNOWN, "1616", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN,
                    "628176504657", new ESMClass(), (byte)0, (byte)1, timeFormatter.format(new Date()), null,
                    registeredDelivery, (byte)0, new GeneralDataCoding(Alphabet.ALPHA_DEFAULT, MessageClass.CLASS1,
                            false), (byte)0, message.getBytes());

            System.out.println("Message submitted, message_id is " + messageId);

        } catch (PDUException e) {
            // Invalid PDU parameter
            System.err.println("Invalid PDU parameter");
            e.printStackTrace();
        } catch (ResponseTimeoutException e) {
            // Response timeout
            System.err.println("Response timeout");
            e.printStackTrace();
        } catch (InvalidResponseException e) {
            // Invalid response
            System.err.println("Receive invalid respose");
            e.printStackTrace();
        } catch (NegativeResponseException e) {
            // Receiving negative response (non-zero command_status)
            System.err.println("Receive negative response");
            e.printStackTrace();
        } catch (IOException e) {
            System.err.println("IO error occur");
            e.printStackTrace();
        }

        // receive Message
        BasicConfigurator.configure();

        // Set listener to receive deliver_sm
        session.setMessageReceiverListener(new MessageReceiverListener() {

            public void onAcceptDeliverSm(DeliverSm deliverSm) throws ProcessRequestException {
                if (MessageType.SMSC_DEL_RECEIPT.containedIn(deliverSm.getEsmClass())) {
                    // delivery receipt
                    try {
                        DeliveryReceipt delReceipt = deliverSm.getShortMessageAsDeliveryReceipt();
                        long id = Long.parseLong(delReceipt.getId()) & 0xffffffff;
                        String messageId = Long.toString(id, 16).toUpperCase();
                        System.out.println("received '" + messageId + "' : " + delReceipt);
                    } catch (InvalidDeliveryReceiptException e) {
                        System.err.println("receive faild");
                        e.printStackTrace();
                    }
                } else {
                    // regular short message
                    System.out.println("Receiving message : " + new String(deliverSm.getShortMessage()));
                }
            }

            public void onAcceptAlertNotification(AlertNotification alertNotification) {
                System.out.println("onAcceptAlertNotification");
            }

            public DataSmResult onAcceptDataSm(DataSm dataSm, Session source) throws ProcessRequestException {
                System.out.println("onAcceptDataSm");
                return null;
            }
        });

        // wait 3 second
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // unbind(disconnect)
        session.unbindAndClose();

        System.out.println("finish!");
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.