Hi,

I'm trying to expose endpoint from the main() method using
producerTemplate.requestBody().

I have two classes; one is main from which I'm requesting an endpoint and
another one(SimpleRouteBuilder) to configure
the route.

public class MainClass {

    public static void main(String args[]) {
        SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder();
        CamelContext ctx = new DefaultCamelContext();
        try {
            ctx.addRoutes(routeBuilder);
            ctx.start();

            ProducerTemplate producerTemplate = ctx.createProducerTemplate();
            String response =
producerTemplate.requestBody("direct:start", "", String.class);
            System.out.println(response);
            Thread.sleep(5 * 1000);
            ctx.stop();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}



public class SimpleRouteBuilder extends RouteBuilder {

    @Override
    public void configure() {
        from("direct:start").setHeader(Exchange.HTTP_METHOD, simple("GET"))
            .to("http://dummy.restapiexample.com/api/v1/employees";);
    }
}

Thanks, Kirti Arora


On Mon, Oct 7, 2019 at 11:43 AM Jean-Baptiste Onofré <j...@nanthrax.net>
wrote:

> Hi,
>
> Your route looks weird to me.
>
> What's the direct:start trigger ?
> What do you do with the reply ?
>
> For instance, a valid testing route would be:
>
> from("timer:foo?period=5000").to("...").log("Received ${body}")
>
> Or at least expose an endpoint as a bridge (as we do in the Karaf example).
>
> Regards
> JB
>
> On 07/10/2019 07:49, Kirti Arora wrote:
> > Hi Jean and Francois,
> >
> > Thanks for the reply :)
> >
> > I have already seen the examples and successfully execute the one given
> in
> > /apache-karaf/examples/karaf-camel-example/karaf-camel-example-java
> >  directory.
> >
> > But when I'm trying to put my own camel code, I'm not able to call the
> > route endpoint.
> >
> > For eg. I want to hit the below mentioned URL
> >
> > from("direct:start")
> >     .setHeader(Exchange.HTTP_METHOD, simple("GET"))
> >     .to("http://dummy.restapiexample.com/api/v1/employees";);
> >
> > How can I do this?
> > Thanks,
> > Kirti Arora
> >
> >
> > On Sat, Oct 5, 2019 at 5:11 PM Jean-Baptiste Onofré <j...@nanthrax.net>
> wrote:
> >
> >> Hi,
> >>
> >> you can take a look on the examples here:
> >>
> >>
> https://github.com/apache/karaf/tree/master/examples/karaf-camel-example
> >>
> >> You have an example using blueprint DSL, an example using Java DSL. I'm
> >> adding SCR package.
> >>
> >> If you have any question, please let me know.
> >>
> >> Regards
> >> JB
> >>
> >> On 04/10/2019 14:22, Kirti Arora wrote:
> >>> Hi,
> >>>
> >>> I'm trying to deploy my camel code(Java) on Apache Karaf. I had put my
> >>> camel code bundle to deploy directory of Karaf but not able to find
> >> routes
> >>> available in the code, also not able to request the endpoints.
> >>>
> >>> Can someone please guide me, how can I deploy camel code on Apache
> Karaf?
> >>> It would be very helpful if someone can provide me an example.
> >>>
> >>> Thanks,
> >>> Kirti Arora
> >>>
> >>
> >> --
> >> Jean-Baptiste Onofré
> >> jbono...@apache.org
> >> http://blog.nanthrax.net
> >> Talend - http://www.talend.com
> >>
> >
>
> --
> Jean-Baptiste Onofré
> jbono...@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>

Reply via email to