use of com.predic8.membrane.core.http.HeaderField in project service-proxy by membrane.
the class HttpServletHandler method writeResponse.
@SuppressWarnings("deprecation")
protected void writeResponse(Response res) throws Exception {
response.setStatus(res.getStatusCode(), res.getStatusMessage());
for (HeaderField header : res.getHeader().getAllHeaderFields()) {
if (header.getHeaderName().equals(Header.TRANSFER_ENCODING))
continue;
response.addHeader(header.getHeaderName().toString(), header.getValue());
}
ServletOutputStream out = response.getOutputStream();
res.getBody().write(new PlainBodyTransferrer(out));
out.flush();
response.flushBuffer();
exchange.setTimeResSent(System.currentTimeMillis());
exchange.collectStatistics();
}
use of com.predic8.membrane.core.http.HeaderField in project service-proxy by membrane.
the class MyInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
System.out.println("MyInterceptor invoked.");
System.out.println("Request headers:");
for (HeaderField headerField : exc.getRequest().getHeader().getAllHeaderFields()) System.out.print(headerField.getHeaderName() + ": " + headerField.getValue());
return Outcome.CONTINUE;
}
use of com.predic8.membrane.core.http.HeaderField in project service-proxy by membrane.
the class AdminRESTInterceptor method getRequestHeader.
@Mapping("/admin/rest/exchanges/(-?\\d+)/(response|request)/header")
public Response getRequestHeader(QueryParameter params, String relativeRootPath) throws Exception {
final AbstractExchange exc = router.getExchangeStore().getExchangeById(params.getGroupInt(1));
if (exc == null) {
return Response.notFound().build();
}
final Message msg = params.getGroup(2).equals("response") ? exc.getResponse() : exc.getRequest();
if (msg == null) {
return Response.noContent().build();
}
return json(new JSONContent() {
public void write(JsonGenerator gen) throws Exception {
gen.writeStartObject();
gen.writeArrayFieldStart("headers");
for (HeaderField hf : msg.getHeader().getAllHeaderFields()) {
gen.writeStartObject();
gen.writeStringField("name", hf.getHeaderName().toString());
gen.writeStringField("value", hf.getValue());
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeEndObject();
}
});
}
use of com.predic8.membrane.core.http.HeaderField in project service-proxy by membrane.
the class HeaderFilterInterceptor method handleMessage.
private void handleMessage(Message msg) {
if (msg == null)
return;
Header h = msg.getHeader();
if (h == null)
return;
for (HeaderField hf : h.getAllHeaderFields()) for (Rule r : rules) if (r.matches(hf.getHeaderName().toString())) {
switch(r.getAction()) {
case REMOVE:
log.debug("Removing HTTP header " + hf.getHeaderName().toString());
h.remove(hf);
break;
case KEEP:
break;
}
break;
}
}
use of com.predic8.membrane.core.http.HeaderField in project service-proxy by membrane.
the class HeaderFilterInterceptorTest method doit.
@Test
public void doit() throws Exception {
Exchange exc = new Exchange(null);
exc.setResponse(Response.ok().header("a", "b").header("c", "d").header("c", "d2").header("e", "f").build());
HeaderFilterInterceptor fhi = new HeaderFilterInterceptor();
fhi.setRules(Lists.newArrayList(new Rule[] { // implicitly set by Response.ok()
new Rule("Server", Action.REMOVE), new Rule("a", Action.KEEP), new Rule("c.*", Action.REMOVE) }));
fhi.handleResponse(exc);
HeaderField[] h = exc.getResponse().getHeader().getAllHeaderFields();
assertEquals(3, h.length);
assertEquals("Content-Length", h[0].getHeaderName().toString());
assertEquals("a", h[1].getHeaderName().toString());
assertEquals("e", h[2].getHeaderName().toString());
}
Aggregations