You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sonu123 <sa...@rediffmail.com> on 2016/06/09 08:18:11 UTC
Rest to Stax not working
Hi,
I have a route which accepts a post request in plain/text format in the REST
DSL, I want to forward it to another route where I intend to parse incoming
body (XML) using stax component. My route look like this.
restConfiguration()
.component("servlet")
.contextPath("Drools-Router/rest")
.port(9090)
.enableCORS(true)
.bindingMode(RestBindingMode.off)
.post().consumes("text/plain")
.type(String.class)
.produces("text/plain")
.outType(String.class)
.to("direct:multicastdemo")
from("direct:mainRoute")
.tracing().routeId("stax-parser")
.log("Content of the body in the main route: ${body}")
.to("stax:com.cacib.passer.handler.UserStory1XMLSaxHandler")
.transform().method("routingService", ,"createRoutingResponse")
.end()
I am getting this exception
/org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 0; Unexpected
EOF in prolog
at [row,col {unknown-source}]: [1,0]/
When I am changing my first route to keep XML Payload into a file and
second route read data from the same file, then it is working as expected.
My modified route, which is working as expected look some like this
.post().consumes("text/plain")
.type(String.class)
.produces("text/plain")
.outType(String.class)
.to("file:target/in?fileName=abc-${date:now:yyyyMMdd}.xml")
.from("file:target/in?noop=true&delay=1000")
.tracing().routeId("stax-parser")
.log("Content of the file in the main route: ${body}")
.to("stax:com.cacib.passer.handler.UserStory1XMLSaxHandler")
.transform().method("routingService", "createRoutingResponse")
.log("After Drools processing : ${body} ")
.end()
.log("Done processing a file: ${body} ");
Can you please tell me where I am doing wrong.
--
View this message in context: http://camel.465427.n5.nabble.com/Rest-to-Stax-not-working-tp5783748.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Rest to Stax not working
Posted by Joseph Kampf <jo...@gmail.com>.
I had a similar problem recently with JaxRS component.
The output of the JaxRS was an instance of javax.ws.rs.core.Response.
I needed to pull the Entity out of the response and set that to my Body before doing an XML parse.
Here is the snippet I had:
Response jaxrsResponse = newExchange.getIn().getBody(Response.class);
if (jaxrsResponse != null)
newExchange.getIn().setBody(jaxrsResponse.getEntity());
return newExchange;
On 6/9/16, 4:18 AM, "sonu123" <sa...@rediffmail.com> wrote:
>Hi,
>I have a route which accepts a post request in plain/text format in the REST
>DSL, I want to forward it to another route where I intend to parse incoming
>body (XML) using stax component. My route look like this.
>
>restConfiguration()
>.component("servlet")
> .contextPath("Drools-Router/rest")
> .port(9090)
> .enableCORS(true)
> .bindingMode(RestBindingMode.off)
>
>.post().consumes("text/plain")
> .type(String.class)
> .produces("text/plain")
> .outType(String.class)
> .to("direct:multicastdemo")
>
>from("direct:mainRoute")
>.tracing().routeId("stax-parser")
> .log("Content of the body in the main route: ${body}")
> .to("stax:com.cacib.passer.handler.UserStory1XMLSaxHandler")
>.transform().method("routingService", ,"createRoutingResponse")
>.end()
>
>I am getting this exception
>/org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 0; Unexpected
>EOF in prolog
> at [row,col {unknown-source}]: [1,0]/
>
>When I am changing my first route to keep XML Payload into a file and
>second route read data from the same file, then it is working as expected.
>My modified route, which is working as expected look some like this
>
>.post().consumes("text/plain")
>.type(String.class)
> .produces("text/plain")
> .outType(String.class)
> .to("file:target/in?fileName=abc-${date:now:yyyyMMdd}.xml")
>
>.from("file:target/in?noop=true&delay=1000")
>.tracing().routeId("stax-parser")
> .log("Content of the file in the main route: ${body}")
> .to("stax:com.cacib.passer.handler.UserStory1XMLSaxHandler")
> .transform().method("routingService", "createRoutingResponse")
>.log("After Drools processing : ${body} ")
>.end()
> .log("Done processing a file: ${body} ");
>
>Can you please tell me where I am doing wrong.
>
>
>
>
>--
>View this message in context: http://camel.465427.n5.nabble.com/Rest-to-Stax-not-working-tp5783748.html
>Sent from the Camel - Users mailing list archive at Nabble.com.