You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jonathan Jenkins <jj...@java2go.com> on 2014/10/25 23:43:39 UTC

ReportIncident tutorial - Logging Issue..

Using version 2.14.0 - First time i've used Camel, so excuse if this is obvious - but I'm having some difficulties getting the first step of the ReportIncident tutorial working. Seems there have been some recent changes to the LogEndpoint (see CAMEL-7599) - might have affected this example :-

http://camel.apache.org/tutorial-example-reportincident-part2.html

I had to modify sendToCamelLog as per below to get it working - call endpoint.setProvidedLogger(..) as well as endpoint.start() ..  

Does this point to a bug or does the example require updating ?

Thx Jon
================
   private void sendToCamelLog(String name) {
        try {
            // get the log component
            Component component = camel.getComponent("log");

            // create an endpoint and configure it.
            // Notice the URI parameters this is a common pratice in Camel to configure
            // endpoints based on URI.
            // com.mycompany.part2 = the log category used. Will log at INFO level as default
            LogEndpoint endpoint = (LogEndpoint) component.createEndpoint("log:org.apache.camel.example?level=DEBUG");
//            endpoint.setCamelContext(camel);
            endpoint.setProvidedLogger(LoggerFactory.getLogger(ReportIncidentEndpointImpl.class));
            endpoint.start();
            // create an Exchange that we want to send to the endpoint
            Exchange exchange = endpoint.createExchange();
            // set the in message payload (=body) with the name parameter
            exchange.getIn().setBody(name);

            // now we want to send the exchange to this endpoint and we then need a producer
            // for this, so we create and start the producer.
            Producer producer = endpoint.createProducer();
            producer.start();
            // process the exchange will send the exchange to the log component, that will process
            // the exchange and yes log the payload
            producer.process(exchange);

            // Exception was being generated during processing, but not thrown.
            Exception exc = exchange.getException();
            if (exc != null) throw exc;

            // stop the producer, we want to be nice and cleanup
            producer.stop();


        } catch (Exception e) {
            // we ignore any exceptions and just rethrow as runtime          
            throw new RuntimeException(e);

        }
    }




Jonathan Jenkins
+44 7789 847427
jj@java2go.com <ma...@tradingscreen.com>

Re: ReportIncident tutorial - Logging Issue..

Posted by javajenks <jj...@java2go.com>.
OK - i have found a few other issues with the tutorial due to API changes, so will log a ticket.

Thanks VM for the link.


> On 27 Oct 2014, at 06:56, Claus Ibsen-2 [via Camel] <ml...@n5.nabble.com> wrote:
> 
> Hi 
> 
> That tutorial is very old, though you have discovered a little bug. So 
> feel free to log a JIRA ticket 
> http://camel.apache.org/support <http://camel.apache.org/support>
> 
> If you want to get started with Camel then I recommend reading this 
> article also - it has a great little example to go along with the 
> article 
> http://java.dzone.com/articles/open-source-integration-apache <http://java.dzone.com/articles/open-source-integration-apache>
> 
> 
> 
> On Sun, Oct 26, 2014 at 12:03 AM, javajenks <[hidden email] <x-msg://47/user/SendEmail.jtp?type=node&node=5758056&i=0>> wrote:
> 
> > Sure - in fact, the message payload was not being logged at all. 
> > 
> > Added code to check the exception after producer.process(..)  - there was a 
> > NPE generated during processing, as the logger had not been initialised - 
> > see below for stacktrace. 
> > 
> > 
> > Caused by: java.lang.NullPointerException: null 
> >         at org.apache.camel.component.log.LogProducer.process(LogProducer.java:39) 
> > ~[camel-core-2.14.0.jar:2.14.0] 
> >         at 
> > org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105) 
> > ~[camel-core-2.14.0.jar:2.14.0] 
> >         at 
> > org.apache.camel.impl.DefaultAsyncProducer.process(DefaultAsyncProducer.java:37) 
> > ~[camel-core-2.14.0.jar:2.14.0] 
> >         at 
> > org.apache.camel.example.reportincident.ReportIncidentEndpointImpl.sendToCamelLog(ReportIncidentEndpointImpl.java:74) 
> > ~[classes/:na] 
> > 
> > 
> > 
> > 
> > -- 
> > View this message in context: http://camel.465427.n5.nabble.com/ReportIncident-tutorial-Logging-Issue-tp5758035p5758037.html <http://camel.465427.n5.nabble.com/ReportIncident-tutorial-Logging-Issue-tp5758035p5758037.html>
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen 
> ----------------- 
> Red Hat, Inc. 
> Email: [hidden email] <x-msg://47/user/SendEmail.jtp?type=node&node=5758056&i=1> 
> Twitter: davsclaus 
> Blog: http://davsclaus.com <http://davsclaus.com/>
> Author of Camel in Action: http://www.manning.com/ibsen <http://www.manning.com/ibsen>
> hawtio: http://hawt.io/ <http://hawt.io/>
> fabric8: http://fabric8.io/ <http://fabric8.io/>
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/ReportIncident-tutorial-Logging-Issue-tp5758035p5758056.html <http://camel.465427.n5.nabble.com/ReportIncident-tutorial-Logging-Issue-tp5758035p5758056.html>
> To unsubscribe from ReportIncident tutorial - Logging Issue.., click here <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5758035&code=ampAamF2YTJnby5jb218NTc1ODAzNXwyMDcwODg5MDQx>.
> NAML <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
Jonathan Jenkins
jj@java2go.com <ma...@java2go.com>
+44 7789 847427





