You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Me Coder <co...@yahoo.com> on 2009/10/15 09:41:29 UTC
Servlet End-Point Route Processing in XML
I'd greatly appreciate help in converting the below route into its XML
equivalent. I am stuck at the part on how to set the content type, charset
header and the body of the response itself.
Thanks...
from("servlet:///hello?matchOnUriPrefix=true").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String contentType =
exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);
String path = exchange.getIn().getHeader(Exchange.HTTP_PATH,
String.class);
assertEquals("Get a wrong content type", CONTENT_TYPE, contentType);
String charsetEncoding =
exchange.getIn().getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class);
assertEquals("Get a wrong charset name", "UTF-8", charsetEncoding);
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, contentType + ";
charset=UTF-8");
exchange.getOut().setHeader("PATH", path);
exchange.getOut().setBody("Hello World");
}
});
--
View this message in context: http://www.nabble.com/Servlet-End-Point-Route-Processing-in-XML-tp25904220p25904220.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Servlet End-Point Route Processing in XML
Posted by Claus Ibsen <cl...@gmail.com>.
There is a setHeader tag. Which accepts an expression. So we can use
the simple language to concat a dynamic string.
<setHeader name="Content-Type"><simple>${in.header.Content-Type};charset=UTF-8</simple></setHeader>
You can also just use the old java code and refer to it as a processor
<bean id="myProcessor" class="com.mycompany.MyProcessor"/>
<from xxxx/>
<processRef ref="myProcessor"/>
...
And have a class
public class MyProcessor implements Processor {
// implement the java code below that sets the headers
}
On Thu, Oct 15, 2009 at 9:41 AM, Me Coder <co...@yahoo.com> wrote:
>
> I'd greatly appreciate help in converting the below route into its XML
> equivalent. I am stuck at the part on how to set the content type, charset
> header and the body of the response itself.
>
> Thanks...
>
> from("servlet:///hello?matchOnUriPrefix=true").process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> String contentType =
> exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);
> String path = exchange.getIn().getHeader(Exchange.HTTP_PATH,
> String.class);
> assertEquals("Get a wrong content type", CONTENT_TYPE, contentType);
> String charsetEncoding =
> exchange.getIn().getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class);
> assertEquals("Get a wrong charset name", "UTF-8", charsetEncoding);
> exchange.getOut().setHeader(Exchange.CONTENT_TYPE, contentType + ";
> charset=UTF-8");
> exchange.getOut().setHeader("PATH", path);
> exchange.getOut().setBody("Hello World");
> }
> });
>
> --
> View this message in context: http://www.nabble.com/Servlet-End-Point-Route-Processing-in-XML-tp25904220p25904220.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus