camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ishwar <>
Subject how to use use only one apache camel context object in java Restful services
Date Thu, 21 Nov 2013 07:00:00 GMT
hi. i need to perform the all operation like the creating the quartz2
scheduler and deleting on only one Apache camel context
using restful service. when i try using following code .each time its
creating the new context object. i do not know how to fix it.
this is my code

this is my java restful services which is call to the quartz scheduler.

java Rest Services.
public class RemainderResource {
	private static org.apache.log4j.Logger log =
	RemainderScheduler remainderScheduler=new RemainderScheduler();
	CamelContext context = new DefaultCamelContext();
	public void create(@PathParam("day") int day,final String userdata)
		log.debug("the starting process of the creating the Remainder");
		JSONObject data=(JSONObject) JSONSerializer.toJSON(userdata);
		String cronExp=data.getString("cronExp");		

This is my java class which is creating schedule job .

public class RemainderScheduler {
	private static org.apache.log4j.Logger log =
	public void sendRemainder(int day)
		log.debug("the starting of the sending the Remainder to user");
	public RouteBuilder createMyRoutes(final String cronExp,final int day) 
	    return new RouteBuilder()
	        public void configure() throws Exception {
	        	log.debug("Before set schedulling");
RemainderScheduler(), "sendRemainder('"+day+"')").routeId("Remainder")
	             .process(new Processor() { 
                    public void process(Exchange exchange) throws Exception
	             log.debug("after set schedulling");

	public void stopService(CamelContext context)
		log.debug("this is going to be stop the route");
		try {
		} catch (Exception e) {
	public void create(final String cronExp,final int day,CamelContext context)
		//this for if all ready exist then stop it.
			log.debug("the starting of the process for creating the Remaider
			context.addRoutes(createMyRoutes(cronExp, day));
			log.debug("the status for removing the services
    	catch(Exception e)


if i execute the above code then the each javaRest ful request create the
new context object. so after object is created and  quartz job scheduling
but when again i calling with next request for stop the quartz scheduling
then also its creating new context object and the try to stop but actually
its not possible because 
the context object is new. i dont know how to perform all operation on only
one context object of apache camel.

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message