use of com.predic8.membrane.core.rules.RuleKey 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.rules.RuleKey in project service-proxy by membrane.
the class OAuth2ResourceInterceptor method setPublicURL.
private void setPublicURL(Exchange exc) {
String xForwardedProto = exc.getRequest().getHeader().getFirstValue(Header.X_FORWARDED_PROTO);
boolean isHTTPS = xForwardedProto != null ? "https".equals(xForwardedProto) : exc.getRule().getSslInboundContext() != null;
publicURL = (isHTTPS ? "https://" : "http://") + exc.getOriginalHostHeader();
RuleKey key = exc.getRule().getKey();
if (!key.isPathRegExp() && key.getPath() != null)
publicURL += key.getPath();
normalizePublicURL();
initPublicURLOnFirstExchange = false;
}
use of com.predic8.membrane.core.rules.RuleKey in project service-proxy by membrane.
the class RuleManager method getMatchingRule.
public Rule getMatchingRule(String hostHeader, String method, String uri, String version, int port, String localIP) {
for (Rule rule : rules) {
RuleKey key = rule.getKey();
log.debug("Host from rule: " + key.getHost() + "; Host from parameter rule key: " + hostHeader);
if (!rule.isActive())
continue;
if (!key.matchesVersion(version))
continue;
if (key.getIp() != null && !key.getIp().equals(localIP))
continue;
if (!key.matchesHostHeader(hostHeader))
continue;
if (key.getPort() != -1 && port != -1 && key.getPort() != port)
continue;
if (!key.getMethod().equals(method) && !key.isMethodWildcard())
continue;
if (key.isUsePathPattern() && !key.matchesPath(uri))
continue;
if (!key.complexMatch(hostHeader, method, uri, version, port, localIP))
continue;
return rule;
}
return null;
}
use of com.predic8.membrane.core.rules.RuleKey in project service-proxy by membrane.
the class AbstractExchange method getPublicUrl.
public String getPublicUrl() {
String xForwardedProto = getRequest().getHeader().getFirstValue(Header.X_FORWARDED_PROTO);
boolean isHTTPS = xForwardedProto != null ? "https".equals(xForwardedProto) : getRule().getSslInboundContext() != null;
String publicURL = (isHTTPS ? "https://" : "http://") + getRequest().getHeader().getHost().replaceFirst(".*:", "");
RuleKey key = getRule().getKey();
if (!key.isPathRegExp() && key.getPath() != null)
publicURL += key.getPath();
return publicURL;
}
use of com.predic8.membrane.core.rules.RuleKey in project service-proxy by membrane.
the class ElasticSearchExchangeStore method getStatistics.
@Override
public StatisticCollector getStatistics(RuleKey ruleKey) {
StatisticCollector statistics = new StatisticCollector(false);
List<AbstractExchange> exchangesList = Arrays.asList(getExchanges(ruleKey));
if (exchangesList == null || exchangesList.isEmpty())
return statistics;
for (int i = 0; i < exchangesList.size(); i++) statistics.collectFrom(exchangesList.get(i));
return statistics;
}
Aggregations