Search in sources :

Example 1 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class RuleMatchingInterceptor method insertXForwardedFor.

private void insertXForwardedFor(AbstractExchange exc) {
    Header h = exc.getRequest().getHeader();
    if (h.getNumberOf(Header.X_FORWARDED_FOR) > maxXForwardedForHeaders) {
        Request r = exc.getRequest();
        throw new RuntimeException("Request caused " + Header.X_FORWARDED_FOR + " flood: " + r.getStartLine() + r.getHeader().toString());
    }
    h.setXForwardedFor(getXForwardedForHeaderValue(exc));
    if (h.getNumberOf(Header.X_FORWARDED_PROTO) > maxXForwardedForHeaders) {
        Request r = exc.getRequest();
        throw new RuntimeException("Request caused " + Header.X_FORWARDED_PROTO + " flood: " + r.getStartLine() + r.getHeader().toString());
    }
    h.setXForwardedProto(getXForwardedProtoHeaderValue(exc));
    if (h.getNumberOf(Header.X_FORWARDED_HOST) > maxXForwardedForHeaders) {
        Request r = exc.getRequest();
        throw new RuntimeException("Request caused " + Header.X_FORWARDED_HOST + " flood: " + r.getStartLine() + r.getHeader().toString());
    }
    h.setXForwardedHost(getXForwardedHostHeaderValue(exc));
}
Also used : Header(com.predic8.membrane.core.http.Header) Request(com.predic8.membrane.core.http.Request)

Example 2 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class WSDLInterceptor method createExchange.

private Exchange createExchange(String uri) throws MalformedURLException {
    URL url = new URL(uri);
    Request req = MessageUtil.getGetRequest(getCompletePath(url));
    req.getHeader().setHost(url.getHost());
    Exchange exc = new Exchange(null);
    exc.setRequest(req);
    exc.getDestinations().add(uri);
    return exc;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Request(com.predic8.membrane.core.http.Request) URL(java.net.URL)

Example 3 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class LimitedMemoryExchangeStore method oldSnap.

private void oldSnap(AbstractExchange exc, Flow flow) {
    // TODO: [fix me] support multi-snap
    // TODO: [fix me] snap message headers and request *here*, not in observer/response
    exc.addExchangeViewerListener(new AbstractExchangeViewerListener() {

        @Override
        public void setExchangeFinished() {
            inflight.remove(exc);
        }
    });
    if (flow == Flow.REQUEST) {
        exc.getRequest().addObserver(new MessageObserver() {

            @Override
            public void bodyRequested(AbstractBody body) {
            }

            @Override
            public void bodyComplete(AbstractBody body) {
                Response r = exc.getResponse();
                if (r != null) {
                    AbstractBody b = r.getBody();
                    if (b != null && b.isRead())
                        // request-bodyComplete might occur after response-bodyComplete
                        return;
                }
                // System.out.println("Exchange put inflight " + exc.hashCode() + " " + exc.getRequest().getStartLine());
                inflight.put(exc, exc.getRequest());
                modify();
            }
        });
        return;
    }
    try {
        Message m = exc.getResponse();
        if (m != null)
            m.addObserver(new MessageObserver() {

                public void bodyRequested(AbstractBody body) {
                }

                public void bodyComplete(AbstractBody body) {
                    snapInternal(exc, flow);
                    inflight.remove(exc);
                    modify();
                // System.out.println("Exchange remove inflight " + exc.hashCode());
                }
            });
        else {
            inflight.remove(exc);
            modify();
        // System.out.println("Exchange remove inflight " + exc.hashCode() + " (2)");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AbstractExchangeViewerListener(com.predic8.membrane.core.model.AbstractExchangeViewerListener)

Example 4 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class LimitedMemoryExchangeStore method getAllExchangesAsList.

public synchronized List<AbstractExchange> getAllExchangesAsList() {
    List<AbstractExchange> ret = new LinkedList<AbstractExchange>();
    for (Map.Entry<AbstractExchange, Request> entry : inflight.entrySet()) {
        AbstractExchange ex = entry.getKey();
        Request req = entry.getValue();
        Exchange newEx = new Exchange(null);
        newEx.setId(ex.getId());
        newEx.setRequest(req);
        newEx.setRule(ex.getRule());
        newEx.setRemoteAddr(ex.getRemoteAddr());
        newEx.setTime(ex.getTime());
        newEx.setTimeReqSent(ex.getTimeReqSent() != 0 ? ex.getTimeReqSent() : ex.getTimeReqReceived());
        newEx.setTimeResReceived(System.currentTimeMillis());
        ret.add(newEx);
    }
    ret.addAll(exchanges);
    return ret;
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange) AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with Request

use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.

the class RequestSnapshot method toRequest.

public Request toRequest() {
    Request request = new Request();
    request.setHeader(convertHeader());
    request.setBody(convertBody());
    request.setMethod(getMethod());
    request.setUri(getUri());
    return request;
}
Also used : Request(com.predic8.membrane.core.http.Request)

Aggregations

Request (com.predic8.membrane.core.http.Request)39 Exchange (com.predic8.membrane.core.exchange.Exchange)20 Test (org.junit.Test)12 IOException (java.io.IOException)11 Header (com.predic8.membrane.core.http.Header)8 Response (com.predic8.membrane.core.http.Response)8 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)5 Message (com.predic8.membrane.core.http.Message)5 Outcome (com.predic8.membrane.core.interceptor.Outcome)5 Body (com.predic8.membrane.core.http.Body)3 Request (com.predic8.membrane.core.http.xml.Request)3 EndOfStreamException (com.predic8.membrane.core.util.EndOfStreamException)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 HeaderField (com.predic8.membrane.core.http.HeaderField)2 ResponseBuilder (com.predic8.membrane.core.http.Response.ResponseBuilder)2 ResolverMap (com.predic8.membrane.core.resolver.ResolverMap)2 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)2 StringReader (java.io.StringReader)2 SocketException (java.net.SocketException)2