use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class EchoInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
Outcome outcome = exc.echo();
exc.getResponse().getHeader().removeFields(Header.CONTENT_LENGTH);
String body = exc.getRequest().getUri() + "\n" + new String(exc.getRequest().getBody().getContent(), Constants.UTF_8_CHARSET);
exc.getResponse().setBodyContent(body.getBytes(Constants.UTF_8_CHARSET));
return outcome;
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
service1 = new HttpRouter();
mockInterceptor1 = new DummyWebServiceInterceptor();
ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), "thomas-bayer.com", 80);
sp1.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add("Connection", "close");
return Outcome.CONTINUE;
}
});
sp1.getInterceptors().add(mockInterceptor1);
service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
service1.init();
service2 = new HttpRouter();
mockInterceptor2 = new DummyWebServiceInterceptor();
ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "thomas-bayer.com", 80);
sp2.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add("Connection", "close");
return Outcome.CONTINUE;
}
});
sp2.getInterceptors().add(mockInterceptor2);
service2.getRuleManager().addProxyAndOpenPortIfNew(sp2);
service2.init();
balancer = new HttpRouter();
ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 7000), "thomas-bayer.com", 80);
balancingInterceptor = new LoadBalancingInterceptor();
balancingInterceptor.setName("Default");
sp3.getInterceptors().add(balancingInterceptor);
balancer.getRuleManager().addProxyAndOpenPortIfNew(sp3);
enableFailOverOn5XX(balancer);
balancer.init();
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 2000);
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 3000);
roundRobinStrategy = new RoundRobinStrategy();
byThreadStrategy = new ByThreadStrategy();
}
use of com.predic8.membrane.core.interceptor.Outcome 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.interceptor.Outcome in project service-proxy by membrane.
the class Exchange method echo.
public Outcome echo() throws IOException {
ResponseBuilder builder = Response.ok();
byte[] content = getRequest().getBody().getContent();
builder.body(content);
String contentType = getRequest().getHeader().getContentType();
if (contentType != null)
builder.header(Header.CONTENT_TYPE, contentType);
String contentEncoding = getRequest().getHeader().getContentEncoding();
if (contentEncoding != null)
builder.header(Header.CONTENT_ENCODING, contentEncoding);
setResponse(builder.build());
return Outcome.RETURN;
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
log.debug("request: " + exc.getOriginalRequestUri());
exc.setTimeReqSent(System.currentTimeMillis());
Outcome o = dispatchRequest(exc);
exc.setReceived();
exc.setTimeResReceived(System.currentTimeMillis());
return o;
}
Aggregations