Search in sources :

Example 56 with Router

use of com.predic8.membrane.core.Router in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleServiceProxyStartRequest.

@Mapping("/admin/service-proxy/start/?(\\?.*)?")
public Response handleServiceProxyStartRequest(Map<String, String> params, String relativeRootPath) throws Exception {
    if (readOnly)
        return createReadOnlyErrorResponse();
    Rule rule = RuleUtil.findRuleByIdentifier(router, params.get("name"));
    Rule newRule = rule.clone();
    router.getRuleManager().replaceRule(rule, newRule);
    return respond(getServiceProxyPage(params, relativeRootPath));
}
Also used : ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Example 57 with Router

use of com.predic8.membrane.core.Router in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handlePruleShowRequest.

@Mapping("/admin/proxy/show/?(\\?.*)?")
public Response handlePruleShowRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
    StringWriter writer = new StringWriter();
    final ProxyRule rule = (ProxyRule) RuleUtil.findRuleByIdentifier(router, params.get("name"));
    return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {

        @Override
        protected int getSelectedTab() {
            return TAB_ID_PROXIES;
        }

        @Override
        protected String getTitle() {
            return super.getTitle() + " " + rule.toString() + " Proxy";
        }

        @Override
        protected void createTabContent() throws Exception {
            h1().text(rule.toString() + " Proxy").end();
            if (rule.getKey().getPort() != -1) {
                table();
                createTr("Listen Port", "" + rule.getKey().getPort());
                end();
            }
            h2().text("Status Codes").end();
            createStatusCodesTable(rule.getStatisticsByStatusCodes());
            h2().text("Interceptors").end();
            createInterceptorTable(rule.getInterceptors());
        }
    }.createPage());
}
Also used : StringWriter(java.io.StringWriter) ProxyRule(com.predic8.membrane.core.rules.ProxyRule)

Example 58 with Router

use of com.predic8.membrane.core.Router in project service-proxy by membrane.

the class ConditionalInterceptor method init.

@Override
public void init(Router router) throws Exception {
    super.init(router);
    LanguageSupport ls = new GroovyLanguageSupport();
    condition = ls.compileExpression(router, test);
}
Also used : LanguageSupport(com.predic8.membrane.core.lang.LanguageSupport) GroovyLanguageSupport(com.predic8.membrane.core.lang.groovy.GroovyLanguageSupport) GroovyLanguageSupport(com.predic8.membrane.core.lang.groovy.GroovyLanguageSupport)

Example 59 with Router

use of com.predic8.membrane.core.Router in project service-proxy by membrane.

the class CoreActivator method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    if (new File("configuration/log4j.properties").exists())
        PropertyConfigurator.configure("configuration/log4j.properties");
    Platform.addLogListener(logListener);
    final MembraneCommandLine cl = new MembraneCommandLine();
    cl.parse(fixArguments(Platform.getCommandLineArgs()));
    if (cl.hasConfiguration()) {
        log.info("loading monitor beans from command line argument: " + getConfigurationFileName(cl));
        router = Router.init(getConfigurationFileName(cl), this.getClass().getClassLoader());
    } else {
        try {
            if (ClassloaderUtil.fileExists(getConfigurationFileName())) {
                log.info("Eclipse framework found config file: " + getConfigurationFileName());
                readBeanConfigWhenStartedAsProduct();
            } else {
                readBeanConfigWhenStartedInEclipse();
            }
        } catch (Exception e1) {
            log.error("Unable to read bean configuration file: " + e1.getMessage());
            log.error("Unable to read bean configuration file: " + e1.getStackTrace());
            e1.printStackTrace();
        }
    }
    sr = context.registerService(router.getClass().getName(), router, null);
}
Also used : MembraneCommandLine(com.predic8.membrane.core.MembraneCommandLine) File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 60 with Router

use of com.predic8.membrane.core.Router in project service-proxy by membrane.

the class RouterUtil method initializeRoutersFromSpringWebContext.

public static Router initializeRoutersFromSpringWebContext(XmlWebApplicationContext appCtx, final ServletContext ctx, String configLocation) {
    appCtx.setServletContext(ctx);
    appCtx.setConfigLocation(configLocation);
    appCtx.refresh();
    Collection<Router> routers = appCtx.getBeansOfType(Router.class).values();
    Router theOne = null;
    for (Router r : routers) {
        r.getResolverMap().addSchemaResolver(new FileSchemaWebAppResolver(ctx));
        if (r.getTransport() instanceof ServletTransport) {
            if (theOne != null)
                throw new RuntimeException("Only one <router> may have a <servletTransport> defined.");
            theOne = r;
        }
    }
    appCtx.start();
    return theOne;
}
Also used : Router(com.predic8.membrane.core.Router) ServletTransport(com.predic8.membrane.servlet.embedded.ServletTransport)

Aggregations

HttpRouter (com.predic8.membrane.core.HttpRouter)24 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)21 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)19 Before (org.junit.Before)18 Rule (com.predic8.membrane.core.rules.Rule)16 IOException (java.io.IOException)9 Router (com.predic8.membrane.core.Router)8 Exchange (com.predic8.membrane.core.exchange.Exchange)6 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)5 Outcome (com.predic8.membrane.core.interceptor.Outcome)5 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)5 StringWriter (java.io.StringWriter)5 Test (org.junit.Test)5 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)3 ProxyRuleKey (com.predic8.membrane.core.rules.ProxyRuleKey)3 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)3 File (java.io.File)3