You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jmandawg <jm...@hotmail.com> on 2016/06/08 15:30:05 UTC

Removing and reloading Rests XML Definitions dynamically

Hi,

I'm trying to remove and reload rest definitions from xml using camel
2.17.1.  I have the following code to load them (stolen from
camel-spring-boot):

for(String restRoutePath : restRoutePaths) {
           try{
    	       RestsDefinition rd =
camelContext.loadRestsDefinition(appContext.getResource(restRoutePath).getInputStream());
    	       camelContext.addRestDefinitions(rd.getRests());
    	       for(RestDefinition xmlDef : rd.getRests()) {
    	           List<RouteDefinition> routeDefs =
xmlDef.asRouteDefinition(camelContext);
    	           camelContext.addRouteDefinitions(routeDefs);
                   //Store loaded Routes
                   loadedRouteDefs.addAll(routeDefs);
    	       }
	       } catch(Exception ex){
	           ex.printStackTrace();
	       }
	   }

To remove the routes I use:
camelContext.removeRouteDefinitions(loadedRouteDefs);

But then when i try to reload the xml again, i get the following error which
makes me think the Rest definitions are not getting completely removed.  It
works fine for regular xml Routes, just not Rest.


org.apache.camel.FailedToStartRouteException: Failed to start route route71
because of duplicate id detected: route75. Please correct ids to be unique
among all your routes.
	at
org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:963)
	at
org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3295)
	at
org.apache.camel.impl.DefaultCamelContext.addRouteDefinitions(DefaultCamelContext.java:908)
	at com.transamerica.isb.api.interfaces.Utils.loadRoutes(Utils.java:90)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)




--
View this message in context: http://camel.465427.n5.nabble.com/Removing-and-reloading-Rests-XML-Definitions-dynamically-tp5783724.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Removing and reloading Rests XML Definitions dynamically

Posted by jmandawg <jm...@hotmail.com>.
So the real problem is, after the app starts I have like 3 RestConfigurations
(jetty, netty-http, restlet) and when i call: 

 List<RouteDefinition> routeDefs = xmlDef.asRouteDefinition(camelContext,
getContext().getRestConfiguration());

It creates a route for each RestConfiguration, which is not what i want.  I
only want them running on the netty-http.

Does it make sense to add this method to RestDefinition so that you can
choose the RestConfiguration you want the route added to?

public List<RouteDefinition> asRouteDefinition(CamelContext camelContext,
RestConfiguration restConfig) {
        // sanity check this rest definition do not have duplicates
        validateUniquePaths();

        List<RouteDefinition> answer = new ArrayList<RouteDefinition>();
        
        addRouteDefinition(camelContext, answer, restConfig.getComponent());
        
        return answer;
    }



--
View this message in context: http://camel.465427.n5.nabble.com/Removing-and-reloading-Rests-XML-Definitions-dynamically-tp5783724p5783733.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Removing and reloading Rests XML Definitions dynamically

Posted by jmandawg <jm...@hotmail.com>.
It seems For some reason RouteBuilder does not check the camelContext for
existing restConfiguration before it goes and creates it's own resulting in
multple restConfigurations.  

#RouteBuilder
public RestConfigurationDefinition restConfiguration(String component) {
        if (restConfigurations == null) {
            restConfigurations = new HashMap<String,
RestConfigurationDefinition>();
        }
        RestConfigurationDefinition restConfiguration =
restConfigurations.get(component);
        if (restConfiguration == null) {
            restConfiguration = new RestConfigurationDefinition();
            if (!component.isEmpty()) {
                restConfiguration.component(component);
            }
            restConfigurations.put(component, restConfiguration);
        }
        return restConfiguration;
    }


Is this how it's supposed to be?



--
View this message in context: http://camel.465427.n5.nabble.com/Removing-and-reloading-Rests-XML-Definitions-dynamically-tp5783724p5783732.html
Sent from the Camel - Users mailing list archive at Nabble.com.