Hello

I use Camel (2.10.2) inside Glassfish (3.1.2.2) with the CdiCamelContext as 
Singleton. I don't want to use Spring, so I use CDI. I have many JMS-Routes, 
which works all fine. But I have a strange issue with "cxfrs" and "Address 
already in use" after a redeployment.
The "cxfrs" route looks like that:
public class RestCamelRoute extends RouteBuilder
{ 
    public RestCamelRoute()
    { }

    @Override
    public void configure() throws Exception
    {
        from("cxfrs://http://127.0.0.1:61621?resourceClasses="; + 
ValidationRestService.class.getName())
            .process(new Processor()
            {
                public void process(Exchange exchange) throws Exception
                {
                    //custom processing here
                }
            })
            .log("-> JAX RS Request Body: \n: ${body}")
            .log("-> JAX RS Request headers: \n: ${headers}")
            .setBody(constant("SUCCESSFULLY"));
    }
}


I can deploy that route on Glassfish only once successfully. When I redeploy 
the route I see "Address already in use" messages in the log-files. It looks 
like that the embedded Jetty-Server is not stopped within an undeployment. 

The @PreDestroy method is called at the undeployment, which only do 
"camelCtx.stop()". Is it possible, that "camelCtx.stop()" is not stopping the 
jetty server, so the port "61621" stays open? 

Here the CDI Singleton:
@Singleton
@Startup
public class CamelBootStrap
{
    Logger logger = Logger.getLogger(CamelBootStrap.class.getName());

    @Inject
    CdiCamelContext camelCtx;

    @Inject
    RestCamelRoute restCamelRoute;

    @PostConstruct
    public void init() throws Exception
    {
        try
        {
            logger.info("$$$$$$ Create CamelContext and register Camel Routes 
... $$$$$$");

            camelCtx.addRoutes(restCamelRoute);

            // Start Camel Context
            camelCtx.start();

            logger.info("$$$$$$ CamelContext created and camel routes started. 
$$$$$$");
        }
        catch (Exception e)
        {
            if(camelCtx != null)
            {
                camelCtx.stop();
                logger.info("!!!!! CamelContext stopped within INIT !!!!!");
            }
        }
    }


    /**
     * Camel Stoppen
     * @throws Exception
     */
    @PreDestroy
    public void stop() throws Exception
    {
        camelCtx.stop();
        logger.info("!!!!! CamelContext stopped within PreDestroy !!!!!");
        System.out.println("$$$$$$$$$$ CAMEL STOPPED $$$$$$$$$$");
    }
}

Would be great if someone could help me.

Greetings
Chris

Reply via email to