You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Gary Liu <Ga...@gmail.com> on 2013/05/15 04:40:19 UTC
Problem from Java DSL to Spring DSL
Hello,
I am trying to translate the following Java DSL (This is the example from
2.10.4). The Java DSL works fine. But I after I translate to Spring DSL,
several things are not working as expected. Would someone please help?
================================Java DSL=======================
from("cxf:bean:reportIncident")
.convertBodyTo(InputReportIncident.class)
.setHeader(Exchange.FILE_NAME,
constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
.wireTap("file://target/inbox/")
.choice().when(simple("${body.givenName} == 'Claus'"))
.transform(constant(ok))
.otherwise()
.bean(new ReportIncidentImpl(), "doReportIncident")
.transform(constant(accepted)
);
===========================SPRING DSL===================
<camel:camelContext id="camel">
<camel:route>
<camel:from uri="cxf:bean:reportIncident" />
<camel:convertBodyTo
type="org.apache.camel.example.reportincident.InputReportIncident" />
<camel:setHeader headerName="${Exchange.FILE_NAME}">
<camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}</camel:constant>
</camel:setHeader>
<camel:wireTap uri="file://target/inbox/"></camel:wireTap>
<camel:choice>
<camel:when>
<camel:simple>${body.givenName} == 'Claus'</camel:simple>
<camel:transform>
<camel:constant>"OK"</camel:constant>
</camel:transform>
</camel:when>
<camel:otherwise>
<camel:transform>
<camel:constant>"Accepted"</camel:constant>
</camel:transform>
</camel:otherwise>
</camel:choice>
</camel:route>
</camel:camelContext>
===========================================================
Here are the things I did not translate propertly:
.choice().when(simple("${body.givenName} == 'Claus'"))
.transform(constant(ok))
NOT THE SAME AS:
<camel:choice>
<camel:when>
<camel:simple>${body.givenName} == 'Claus'</camel:simple>
<camel:transform>
<camel:constant>"OK"</camel:constant>
</camel:transform>
</camel:when>
.setHeader(Exchange.FILE_NAME,
constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
NOT THE SAME AS:
<camel:setHeader headerName="${Exchange.FILE_NAME}">
<camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}
Thanks,
--Gary
--
View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Problem from Java DSL to Spring DSL
Posted by Gary Liu <Ga...@gmail.com>.
When I test using soupUI with the following input:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:rep="http://reportincident.example.camel.apache.org">
<soapenv:Header/>
<soapenv:Body>
<rep:inputReportIncident>
<incidentId>111</incidentId>
<incidentDate>2013-05-09</incidentDate>
<givenName>Claus</givenName>
<familyName>Muller</familyName>
<summary>bla</summary>
<details>bla</details>
gliu@vha.com
<phone>678-447-2399</phone>
</rep:inputReportIncident>
</soapenv:Body>
</soapenv:Envelope>
I got Response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Part
{http://reportincident.example.camel.apache.org}out should be of type
org.apache.camel.example.reportincident.OutputReportIncident, not
java.lang.String</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
--
View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5732559.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Problem from Java DSL to Spring DSL
Posted by Willem jiang <wi...@gmail.com>.
Hi,
Can you check if you put the camel-jaxb jar into your class path?
--
Willem Jiang
Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang
Weibo: 姜宁willem
On Wednesday, May 15, 2013 at 11:09 AM, Gary Liu wrote:
> Thanks William! That works.
>
> Now, my transform part is still not working. Any sugguestions?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5732563.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).
Re: Problem from Java DSL to Spring DSL
Posted by Gary Liu <Ga...@gmail.com>.
Thanks William! That works.
Now, my transform part is still not working. Any sugguestions?
--
View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5732563.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Problem from Java DSL to Spring DSL
Posted by Claus Ibsen <cl...@gmail.com>.
You need to create a OutputReportIncident as the response, you can do
this from xml with
<bean id="ok" class="... OutputReportIncident">
<constructor-arg ...>
</bean>
And then in the Camel xml route, then refer to this bean as the body
<transform>
<simple>ref:ok</simple>
</transform>
On Wed, May 15, 2013 at 3:28 PM, Gary Liu <Ga...@gmail.com> wrote:
> Thanks Claus! The following code works.
>
> <camel:setHeader headerName="Exchange.FILE_NAME">
>
> <camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}</camel:constant>
> </camel:setHeader>
>
>
> I still don't understand how the following Java DSL works, i mean
> "transform" part :
> from("cxf:bean:reportIncident")
> .convertBodyTo(InputReportIncident.class)
> .setHeader(Exchange.FILE_NAME,
> constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
> .wireTap("file://target/inbox/")
> .choice().when(simple("${body.givenName} == 'Claus'"))
> .transform(constant(ok))
> .otherwise()
> .bean(new ReportIncidentImpl(), "doReportIncident")
> .transform(constant(accepted)
>
> );
>
>
> To me transform(constant(ok)) will return a string "ok", but client is
> expect OutputReportIncident. Of course, the Java DSL works, and my
> translation of Spring DSL did not work. Why?
>
> I created a bean:
> @Override
> @WebResult(name = "outputReportIncident", targetNamespace =
> "http://reportincident.example.camel.apache.org", partName = "out")
> @WebMethod(action =
> "http://reportincident.example.camel.apache.org/ReportIncident")
> public OutputReportIncident doReportIncident(
> @WebParam(partName = "in", name = "inputReportIncident", targetNamespace
> = "http://reportincident.example.camel.apache.org") InputReportIncident in)
> {
> // TODO Auto-generated method stub
> System.out.println("===================================================");
> System.out.println(in.familyName);
> // in.setGivenName("IChangeIt");
> OutputReportIncident output = new OutputReportIncident();
> if(in.getGivenName().equalsIgnoreCase("Claus")){
> output.setCode("OK");
> } else {
> output.setCode("Accepted");
> }
> return output;
> }
>
> That works.
>
> What have I missed?
>
> Thanks,
> --Gary
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5732613.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Problem from Java DSL to Spring DSL
Posted by Gary Liu <Ga...@gmail.com>.
Thanks Claus! The following code works.
<camel:setHeader headerName="Exchange.FILE_NAME">
<camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}</camel:constant>
</camel:setHeader>
I still don't understand how the following Java DSL works, i mean
"transform" part :
from("cxf:bean:reportIncident")
.convertBodyTo(InputReportIncident.class)
.setHeader(Exchange.FILE_NAME,
constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
.wireTap("file://target/inbox/")
.choice().when(simple("${body.givenName} == 'Claus'"))
.transform(constant(ok))
.otherwise()
.bean(new ReportIncidentImpl(), "doReportIncident")
.transform(constant(accepted)
);
To me transform(constant(ok)) will return a string "ok", but client is
expect OutputReportIncident. Of course, the Java DSL works, and my
translation of Spring DSL did not work. Why?
I created a bean:
@Override
@WebResult(name = "outputReportIncident", targetNamespace =
"http://reportincident.example.camel.apache.org", partName = "out")
@WebMethod(action =
"http://reportincident.example.camel.apache.org/ReportIncident")
public OutputReportIncident doReportIncident(
@WebParam(partName = "in", name = "inputReportIncident", targetNamespace
= "http://reportincident.example.camel.apache.org") InputReportIncident in)
{
// TODO Auto-generated method stub
System.out.println("===================================================");
System.out.println(in.familyName);
// in.setGivenName("IChangeIt");
OutputReportIncident output = new OutputReportIncident();
if(in.getGivenName().equalsIgnoreCase("Claus")){
output.setCode("OK");
} else {
output.setCode("Accepted");
}
return output;
}
That works.
What have I missed?
Thanks,
--Gary
--
View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5732613.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Problem from Java DSL to Spring DSL
Posted by MC <23...@gmail.com>.
Thank you Claus.
--
View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5769102.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Problem from Java DSL to Spring DSL
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
No headerName is a string attribute and cannot be dynamic. You can use
a property placeholder though but its only resolved once during route
creation.
Currently its only the constants from Exchange that are supported such
as Exchange.FILE_NAME.
On Thu, Jul 9, 2015 at 8:02 PM, MC <23...@gmail.com> wrote:
> Hi Claus,
>
> I replied to this question a couple of days ago with a similar question, but
> I am not sure why it is not showing up. Thats why I posting it again. I
> apologize if it is duplicate.
>
> Is it possible to use a random Java Constant or enum in headerName of
> <setHeader> in spring dsl. I tied with simple and spel expressions with no
> success. Below are the things I tried with.
>
> <setHeader
> headerName="#{T(org.apache.camel.component.cxf.common.message.CxfConstants).OPERATION_NAME}">
>
> <simple>${enum:org.apache.camel.component.cxf.common.message.CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE}</simple>
> </setHeader>
> <setHeader
> headerName="$simple{type:org.apache.camel.component.cxf.common.message.CxfConstants.OPERATION_NAME}">
>
> <simple>${enum:org.apache.camel.component.cxf.common.message.CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE}</simple>
> </setHeader>
> <setHeader
> headerName="${type:org.apache.camel.component.cxf.common.message.CxfConstants.OPERATION_NAME}">
>
> <simple>${enum:org.apache.camel.component.cxf.common.message.CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE}</simple>
> </setHeader>
>
> Value is resolved, but expressions in headerName are not.
>
> Thanks in advance.
> MC
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5769067.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: Problem from Java DSL to Spring DSL
Posted by MC <23...@gmail.com>.
Hi Claus,
I replied to this question a couple of days ago with a similar question, but
I am not sure why it is not showing up. Thats why I posting it again. I
apologize if it is duplicate.
Is it possible to use a random Java Constant or enum in headerName of
<setHeader> in spring dsl. I tied with simple and spel expressions with no
success. Below are the things I tried with.
<setHeader
headerName="#{T(org.apache.camel.component.cxf.common.message.CxfConstants).OPERATION_NAME}">
<simple>${enum:org.apache.camel.component.cxf.common.message.CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE}</simple>
</setHeader>
<setHeader
headerName="$simple{type:org.apache.camel.component.cxf.common.message.CxfConstants.OPERATION_NAME}">
<simple>${enum:org.apache.camel.component.cxf.common.message.CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE}</simple>
</setHeader>
<setHeader
headerName="${type:org.apache.camel.component.cxf.common.message.CxfConstants.OPERATION_NAME}">
<simple>${enum:org.apache.camel.component.cxf.common.message.CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE}</simple>
</setHeader>
Value is resolved, but expressions in headerName are not.
Thanks in advance.
MC
--
View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5769067.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Problem from Java DSL to Spring DSL
Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, May 15, 2013 at 5:06 AM, Willem jiang <wi...@gmail.com> wrote:
> Hi,
>
> I think you cannot use the constant of Exchange.FILE_NAME directly in the Spring DSL.
> You should use the String directly like this
Yes you can. The DSL has special support for that so it makes
converting from java <-> xml easier.
But you should not have ${ } etc just do as you would do in Java DSL
<camel:setHeader headerName="Exchange.FILE_NAME">
When a key starts with Exchange. then Camel checks if its a field from
the Exchange interface and uses its value.
> <camel:setHeader headerName="CamelFileName"/>
> <camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}</camel:constant>
>
And btw use simple instead of constant. As constant is really just a
hardcoded fixed constant value. So if you want the current date, use
the simple language that has this function.
>
> --
> Willem Jiang
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Web: http://www.fusesource.com | http://www.redhat.com
> Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
> http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
> Twitter: willemjiang
> Weibo: 姜宁willem
>
>
>
>
>
> On Wednesday, May 15, 2013 at 10:40 AM, Gary Liu wrote:
>
>> Hello,
>>
>> I am trying to translate the following Java DSL (This is the example from
>> 2.10.4). The Java DSL works fine. But I after I translate to Spring DSL,
>> several things are not working as expected. Would someone please help?
>> ================================Java DSL=======================
>> from("cxf:bean:reportIncident")
>> .convertBodyTo(InputReportIncident.class)
>> .setHeader(Exchange.FILE_NAME,
>> constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
>> .wireTap("file://target/inbox/")
>> .choice().when(simple("${body.givenName} == 'Claus'"))
>> .transform(constant(ok))
>> .otherwise()
>> .bean(new ReportIncidentImpl(), "doReportIncident")
>> .transform(constant(accepted)
>>
>> );
>>
>> ===========================SPRING DSL===================
>> <camel:camelContext id="camel">
>>
>>
>> <camel:route>
>> <camel:from uri="cxf:bean:reportIncident" />
>> <camel:convertBodyTo
>> type="org.apache.camel.example.reportincident.InputReportIncident" />
>> <camel:setHeader headerName="${Exchange.FILE_NAME}">
>>
>> <camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}</camel:constant>
>> </camel:setHeader>
>> <camel:wireTap uri="file://target/inbox/"></camel:wireTap>
>> <camel:choice>
>> <camel:when>
>> <camel:simple>${body.givenName} == 'Claus'</camel:simple>
>> <camel:transform>
>> <camel:constant>"OK"</camel:constant>
>> </camel:transform>
>> </camel:when>
>> <camel:otherwise>
>> <camel:transform>
>> <camel:constant>"Accepted"</camel:constant>
>> </camel:transform>
>> </camel:otherwise>
>> </camel:choice>
>> </camel:route>
>> </camel:camelContext>
>> ===========================================================
>>
>> Here are the things I did not translate propertly:
>>
>> .choice().when(simple("${body.givenName} == 'Claus'"))
>> .transform(constant(ok))
>>
>> NOT THE SAME AS:
>> <camel:choice>
>> <camel:when>
>> <camel:simple>${body.givenName} == 'Claus'</camel:simple>
>> <camel:transform>
>> <camel:constant>"OK"</camel:constant>
>> </camel:transform>
>> </camel:when>
>>
>>
>> .setHeader(Exchange.FILE_NAME,
>> constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
>>
>> NOT THE SAME AS:
>>
>> <camel:setHeader headerName="${Exchange.FILE_NAME}">
>> <camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}
>>
>> Thanks,
>> --Gary
>>
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558.html
>> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).
>
>
>
--
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Problem from Java DSL to Spring DSL
Posted by Willem jiang <wi...@gmail.com>.
Hi,
I think you cannot use the constant of Exchange.FILE_NAME directly in the Spring DSL.
You should use the String directly like this
<camel:setHeader headerName="CamelFileName"/>
<camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}</camel:constant>
--
Willem Jiang
Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang
Weibo: 姜宁willem
On Wednesday, May 15, 2013 at 10:40 AM, Gary Liu wrote:
> Hello,
>
> I am trying to translate the following Java DSL (This is the example from
> 2.10.4). The Java DSL works fine. But I after I translate to Spring DSL,
> several things are not working as expected. Would someone please help?
> ================================Java DSL=======================
> from("cxf:bean:reportIncident")
> .convertBodyTo(InputReportIncident.class)
> .setHeader(Exchange.FILE_NAME,
> constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
> .wireTap("file://target/inbox/")
> .choice().when(simple("${body.givenName} == 'Claus'"))
> .transform(constant(ok))
> .otherwise()
> .bean(new ReportIncidentImpl(), "doReportIncident")
> .transform(constant(accepted)
>
> );
>
> ===========================SPRING DSL===================
> <camel:camelContext id="camel">
>
>
> <camel:route>
> <camel:from uri="cxf:bean:reportIncident" />
> <camel:convertBodyTo
> type="org.apache.camel.example.reportincident.InputReportIncident" />
> <camel:setHeader headerName="${Exchange.FILE_NAME}">
>
> <camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}</camel:constant>
> </camel:setHeader>
> <camel:wireTap uri="file://target/inbox/"></camel:wireTap>
> <camel:choice>
> <camel:when>
> <camel:simple>${body.givenName} == 'Claus'</camel:simple>
> <camel:transform>
> <camel:constant>"OK"</camel:constant>
> </camel:transform>
> </camel:when>
> <camel:otherwise>
> <camel:transform>
> <camel:constant>"Accepted"</camel:constant>
> </camel:transform>
> </camel:otherwise>
> </camel:choice>
> </camel:route>
> </camel:camelContext>
> ===========================================================
>
> Here are the things I did not translate propertly:
>
> .choice().when(simple("${body.givenName} == 'Claus'"))
> .transform(constant(ok))
>
> NOT THE SAME AS:
> <camel:choice>
> <camel:when>
> <camel:simple>${body.givenName} == 'Claus'</camel:simple>
> <camel:transform>
> <camel:constant>"OK"</camel:constant>
> </camel:transform>
> </camel:when>
>
>
> .setHeader(Exchange.FILE_NAME,
> constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
>
> NOT THE SAME AS:
>
> <camel:setHeader headerName="${Exchange.FILE_NAME}">
> <camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}
>
> Thanks,
> --Gary
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).
Re: Problem from Java DSL to Spring DSL
Posted by Gary Liu <Ga...@gmail.com>.
OK. I got the set file name part work.
<camel:setHeader headerName="CamelFileName">
<camel:constant>request-${date:now:yyyy-MM-dd-HHmmssSSS}</camel:constant>
</camel:setHeader>
is equivalent as:
setHeader(Exchange.FILE_NAME,
constant("request-${date:now:yyyy-MM-dd-HHmmssSSS}"))
--
View this message in context: http://camel.465427.n5.nabble.com/Problem-from-Java-DSL-to-Spring-DSL-tp5732558p5732562.html
Sent from the Camel - Users mailing list archive at Nabble.com.