use of com.predic8.membrane.core.rules.AbstractServiceProxy in project service-proxy by membrane.
the class AdminPageBuilder method createServiceProxyVisualization.
public void createServiceProxyVisualization(AbstractServiceProxy proxy, String relativeRootPath) {
List<Interceptor> leftStack = new ArrayList<Interceptor>(), rightStack = new ArrayList<Interceptor>();
List<Interceptor> list = new ArrayList<Interceptor>(proxy.getInterceptors());
list.add(new // fake interceptor so that both stacks end with the same size
AbstractInterceptor() {
@Override
public EnumSet<Flow> getFlow() {
return Flow.Set.REQUEST_RESPONSE;
}
});
// build left and right stacks
for (Interceptor i : list) {
EnumSet<Flow> f = i.getFlow();
if (i instanceof ResponseInterceptor) {
for (Interceptor i2 : ((ResponseInterceptor) i).getInterceptors()) rightStack.add(i2);
} else if (i instanceof RequestInterceptor) {
for (Interceptor i3 : ((RequestInterceptor) i).getInterceptors()) leftStack.add(i3);
} else if (f.contains(Flow.REQUEST)) {
if (f.contains(Flow.RESPONSE)) {
// fill left and right to same height
while (leftStack.size() < rightStack.size()) leftStack.add(null);
while (rightStack.size() < leftStack.size()) rightStack.add(null);
// put i into both
leftStack.add(i);
rightStack.add(i);
} else {
leftStack.add(i);
}
} else {
if (f.contains(Flow.RESPONSE)) {
rightStack.add(i);
}
}
}
boolean noTarget = proxy.getTargetURL() == null && proxy.getTargetHost() == null;
table().cellspacing("0px").cellpadding("0px").classAttr("spv").style("width:662px");
createListenerRow(proxy);
if (leftStack.size() > 1 || !noTarget) {
createBeginArrowsRow();
for (int i = 0; i < leftStack.size() - 1 - (noTarget ? 1 : 0); i++) {
tr().style("background:url(\"" + relativeRootPath + "/admin/images/spv-middle.png\");background-repeat:repeat-y;display:inline-table");
createInterceptorRow(leftStack, rightStack, i, false);
end();
}
createEndArrowsRow();
if (noTarget) {
tr();
createInterceptorRow(leftStack, rightStack, leftStack.size() - 2, true);
end();
} else {
createTargetRow(proxy);
}
}
end();
}
use of com.predic8.membrane.core.rules.AbstractServiceProxy in project service-proxy by membrane.
the class AdminRESTInterceptor method getProxies.
@Mapping("/admin/rest/proxies(/?\\?.*)?")
public Response getProxies(final QueryParameter params, String relativeRootPath) throws Exception {
final List<AbstractServiceProxy> proxies = getServiceProxies();
if ("order".equals(params.getString("sort"))) {
if (params.getString("order", "asc").equals("desc"))
Collections.reverse(proxies);
} else {
Collections.sort(proxies, ComparatorFactory.getAbstractServiceProxyComparator(params.getString("sort", "name"), params.getString("order", "asc")));
}
final int offset = params.getInt("offset", 0);
int max = params.getInt("max", proxies.size());
final List<AbstractServiceProxy> paginated = proxies.subList(offset, Math.min(offset + max, proxies.size()));
return json(new JSONContent() {
public void write(JsonGenerator gen) throws Exception {
gen.writeStartObject();
gen.writeArrayFieldStart("proxies");
int i = offset;
if (params.getString("order", "asc").equals("desc"))
i = proxies.size() - i + 1;
for (AbstractServiceProxy p : paginated) {
gen.writeStartObject();
gen.writeNumberField("order", i += params.getString("order", "asc").equals("desc") ? -1 : 1);
gen.writeStringField("name", p.toString());
gen.writeBooleanField("active", p.isActive());
if (!p.isActive())
gen.writeStringField("error", p.getErrorState());
gen.writeNumberField("listenPort", p.getKey().getPort());
gen.writeStringField("virtualHost", p.getKey().getHost());
gen.writeStringField("method", p.getKey().getMethod());
gen.writeStringField("path", p.getKey().getPath());
gen.writeStringField("targetHost", p.getTargetHost());
gen.writeNumberField("targetPort", p.getTargetPort());
gen.writeNumberField("count", p.getCount());
gen.writeObjectFieldStart("actions");
if (!isReadOnly()) {
gen.writeStringField("delete", "/admin/service-proxy/delete?name=" + URLEncoder.encode(RuleUtil.getRuleIdentifier(p), "UTF-8"));
}
if (!p.isActive())
gen.writeStringField("start", "/admin/service-proxy/start?name=" + URLEncoder.encode(RuleUtil.getRuleIdentifier(p), "UTF-8"));
gen.writeEndObject();
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeNumberField("total", proxies.size());
gen.writeEndObject();
}
});
}
use of com.predic8.membrane.core.rules.AbstractServiceProxy in project service-proxy by membrane.
the class RuleMatchingInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
if (exc.getRule() != null)
return Outcome.CONTINUE;
Rule rule = getRule(exc);
exc.setRule(rule);
if (exc.getRule().getSslOutboundContext() != null) {
exc.setProperty(Exchange.SSL_CONTEXT, exc.getRule().getSslOutboundContext());
}
if (rule instanceof NullRule) {
handleNoRuleFound(exc);
return Outcome.ABORT;
}
if (xForwardedForEnabled && (rule instanceof AbstractServiceProxy))
insertXForwardedFor(exc);
return Outcome.CONTINUE;
}
Aggregations