use of com.predic8.membrane.core.http.Header 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.http.Header in project service-proxy by membrane.
the class ElasticSearchExchangeStore method getFromElasticSearchById.
private AbstractExchangeSnapshot getFromElasticSearchById(int id) {
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" + " \"id\": \"" + id + "\"\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " }\n" + "}").header("Content-Type", "application/json").buildExchange();
exc = client.call(exc);
Map res = responseToMap(exc);
Map excJson = getSourceElementFromElasticSearchResponse(res).get(0);
return mapper.readValue(mapper.writeValueAsString(excJson), AbstractExchangeSnapshot.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.predic8.membrane.core.http.Header in project service-proxy by membrane.
the class ElasticSearchExchangeStore method sendToElasticSearch.
private void sendToElasticSearch(List<AbstractExchangeSnapshot> exchanges) throws Exception {
StringBuilder data = exchanges.stream().map(exchange -> wrapForBulkOperationElasticSearch(index, type, getLocalMachineNameWithSuffix() + "-" + exchange.getId(), collectExchangeDataFrom(exchange))).collect(StringBuilder::new, (sb, str) -> sb.append(str), (sb1, sb2) -> sb1.append(sb2));
Exchange elasticSearchExc = new Request.Builder().post(location + "/_bulk").header("Content-Type", "application/x-ndjson").body(data.toString()).buildExchange();
client.call(elasticSearchExc);
}
use of com.predic8.membrane.core.http.Header in project service-proxy by membrane.
the class HeaderFilterInterceptor method handleMessage.
private void handleMessage(Message msg) {
if (msg == null)
return;
Header h = msg.getHeader();
if (h == null)
return;
for (HeaderField hf : h.getAllHeaderFields()) for (Rule r : rules) if (r.matches(hf.getHeaderName().toString())) {
switch(r.getAction()) {
case REMOVE:
log.debug("Removing HTTP header " + hf.getHeaderName().toString());
h.remove(hf);
break;
case KEEP:
break;
}
break;
}
}
use of com.predic8.membrane.core.http.Header in project service-proxy by membrane.
the class AuthHead2BodyInterceptor method getUsername.
private Node getUsername(Document doc, Element header) {
Element e = doc.createElement("username");
e.appendChild(doc.createTextNode(((Element) doc.getElementsByTagNameNS(COM_NS, "userName").item(0)).getTextContent()));
e.setAttributeNS(XSI_NS, "xsi:type", "xsd:string");
return e;
}
Aggregations