You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by camelcoder07 <dm...@hotmail.com> on 2014/10/07 22:30:51 UTC

Camel Spring HTTP Consumer using remote Rest web service

Hi, I need some help setting up my camel configuration to consume data from a
remote rest web service using camel.  This remote service is https and uses
api-key for authentication.  I also need to POST to this web service with a
query as well to get data returned.

I need help with how to pass the query to the POST.  Also if you see
anything else that could be done cleaner please let me know.

Below is the query that I must pass to the web service:

{

    "sinceTime": time,

    "untilTime": time,

    "timezoneOffset": 0,

    "details": {

        "widgetType": "Place"

    },

    "filters": [

        {

            "dimension": "SOURCE",

            "filterValues": [

                "Site1",

                "Site2"

          

            ]

        }

    ],

    "metric": "TEST",

    "start": 0,

    "rows": 200

}


As a side note I am using JBoss Developer Studio as this will eventually run
in an JBoss environment.

Below is the code that I currently have:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-http.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:start"/>
        <setHeader headerName="CamelHttpMethod">
            <constant>POST</constant>
        </setHeader>
        <to
uri="https://api.host.com/api/v3.1/link/query/place/?apiKey=1234"/>
        <log message="Message Recieved"/>
        <to uri="file:target/messages/test"/>
    </route>
</camelContext>
</beans>



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Spring HTTP Consumer using remote Rest web service

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

I think Charles already show you how to do it by using setBody DSL.
BTW, if you using direct:start, you need to use producer template to send the message to the direct:start endpoint to kick the route.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On October 9, 2014 at 5:16:29 AM, camelcoder07 (dmhumph@hotmail.com) wrote:
> I fixed this issue now by using a timer instead of direct:start.
>  
> Can anyone tell me how to set the body type to application/json when sending
> the data to the web service?
>  
> Thank you
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395p5757420.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: Camel Spring HTTP Consumer using remote Rest web service

Posted by camelcoder07 <dm...@hotmail.com>.
I don't know if I should create a new thread for this question or not but I
was wanting to know if anyone had any suggestions on where to look for
passing a dynamic value to body in the values for sincetime and until time. 
What I want to do is be able to insert the value in milliseconds for 5
minutes in the past for the value "sincetime", and then just pass the value
in milliseconds for the current time to the value "untiltime".  I am not
sure where to start looking to configure this functionality so any
suggestions would be greatly appreciated.

Thank you



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395p5757452.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Spring HTTP Consumer using remote Rest web service

Posted by camelcoder07 <dm...@hotmail.com>.
Ok, I now have this working.  I needed to add a ? before the apikey in the
https uri.

Thanks to all for the help.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395p5757450.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Spring HTTP Consumer using remote Rest web service

Posted by camelcoder07 <dm...@hotmail.com>.
Thank you for the reply.  I am getting the bellow error now when executing my
camel context, and I want to know if this is being returned from the web
service or if this is an internal error from camel?  If it is in my camel
context is there something different that I should be doing here?  Thanks
again for the help, and sorry for any n00b questions but I am new to camel.

org.apache.camel.component.http.HttpOperationFailedException: HTTP operation
failed invoking https://api.host.com/api/v3.1/link/query/place/?apiKey=1234
with statusCode: 500
	at
org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:228)
	at
org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:156)
	at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
	at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)
	at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
	at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at
org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:139)
	at
org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:64)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)
[mel-1) thread #0 - timer://foo] TimerConsumer                  WARN  Error
processing exchange. Exchange[Message: { 

    "sinceTime": time, 

    "untilTime": time, 

    "timezoneOffset": 0, 

    "details": { 

        "widgetType": "Place" 

    }, 

    "filters": [ 

        { 

            "dimension": "SOURCE", 

            "filterValues": [ 

                "Site1", 

                "Site2" 

          

            ] 

        } 

    ], 

    "metric": "TEST", 

    "start": 0, 

    "rows": 200 

}]. Caused by: [org.apache.camel.component.http.HttpOperationFailedException
- HTTP operation failed invoking
https://api.host.com/api/v3.1/link/query/place/?apiKey=1234 with statusCode:
500]
org.apache.camel.component.http.HttpOperationFailedException: HTTP operation
failed invoking https://api.host.com/api/v3.1/link/query/place/?apiKey=1234
with statusCode: 500
	at
