use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class AbstractExchangeStore method notifyListenersOnExchangeRemoval.
public void notifyListenersOnExchangeRemoval(AbstractExchange exchange) {
for (IExchangesStoreListener listener : exchangesStoreListeners) {
exchange.removeExchangeStoreListener(listener);
listener.removeExchange(exchange);
}
}
use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class AbstractExchangeStore method notifyListenersOnExchangeAdd.
public void notifyListenersOnExchangeAdd(Rule rule, AbstractExchange exchange) {
for (IExchangesStoreListener listener : exchangesStoreListeners) {
exchange.addExchangeStoreListener(listener);
listener.addExchange(rule, exchange);
}
}
use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class ElasticSearchExchangeStore method getExchanges.
@Override
public AbstractExchange[] getExchanges(RuleKey ruleKey) {
int port = ruleKey.getPort();
try {
Exchange exc = new Request.Builder().post(getElasticSearchExchangesPath() + "_search").body("{\n" + " \"query\": {\n" + " \"bool\": {\n" + " \"must\": [\n" + " {\n" + " \"wildcard\": {\n" + " \"issuer\": \"" + documentPrefix + "\"\n" + " }\n" + " },\n" + " {\n" + " \"match\": {\n" + " \"rule.port\": \"" + port + "\"\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " }\n" + "}").header("Content-Type", "application/json").buildExchange();
exc = client.call(exc);
List source = getSourceElementFromElasticSearchResponse(responseToMap(exc));
AbstractExchangeSnapshot[] snapshots = mapper.readValue(mapper.writeValueAsString(source), AbstractExchangeSnapshot[].class);
return Stream.of(snapshots).map(snapshot -> snapshot.toAbstractExchange()).collect(Collectors.toList()).toArray(new AbstractExchange[0]);
} catch (Exception e) {
e.printStackTrace();
return new AbstractExchange[0];
}
}
use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class ElasticSearchExchangeStore method getAllExchangesAsList.
@Override
public List<AbstractExchange> getAllExchangesAsList() {
try {
Exchange exc = new Request.Builder().post(getElasticSearchExchangesPath() + "_search").header("Content-Type", "application/json").body("{\n" + " \"query\": {\n" + " \"wildcard\": {\n" + " \"issuer\": \"" + documentPrefix + "\"\n" + " }\n" + " }\n" + "}").buildExchange();
exc = client.call(exc);
if (!exc.getResponse().isOk())
return new ArrayList<>();
List sources = getSourceElementFromElasticSearchResponse(responseToMap(exc));
return (List) sources.stream().map(source -> {
try {
return mapper.readValue(mapper.writeValueAsString(source), AbstractExchangeSnapshot.class).toAbstractExchange();
} catch (IOException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.predic8.membrane.core.exchange.AbstractExchange 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;
}
Aggregations