Reputation: 139
I'm trying to call camel/java-ee/class (it's very long programs, so no time to convert) from a spring-boot. So for now the solution is to just start with spring-boot and call the main class.
Here's the main application of springboot that will call the javaee/class, I tried the simple bean calling before, so this my latest test for I thought its about the proper call of bean, but unfortunately, even the proper calling of bean have the same error as the simple calling of bean,
@SpringBootApplication
public class App {
public static void main(String[] args) throws Exception {
ApplicationContext applicationContext = SpringApplication.run(App.class, args);
BeanAppService service = applicationContext.getBean(BeanAppService.class);
service.callInitCamelJavaEE();
}
}
Service interface,
public interface BeanAppService {
void callInitCamelJavaEE() throws Exception;
}
Configuration,
@Configuration
public class BeanAppConfig {
@Bean
public BeanAppService beanAppConfig() {
return new BeanApp();
}
}
BeanApp (this is the original main class with args in java/ee),
public class BeanApp implements BeanAppService {
public BeanApp() {}
protected <I extends SpongeRequest, O extends SpongeResponse> void createOperation(RestDefinition restDefinition, String operation,
String operationDescription, Class<I> requestClass, String requestDescription, Class<O> responseClass,
String responseDescription, BiFunction<I, Exchange, O> operationHandler) {
restDefinition.post(operation).description(operationDescription).type(requestClass).outType(responseClass).param().name("body")
.type(body).description(requestDescription).endParam().responseMessage().code(200).message(responseDescription)
.endResponseMessage().route().id("sponge-" + operation).process(exchange -> {
String requestBody = exchange.getIn().getBody(String.class);
if (logger.isDebugEnabled()) {
logger.debug("REST API {} request: {}", operation, RestApiUtils.obfuscatePassword(requestBody));
}
try {
setupResponse(operation, exchange,
operationHandler.apply(getObjectMapper().readValue(requestBody, requestClass), exchange));
} catch (Throwable processingException) {
logger.info("REST API error", processingException);
try {
setupResponse(operation, exchange, apiService.createGenericErrorResponse(processingException, exchange));
} catch (Throwable e) {
logger.error("REST API send error response failure", e);
throw e;
}
}
}).endRest();
}
@Override
public void callInitCamelJavaEE() throws Exception {
try (CamelContext camelContext = new DefaultCamelContext()) {
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
restConfiguration().enableCORS(true).setPort("8080");
}
});
camelContext.start();
Thread.sleep(6000000);
camelContext.stop();
}
}
The error,
StreamCaching is not in use. If using streams then it's recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
Error starting CamelContext (camel-2) due to exception thrown: Failed to start route route1 because of null
org.apache.camel.FailedToStartRouteException: Failed to start route route1 because of null
at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:122) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.InternalRouteStartupManager.doWarmUpRoutes(InternalRouteStartupManager.java:270) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:157) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRoutes(InternalRouteStartupManager.java:115) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:2889) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.AbstractCamelContext.doStartContext(AbstractCamelContext.java:2702) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2665) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.support.service.BaseService.start(BaseService.java:115) ~[camel-api-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2431) ~[camel-base-engine-3.7.0.jar:3.7.0]
at ca.toronto.eis.dwork2.BeanApp.BeanAppApp.callMain(BeanAppApp.java:531) ~[main/:?]
at ca.toronto.eis.dwork2.Dwork2Application.main(Dwork2Application.java:29) ~[main/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_202]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.7.0.jar:2.7.0]
Caused by: java.lang.IllegalStateException: Cannot find RestConsumerFactory in Registry or as a Component to use
at org.apache.camel.component.rest.RestEndpoint.createConsumer(RestEndpoint.java:602) ~[camel-rest-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.DefaultRoute.addServices(DefaultRoute.java:575) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.DefaultRoute.onStartingServices(DefaultRoute.java:160) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.RouteService.doWarmUp(RouteService.java:150) ~[camel-base-engine-3.7.0.jar:3.7.0]
at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:120) ~[camel-base-engine-3.7.0.jar:3.7.0]
... 15 more
Apache Camel 3.7.0 (camel-2) is shutting down
Apache Camel 3.7.0 (camel-2) uptime 28ms
Apache Camel 3.7.0 (camel-2) is shutdown in 10ms
Anyone who have encountered this before?
Upvotes: 0
Views: 482
Reputation: 36
Seems like in the route builder you have not configured any route.
@Override
public void callInitCamelJavaEE() throws Exception {
try (CamelContext camelContext = new DefaultCamelContext()) {
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
restConfiguration().enableCORS(true).setPort("8080");
}
});
camelContext.start();
Thread.sleep(6000000);
camelContext.stop();
}
}
Assuming you are using Rest here is How to configure a route in RouteBuilder using REST DSL
Upvotes: 2