You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Philippe de Rochambeau <ph...@free.fr> on 2013/11/24 22:28:20 UTC
Problem with exec
Hello,
I have adapted the « exec » example shown on the http://camel.apache.org/exec.html page, as follows.
Unfortunately, nothing appears on the console.
Why is that?
Many thanks.
Philippe
from("direct:exec")
.to("exec:/usr/bin/java?args=-server -version")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
// By default, the body is ExecResult instance
// assertIsInstanceOf(ExecResult.class, exchange.getIn().getBody());
// Use the Camel Exec String type converter to convert the ExecResult to String
// In this case, the stdout is considered as output
Object obj = exchange.getIn().getBody();
Object obj1 = exchange.getIn().getHeader(ExecBinding.EXEC_EXIT_VALUE);
System.out.println("obj = " + obj);
System.out.println("obj1 = " + obj1);
}
})
.to("stream:out");
Re: Problem with exec
Posted by Charles Moulliard <ch...@gmail.com>.
As the output has not been converted, you get a NPE.
I suggest that you have a look to this example as they show you how to do
the conversion
https://github.com/apache/camel/blob/master/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
On Sun, Nov 24, 2013 at 10:28 PM, Philippe de Rochambeau <ph...@free.fr>wrote:
>
> Hello,
>
> I have adapted the « exec » example shown on the
> http://camel.apache.org/exec.html page, as follows.
>
> Unfortunately, nothing appears on the console.
>
> Why is that?
>
> Many thanks.
>
> Philippe
>
>
> from("direct:exec")
> .to("exec:/usr/bin/java?args=-server -version")
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> // By default, the body is ExecResult instance
> // assertIsInstanceOf(ExecResult.class, exchange.getIn().getBody());
> // Use the Camel Exec String type converter to convert the ExecResult to
> String
> // In this case, the stdout is considered as output
>
> Object obj = exchange.getIn().getBody();
> Object obj1 = exchange.getIn().getHeader(ExecBinding.EXEC_EXIT_VALUE);
> System.out.println("obj = " + obj);
> System.out.println("obj1 = " + obj1);
> }
> })
> .to("stream:out");
--
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog : http://cmoulliard.github.io
AW: Problem with exec
Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
I tried that and got a nested NPE.
Jan
2013-11-25 08:05:29,427 [main ] ERROR DefaultErrorHandler
- Failed delivery for (MessageId: ID-Jan-mySN-54051-1385363128177-0-1 on
ExchangeId: ID-Jan-mySN-54051-1385363128177-0-2). Exhausted after delivery
attempt: 1 caught: org.apache.camel.TypeConversionException: Error during
type conversion from type: org.apache.camel.component.exec.ExecResult to the
required type: byte[] with value
org.apache.camel.component.exec.ExecResult@71e2cfdc due
java.lang.NullPointerException
Message History
----------------------------------------------------------------------------
-----------------------------------------------------------
RouteId ProcessorId Processor
Elapsed (ms)
[route2 ] [route2 ] [direct://exec
] [ 255]
[route2 ] [to2 ] [exec:java?args=-version
] [ 240]
[route2 ] [to3 ] [stream:out
] [ 5]
Exchange
----------------------------------------------------------------------------
-----------------------------------------------------------
Exchange[
Id ID-Jan-mySN-54051-1385363128177-0-2
ExchangePattern InOnly
Headers
{breadcrumbId=ID-Jan-mySN-54051-1385363128177-0-1, CamelExecExitValue=0,
CamelExecStderr=java.io.ByteArrayInputStream@53d5f8be,
CamelRedelivered=false, CamelRedeliveryCounter=0}
BodyType org.apache.camel.component.exec.ExecResult
Body
]
Stacktrace
----------------------------------------------------------------------------
-----------------------------------------------------------
org.apache.camel.TypeConversionException: Error during type conversion from
type: org.apache.camel.component.exec.ExecResult to the required type:
byte[] with value org.apache.camel.component.exec.ExecResult@71e2cfdc due
java.lang.NullPointerException
at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseType
ConverterRegistry.java:130)[camel-core-2.12.0.jar:2.12.0]
at
org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:72)[camel-c
ore-2.12.0.jar:2.12.0]
at
org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:47)[camel-c
ore-2.12.0.jar:2.12.0]
at
org.apache.camel.component.stream.StreamProducer.writeToStream(StreamProduce
r.java:128)[camel-stream-2.12.0.jar:2.12.0]
at
org.apache.camel.component.stream.StreamProducer.process(StreamProducer.java
:79)[camel-stream-2.12.0.jar:2.12.0]
[...]
Output of Eclipse JUnitRunner
----------------------------------------------------------------------------
-----------------------------------------------------------
org.apache.camel.CamelExecutionException: Exception occurred during
execution on the exchange: Exchange[Message: ]
at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.
java:1360)
at
org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:6
19)
[...]
Caused by: org.apache.camel.TypeConversionException: Error during type
conversion from type: org.apache.camel.component.exec.ExecResult to the
required type: byte[] with value
org.apache.camel.component.exec.ExecResult@71e2cfdc due
java.lang.NullPointerException
at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseType
ConverterRegistry.java:130)
at
org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:72)
at
org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:47)
at
org.apache.camel.component.stream.StreamProducer.writeToStream(StreamProduce
r.java:128)
[...]
Caused by: org.apache.camel.RuntimeCamelException:
java.lang.NullPointerException
at
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.ja
va:1344)
at
org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:986)
at
org.apache.camel.impl.converter.StaticMethodTypeConverter.convertTo(StaticMe
thodTypeConverter.java:59)
at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.doConvertTo(BaseTy
peConverterRegistry.java:275)
at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseType
ConverterRegistry.java:113)
... 51 more
Caused by: java.lang.NullPointerException
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:999)
at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:218)
at
org.apache.camel.component.exec.ExecResultConverter.convertToByteArray(ExecR
esultConverter.java:56)
[...]
> -----Ursprüngliche Nachricht-----
> Von: Philippe de Rochambeau [mailto:phiroc@free.fr]
> Gesendet: Sonntag, 24. November 2013 22:28
> An: users@camel.apache.org
> Betreff: Problem with exec
>
>
> Hello,
>
> I have adapted the « exec » example shown on the
> http://camel.apache.org/exec.html page, as follows.
>
> Unfortunately, nothing appears on the console.
>
> Why is that?
>
> Many thanks.
>
> Philippe
>
>
> from("direct:exec")
> .to("exec:/usr/bin/java?args=-server -version") .process(new
> Processor() { public void process(Exchange exchange) throws Exception {
> // By default, the body is ExecResult instance //
> assertIsInstanceOf(ExecResult.class, exchange.getIn().getBody()); //
> Use the Camel Exec String type converter to convert the ExecResult to
> String // In this case, the stdout is considered as output
>
> Object obj = exchange.getIn().getBody(); Object obj1 =
> exchange.getIn().getHeader(ExecBinding.EXEC_EXIT_VALUE);
> System.out.println("obj = " + obj);
> System.out.println("obj1 = " + obj1);
> }
> })
> .to("stream:out");