Hi,

If you don't run in Karaf, that won't work because you are in two
different JVM: the one executing your Main, the one for Karaf.

direct endpoints are visible only in the same JVM and for direct it's in
the same CamelContext ! If you want to communicate between two routes
from different camel context (still in the same JVM), you have to use
direct-vm.

If you try to execute your Main in Karaf (by dropping the jar in deploy
folder), it's what I understood, that won't work.
To do that, you have to use exec in Karaf or create a bundle with a
activator (acting as kind of main).

It would be easier to actually expose a concrete endpoint (as we do in
example with jetty for instance).

Regards
JB

On 07/10/2019 09:14, Kirti Arora wrote:
> 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
>>
> 

-- 
Jean-Baptiste Onofré
jbono...@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Reply via email to