Looking at the stack trace it looks like the problem is with what it being returned from your call to the Web Service. Reading from the properties file, I normally like to use a configuration class in Spring to hold these values. Then just Autowire it into the Route Builder class. Here's an example:
https://github.com/runstache/java-came-metrics The AppSettings Class is populated with the values in the application.properties file. Also going this route, you can swap in different properties files based on a spring profile or inject the class for things like unit testing different routes and processors. Once you have them in a config class, it's really just string building then in the Camel DSL for the route. Note: The application.properties file in this project is utilizing environment variables for it's values. On Mon, Aug 5, 2019 at 3:44 AM Viki Keaton <[email protected]> wrote: > Hello- > I'm new to Camel and excited about it's use. However, I find myself very > frustrated with what seems to be the simplest of things. I have several > questions, but will try and keep them in separate posts. > > I am using Eclipse, Camel 2.24.0, Spring Boot 2.2.0, Java 1.8, and I can > not use any xml. > > I would like to dynamically build my URIs based on properties from an > application.properties file that is on the classpath, as well as use > exchange header parameters. > I thought I could use toD() to create dynamic URIs? This seems to be > blank. What am I doing wrong? Also, please note that I tried to print my > application.properties value for the key "data.trans.vm", and I get nothing. > > My goal is to be able to use the applications.properties file as well as > header parameters. Thanks in advance for your help. > > > My ~/src/main/resources/applications.properties file: > data.trans.greeting=Hello Viki > > @Component > public class DataTransRouteBuilder extends RouteBuilder { > @Override > public void configure() throws Exception { > > from("jetty:http://localhost:8081/foobar").tracing() > .log("data mart id is: ${header.dataMartId}") > .to("direct:getDataMart"); > > > from("direct:getDataMart").tracing() > .log("at direct:getDataMart") > .log("properties: DATA_TRANS_VM is > properties:{{data.trans.greeting}}") > .setBody().constant(null) > .setHeader(Exchange.HTTP_METHOD, simple("GET")) > .setHeader("Content-Type", constant("application/json")) > .setHeader("Accept", constant("application/json")) > .setHeader("Accept-Encoding", constant("identity")) > .setHeader("Authorization", constant(BASIC_AUTH)) > .log("call data mart url for id=${header.dataMartId}") > .toD("http://<MY REMOTE REST > SERIVE>:<PORT>/${header.dataMartId}/build?bridgeEndpoint=true") > .choice() > > .when().simple("${header.CamelHttpResponseCode} != 200") > .log("Failure to call: " + DATA_TRANS_DATAMART_URL) > .to("direct:ERROR") > .end() > > .unmarshal().json(JsonLibrary.Jackson, JobInfo.class) > .bean(dataTransJobInfoProcessor, "process") > ... > From my console: > ... > 2019-08-03 23:39:32.195 INFO 7612 --- [ main] > o.a.camel.spring.SpringCamelContext : Apache Camel 2.24.0 > (CamelContext: camel-1) started in 0.918 seconds > 2019-08-03 23:39:32.254 INFO 7612 --- [ main] > o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 > (http) with context path '' > 2019-08-03 23:39:32.258 INFO 7612 --- [ main] > a.r.l.a.ReckonLineageAdaptersApplication : Started > ReckonLineageAdaptersApplication in 16.714 seconds (JVM running for 17.413) > 2019-08-03 23:39:41.859 INFO 7612 --- [tp1955991197-25] route1 > : data mart id is: 12345 > 2019-08-03 23:39:41.860 INFO 7612 --- [tp1955991197-25] route2 > : at direct:getDataMart > 2019-08-03 23:39:41.860 INFO 7612 --- [tp1955991197-25] route2 > : properties: DATA_TRANS_VM is > properties:{{data.trans.vm}} > 2019-08-03 23:39:41.861 INFO 7612 --- [tp1955991197-25] route2 > : call data mart url for id=12345 > 2019-08-03 23:39:42.197 ERROR 7612 --- [tp1955991197-25] > o.a.camel.processor.DefaultErrorHandler : Failed delivery for (MessageId: > ID-vkeat01116-1564893569848-0-3 on ExchangeId: > ID-vkeat01116-1564893569848-0-1). Exhausted after delivery attempt: 1 > caught: com.fasterxml.jackson.databind.exc.MismatchedInputException: No > content to map due to end-of-input > at [Source: > (org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream); > line: 1, column: 0] > ... > > Message History > > --------------------------------------------------------------------------------------------------------------------------------------- > RouteId ProcessorId Processor > Elapsed (ms) > [route1 ] [route1 ] [jetty: > http://localhost:8081/foobar ] > [ 338] > [route1 ] [log1 ] [log > ] [ 2] > [route1 ] [to1 ] [direct:getDataMart > ] [ 0] > [route2 ] [log2 ] [log > ] [ 0] > [route2 ] [log3 ] [log > ] [ 0] > [route2 ] [setBody1 ] [setBody[{null}] > ] [ 0] > [route2 ] [setHeader1 ] [setHeader[CamelHttpMethod] > ] [ 1] > [route2 ] [setHeader2 ] [setHeader[Content-Type] > ] [ 0] > [route2 ] [setHeader3 ] [setHeader[Accept] > ] [ 0] > [route2 ] [setHeader4 ] [setHeader[Accept-Encoding] > ] [ 0] > [route2 ] [setHeader5 ] [setHeader[Authorization] > ] [ 0] > [route2 ] [log4 ] [log > ] [ 0] > [route2 ] [toD1 ] [ > ] [ 309] > [route2 ] [choice1 ] > [when[simple{${header.CamelHttpResponseCode} != 200}]choice[] > ] [ 8] > [route2 ] [unmarshal1 ] > [unmarshal[org.apache.camel.model.dataformat.JsonDataFormat@f6e1ef6] > ] [ 13] > > Stacktrace > > --------------------------------------------------------------------------------------------------------------------------------------- > > com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to > map due to end-of-input > at [Source: > (org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream); > line: 1, column: 0] > at > com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) > ~[jackson-databind-2.9.9.jar:2.9.9] > at > com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4145) > ~[jackson-databind-2.9.9.jar:2.9.9] > at > com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4000) > ~[jackson-databind-2.9.9.jar:2.9.9] > at > com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070) > ~[jackson-databind-2.9.9.jar:2.9.9] > at > org.apache.camel.component.jackson.JacksonDataFormat.unmarshal(JacksonDataFormat.java:194) > ~[camel-jackson-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69) > ~[camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.Pipeline.process(Pipeline.java:138) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.Pipeline.process(Pipeline.java:101) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:76) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.Pipeline.process(Pipeline.java:138) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.Pipeline.process(Pipeline.java:101) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) > [camel-core-2.24.0.jar:2.24.0] > at > org.apache.camel.component.jetty.CamelContinuationServlet.doService(CamelContinuationServlet.java:220) > [camel-jetty-common-2.24.0.jar:2.24.0] > at > org.apache.camel.http.common.CamelServlet.service(CamelServlet.java:79) > [camel-http-common-2.24.0.jar:2.24.0] > at > javax.servlet.http.HttpServlet.service(HttpServlet.java:741) > [tomcat-embed-core-9.0.21.jar:9.0.21] > at > org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:876) > [jetty-servlet-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1623) > [jetty-servlet-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:150) > [jetty-servlets-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43) > [camel-jetty-common-2.24.0.jar:2.24.0] > at > org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) > [jetty-servlet-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540) > [jetty-servlet-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1347) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480) > [jetty-servlet-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1249) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at org.eclipse.jetty.server.Server.handle(Server.java:505) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267) > [jetty-server-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305) > [jetty-io-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) > [jetty-io-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) > [jetty-io-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:781) > [jetty-util-9.4.19.v20190610.jar:9.4.19.v20190610] > at > org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:917) > [jetty-util-9.4.19.v20190610.jar:9.4.19.v20190610] > at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144] > > > *************************************************************************** > The information contained in this communication is confidential, is > intended only for the use of the recipient named above, and may be legally > privileged. > > If the reader of this message is not the intended recipient, you are > hereby notified that any dissemination, distribution or copying of this > communication is strictly prohibited. > > If you have received this communication in error, please resend this > communication to the sender and delete the original message or any copy > of it from your computer system. > > Thank You. > > **************************************************************************** >
