Akka-Camel how to call http endpoint with parameters

1,981 views
Skip to first unread message

Darshana Samanpura

unread,
Jul 14, 2013, 10:31:08 AM7/14/13
to akka...@googlegroups.com

I am new to Akka Camel and trying to introduce Akka framework to my organization.
I have to call following URL with paramets in following patters 
can anyone help me that how to set parameters in outgoing message by using UntypedProducerActor

Akka Team

unread,
Jul 15, 2013, 7:23:55 AM7/15/13
to Akka User List
Hi Darshana,

Have you looked into the Camel documentation https://camel.apache.org/http.html ? You should be able to set the headers using "withHeaders" on CamelMessage (since the Akka CamelMessage is immutable, there is no setHeader).

-Endre


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Akka Team
Typesafe - The software stack for applications that scale
Blog: letitcrash.com
Twitter: @akkateam

Alvaro Rodriguez

unread,
Jul 15, 2013, 8:52:06 AM7/15/13
to akka...@googlegroups.com
Hi Darshana,

Maybe this helps if you are producing your messages by code rather than as part of a route.
I have a "extends Actor with Producer" where I'm doing this by redefining the method

override def transformOutgoingMessage(msg: Any)

This method must return the CamelMessage that will be sent to the endpoint, and you can set whatever you need in the headers:

      Exchange.HTTP_URI -> "myUrl",
      Exchange.HTTP_METHOD -> "GET",
etc.

You can obviously set your parameters in the HTTP_URI but I think the Exchange class may have something more specific.

Regards
alvaro.

Darshana Samanpura

unread,
Jul 17, 2013, 5:07:16 AM7/17/13
to akka...@googlegroups.com
I was trying by setting Camel header with HTTP headers but there is no luck, I also try with head.put("CamelHttpQuery","message=message") to test weather this parameters will reflect in URL call but it was not,
The only way I found to send parameters is through template as below

            ProducerTemplate template = camel.template();
            getSender().tell(template.request("http://localhost:9000/testMessage?message=4444",null),getSelf()); 

I ma still searching a way to get this done from UntypedProducerActor. 

Thank You,
Darshana

Darshana Samanpura

unread,
Jul 26, 2013, 12:11:48 PM7/26/13
to akka...@googlegroups.com
Hi All,

As the clue of Alvaro Rodriguez I was able to solve the problem. Please find the code as below. Much more thanks to  Alvaro Rodriguez all the others who
 help to solve the problem.


    @Override
    public Object onTransformOutgoingMessage(Object message) {

        
        CamelMessage camelMessage = (CamelMessage) message;        
        String body = ((CamelMessage) message).getBodyAs(String.class,getCamelContext());
        Map<String,Object> head = new HashMap<String, Object>();
        head.put(Exchange.HTTP_URI,getEndpointUri());
        head.put(Exchange.HTTP_METHOD,"GET");
        head.put(Exchange.HTTP_QUERY,"ordId=100&qty=15&price=456");

        CamelMessage outMessage = new CamelMessage(body,head);
        Map<String,Object> map = outMessage.getHeaders();

        return outMessage;

    }

Cheers,
Darshana

On Sunday, July 14, 2013 8:01:08 PM UTC+5:30, Darshana Samanpura wrote:

Darshana Samanpura

unread,
Jul 26, 2013, 12:13:14 PM7/26/13
to akka...@googlegroups.com
Hi Alvaro,

Thank you for your clue, my problem is solved.

    @Override
    public Object onTransformOutgoingMessage(Object message) {


        CamelMessage camelMessage = (CamelMessage) message;
        String body = ((CamelMessage) message).getBodyAs(String.class,getCamelContext());
        Map<String,Object> head = new HashMap<String, Object>();
        head.put(Exchange.HTTP_URI,getEndpointUri());
        head.put(Exchange.HTTP_METHOD,"GET");
        head.put(Exchange.HTTP_QUERY,"ordId=100&qty=15&price=456");

        CamelMessage outMessage = new CamelMessage(body,head);
        Map<String,Object> map = outMessage.getHeaders();

        return outMessage;

    }

Regards,
Darshana
Reply all
Reply to author
Forward
0 new messages