use of com.predic8.membrane.core.interceptor.HTTPClientInterceptor in project service-proxy by membrane.
the class LargeBodyTest method setup.
public void setup() throws Exception {
// streaming only works for maxRetries = 1
hcc = new HttpClientConfiguration();
hcc.setMaxRetries(1);
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3040), "thomas-bayer.com", 80);
rule.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
exc.setResponse(Response.ok().body("").build());
return Outcome.RETURN;
}
});
router = new HttpRouter();
((HTTPClientInterceptor) router.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
router.init();
Rule rule1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3041), "localhost", 3040);
router2 = new HttpRouter();
((HTTPClientInterceptor) router2.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
router2.getRuleManager().addProxyAndOpenPortIfNew(rule1);
router2.init();
}
use of com.predic8.membrane.core.interceptor.HTTPClientInterceptor in project service-proxy by membrane.
the class HttpRouter method createTransport.
/**
* Same as the default config from monitor-beans.xml
*/
private Transport createTransport(ProxyConfiguration proxyConfiguration) {
Transport transport = new HttpTransport();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(new RuleMatchingInterceptor());
interceptors.add(new DispatchingInterceptor());
interceptors.add(new UserFeatureInterceptor());
HTTPClientInterceptor httpClientInterceptor = new HTTPClientInterceptor();
interceptors.add(httpClientInterceptor);
transport.setInterceptors(interceptors);
return transport;
}
use of com.predic8.membrane.core.interceptor.HTTPClientInterceptor in project service-proxy by membrane.
the class StatisticCollector method collectFrom.
public void collectFrom(AbstractExchange exc) {
totalCount++;
if (exc.getStatus() == ExchangeState.FAILED) {
errorCount++;
if (!countErrorExchanges)
return;
}
long timeReqSent = exc.getTimeReqSent();
if (timeReqSent == 0)
// this Exchange did not reach the HTTPClientInterceptor
return;
long timeResSent = exc.getTimeResSent();
if (timeResSent == 0)
// this Exchange is not yet completed
return;
goodCount++;
int time = (int) (timeResSent - timeReqSent);
if (time < minTime)
minTime = time;
if (time > maxTime)
maxTime = time;
totalTime += time;
try {
AbstractBody requestBody = exc.getRequest().getBody();
totalBytesSent += requestBody.isRead() ? requestBody.getLength() : 0;
AbstractBody responseBody = exc.getResponse().getBody();
totalBytesReceived += responseBody.isRead() ? responseBody.getLength() : 0;
} catch (IOException e) {
log.warn("", e);
}
}
use of com.predic8.membrane.core.interceptor.HTTPClientInterceptor in project service-proxy by membrane.
the class Transport method init.
public void init(Router router) throws Exception {
this.router = router;
if (interceptors.isEmpty()) {
interceptors.add(new RuleMatchingInterceptor());
interceptors.add(new ExchangeStoreInterceptor(router.getExchangeStore()));
interceptors.add(new DispatchingInterceptor());
interceptors.add(new ReverseProxyingInterceptor());
interceptors.add(new UserFeatureInterceptor());
interceptors.add(new HTTPClientInterceptor());
}
for (Interceptor interceptor : interceptors) {
interceptor.init(router);
}
}
Aggregations