use of com.predic8.membrane.core.rules.Rule 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.Rule in project service-proxy by membrane.
the class RuleManager method openPorts.
public synchronized void openPorts() throws IOException {
HashMap<IpPort, SSLProvider> sslProviders;
try {
HashMap<IpPort, SSLContextCollection.Builder> sslContexts = new HashMap<IpPort, SSLContextCollection.Builder>();
for (Rule rule : rules) {
SSLContext sslContext = rule.getSslInboundContext();
if (sslContext != null) {
IpPort ipPort = new IpPort(rule.getKey().getIp(), rule.getKey().getPort());
SSLContextCollection.Builder builder = sslContexts.get(ipPort);
if (builder == null) {
builder = new SSLContextCollection.Builder();
sslContexts.put(ipPort, builder);
}
builder.add(sslContext);
}
}
sslProviders = new HashMap<IpPort, SSLProvider>();
for (Map.Entry<IpPort, SSLContextCollection.Builder> entry : sslContexts.entrySet()) sslProviders.put(entry.getKey(), entry.getValue().build());
} catch (ConfigurationException e) {
throw new IOException(e);
}
for (Rule rule : rules) {
IpPort ipPort = new IpPort(rule.getKey().getIp(), rule.getKey().getPort());
router.getTransport().openPort(rule.getKey().getIp(), rule.getKey().getPort(), sslProviders.get(ipPort));
}
}
use of com.predic8.membrane.core.rules.Rule 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.Rule 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.Rule in project service-proxy by membrane.
the class RESTBLZServiceIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3005), "thomas-bayer.com", 80);
router = new HttpRouter();
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
HTTP2XMLInterceptor http2xml = new HTTP2XMLInterceptor();
router.getTransport().getInterceptors().add(http2xml);
RewriteInterceptor urlRewriter = new RewriteInterceptor();
List<Mapping> mappings = new ArrayList<Mapping>();
mappings.add(new Mapping("/bank/.*", "/axis2/services/BLZService", null));
urlRewriter.setMappings(mappings);
router.getTransport().getInterceptors().add(urlRewriter);
XSLTInterceptor xslt = new XSLTInterceptor();
xslt.setXslt("classpath:/blz-httpget2soap-request.xsl");
xslt.setFlow(Flow.Set.REQUEST);
xslt.setXslt("classpath:/strip-soap-envelope.xsl");
xslt.setFlow(Flow.Set.RESPONSE);
router.getTransport().getInterceptors().add(xslt);
}
Aggregations