use of org.apache.camel.http.common.HttpMessage in project camel by apache.
the class RestletProducerSessionTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to(url).to(url).to("mock:result");
from("direct:instance").to(url + "&cookieHandler=#instanceCookieHandler").to(url + "&cookieHandler=#instanceCookieHandler").to("mock:result");
from("direct:exchange").to(url + "&cookieHandler=#exchangeCookieHandler").to(url + "&cookieHandler=#exchangeCookieHandler").to("mock:result");
from("jetty://http://127.0.0.1:" + portNum + "/session?sessionSupport=true").process(new Processor() {
public void process(Exchange exchange) throws Exception {
HttpMessage message = exchange.getIn(HttpMessage.class);
HttpSession session = message.getRequest().getSession();
String body = message.getBody(String.class);
if (body.length() > 2) {
body = body.substring(1, body.length() - 1);
}
if ("bar".equals(session.getAttribute("foo"))) {
body = "{Old " + body + "}";
} else {
session.setAttribute("foo", "bar");
body = "{New " + body + "}";
}
exchange.getOut().setBody(body);
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json");
}
});
}
};
}
use of org.apache.camel.http.common.HttpMessage in project camel by apache.
the class Http4RouteTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
port1 = AvailablePortFinder.getNextAvailable(8000);
port2 = AvailablePortFinder.getNextAvailable(9000);
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jetty:http://localhost:" + port1 + "/test").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
HttpMessage message = (HttpMessage) exchange.getIn();
assertNotNull(message.getRequest());
assertEquals("GET", message.getRequest().getMethod());
exchange.getOut().setBody(message.getRequest().getQueryString());
}
});
from("jetty:http://localhost:" + port2 + "/test").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
HttpMessage message = (HttpMessage) exchange.getIn();
assertNotNull(message.getRequest());
assertEquals("GET", message.getRequest().getMethod());
exchange.getOut().setBody(message.getRequest().getQueryString() + "&2");
}
});
from("direct:start1").to("http4://localhost:" + port1 + "/test");
from("direct:start2").to("http4://localhost:" + port2 + "/test");
}
};
}
use of org.apache.camel.http.common.HttpMessage in project camel by apache.
the class NettyHttpProducerSessionTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").toF("netty4-http:http://127.0.0.1:%d/session", getPort()).toF("netty4-http:http://127.0.0.1:%d/session", getPort()).to("mock:result");
from("direct:instance").toF("netty4-http:http://127.0.0.1:%d/session?cookieHandler=#instanceCookieHandler", getPort()).toF("netty4-http:http://127.0.0.1:%d/session?cookieHandler=#instanceCookieHandler", getPort()).to("mock:result");
from("direct:exchange").toF("netty4-http:http://127.0.0.1:%d/session?cookieHandler=#exchangeCookieHandler", getPort()).toF("netty4-http:http://127.0.0.1:%d/session?cookieHandler=#exchangeCookieHandler", getPort()).to("mock:result");
fromF("jetty:http://127.0.0.1:%d/session?sessionSupport=true", getPort()).process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
HttpMessage message = exchange.getIn(HttpMessage.class);
HttpSession session = message.getRequest().getSession();
String body = message.getBody(String.class);
if ("bar".equals(session.getAttribute("foo"))) {
message.setBody("Old " + body);
} else {
session.setAttribute("foo", "bar");
message.setBody("New " + body);
}
}
});
}
};
}
use of org.apache.camel.http.common.HttpMessage in project camel by apache.
the class HttpConverterTest method testNulls.
@Test
public void testNulls() throws Exception {
HttpMessage msg = null;
assertNull(HttpConverter.toInputStream(msg, null));
assertNull(HttpConverter.toServletInputStream(msg));
assertNull(HttpConverter.toServletRequest(msg));
assertNull(HttpConverter.toServletResponse(msg));
HttpServletRequest req = null;
assertNull(HttpConverter.toInputStream(req, null));
}
use of org.apache.camel.http.common.HttpMessage in project camel by apache.
the class JettyHttpProducerSessionTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("jetty://" + getTestServerEndpointSessionUrl()).to("jetty://" + getTestServerEndpointSessionUrl()).to("mock:result");
from("direct:instance").to("jetty://" + getTestServerEndpointSessionUrl() + "?cookieHandler=#instanceCookieHandler").to("jetty://" + getTestServerEndpointSessionUrl() + "?cookieHandler=#instanceCookieHandler").to("mock:result");
from("direct:exchange").to("jetty://" + getTestServerEndpointSessionUrl() + "?cookieHandler=#exchangeCookieHandler").to("jetty://" + getTestServerEndpointSessionUrl() + "?cookieHandler=#exchangeCookieHandler").to("mock:result");
from(getTestServerEndpointSessionUri()).process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
HttpMessage message = exchange.getIn(HttpMessage.class);
HttpSession session = message.getRequest().getSession();
String body = message.getBody(String.class);
if ("bar".equals(session.getAttribute("foo"))) {
message.setBody("Old " + body);
} else {
session.setAttribute("foo", "bar");
message.setBody("New " + body);
}
}
});
}
};
}
Aggregations