use of com.predic8.membrane.core.rules.AbstractServiceProxy in project service-proxy by membrane.
the class DispatchingInterceptor method getForwardingDestination.
public static String getForwardingDestination(Exchange exc) throws Exception {
AbstractServiceProxy p = (AbstractServiceProxy) exc.getRule();
if (p.getTargetURL() != null) {
log.debug("destination: " + p.getTargetURL());
return p.getTargetURL();
}
if (p.getTargetHost() != null) {
String url = new URL(p.getTargetScheme(), p.getTargetHost(), p.getTargetPort(), exc.getRequest().getUri()).toString();
log.debug("destination: " + url);
return url;
}
return exc.getRequest().getUri();
}
use of com.predic8.membrane.core.rules.AbstractServiceProxy in project service-proxy by membrane.
the class IndexInterceptor method getServiceInfo.
private ServiceInfo getServiceInfo(Exchange exc, AbstractServiceProxy sp) {
if (sp.getInterceptors().size() == 1 && sp.getInterceptors().get(0) instanceof IndexInterceptor)
return null;
ServiceProxyKey k = (ServiceProxyKey) sp.getKey();
ServiceInfo ri = new ServiceInfo();
ri.method = k.getMethod();
// NOTE: when running as servlet, we have no idea what the protocol was
ri.ssl = sp.getSslInboundContext() != null;
String protocol = ri.ssl ? "https" : "http";
String host = k.isHostWildcard() ? new HostColonPort(ri.ssl, exc.getRequest().getHeader().getHost()).host : fullfillRegexp(ServiceProxyKey.createHostPattern(k.getHost()));
if (host == null || host.length() == 0)
host = exc.getHandler().getLocalAddress().getHostAddress().toString();
int port = k.getPort();
if (port == -1 || !exc.getHandler().isMatchLocalPort())
port = exc.getHandler().getLocalPort();
String path;
if (!k.isUsePathPattern()) {
path = "/";
} else if (k.isPathRegExp()) {
path = fullfillRegexp(k.getPath());
} else {
path = "/" + StringUtils.removeStart(k.getPath(), "/");
}
if (!"".equals(exc.getHandler().getContextPath(exc))) {
path = StringUtils.removeEnd(exc.getHandler().getContextPath(exc), "/") + "/" + StringUtils.removeStart(path, "/");
}
ri.name = sp.getName();
if (path != null)
ri.url = protocol + "://" + host + ":" + port + path;
ri.host = k.isHostWildcard() ? "" : StringEscapeUtils.escapeHtml(k.getHost());
ri.port = k.getPort() == -1 ? "" : "" + k.getPort();
ri.path = k.isUsePathPattern() ? "<tt>" + StringEscapeUtils.escapeHtml(k.getPath()) + "</tt>" + (k.isPathRegExp() ? " (regex)" : "") : "";
return ri;
}
use of com.predic8.membrane.core.rules.AbstractServiceProxy in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleServiceProxyShowRequest.
@Mapping("/admin/service-proxy/show/?(\\?.*)?")
public Response handleServiceProxyShowRequest(final Map<String, String> params, final String relativeRootPath) throws Exception {
final StringWriter writer = new StringWriter();
final AbstractServiceProxy rule = (AbstractServiceProxy) RuleUtil.findRuleByIdentifier(router, params.get("name"));
return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {
@Override
protected int getSelectedTab() {
return TAB_ID_SERVICE_PROXIES;
}
@Override
protected String getTitle() {
return super.getTitle() + " " + rule.toString() + " ServiceProxy";
}
@Override
protected void createTabContent() throws Exception {
h1().text(rule.toString() + " ServiceProxy").end();
script().raw("$(function() {\r\n" + " $( \"#subtab\" ).tabs();\r\n" + " });").end();
div().id("subtab");
ul();
li().a().href("#tab1").text("Visualization").end(2);
li().a().href("#tab2").text("Statistics").end(2);
// li().a().href("#tab3").text("XML Configuration").end(2);
end();
div().id("tab1");
createServiceProxyVisualization(rule, relativeRootPath);
end();
div().id("tab2");
createStatusCodesTable(rule.getStatisticsByStatusCodes());
br();
createButton("View Messages", "calls", null, createQueryString("proxy", rule.toString()));
end();
end();
}
}.createPage());
}
use of com.predic8.membrane.core.rules.AbstractServiceProxy in project service-proxy by membrane.
the class EtcdRegistryApiConfig method findAdminConsole.
private EtcdNodeInformation findAdminConsole() {
Object routerObj = context.getBean(Router.class);
if (routerObj == null)
throw new RuntimeException("Router not found, cannot publish admin console");
Router router = (Router) routerObj;
for (Rule r : router.getRuleManager().getRules()) {
if (!(r instanceof AbstractServiceProxy))
continue;
for (Interceptor i : r.getInterceptors()) {
if (i instanceof AdminConsoleInterceptor) {
String name = r.getName();
String host = ((ServiceProxy) r).getExternalHostname();
if (host == null)
host = getLocalHostname();
String port = Integer.toString(((AbstractServiceProxy) r).getPort());
EtcdNodeInformation node = new EtcdNodeInformation(null, null, host, port, name);
return node;
}
}
}
throw new RuntimeException("Admin console not found but is needed. Add a service proxy with an admin console.");
}
use of com.predic8.membrane.core.rules.AbstractServiceProxy in project service-proxy by membrane.
the class TestServiceInterceptor method init.
@Override
public void init(final Router router) throws Exception {
super.init(router);
wi.init(router);
Rule r = router.getParentProxy(this);
if (r instanceof AbstractServiceProxy) {
final Path path = ((AbstractServiceProxy) r).getPath();
if (path != null) {
if (path.isRegExp())
throw new Exception("<testService> may not be used together with <path isRegExp=\"true\">.");
final String keyPath = path.getValue();
final String name = URLUtil.getName(router.getUriFactory(), keyPath);
wi.setPathRewriter(new PathRewriter() {
@Override
public String rewrite(String path2) {
try {
if (path2.contains("://")) {
path2 = new URL(new URL(path2), keyPath).toString();
} else {
Matcher m = RELATIVE_PATH_PATTERN.matcher(path2);
path2 = m.replaceAll("./" + name + "?");
}
} catch (MalformedURLException e) {
}
return path2;
}
});
}
}
}
Aggregations