Search in sources :

Example 1 with HTTPClientInterceptor

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();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) HTTPClientInterceptor(com.predic8.membrane.core.interceptor.HTTPClientInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) HttpClientConfiguration(com.predic8.membrane.core.transport.http.client.HttpClientConfiguration) IOException(java.io.IOException)

Example 2 with HTTPClientInterceptor

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;
}
Also used : HttpTransport(com.predic8.membrane.core.transport.http.HttpTransport) HTTPClientInterceptor(com.predic8.membrane.core.interceptor.HTTPClientInterceptor) ArrayList(java.util.ArrayList) HttpTransport(com.predic8.membrane.core.transport.http.HttpTransport) Transport(com.predic8.membrane.core.transport.Transport) HTTPClientInterceptor(com.predic8.membrane.core.interceptor.HTTPClientInterceptor) RuleMatchingInterceptor(com.predic8.membrane.core.interceptor.RuleMatchingInterceptor) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) UserFeatureInterceptor(com.predic8.membrane.core.interceptor.UserFeatureInterceptor) DispatchingInterceptor(com.predic8.membrane.core.interceptor.DispatchingInterceptor) UserFeatureInterceptor(com.predic8.membrane.core.interceptor.UserFeatureInterceptor) RuleMatchingInterceptor(com.predic8.membrane.core.interceptor.RuleMatchingInterceptor) DispatchingInterceptor(com.predic8.membrane.core.interceptor.DispatchingInterceptor)

Example 3 with HTTPClientInterceptor

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);
    }
}
Also used : AbstractBody(com.predic8.membrane.core.http.AbstractBody) IOException(java.io.IOException)

Example 4 with HTTPClientInterceptor

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);
    }
}
Also used : HTTPClientInterceptor(com.predic8.membrane.core.interceptor.HTTPClientInterceptor) ReverseProxyingInterceptor(com.predic8.membrane.core.interceptor.rewrite.ReverseProxyingInterceptor) ExchangeStoreInterceptor(com.predic8.membrane.core.interceptor.ExchangeStoreInterceptor) HTTPClientInterceptor(com.predic8.membrane.core.interceptor.HTTPClientInterceptor) DispatchingInterceptor(com.predic8.membrane.core.interceptor.DispatchingInterceptor) RuleMatchingInterceptor(com.predic8.membrane.core.interceptor.RuleMatchingInterceptor) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) UserFeatureInterceptor(com.predic8.membrane.core.interceptor.UserFeatureInterceptor) ReverseProxyingInterceptor(com.predic8.membrane.core.interceptor.rewrite.ReverseProxyingInterceptor) ExchangeStoreInterceptor(com.predic8.membrane.core.interceptor.ExchangeStoreInterceptor) UserFeatureInterceptor(com.predic8.membrane.core.interceptor.UserFeatureInterceptor) RuleMatchingInterceptor(com.predic8.membrane.core.interceptor.RuleMatchingInterceptor) DispatchingInterceptor(com.predic8.membrane.core.interceptor.DispatchingInterceptor)

Aggregations

HTTPClientInterceptor (com.predic8.membrane.core.interceptor.HTTPClientInterceptor)3 DispatchingInterceptor (com.predic8.membrane.core.interceptor.DispatchingInterceptor)2 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)2 RuleMatchingInterceptor (com.predic8.membrane.core.interceptor.RuleMatchingInterceptor)2 UserFeatureInterceptor (com.predic8.membrane.core.interceptor.UserFeatureInterceptor)2 IOException (java.io.IOException)2 HttpRouter (com.predic8.membrane.core.HttpRouter)1 Exchange (com.predic8.membrane.core.exchange.Exchange)1 AbstractBody (com.predic8.membrane.core.http.AbstractBody)1 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)1 ExchangeStoreInterceptor (com.predic8.membrane.core.interceptor.ExchangeStoreInterceptor)1 Outcome (com.predic8.membrane.core.interceptor.Outcome)1 ReverseProxyingInterceptor (com.predic8.membrane.core.interceptor.rewrite.ReverseProxyingInterceptor)1 Rule (com.predic8.membrane.core.rules.Rule)1 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)1 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)1 Transport (com.predic8.membrane.core.transport.Transport)1 HttpTransport (com.predic8.membrane.core.transport.http.HttpTransport)1 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)1 ArrayList (java.util.ArrayList)1