You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ibrahimis <ib...@gmail.com> on 2016/09/23 10:39:43 UTC
Need input on accessing http servlet
Hi, I have created servlet which will return a JSON object. I am trying to
connect the servlet using Camel and put it in a buffer. But my servlet
didn't invoked at all and not throwing any error. I am currently in the
beginning stage on using camel.
Please help.
I have used the following code.
package com.test.camel;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
public class TestRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("servlet:localhost:9078/ThirdPartyApplication/MaintainCases")
.setHeader("stream", constant(mystream))
.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_URI, String.class);
path = path.substring(path.lastIndexOf("/"));
exchange.getOut().setHeader(Exchange.CONTENT_TYPE,
contentType + "; charset=UTF-8");
exchange.getOut().setHeader("PATH", path);
exchange.getOut().setBody("*Hello World*");
}
}).to("stream:header");
}
private OutputStream mystream = new MyOutputStream();
private StringBuilder sb = new StringBuilder();
private class MyOutputStream extends OutputStream {
public void write(int b) throws IOException {
sb.append((char) b);
}
}
}
--
View this message in context: http://camel.465427.n5.nabble.com/Need-input-on-accessing-http-servlet-tp5787954.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Need input on accessing http servlet
Posted by David Parker <df...@gmail.com>.
As a work-around, you might create a class that invokes a HTTPClient or
other URL-friendly utility.
Invoke that logic in your route to retrieve data and then process it.
On Fri, Sep 23, 2016 at 3:08 AM, jpeschke <pe...@etone.de> wrote:
> Hi,
> You cannot use the Servlet component to connect to a third party servlet on
> your server context.
> The "servlet:" endpoint is only to offer a servlet interface to your camel
> routes. See documentation at http://camel.apache.org/servlet.html:
>
>
> > You can consume only from endpoints generated by the Servlet component.
> > Therefore, it should be used only as input into your Camel routes. To
> > issue HTTP requests against other HTTP endpoints, use the HTTP Component
>
> So the HTTP-Component (http://camel.apache.org/http.html) or the
> Jetty-Component (http://camel.apache.org/jetty.html) should do the trick.
>
> Best regards,
> Joerg
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Need-input-on-accessing-http-servlet-tp5787954p5787964.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: Need input on accessing http servlet
Posted by jpeschke <pe...@etone.de>.
Hi,
You cannot use the Servlet component to connect to a third party servlet on
your server context.
The "servlet:" endpoint is only to offer a servlet interface to your camel
routes. See documentation at http://camel.apache.org/servlet.html:
> You can consume only from endpoints generated by the Servlet component.
> Therefore, it should be used only as input into your Camel routes. To
> issue HTTP requests against other HTTP endpoints, use the HTTP Component
So the HTTP-Component (http://camel.apache.org/http.html) or the
Jetty-Component (http://camel.apache.org/jetty.html) should do the trick.
Best regards,
Joerg
--
View this message in context: http://camel.465427.n5.nabble.com/Need-input-on-accessing-http-servlet-tp5787954p5787964.html
Sent from the Camel - Users mailing list archive at Nabble.com.