Java 类org.apache.camel.processor.interceptor.Tracer 实例源码

项目:Camel    文件:DefaultDebugger.java   
@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);
    }
}
项目:Camel    文件:TraceInterceptorWithOutBodyTraceTest.java   
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");
        }
    };
}
项目:Camel    文件:OnCompletionGlobalTraceTest.java   
@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
        }
    };
}
项目:Camel    文件:InterceptSimpleRouteTraceTest.java   
@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");
        }
    };
}
项目:Camel    文件:TracePerRouteTest.java   
@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");
        }
    };
}
项目:Camel    文件:ManagedRouteContextTracerTest.java   
@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");
        }
    };
}
项目:Camel    文件:FileSplitInSplitTest.java   
@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");

        }
    };
}
项目:Camel    文件:PaddyRouteTest.java   
@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");
        }
    };
}
项目:Camel    文件:BindySimpleFixedLengthMarshallTest.java   
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);
        }
项目:Camel    文件:BindySimpleFixedLengthObjectMarshallTest.java   
@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);
        }
    };
}
项目:Camel    文件:BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java   
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);
        }
项目:Camel    文件:BindyPojoSimpleCsvMarshallTest.java   
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);
}
项目:Camel    文件:TracingTestBase.java   
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();
}
项目:cxf_over_jms_kata    文件:CommonCreateCamelContext.java   
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();
}
项目:camel-cookbook-examples    文件:TraceRouteBuilder.java   
@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");
}
项目:Camel    文件:DefaultCamelContext.java   
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());
    }
}
项目:Camel    文件:RecipientListReturnValueTest.java   
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");
        }
    };
}
项目:Camel    文件:DefaultErrorHandlerOnExceptionTraceTest.java   
@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");
        }
    };
}
项目:Camel    文件:TracerConfigurationTest.java   
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");
        }
    };
}
项目:Camel    文件:AsyncTraceHandlerTest.java   
@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;
}
项目:Camel    文件:ManagedCamelContextTracerTest.java   
@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");
        }
    };
}
项目:switchyard    文件:DomainCamelContextConfigurationTest.java   
@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());
}
项目:spring-camel    文件:TracerFactory.java   
@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;
}
项目:Camel    文件:ManagedTracer.java   
public ManagedTracer(CamelContext camelContext, Tracer tracer) {
    this.camelContext = camelContext;
    this.tracer = tracer;
    jmxTraceHandler = new JMXNotificationTraceEventHandler(tracer);
    tracer.addTraceHandler(jmxTraceHandler);
}
项目:Camel    文件:ManagedTracer.java   
public Tracer getTracer() {
    return tracer;
}
项目:Camel    文件:JMXNotificationTraceEventHandler.java   
public JMXNotificationTraceEventHandler(Tracer tracer) {
    this.tracer = tracer;
}
项目:Camel    文件:BindySimpleCsvUnmarshallPositionModifiedTest.java   
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);

        }
项目:Camel    文件:BindySimpleCsvUnmarshallTest.java   
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);
}
项目:Camel    文件:BindySimpleCsvUnmarshallBadIntegerTest.java   
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);

        }
项目:Camel    文件:BindySimpleCsvMarshallPositionModifiedTest.java   
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);
        }
项目:Camel    文件:BindySimpleCsvBooleanUnmarshallTest.java   
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);
}
项目:Camel    文件:BindySimpleCsvMarshallTest.java   
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);
        }
项目:Camel    文件:TracingTestBase.java   
protected List<StringBuilder> getTracedMessages() {
    Tracer tracer = this.applicationContext.getBean("tracer", Tracer.class);
    TraceHandlerTestHandler handler = (TraceHandlerTestHandler) tracer.getTraceHandlers().get(0);
    return handler.getEventMessages();
}
项目:metasfresh    文件:AbstractEDITest.java   
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
}