You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hilde <hi...@yahoo.de> on 2012/06/27 11:16:59 UTC

camel-exec: System Path is empty

Hello everybody!

In a highly integration based project we would like to use the camel exec://
component. My first tests however let me ask why some executables that must
be in the system path by default are not found with exec://. Please see the
following example:

public class TestCamelExecSpike extends CamelTestSupport {

	private static final Logger logger =
LoggerFactory.getLogger(TestCamelExecSpike.class);
	private static final String echoExecutable = "echo";
	private static final String echoParam = "Hello world";

	@Override
	protected RouteBuilder createRouteBuilder() throws Exception {
		return new RouteBuilder() {
			@Override
			public void configure() throws Exception {
				from("direct:startExec").to("exec:" + echoExecutable + "?args=" +
echoParam).to(
						"mock:result");
			}
		};
	}

	@Test
	public void testCamelExec() throws Exception {

		MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
		mockEndpoint.expectedMessageCount(1);

		template.sendBody("direct:startExec", null);

		mockEndpoint.assertIsSatisfied();
		List<Exchange> exchanges = mockEndpoint.getExchanges();
		String stdout = exchanges.get(0).getIn().getBody(String.class);
		logger.info(stdout);
		assertEquals("Hello world", stdout);
	}
}

When I execute the test I encounter the following error:

org.apache.camel.CamelExecutionException: Exception occurred during
execution on the exchange: Exchange[Message: [Body is null]]
	at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1296)
	at
org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:618)
	at
org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:442)

Caused by: org.apache.camel.component.exec.ExecException: *Unable to execute
command ExecCommand [args=[Hello, world], executable=echo,
timeout=9223372036854775807, outFile=null, workingDir=null,
useStderrOnEmptyStdout=false]*
	at
org.apache.camel.component.exec.impl.DefaultExecCommandExecutor.execute(DefaultExecCommandExecutor.java:81)
	at
org.apache.camel.component.exec.ExecProducer.process(ExecProducer.java:46)
	at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)

Actually the command /echo/ should be found but it wasn't. Can someone
please explain me how the system path can be set properly to avoid setting
the whole path for the executables?

Thanks
Hilde

--
View this message in context: http://camel.465427.n5.nabble.com/camel-exec-System-Path-is-empty-tp5715145.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-exec: System Path is empty

Posted by mi...@icw.de.
Hi 

I just put this case in the documentation to avoid confusion in the 
future. 

Regards, 
Mitko



From:
Hilde <hi...@yahoo.de>
To:
users@camel.apache.org
Date:
27.06.2012 13:47
Subject:
Re: camel-exec: System Path is empty



Hi Magnus!

Thanks for this information, though it is not satisfying me. I supposed a
command via exec: that would be executed both on windows and linux. 
However
I got it that echo, perl, dir, etc. need an environment again to be 
executed
and that is e.g. cmd.exe on windows or /bin/bash on linux. My first
assumption was that exec: would do it for you. Oh god I was so naive.

Thanks!
Hilde



--
View this message in context: 
http://camel.465427.n5.nabble.com/camel-exec-System-Path-is-empty-tp5715145p5715159.html

Sent from the Camel - Users mailing list archive at Nabble.com.


�� 
InterComponentWare AG:  
Vorstand: Peter Kirschbauer (Vors.), J�rg Stadler  
Aufsichtsratsvors.: Prof. Dr. Christof Hettich  
Firmensitz: 69190 Walldorf, Altrottstra�e 31  
AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516  

Re: camel-exec: System Path is empty

Posted by Hilde <hi...@yahoo.de>.
Hi Magnus!

Thanks for this information, though it is not satisfying me. I supposed a
command via exec: that would be executed both on windows and linux. However
I got it that echo, perl, dir, etc. need an environment again to be executed
and that is e.g. cmd.exe on windows or /bin/bash on linux. My first
assumption was that exec: would do it for you. Oh god I was so naive.

Thanks!
Hilde



--
View this message in context: http://camel.465427.n5.nabble.com/camel-exec-System-Path-is-empty-tp5715145p5715159.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-exec: System Path is empty

Posted by Magnus Palmér <ma...@gmail.com>.
Hello,

On Windows I do this (simplified but works):
from("direct:exec").to("exec:cmd?args=/C echo echoString" ).to("mock:exec");

That is the exec is my command interpreter, and echo is an argument to the
interpreter.
(On Windows I need the /C otherwise I just get the data from starting the
cmd.exe)


/Magnus

2012/6/27 Hilde <hi...@yahoo.de>

> Hello everybody!
>
> In a highly integration based project we would like to use the camel
> exec://
> component. My first tests however let me ask why some executables that must
> be in the system path by default are not found with exec://. Please see the
> following example:
>
> public class TestCamelExecSpike extends CamelTestSupport {
>
>        private static final Logger logger =
> LoggerFactory.getLogger(TestCamelExecSpike.class);
>        private static final String echoExecutable = "echo";
>        private static final String echoParam = "Hello world";
>
>        @Override
>        protected RouteBuilder createRouteBuilder() throws Exception {
>                return new RouteBuilder() {
>                        @Override
>                        public void configure() throws Exception {
>                                from("direct:startExec").to("exec:" +
> echoExecutable + "?args=" +
> echoParam).to(
>                                                "mock:result");
>                        }
>                };
>        }
>
>        @Test
>        public void testCamelExec() throws Exception {
>
>                MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
>                mockEndpoint.expectedMessageCount(1);
>
>                template.sendBody("direct:startExec", null);
>
>                mockEndpoint.assertIsSatisfied();
>                List<Exchange> exchanges = mockEndpoint.getExchanges();
>                String stdout =
> exchanges.get(0).getIn().getBody(String.class);
>                logger.info(stdout);
>                assertEquals("Hello world", stdout);
>        }
> }
>
> When I execute the test I encounter the following error:
>
> org.apache.camel.CamelExecutionException: Exception occurred during
> execution on the exchange: Exchange[Message: [Body is null]]
>        at
>
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1296)
>        at
>
> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:618)
>        at
>
> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:442)
>
> Caused by: org.apache.camel.component.exec.ExecException: *Unable to
> execute
> command ExecCommand [args=[Hello, world], executable=echo,
> timeout=9223372036854775807, outFile=null, workingDir=null,
> useStderrOnEmptyStdout=false]*
>        at
>
> org.apache.camel.component.exec.impl.DefaultExecCommandExecutor.execute(DefaultExecCommandExecutor.java:81)
>        at
> org.apache.camel.component.exec.ExecProducer.process(ExecProducer.java:46)
>        at
>
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
>
> Actually the command /echo/ should be found but it wasn't. Can someone
> please explain me how the system path can be set properly to avoid setting
> the whole path for the executables?
>
> Thanks
> Hilde
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/camel-exec-System-Path-is-empty-tp5715145.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>