--
View this message in context: http://camel.465427.n5.nabble.com/ReportIncident-tutorial-Logging-Issue-tp5758035p5758065.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ReportIncident tutorial - Logging Issue..

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

That tutorial is very old, though you have discovered a little bug. So
feel free to log a JIRA ticket
http://camel.apache.org/support

If you want to get started with Camel then I recommend reading this
article also - it has a great little example to go along with the
article
http://java.dzone.com/articles/open-source-integration-apache



On Sun, Oct 26, 2014 at 12:03 AM, javajenks <jj...@java2go.com> wrote:
> Sure - in fact, the message payload was not being logged at all.
>
> Added code to check the exception after producer.process(..)  - there was a
> NPE generated during processing, as the logger had not been initialised -
> see below for stacktrace.
>
>
> Caused by: java.lang.NullPointerException: null
>         at org.apache.camel.component.log.LogProducer.process(LogProducer.java:39)
> ~[camel-core-2.14.0.jar:2.14.0]
>         at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
> ~[camel-core-2.14.0.jar:2.14.0]
>         at
> org.apache.camel.impl.DefaultAsyncProducer.process(DefaultAsyncProducer.java:37)
> ~[camel-core-2.14.0.jar:2.14.0]
>         at
> org.apache.camel.example.reportincident.ReportIncidentEndpointImpl.sendToCamelLog(ReportIncidentEndpointImpl.java:74)
> ~[classes/:na]
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ReportIncident-tutorial-Logging-Issue-tp5758035p5758037.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: ReportIncident tutorial - Logging Issue..

Posted by javajenks <jj...@java2go.com>.
Sure - in fact, the message payload was not being logged at all.

Added code to check the exception after producer.process(..)  - there was a
NPE generated during processing, as the logger had not been initialised -
see below for stacktrace.


Caused by: java.lang.NullPointerException: null
	at org.apache.camel.component.log.LogProducer.process(LogProducer.java:39)
~[camel-core-2.14.0.jar:2.14.0]
	at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
~[camel-core-2.14.0.jar:2.14.0]
	at
org.apache.camel.impl.DefaultAsyncProducer.process(DefaultAsyncProducer.java:37)
~[camel-core-2.14.0.jar:2.14.0]
	at
org.apache.camel.example.reportincident.ReportIncidentEndpointImpl.sendToCamelLog(ReportIncidentEndpointImpl.java:74)
~[classes/:na]




--
View this message in context: http://camel.465427.n5.nabble.com/ReportIncident-tutorial-Logging-Issue-tp5758035p5758037.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ReportIncident tutorial - Logging Issue..

Posted by Henryk Konsek <he...@gmail.com>.
Hi Jon,

Could you describe what was your original issue? Stacktrace will be useful :) .

Cheers.

On Sat, Oct 25, 2014 at 11:43 PM, Jonathan Jenkins <jj...@java2go.com> wrote:
> Using version 2.14.0 - First time i've used Camel, so excuse if this is obvious - but I'm having some difficulties getting the first step of the ReportIncident tutorial working. Seems there have been some recent changes to the LogEndpoint (see CAMEL-7599) - might have affected this example :-
>
> http://camel.apache.org/tutorial-example-reportincident-part2.html
>
> I had to modify sendToCamelLog as per below to get it working - call endpoint.setProvidedLogger(..) as well as endpoint.start() ..
>
> Does this point to a bug or does the example require updating ?
>
> Thx Jon
> ================
>    private void sendToCamelLog(String name) {
>         try {
>             // get the log component
>             Component component = camel.getComponent("log");
>
>             // create an endpoint and configure it.
>             // Notice the URI parameters this is a common pratice in Camel to configure
>             // endpoints based on URI.
>             // com.mycompany.part2 = the log category used. Will log at INFO level as default
>             LogEndpoint endpoint = (LogEndpoint) component.createEndpoint("log:org.apache.camel.example?level=DEBUG");
> //            endpoint.setCamelContext(camel);
>             endpoint.setProvidedLogger(LoggerFactory.getLogger(ReportIncidentEndpointImpl.class));
>             endpoint.start();
>             // create an Exchange that we want to send to the endpoint
>             Exchange exchange = endpoint.createExchange();
>             // set the in message payload (=body) with the name parameter
>             exchange.getIn().setBody(name);
>
>             // now we want to send the exchange to this endpoint and we then need a producer
>             // for this, so we create and start the producer.
>             Producer producer = endpoint.createProducer();
>             producer.start();
>             // process the exchange will send the exchange to the log component, that will process
>             // the exchange and yes log the payload
>             producer.process(exchange);
>
>             // Exception was being generated during processing, but not thrown.
>             Exception exc = exchange.getException();
>             if (exc != null) throw exc;
>
>             // stop the producer, we want to be nice and cleanup
>             producer.stop();
>
>
>         } catch (Exception e) {
>             // we ignore any exceptions and just rethrow as runtime
>             throw new RuntimeException(e);
>
>         }
>     }
>
>
>
>
> Jonathan Jenkins
> +44 7789 847427
> jj@java2go.com <ma...@tradingscreen.com>



-- 
Henryk Konsek
http://henryk-konsek.blogspot.com