use of com.predic8.membrane.core.http.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));
}
use of com.predic8.membrane.core.http.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;
}
use of com.predic8.membrane.core.http.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);
}
}
use of com.predic8.membrane.core.http.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;
}
use of com.predic8.membrane.core.http.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;
}
Aggregations