org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:228)
	at
org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:156)
	at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
	at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)
	at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
	at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at
org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:139)
	at
org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:64)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395p5757449.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Spring HTTP Consumer using remote Rest web service

Posted by Charles Moulliard <ch...@gmail.com>.
Hi,

ContentType should be passed as Apache Camel Header
Example : setHeader("Content-Type", "application/json")

Regards,


On Wed, Oct 8, 2014 at 11:16 PM, camelcoder07 <dm...@hotmail.com> wrote:

> I fixed this issue now by using a timer instead of direct:start.
>
> Can anyone tell me how to set the body type to application/json when
> sending
> the data to the web service?
>
> Thank you
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395p5757420.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io

Re: Camel Spring HTTP Consumer using remote Rest web service

Posted by camelcoder07 <dm...@hotmail.com>.
I fixed this issue now by using a timer instead of direct:start.

Can anyone tell me how to set the body type to application/json when sending
the data to the web service?

Thank you



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395p5757420.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Spring HTTP Consumer using remote Rest web service

Posted by camelcoder07 <dm...@hotmail.com>.
Thank you for this information.  For some reason it does not look like I am
even calling the REST endpoint.  Is there a way to find out where this is
hanging up at?  When I run my camel-context.xml test all it says is that
there is a total of 1 routes and of which 1 is started.

Any help is much appreciated.

Thank you



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395p5757416.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Spring HTTP Consumer using remote Rest web service

Posted by Charles Moulliard <ch...@gmail.com>.
Hi,

You json string message should be added to the body of the Camel Exchange
before to call the HTTPS endpoint

<setBody>
     <constant>YOUR JSON STRING</constant>
</setBody>

Regards,


On Tue, Oct 7, 2014 at 10:30 PM, camelcoder07 <dm...@hotmail.com> wrote:

> Hi, I need some help setting up my camel configuration to consume data
> from a
> remote rest web service using camel.  This remote service is https and uses
> api-key for authentication.  I also need to POST to this web service with a
> query as well to get data returned.
>
> I need help with how to pass the query to the POST.  Also if you see
> anything else that could be done cleaner please let me know.
>
> Below is the query that I must pass to the web service:
>
> {
>
>     "sinceTime": time,
>
>     "untilTime": time,
>
>     "timezoneOffset": 0,
>
>     "details": {
>
>         "widgetType": "Place"
>
>     },
>
>     "filters": [
>
>         {
>
>             "dimension": "SOURCE",
>
>             "filterValues": [
>
>                 "Site1",
>
>                 "Site2"
>
>
>
>             ]
>
>         }
>
>     ],
>
>     "metric": "TEST",
>
>     "start": 0,
>
>     "rows": 200
>
> }
>
>
> As a side note I am using JBoss Developer Studio as this will eventually
> run
> in an JBoss environment.
>
> Below is the code that I currently have:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xmlns:camel="http://camel.apache.org/schema/spring"
>        xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>        http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
>        http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-http.xsd">
>
>   <camelContext xmlns="http://camel.apache.org/schema/spring">
>     <route>
>         <from uri="direct:start"/>
>         <setHeader headerName="CamelHttpMethod">
>             <constant>POST</constant>
>         </setHeader>
>         <to
> uri="https://api.host.com/api/v3.1/link/query/place/?apiKey=1234"/>
>         <log message="Message Recieved"/>
>         <to uri="file:target/messages/test"/>
>     </route>
> </camelContext>
> </beans>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-Spring-HTTP-Consumer-using-remote-Rest-web-service-tp5757395.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io