Saturday, April 5, 2014

Parlay Rest SMS with Apache Camel

Following sample will use http4 Apache component to send Sms using Parlay Rest Specification


import org.apache.camel.main.Main;

public class TestRestSms {

public static void main(String[] args) throws Exception {
            Main main = new Main();
            main.addRouteBuilder(new TestRestSmsRoute());
            System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n");

Following is RouterClass

import org.apache.camel.builder.RouteBuilder;

public class TestRestSmsRoute extends RouteBuilder {

public void configure() throws Exception {

.process(new SendSmsRequest())
.process(new SendSmsResponse())


Following are processor classes

import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
import org.apache.camel.Processor;

public class SendSmsRequest implements Processor  {

public void process(Exchange exchange) throws Exception {

exchange.getIn().setHeader(Exchange.HTTP_METHOD, "POST");
String toAddress = "\"addresses\": [\"tel:6666666666\"]";
String fromAddress = "\"senderName\": \"tel:321\"";
String msgText = "\"message\": \"hello world\"";
        String sms                 = "{"+toAddress+","+fromAddress+","+msgText+"}";


} //


public class SendSmsResponse implements Processor  {

public void process(Exchange exchange) throws Exception {

Object result = exchange.getIn().getBody();

System.out.println("sms response="+result);



No comments: