You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Gunjara <mg...@gmail.com> on 2016/10/26 11:13:38 UTC

How to Pass Dynamic Parameters to invoke rest url.

HI Please help me , how to pass query paramets.

package org.tesco.storeapi.routes;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class TestRoute extends RouteBuilder {

	@Override
	public void configure() throws Exception {
		
		from("direct:restClient")
        .log("starting route")
        .setHeader(Exchange.HTTP_METHOD,
constant(org.apache.camel.component.http4.HttpMethods.GET))
       
.to("http4://jsonplaceholder.typicode.com/posts/1").to("file:output");
        
//        .log(LoggingLevel.INFO, "Output was ${body}");
}

 public static void main(String[] args) throws Exception {
        CamelContext context = new DefaultCamelContext();
        try {
            context.addRoutes(new TestRoute());
            ProducerTemplate template = context.createProducerTemplate();
            context.start();
            Thread.sleep(20000);
            template.sendBody("direct:restClient", "Test Input");

        } finally {
            context.stop();
        }
    }		
}

Here how can i pass query parameters like this
http4://jsonplaceholder.typicode.com/posts/{Id}





--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Pass-Dynamic-Parameters-to-invoke-rest-url-tp5789276.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Pass Dynamic Parameters to invoke rest url.

Posted by Claus Ibsen <cl...@gmail.com>.
You can set a header with key

   .setHeader(Exchange.HTTP_QUERY,

And then pass in a value with the query parameters. If you have more
parameters then separate with &.

See the docs
http://camel.apache.org/http4


On Wed, Oct 26, 2016 at 1:13 PM, Gunjara <mg...@gmail.com> wrote:
> HI Please help me , how to pass query paramets.
>
> package org.tesco.storeapi.routes;
>
> import org.apache.camel.CamelContext;
> import org.apache.camel.Exchange;
> import org.apache.camel.LoggingLevel;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.impl.DefaultCamelContext;
>
> public class TestRoute extends RouteBuilder {
>
>         @Override
>         public void configure() throws Exception {
>
>                 from("direct:restClient")
>         .log("starting route")
>         .setHeader(Exchange.HTTP_METHOD,
> constant(org.apache.camel.component.http4.HttpMethods.GET))
>
> .to("http4://jsonplaceholder.typicode.com/posts/1").to("file:output");
>
> //        .log(LoggingLevel.INFO, "Output was ${body}");
> }
>
>  public static void main(String[] args) throws Exception {
>         CamelContext context = new DefaultCamelContext();
>         try {
>             context.addRoutes(new TestRoute());
>             ProducerTemplate template = context.createProducerTemplate();
>             context.start();
>             Thread.sleep(20000);
>             template.sendBody("direct:restClient", "Test Input");
>
>         } finally {
>             context.stop();
>         }
>     }
> }
>
> Here how can i pass query parameters like this
> http4://jsonplaceholder.typicode.com/posts/{Id}
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-Pass-Dynamic-Parameters-to-invoke-rest-url-tp5789276.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2