@Override public void start() throws Exception { ObjectHelper.notNull(camelContext, "CamelContext", this); // register our event notifier ServiceHelper.startService(debugEventNotifier); camelContext.getManagementStrategy().addEventNotifier(debugEventNotifier); if (isUseTracer()) { Tracer tracer = Tracer.getTracer(camelContext); if (tracer == null) { // tracer is disabled so enable it silently so we can leverage it to trace the Exchanges for us tracer = Tracer.createTracer(camelContext); tracer.setLogLevel(LoggingLevel.OFF); camelContext.addService(tracer); camelContext.addInterceptStrategy(tracer); } // make sure tracer is enabled so the debugger can leverage the tracer for debugging purposes tracer.setEnabled(true); } }
protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { // START SNIPPET: tracingOutExchanges Tracer tracer = new Tracer(); tracer.setTraceOutExchanges(true); // we configure the default trace formatter where we can // specify which fields we want in the output DefaultTraceFormatter formatter = new DefaultTraceFormatter(); formatter.setShowOutBody(true); formatter.setShowOutBodyType(true); // set to use our formatter tracer.setFormatter(formatter); getContext().addInterceptStrategy(tracer); // END SNIPPET: tracingOutExchanges from("direct:start"). transform().body(). to("mock:a"). to("mock:b"); } }; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { Tracer tracer = new Tracer(); tracer.setDestinationUri("mock:trace"); context.addInterceptStrategy(tracer); // START SNIPPET: e1 // define a global on completion that is invoked when the exchange is complete onCompletion().to("log:global").to("mock:sync"); from("direct:start") .process("myProcessor") .to("mock:result"); // END SNIPPET: e1 } }; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { Tracer tracer = new Tracer(); tracer.setDestinationUri("mock:trace"); context.addInterceptStrategy(tracer); intercept().to("mock:intercepted"); from("direct:start") .to("mock:foo").to("mock:bar").to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { Tracer tracer = new Tracer(); tracer.setDestinationUri("mock:traced"); tracer.setLogName("foo"); context.addInterceptStrategy(tracer); from("direct:a").to("mock:a"); from("direct:b").noTracing().to("mock:b"); from("direct:c").tracing().to("mock:c"); } }; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { Tracer tracer = new Tracer(); tracer.setDestinationUri("mock:traced"); tracer.setLogLevel(LoggingLevel.OFF); context.addInterceptStrategy(tracer); from("direct:start").to("log:foo").to("mock:result"); from("direct:foo").noTracing().to("mock:foo"); } }; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { Tracer tracer = new Tracer(); getContext().addInterceptStrategy(tracer); from("file:target/split").routeId("foo").noAutoStartup() .split(body().tokenize(comma)) .parallelProcessing() .streaming() .setProperty("split", new SimpleExpression("${property.CamelSplitIndex}")) .split(body().tokenize(LS)) .parallelProcessing() .streaming() .setBody(body().append(":Status=OK").append(LS)) .to("file:target/split/outbox?fileExist=Append&fileName=result${property.split}.txt") .end() .setBody(new SimpleExpression("${property.split} complete")) .to("file:target/split/outbox?fileExist=Append&fileName=result${property.split}.txt") .end().to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { getContext().addInterceptStrategy(new Tracer()); from(getFtpUrl()).process(new Processor() { public void process(Exchange exchange) throws Exception { assertNotNull(exchange.getIn().getHeader(Exchange.FILE_NAME)); assertEquals("hello.txt", exchange.getIn().getHeader(Exchange.FILE_NAME_ONLY)); assertEquals("Hello World", exchange.getIn().getBody(String.class)); } }).to("mock:result"); } }; }
public void configure() { Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); getContext().addInterceptStrategy(tracer); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliveryDelay(0)); onException(Exception.class).maximumRedeliveries(0).handled(true); BindyDataFormat bindy = new BindyDataFormat(); bindy.setLocale("en"); bindy.setClassType(Order.class); bindy.setType(BindyType.Fixed); from(URI_DIRECT_START) .marshal(bindy) .to(URI_MOCK_RESULT); }
@Bean @Override public RouteBuilder route() { return new RouteBuilder() { public void configure() { Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); getContext().addInterceptStrategy(tracer); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliveryDelay(0)); onException(Exception.class).maximumRedeliveries(0).handled(true); BindyDataFormat bindy = new BindyDataFormat(); bindy.setLocale("en"); bindy.setClassType(Order.class); bindy.setType(BindyType.Fixed); from(URI_DIRECT_START) .marshal(bindy) .to(URI_MOCK_RESULT); } }; }
public void configure() { Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); tracer.setLogStackTrace(true); tracer.setTraceExceptions(true); getContext().addInterceptStrategy(tracer); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR)); onException(IllegalArgumentException.class).maximumRedeliveries(0).handled(true); from(URI_DIRECT_START).marshal(orderBindyDataFormat).to(URI_MOCK_RESULT); }
public void configure() { BindyCsvDataFormat camelDataFormat = new BindyCsvDataFormat(org.apache.camel.dataformat.bindy.model.simple.oneclass.Order.class); camelDataFormat.setLocale("en"); Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); getContext().addInterceptStrategy(tracer); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliveryDelay(0)); onException(Exception.class).maximumRedeliveries(0).handled(true); from(URI_DIRECT_START).marshal(camelDataFormat).to(URI_MOCK_RESULT); }
public void testTracerExceptionInOut() throws Exception { MockEndpoint result = getMockEndpoint("mock:result"); ((Tracer) context.getDefaultTracer()).setTraceOutExchanges(true); result.expectedMessageCount(3); prepareTestTracerExceptionInOut(); template.sendBody("direct:start", "Hello World"); template.sendBody("direct:start", "Bye World"); try { template.sendBody("direct:start", "Kaboom"); fail("Should have thrown exception"); } catch (Exception e) { // expected } template.sendBody("direct:start", "Hello Camel"); assertMockEndpointsSatisfied(); validateTestTracerExceptionInOut(); }
protected void createContextWithGivenRoute(RouteBuilder route, int timeWork) throws Exception, InterruptedException { SimpleRegistry registry = new SimpleRegistry(); ModelCamelContext context = new DefaultCamelContext(registry); Tracer tracer = new Tracer(); tracer.setLogName("MyTracerLog"); tracer.getDefaultTraceFormatter().setShowProperties(false); tracer.getDefaultTraceFormatter().setShowHeaders(false); tracer.getDefaultTraceFormatter().setShowBody(true); context.addInterceptStrategy(tracer); context.addRoutes(route); context.addComponent("activeMq", activeMq); this.camelContext = context; this.ct = context.createConsumerTemplate(); this.pt = context.createProducerTemplate(); context.start(); context.setTracing(false); Thread.sleep(timeWork); context.stop(); }
@Override public void configure() throws Exception { getContext().setTracing(true); Tracer tracer = new Tracer(); tracer.setLogName("MyTracerLog"); tracer.getDefaultTraceFormatter().setShowProperties(true); tracer.getDefaultTraceFormatter().setShowHeaders(false); getContext().addInterceptStrategy(tracer); from("direct:start") .setBody(simple("Tracing ${body}")) .to("mock:result"); }
public void addInterceptStrategy(InterceptStrategy interceptStrategy) { getInterceptStrategies().add(interceptStrategy); // for backwards compatible or if user add them here instead of the setXXX methods if (interceptStrategy instanceof Tracer) { setTracing(true); } else if (interceptStrategy instanceof HandleFault) { setHandleFault(true); } else if (interceptStrategy instanceof StreamCaching) { setStreamCaching(true); } else if (interceptStrategy instanceof Delayer) { setDelayer(((Delayer)interceptStrategy).getDelay()); } }
protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { getContext().addInterceptStrategy(new Tracer()); from("direct:beanRef").bean("myBean", "route"); from("direct:recipientList").recipientList().method("myBean", "recipientList"); from("direct:a").transform(constant("Hello a")).to("mock:a"); from("direct:b").transform(constant("Hello b")).to("mock:b"); } }; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { Tracer tracer = new Tracer(); tracer.setDestinationUri("mock:trace"); context.addInterceptStrategy(tracer); onException(IllegalArgumentException.class).handled(true).to("log:boom").to("mock:boom"); from("direct:start").process("myProcessor").to("mock:result"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("com.mycompany"); getContext().addInterceptStrategy(tracer); from("direct:start").to("mock:result"); } }; }
@Override protected CamelContext createCamelContext() throws Exception { CamelContext contextLocal = super.createCamelContext(); Tracer tracer = (Tracer) contextLocal.getDefaultTracer(); tracer.setEnabled(true); tracer.getTraceHandlers().clear(); tracer.getTraceHandlers().add(new MyTraceHandler()); tracer.setTraceOutExchanges(true); return contextLocal; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { Tracer tracer = new Tracer(); tracer.setDestinationUri("mock:traced"); tracer.setLogLevel(LoggingLevel.OFF); context.addInterceptStrategy(tracer); from("direct:start").to("log:foo").to("mock:result"); } }; }
@Test public void testConfiguration() throws Exception { Assert.assertNotNull(_camelContext.getProperty("abc")); Assert.assertEquals("xyz", _camelContext.getProperty("abc")); Assert.assertEquals("foobar-camel-context", _camelContext.getName()); Assert.assertEquals(true, _camelContext.isUseMDCLogging()); Assert.assertEquals(ManagementStatisticsLevel.RoutesOnly , _camelContext.getManagementStrategy().getStatisticsLevel()); Assert.assertEquals(false, _camelContext.isAllowUseOriginalMessage()); Assert.assertEquals(true, _camelContext.isStreamCaching()); DataFormatDefinition dfd = _camelContext.getDataFormats().get("transform-json"); Assert.assertNotNull(dfd); Assert.assertEquals("json-jackson", dfd.getDataFormatName()); Assert.assertTrue(dfd instanceof JsonDataFormat); MockEndpoint mock = _camelContext.getEndpoint("mock:output", MockEndpoint.class); mock.expectedMessageCount(1); mock.expectedBodiesReceived("foobar-input"); _camelContext.createProducerTemplate().sendBody("direct:input", "foobar-input"); mock.assertIsSatisfied(); // CamelContext should be able to find CDI beans produced by this class from registry. Assert.assertEquals(true, _camelContext.isTracing()); DefaultTraceFormatter formatter = (DefaultTraceFormatter) ((Tracer)_camelContext.getDefaultTracer()).getFormatter(); Assert.assertEquals(false, formatter.isShowBody()); Assert.assertEquals(false, formatter.isShowBreadCrumb()); Assert.assertEquals(100, formatter.getMaxChars()); @SuppressWarnings("deprecation") ErrorHandlerBuilder builder = _camelContext.getErrorHandlerBuilder(); Assert.assertEquals(ErrorHandlerBuilderRef.class, builder.getClass()); Assert.assertEquals("foobarErrorHandler", ((ErrorHandlerBuilderRef)builder).getRef()); }
@Bean public Tracer camelTracer() { Tracer tracer = new Tracer(); tracer.setEnabled(true); tracer.setTraceExceptions(true); tracer.setTraceInterceptors(true); tracer.setTraceOutExchanges(false); tracer.setLogLevel(LoggingLevel.WARN); tracer.setFormatter(formatter()); tracer.setTraceInterceptors(true); return tracer; }
public ManagedTracer(CamelContext camelContext, Tracer tracer) { this.camelContext = camelContext; this.tracer = tracer; jmxTraceHandler = new JMXNotificationTraceEventHandler(tracer); tracer.addTraceHandler(jmxTraceHandler); }
public Tracer getTracer() { return tracer; }
public JMXNotificationTraceEventHandler(Tracer tracer) { this.tracer = tracer; }
public void configure() { Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); getContext().addInterceptStrategy(tracer); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliveryDelay(0)); onException(Exception.class).maximumRedeliveries(0).handled(true); from(URI_DIRECT_START).unmarshal(orderBindyDataFormat).to(URI_MOCK_RESULT); }
public void configure() { // from("file://src/test/data?move=./target/done").unmarshal(camelDataFormat).to("mock:result"); Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); getContext().addInterceptStrategy(tracer); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliveryDelay(0)); onException(Exception.class).maximumRedeliveries(0).handled(true); from(URI_DIRECT_START).unmarshal(camelDataFormat).to(URI_MOCK_RESULT); }
public void configure() { Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); tracer.setLogStackTrace(true); tracer.setTraceExceptions(true); getContext().addInterceptStrategy(tracer); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR)); onException(Exception.class).maximumRedeliveries(0).handled(true); from(URI_DIRECT_START).unmarshal(orderBindyDataFormat).to(URI_MOCK_RESULT); }
public void configure() { Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); getContext().addInterceptStrategy(tracer); BindyCsvDataFormat csvBindyDataFormat = new BindyCsvDataFormat(org.apache.camel.dataformat.bindy.model.simple.oneclassdifferentposition.Order.class); csvBindyDataFormat.setLocale("en"); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliveryDelay(0)); onException(Exception.class).maximumRedeliveries(0).handled(true); from(URI_DIRECT_START).marshal(csvBindyDataFormat).to(URI_MOCK_RESULT); }
public void configure() { Tracer tracer = new Tracer(); tracer.setLogLevel(LoggingLevel.ERROR); tracer.setLogName("org.apache.camel.bindy"); getContext().addInterceptStrategy(tracer); BindyCsvDataFormat camelDataFormat = new BindyCsvDataFormat(org.apache.camel.dataformat.bindy.model.simple.oneclass.Order.class); camelDataFormat.setLocale("en"); // default should errors go to mock:error errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliveryDelay(0)); onException(Exception.class).maximumRedeliveries(0).handled(true); from(URI_DIRECT_START).marshal(camelDataFormat).to(URI_MOCK_RESULT); }
protected List<StringBuilder> getTracedMessages() { Tracer tracer = this.applicationContext.getBean("tracer", Tracer.class); TraceHandlerTestHandler handler = (TraceHandlerTestHandler) tracer.getTraceHandlers().get(0); return handler.getEventMessages(); }
public void enableTracing() { try { final InputStream in = getClass().getResourceAsStream("/tracing.log.properties"); if (in != null) { LogManager.getLogManager().readConfiguration(in); } } catch (final Exception e) { throw new RuntimeCamelException(e); } context.setTracing(true); // context.setDelayer(Long.valueOf(1000*1)); final Tracer tracer = new Tracer(); final DefaultTraceFormatter formatter = new DefaultTraceFormatter(); formatter.setShowOutBody(true); formatter.setShowOutBodyType(true); formatter.setShowException(true); // formatter.setShowBreadCrumb(false); // formatter.setShowNode(false); tracer.setFormatter(formatter); tracer.setLogLevel(LoggingLevel.DEBUG); context.addInterceptStrategy(tracer); Logger.getLogger("org.apache.commons.httpclient.HttpClient") .setLevel(Level.WARNING); // logging is not needed Logger.getLogger("org.apache.commons.httpclient.Wire") .setLevel(Level.WARNING); // logging is not needed Logger.getLogger("org.apache.commons.httpclient.HttpConnection") .setLevel(Level.WARNING); // logging is not needed Logger.getLogger("org.apache.commons.httpclient.HttpMethodBase") .setLevel(Level.WARNING); // logging is not needed Logger.getLogger("org.apache.camel.impl.converter.BaseTypeConverterRegistry") .setLevel(Level.WARNING); // logging is not needed }