use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class AbstractExchangeSnapshot method toAbstractExchange.
public AbstractExchange toAbstractExchange() {
Exchange exc = new Exchange(null);
if (getRequest() != null)
exc.setRequest(this.getRequest().toRequest());
if (getResponse() != null)
exc.setResponse(this.getResponse().toResponse());
exc.setOriginalRequestUri(getOriginalRequestUri());
exc.setTime(getTime());
exc.setErrorMessage(getErrorMessage());
exc.setStatus(getStatus());
exc.setTimeReqSent(getTimeReqSent());
exc.setTimeReqReceived(getTimeReqReceived());
exc.setTimeResSent(getTimeResSent());
exc.setTimeResReceived(getTimeResReceived());
exc.setDestinations(getDestinations().stream().collect(Collectors.toList()));
exc.setRemoteAddr(getRemoteAddr());
exc.setRemoteAddrIp(getRemoteAddrIp());
exc.setId(getId());
exc.setRule(getRule());
setServer(getServer());
return exc;
}
use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class ExchangeComparator method compare.
@SuppressWarnings({ "rawtypes", "unchecked" })
public int compare(AbstractExchange e1, AbstractExchange e2) {
if (e1.getResponse() == null || e2.getResponse() == null)
return 0;
for (ExchangeAccessor accessor : accessors) {
Comparable comp1 = (Comparable) accessor.get(e1);
Comparable comp2 = (Comparable) accessor.get(e2);
int result = comp1.compareTo(comp2);
if (result != 0) {
if (ascending) {
return comp1.compareTo(comp2);
} else {
return comp2.compareTo(comp1);
}
}
}
return 0;
}
use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class AdminRESTInterceptor method getRaw.
@Mapping("/admin/rest/exchanges/(-?\\d+)/(response|request)/raw")
public Response getRaw(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) {
return Response.noContent().build();
}
// TODO uses body.toString that doesn't handle different encodings than utf-8
return Response.ok().contentType(MimeType.TEXT_PLAIN_UTF8).body(msg.toString()).build();
}
use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.
the class ElasticSearchExchangeStore method removeAllExchanges.
@Override
public void removeAllExchanges(AbstractExchange[] exchanges) {
StringBuilder sb = Stream.of(exchanges).map(exc -> exc.getId()).collect(() -> {
StringBuilder acc = new StringBuilder();
acc.append("[");
return acc;
}, (acc, id) -> acc.append(id).append(","), (acc1, acc2) -> acc1.append(",").append(acc2));
sb.deleteCharAt(sb.length() - 1);
sb.append("]");
String exchangeIdsAsJsonArray = sb.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" + " \"terms\": {\n" + " \"id\": \"" + exchangeIdsAsJsonArray + "\"\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.AbstractExchange in project service-proxy by membrane.
the class ElasticSearchExchangeStore method snap.
@Override
public void snap(AbstractExchange exc, Interceptor.Flow flow) {
AbstractExchangeSnapshot excCopy = null;
try {
if (flow == Interceptor.Flow.REQUEST) {
excCopy = new DynamicAbstractExchangeSnapshot(exc, this::addForElasticSearch);
addForElasticSearch(excCopy);
} else {
excCopy = getExchangeDtoById((int) exc.getId());
DynamicAbstractExchangeSnapshot.addObservers(exc, excCopy, this::addForElasticSearch);
excCopy = excCopy.updateFrom(exc);
addForElasticSearch(excCopy);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations