use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class ElasticSearchExchangeStore method removeAllExchanges.
@Override
public void removeAllExchanges(Rule rule) {
String name = rule.toString();
try {
Exchange exc = new Request.Builder().post(getElasticSearchExchangesPath() + "_delete_by_query").body("{\n" + " \"query\": {\n" + " \"bool\": {\n" + " \"must\": [\n" + " {\n" + " \"wildcard\": {\n" + " \"issuer\": \"" + documentPrefix + "\"\n" + " }\n" + " },\n" + " {\n" + " \"match\": {\n" + " \"rule.name\": \"" + name + "\"\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " }\n" + "}").header("Content-Type", "application/json").buildExchange();
client.call(exc);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class AuthHead2BodyInterceptor method handleRequest.
public Outcome handleRequest(AbstractExchange exchange) throws Exception {
Document doc = getDocument(exchange.getRequest().getBodyAsStreamDecoded(), exchange.getRequest().getCharset());
Element header = getAuthorisationHeader(doc);
if (header == null)
return Outcome.CONTINUE;
// System.out.println(DOM2String(doc));
Element nor = getNorElement(doc);
nor.appendChild(getUsername(doc, header));
nor.appendChild(getPassword(doc, header));
header.getParentNode().removeChild(header);
exchange.getRequest().setBody(new Body(DOM2String(doc).getBytes(exchange.getRequest().getCharset())));
return Outcome.CONTINUE;
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class DispatchingInterceptor method getForwardingDestination.
public static String getForwardingDestination(Exchange exc) throws Exception {
AbstractServiceProxy p = (AbstractServiceProxy) exc.getRule();
if (p.getTargetURL() != null) {
log.debug("destination: " + p.getTargetURL());
return p.getTargetURL();
}
if (p.getTargetHost() != null) {
String url = new URL(p.getTargetScheme(), p.getTargetHost(), p.getTargetPort(), exc.getRequest().getUri()).toString();
log.debug("destination: " + url);
return url;
}
return exc.getRequest().getUri();
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class UserFeatureInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
Rule predecessorRule = exc.getRule();
Outcome outcome = flowController.invokeRequestHandlers(exc, predecessorRule.getInterceptors());
while (isTargetInternalAndContinue(exc, outcome)) {
log.debug("routing to serviceProxy with name: " + getServiceProxyName(exc));
// rule matching
String destination = exc.getDestinations().get(0);
Rule newRule = getRuleByDest(destination);
if (newRule == null)
throw new Exception("No proxy found for destination " + destination);
exc.setRule(newRule);
// dispatching
exc.getDestinations().clear();
exc.getDestinations().add(DispatchingInterceptor.getForwardingDestination(exc));
// user feature
outcome = flowController.invokeRequestHandlers(exc, newRule.getInterceptors());
}
exc.setRule(predecessorRule);
return outcome;
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class WADLInterceptor method rewrite.
@Override
protected void rewrite(Exchange exc) throws Exception, IOException {
log.debug("Changing endpoint address in WADL");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Relocator relocator = new Relocator(new OutputStreamWriter(stream, exc.getResponse().getCharset()), getLocationProtocol(), getLocationHost(exc), getLocationPort(exc), pathRewriter);
relocator.getRelocatingAttributes().put(new QName(WADL_NS, "resources"), "base");
relocator.getRelocatingAttributes().put(new QName(WADL_NS, "include"), "href");
relocator.relocate(new InputStreamReader(exc.getResponse().getBodyAsStreamDecoded(), exc.getResponse().getCharset()));
exc.getResponse().setBodyContent(stream.toByteArray());
}
Aggregations