You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by wagner <wa...@gmail.com> on 2012/11/01 00:40:43 UTC
How to set camel-exec command dinamically
Hi,
I would like to pass the exec:*command* from a "command" get parameter.
So by issue http://localhost:8891/jetty_batch?command=mvn request,
I was expecting that my route runs the "mvn" command.
So, I would like to ask: Setting "ExecBinding.EXEC_COMMAND_EXECUTABLE" as
below, camel should not overrides the uri exec command?
To provide more informations I am exposing below the route, the log and the
inspected message that are camming from the request with the the
ExecBinding.EXEC_COMMAND_EXECUTABLE configured.
thanks in advance and Best Regards!!!
*[THE ROUTE]*
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="jetty_to_exec_camel_route">
<from uri="jetty:http://localhost:8891/jetty_batch" />
<setHeader headerName="ExecBinding.EXEC_COMMAND_EXECUTABLE">
<simple>${in.header.command}</simple>
</setHeader>
<process ref="messageInspectProcessor"/>
<to
uri="exec:<b>shoud_be_overrided_by_ExecBinding.EXEC_COMMAND_EXECUTABLE_header"*
/>
</route>
</camelContext>
*[THE LOG]*
by issue the request I am receiving the following output:
org.apache.camel.component.exec.ExecException: Unable to execute command
ExecCommand [args=[],
executable=*shoud_be_overrided_by_ExecBinding.EXEC_COMMAND_EXECUTABLE_header*,
*[THE MESSAGE JUST BEFORE BE PASSED TO EXEC ENDPOINT]*
Beside this I am assured that ${in.header.command} is camming to route as
expected because my "messageInspectProcessor puts the folowing at standard
output:
karaf@root> public class MessageInspectProcessor implements Processor{...
exchange.getIn().getBody(String.class) = null
exchange.getIn().getHeaders()...
.
.
.
.
headerKey = CamelHttpPath
headerValue = /jetty_batch
.
headerKey = CamelHttpUrl
headerValue = http://localhost:8891/jetty_batch
.
headerKey = User-Agent
headerValue = Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20100101
Firefox/16.0
.
headerKey = CamelHttpQuery
headerValue = command=mvn_create_archetype
.
headerKey = Accept-Encoding
headerValue = gzip, deflate
.
*headerKey = ExecBinding.EXEC_COMMAND_EXECUTABLE
headerValue = mvn*
.
headerKey = CamelHttpUri
headerValue = /jetty_batch
.
headerKey = Host
headerValue = localhost:8891
.
headerKey = CamelHttpServletRequest
headerValue = [GET /jetty_batch?command=mvn_create_archetype]@28826024
org.eclipse.jetty.server.Request@1b7d9a8
.
headerKey = Cookie
headerValue =
__utma=111872281.740881599.1344432450.1351684903.1351724854.46;
__utmz=111872281.1344432450.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
__utmv=111872281.|1=Treatment=A=1;
ys-healthcheck-summary-size-delta=o%3Awidth%3Dn%253A0%5Eheight%3Dn%253A0;
__utmb=111872281.4.10.1351724854; __utmc=111872281
.
headerKey = Accept-Language
headerValue = pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
.
headerKey = command
headerValue = mvn_create_archetype
.
headerKey = DNT
headerValue = 1
.
headerKey = Content-Type
headerValue = null
.
headerKey = breadcrumbId
headerValue = ID-localhost-46893-1351725750963-2-2
.
headerKey = Connection
headerValue = keep-alive
.
headerKey = CamelHttpServletResponse
headerValue = HTTP/1.1 200
.
headerKey = Accept
headerValue =
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
.
headerKey = CamelHttpMethod
headerValue = GET
header.toString()...
header is not null ...
mvn_create_archetype
--
View this message in context: http://servicemix.396122.n5.nabble.com/How-to-set-camel-exec-command-dinamically-tp5714807.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to set camel-exec command dinamically
Posted by wagner <wa...@gmail.com>.
Willem, I am really gratefull for you help.
But to achieve my goal I believe that must be little camel trick to figure
out in the -Dversion=1.0-SNAPSHOT arg. I will explain:
my purpose is to create a maven project as described by my processor below
(I decided set the header in a processor rather in spring dsl)
This is my processor:
package br.edu.fzlbpms.template.camel.batch.impl;
import java.util.ArrayList;
import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class SetExecCommandAndArgsProcessor implements Processor{
public void process(Exchange exchange ) throws Exception {
String command = (String)exchange.getIn().getHeader("command");
System.out.println(command);
String bOfBatch = "-B";
System.out.println(bOfBatch);
String DinteractiveMode = "false";
System.out.println(DinteractiveMode);
String archetype_and_goal =
(String)exchange.getIn().getHeader("archetype_and_goal");
System.out.println(archetype_and_goal);
String DarchetypeGroupId =
(String)exchange.getIn().getHeader("DarchetypeGroupId");
System.out.println(DarchetypeGroupId);
String DarchetypeArtifactId =
(String)exchange.getIn().getHeader("DarchetypeArtifactId");
System.out.println(DarchetypeArtifactId);
String Dversion = (String)exchange.getIn().getHeader("Dversion");
System.out.println(Dversion);
String DgroupId = (String)exchange.getIn().getHeader("DgroupId");
System.out.println(DgroupId);
String DartifactId = (String)exchange.getIn().getHeader("DartifactId");
System.out.println(DartifactId);
List<String> listArgs = new ArrayList<String>();
listArgs.add(bOfBatch);
listArgs.add(archetype_and_goal);
listArgs.add("-DarchetypeGroupId="+DarchetypeGroupId);
listArgs.add("-DarchetypeArtifactId="+DarchetypeArtifactId);
listArgs.add("-Dversion="+Dversion);
listArgs.add("-DgroupId="+DgroupId);
listArgs.add("-DartifactId="+DartifactId);
listArgs.add("-DinteractiveMode="+DinteractiveMode);
exchange.getOut().setHeader("CamelExecCommandWorkingDir","/run/media/wagner/fzlbpms_env/PROGSATIVOS/fzlbpms/workdirs");
exchange.getOut().setHeader("CamelExecCommandExecutable", command);
exchange.getOut().setHeader("CamelExecCommandArgs", listArgs);
}
}
In fact the headers are working very well. I think that the problem is about
the -Dversion=1.0-SNAPSHOT because issuing the folowing url in the browser
http://localhost:8891/jetty_batch?*command=mvn*&*b=b*&*archetype_and_goal=archetype:generate*&*DarchetypeGroupId=br.edu.fzlbmps.template*&*DarchetypeArtifactId=fzlbpms_process_parent_template-archetype*&*Dversion=1.0-SNAPSHOT*&*DgroupId=com.br.nome_empresa.processos*&*DartifactId=nome_empresa_processo_helloworld*
I am receiving (in the browser) the folowing output that show problems with
version parameter:
[INFO] Scanning for projects...
[INFO]
[INFO]
------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO]
------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @
standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @
standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @
standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] Specified archetype not found.
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 4.053s
[INFO] Finished at: Thu Nov 01 22:23:22 BRST 2012
[INFO] Final Memory: 8M/80M
[INFO]
------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli)
on project standalone-pom: *The desired archetype does not exist
(br.edu.fzlbmps.template:fzlbpms_process_parent_template-archetype:1.0) *->
[Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please
read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
In fact, the archetype
(br.edu.fzlbmps.template:fzlbpms_process_parent_template-archetype:*1.0*)
should be
(br.edu.fzlbmps.template:fzlbpms_process_parent_template-archetype:*1.0-SNAPSHOT*)
to be find properly by command.
The camel are receiving the version parameter correctly because my message
inspector print the CamelExecCommandArgs header as below:
headerKey = CamelExecCommandArgs
headerValue = [-B, archetype:generate,
-DarchetypeGroupId=br.edu.fzlbmps.template,
-DarchetypeArtifactId=fzlbpms_process_parent_template-archetype,
*-Dversion=1.0-SNAPSHOT*, -DgroupId=com.br.nome_empresa.processos,
-DartifactId=nome_empresa_processo_helloworld, -DinteractiveMode=false]
So my guess is that, when came issue the composed command maybe there are a
problem to deal with the dash caracter of version parameter, but its just a
guess.
Could you help me a little more? My thanks to this forum will be present in
my undergraduate term paper thanks session :)
best regards
--
View this message in context: http://servicemix.396122.n5.nabble.com/How-to-set-camel-exec-command-dinamically-tp5714807p5714819.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to set camel-exec command dinamically
Posted by "Willem.Jiang" <wi...@gmail.com>.
You should use header value "CamelExecCommandExecutable" instead of
ExecBinding.EXEC_COMMAND_EXECUTABLE.
Willem
--
View this message in context: http://servicemix.396122.n5.nabble.com/How-to-set-camel-exec-command-dinamically-tp5714807p5714812.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.