Hi Kasim,
I'm not sure that I understood your problem, but starting the Camel
context and starting the routes have different semantics. You should
not ignore Camel context startup failure, in the example you provided
you just print the stack trace.
With the Camel context started you can add (CamelContext::addRoutes)
or start/stop (CamelContext::startRoute, CamelContext::stopRoute)
routes dynamically as needed.
As you're using Camel Spring Boot support and have set
auto-startup=false you can define the RouteBuilder as separate beans
in the Spring Context. Also perhaps use some of the Spring Boot
conditional beans to have them defined when needed.

zoran

On Tue, Jul 18, 2017 at 10:00 AM, Kasim Sert (Ibtech-Software
Infrastructure) <[email protected]> wrote:
> Hi,
>
> I am using spring boot with camel cxf to expose rest/soap web services. 
> However since I have many services and some of them are not well defined, I 
> want to register each of them one by one, catch if any exception occurs and 
> continue with remaining valid services. But when I set 
> camel.springboot.auto-startup=false I can not manage to open cxf service 
> again. (Please note that timer route can be started by this way). Any 
> solution or suggestion ?
>
> Thank you
>
> Here is the code :
>
> @Component
> public class TestRoutes {
>
>      @Autowired CamelContext camelContext;
>      @Autowired Swagger2Feature swagger2Feature;
>
>      @PostConstruct
>      public void init(){
>           try {
>                 camelContext.start();
>           } catch (Exception e1) {
>                 e1.printStackTrace();
>           }
>           HelloResponse response = new HelloResponse();
>           response.setCevap("response");
>           List<Object> providers = new ArrayList<>();
>           CxfRsComponent cxfComponent = new CxfRsComponent(camelContext);
>
>     CxfRsEndpoint serviceEndpoint = new CxfRsEndpoint("/rest2", cxfComponent);
>     serviceEndpoint.addResourceClass(Service1.class);
>     serviceEndpoint.setProviders(providers);
>     serviceEndpoint.setSynchronous(true);
>     serviceEndpoint.setAddress("/rest2");
>     serviceEndpoint.getFeatures().add(swagger2Feature);
>
>     RouteBuilder builder = new RouteBuilder(camelContext) {
>                 @Override
>                 public void configure() throws Exception {
>                      from(serviceEndpoint)
>                      .id(Service1.class.getCanonicalName()+"rest")
>                      .log("${header.operationName} message here")
>                      .setBody(constant(response));
>
>                      from("timer:mytimer?period=5000")
>                           .id("timer")
>                           .log("hi");
>
>                 }
>           };
>           try {
>                
> camelContext.startRoute(Service1.class.getCanonicalName()+"rest");
>                 camelContext.startRoute("timer");
>           } catch (Exception e) {
>                 e.printStackTrace();
>           }
>      }
> }
>
> Startup log:
> 017-07-18 10:50:49.076  INFO 12052 --- [           main] 
> ationConfigEmbeddedWebApplicationContext : Refreshing 
> org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5149d738:
>  startup date [Tue Jul 18 10:50:49 EEST 2017]; root of context hierarchy
> 2017-07-18 10:50:52.413  INFO 12052 --- [           main] 
> trationDelegate$BeanPostProcessorChecker : Bean 
> 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type 
> [org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$5d14135]
>  is not eligible for getting processed by all BeanPostProcessors (for 
> example: not eligible for auto-proxying)
> 2017-07-18 10:50:53.063  INFO 12052 --- [           main] 
> s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 
> 8080 (http)
> 2017-07-18 10:50:53.085  INFO 12052 --- [           main] 
> o.apache.catalina.core.StandardService   : Starting service Tomcat
> 2017-07-18 10:50:53.086  INFO 12052 --- [           main] 
> org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache 
> Tomcat/8.5.11
> 2017-07-18 10:50:53.341  INFO 12052 --- [ost-startStop-1] 
> o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded 
> WebApplicationContext
> 2017-07-18 10:50:53.342  INFO 12052 --- [ost-startStop-1] 
> o.s.web.context.ContextLoader            : Root WebApplicationContext: 
> initialization completed in 4269 ms
> 2017-07-18 10:50:53.974  INFO 12052 --- [ost-startStop-1] 
> o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 
> 'dispatcherServlet' to [/]
> 2017-07-18 10:50:53.976  INFO 12052 --- [ost-startStop-1] 
> o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'CXFServlet' to 
> [/services/*]
> 2017-07-18 10:50:53.981  INFO 12052 --- [ost-startStop-1] 
> o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 
> 'characterEncodingFilter' to: [/*]
> 2017-07-18 10:50:53.982  INFO 12052 --- [ost-startStop-1] 
> o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 
> 'hiddenHttpMethodFilter' to: [/*]
> 2017-07-18 10:50:53.982  INFO 12052 --- [ost-startStop-1] 
> o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 
> 'httpPutFormContentFilter' to: [/*]
> 2017-07-18 10:50:53.982  INFO 12052 --- [ost-startStop-1] 
> o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 
> 'requestContextFilter' to: [/*]
> 2017-07-18 10:50:54.682  INFO 12052 --- [           main] 
> o.a.camel.spring.SpringCamelContext      : Apache Camel 2.19.1 (CamelContext: 
> camel-1) is starting
> 2017-07-18 10:50:54.685  INFO 12052 --- [           main] 
> o.a.c.m.ManagedManagementStrategy        : JMX is enabled
> 2017-07-18 10:50:54.999  INFO 12052 --- [           main] 
> o.a.c.i.converter.DefaultTypeConverter   : Loaded 214 type converters
> 2017-07-18 10:50:55.064  INFO 12052 --- [           main] 
> o.a.c.i.DefaultRuntimeEndpointRegistry   : Runtime endpoint registry is in 
> extended mode gathering usage statistics of all incoming and outgoing 
> endpoints (cache limit: 1000)
> 2017-07-18 10:50:55.094  INFO 12052 --- [           main] 
> o.a.camel.spring.SpringCamelContext      : StreamCaching is not in use. If 
> using streams then its recommended to enable stream caching. See more details 
> at http://camel.apache.org/stream-caching.html
> 2017-07-18 10:50:55.095  INFO 12052 --- [           main] 
> o.a.camel.spring.SpringCamelContext      : Total 0 routes, of which 0 are 
> started.
> 2017-07-18 10:50:55.097  INFO 12052 --- [           main] 
> o.a.camel.spring.SpringCamelContext      : Apache Camel 2.19.1 (CamelContext: 
> camel-1) started in 0.415 seconds
> 2017-07-18 10:50:55.301  WARN 12052 --- [           main] 
> o.apache.cxf.jaxrs.utils.ResourceUtils   : No resource methods have been 
> found for resource class java.lang.Class
> 2017-07-18 10:50:55.433  INFO 12052 --- [           main] 
> org.apache.cxf.endpoint.ServerImpl       : Setting the server's publish 
> address to be /rest1
> 2017-07-18 10:50:55.636  INFO 12052 --- [           main] 
> org.reflections.Reflections              : Reflections took 60 ms to scan 1 
> urls, producing 21 keys and 25 values
> 2017-07-18 10:50:56.106  INFO 12052 --- [           main] 
> s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: 
> org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5149d738:
>  startup date [Tue Jul 18 10:50:49 EEST 2017]; root of context hierarchy
> 2017-07-18 10:50:56.206  INFO 12052 --- [           main] 
> s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public 
> org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, 
> java.lang.Object>> 
> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
> 2017-07-18 10:50:56.208  INFO 12052 --- [           main] 
> s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped 
> "{[/error],produces=[text/html]}" onto public 
> org.springframework.web.servlet.ModelAndView 
> org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
> 2017-07-18 10:50:56.267  INFO 12052 --- [           main] 
> o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto 
> handler of type [class 
> org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
> 2017-07-18 10:50:56.267  INFO 12052 --- [           main] 
> o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler 
> of type [class 
> org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
> 2017-07-18 10:50:56.330  INFO 12052 --- [           main] 
> o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] 
> onto handler of type [class 
> org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
> 2017-07-18 10:50:57.591  INFO 12052 --- [           main] 
> o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure 
> on startup
> 2017-07-18 10:50:57.686  INFO 12052 --- [           main] 
> s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 
> (http)
> 2017-07-18 10:50:57.694  INFO 12052 --- [           main] 
> c.e.demo.AutoStartupFalseApplication     : Started 
> AutoStartupFalseApplication in 9.057 seconds (JVM running for 9.764)
>
>
>
>
>
> Bu e-posta'n?n i?erdi?i bilgiler (ekleri dahil olmak ?zere) gizlidir. 
> Onay?m?z olmaks?z?n ???nc? ki?ilere a?iklanamaz. Bu mesaj?n g?nderilmek 
> istendi?i ki?i de?ilseniz, l?tfen mesaj? sisteminizden derhal siliniz. IBTech 
> A.?. bu mesaj?n i?erdi?i bilgilerin do?rulu?u veya eksiksiz oldu?u konusunda 
> bir garanti vermemektedir. Bu nedenle bilgilerin ne ?ekilde olursa olsun 
> i?eri?inden, iletilmesinden, al?nmas?ndan, saklanmas?ndan sorumlu de?ildir. 
> Bu mesaj?n i?eri?i yazar?na ait olup, IBTech A.?.'nin g?r??lerini 
> i?ermeyebilir.
>
> The information contained in this e-mail (including any attachments)is 
> confidential. It must not be disclosed to any person without our authority. 
> If you are not the intended recipient, please delete it from your system 
> immediately. IBTech A.S. makes no warranty as to the accuracy or completeness 
> of any information contained in this message and hereby excludes any 
> liability of any kind for the information contained therein or for the 
> information transmission, reception, storage or use of such in any way 
> whatsoever. Any opinions expressed in this message are those of the author 
> and may not necessarily reflect the opinions of IBTech A.S.



-- 
Zoran Regvart

Reply via email to