[ 
https://issues.apache.org/activemq/browse/CAMEL-2549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59036#action_59036
 ] 

Thomas Demande commented on CAMEL-2549:
---------------------------------------

I'm trying to use this component, and I'm currently seeing 2 problems:
- When invoking a program that fills {{stdErr}}, the content of that cannot be 
easily accessed without a deep inspection of the ExecResult.
I would have expected that the Converter would send the ExecResult {{stdErr()}} 
if it is not null.
- When *not* using the {{outFile}} parameter, the ExecResult {{stdOut}} (but 
also the {{stdErr}}) have to be reset, otherwise the Converter will return 
nothing as Body.

I'm using the latest revision of the component, and currently having such a 
route (in a Windows environment):
{code:xml}
(...)
    <to uri="exec:dir"/>
    <to uri="log:myLogger />
(...)
{code}
results in: {code}INFO: 
Exchange[BodyType:org.apache.camel.component.exec.ExecResult, Body:]{code} 
without the reset().

And, (worse), using the example
{code:xml}
(...)
    <to uri="exec:java?args=-version"/>
    <to uri="log:myLogger />
(...)
{code}
results in{code} INFO: 
Exchange[BodyType:org.apache.camel.component.exec.ExecResult, 
Body:org.apache.camel.component.exec.execres...@14382c6]{code}
as in this case it is in fact the {{stdErr}} that is filled.

Here's a diff excerpt (thrown exceptions should be also changed) that 
summarizes the solutions I quickly made to get it working like I thought it 
would be:
{code:java}
Index: 
components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java
===================================================================
@@ -105,10 +103,16 @@
         if (execResult.getCommand().getOutFile() != null) {
             return new FileInputStream(execResult.getCommand().getOutFile());
         } else {
-            if (execResult.getStdout() == null) {
-                LOG.warn("Received null stdout of the ExecResult for 
conversion!");
-            }
-            return execResult.getStdout();
+               if(execResult.getStderr() != null){
+                   execResult.getStderr().reset();
+                   return execResult.getStderr();
+               } else {
+                   if (execResult.getStdout() == null) {
+                       LOG.warn("Received null stdout of the ExecResult for 
conversion!");
+                   }
+                   execResult.getStdout().reset();
+                   return execResult.getStdout();
+               }
         }
     }
 }

{code}

I may be wrong, but I think that such a behavior would be more usable.

Regards,
Thomas

> Camel Exec component
> --------------------
>
>                 Key: CAMEL-2549
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2549
>             Project: Apache Camel
>          Issue Type: New Feature
>    Affects Versions: 2.3.0
>         Environment: Tested on Windows XP and Linux
>            Reporter: Mitko Kolev
>            Assignee: Martin Krasser
>             Fix For: 2.3.0
>
>         Attachments: camel-exec-3.diff, camel-exec-component-feedback.zip, 
> camel-exec-patch.diff, camel-exec-patch2.diff, exec-wiki.txt
>
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to