use of com.predic8.membrane.core.exchange.AbstractExchange 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.exchange.AbstractExchange 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.exchange.AbstractExchange 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.exchange.AbstractExchange in project service-proxy by membrane.
the class REST2SOAPInterceptor method modifyRequest.
private void modifyRequest(AbstractExchange exc, Mapping mapping) {
exc.getRequest().setMethod("POST");
exc.getRequest().getHeader().setSOAPAction(mapping.soapAction);
Header header = exc.getRequest().getHeader();
header.removeFields(Header.CONTENT_TYPE);
header.setContentType(isSOAP12(exc) ? MimeType.APPLICATION_SOAP : MimeType.TEXT_XML_UTF8);
exc.setProperty("mapping", mapping);
setServiceEndpoint(exc, mapping);
}
use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class AdminRESTInterceptor method getBeautifiedBody.
@Mapping("/admin/web/exchanges/(-?\\d+)/(response|request)/body")
public Response getBeautifiedBody(QueryParameter params, String relativeRootPath) throws Exception {
AbstractExchange exc = router.getExchangeStore().getExchangeById(params.getGroupInt(1));
if (exc == null) {
return Response.notFound().build();
}
Message msg = params.getGroup(2).equals("response") ? exc.getResponse() : exc.getRequest();
if (msg == null || msg.isBodyEmpty()) {
return Response.noContent().build();
}
return Response.ok().contentType(MimeType.TEXT_HTML_UTF8).body(TextUtil.formatXML(new InputStreamReader(msg.getBodyAsStreamDecoded(), msg.getCharset()), true)).build();
}
Aggregations