In order to debug the camel routes and find why there problem transferring or processing messages there is an option to set tracing on camel .
Adding tracing to the camel-config.Xml file :
<bean id="camelTracer" class="org.apache.camel.processor.interceptor.Tracer"><property name="traceExceptions" value="true"/><property name="traceInterceptors" value="true"/><property name="logLevel" value="INFO"/><property name="logName" value="com.mycompany.messages"/></bean><camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
Add to the log4j configuration file appender in order to make the log more readably
log4j.appender.file=org.apache.log4j.RollingFileAppenderlog4j.appender.file.File=D:\\Temp\\loging.txtlog4j.appender.file.MaxFileSize=10MBlog4j.appender.file.MaxBackupIndex=1log4j.appender.file.layout=org.apache.log4j.PatternLayoutlog4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
In the route builder in the configure method we can call to set the logging output formatting:
@Overridepublic void configure() throws Exception {Tracer tracer = new Tracer();tracer.setTraceOutExchanges(true);// we configure the default trace formatter where we can// specify which fields we want in the outputDefaultTraceFormatter formatter = new DefaultTraceFormatter();formatter.setShowOutBody(true);formatter.setShowOutBodyType(true);formatter.setShowException(true);formatter.setShowExchangePattern(true);formatter.setShowProperties(true);formatter.setShowOutHeaders(true);// set to use our formattertracer.setFormatter(formatter);getContext().addInterceptStrategy(tracer);....
The logging information is dump to both the tomcat server console log and to the log file that has bean declared in the log4j configuration file :
2014-04-25 11:46:28,576 [io-8080-exec-42] INFO messages - ID-Zvika-PC-2757-1398415530094-0-14 >>> (route2) wireTap(Endpoint[seda://tap]) --> org.apache.camel.example.cxf.CamelRoute$1@1a304efc <<< Pattern:InOut, Headers:{breadcrumbId=ID-Zvika-PC-2757-1398415530094-0-13, connection=Keep-Alive, user-agent=Apache-HttpClient/4.1.1 (java 1.5), CamelCxfRsResponseGenericType=class javax.ws.rs.core.Response, CamelCxfRsOperationResourceInfoStack=[org.apache.cxf.jaxrs.model.MethodInvocationInfo@6b6e21bb], CamelAcceptContentType=*/*, CamelCxfMessage=org.apache.cxf.message.XMLMessage@99357e13, operationName=SayHello, CamelCxfRsResponseClass=class javax.ws.rs.core.Response, Name=EtiGoldfarb, CamelHttpPath=/RsService/SayHello/EtiGoldfarb, accept-encoding=gzip,deflate, CamelHttpMethod=GET, host=localhost:8080, CamelHttpUri=/camel-example-cxfrs-tomcat/webservices/myData/RsService/SayHello/EtiGoldfarb}, BodyType:org.apache.cxf.message.MessageContentsList, Body:EtiGoldfarb
2014-04-25 11:46:28,578 [#0 - seda://tap] INFO messages - ID-Zvika-PC-2757-1398415530094-0-16 >>> (route1) from(seda://tap) --> log[the body ${body}] <<< Pattern:InOnly, Headers:{CamelHttpUri=/camel-example-cxfrs-tomcat/webservices/myData/RsService/SayHello/EtiGoldfarb, CamelHttpPath=/RsService/SayHello/EtiGoldfarb, host=localhost:8080, CamelAcceptContentType=*/*, operationName=SayHello, CamelCxfRsResponseGenericType=class javax.ws.rs.core.Response, breadcrumbId=ID-Zvika-PC-2757-1398415530094-0-13, CamelCxfRsResponseClass=class javax.ws.rs.core.Response, connection=Keep-Alive, accept-encoding=gzip,deflate, CamelCxfRsOperationResourceInfoStack=[org.apache.cxf.jaxrs.model.MethodInvocationInfo@6b6e21bb], CamelHttpMethod=GET, Name=EtiGoldfarb, user-agent=Apache-HttpClient/4.1.1 (java 1.5), CamelCxfMessage=org.apache.cxf.message.XMLMessage@99357e13}, BodyType:org.apache.cxf.message.MessageContentsList, Body:EtiGoldfarb
Example for detailed exception in the log :
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> From[seda:tap2] <<< in route: Route(route1)[[From[seda:tap2]] -> []] because of Route route1 has no output processors. You need to add outputs to the route such as to("log:foo").
אין תגובות:
הוסף רשומת תגובה