Search in sources :

Example 61 with Router

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

the class MembraneServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    try {
        appCtx = new BaseLocationXmlWebApplicationContext();
        log.debug("loading beans configuration from: " + getProxiesXmlLocation(config));
        router = RouterUtil.initializeRoutersFromSpringWebContext(appCtx, config.getServletContext(), getProxiesXmlLocation(config));
        if (router == null)
            throw new RuntimeException("No <router> with a <servletTransport> was found. To use <router> with <transport>, use MembraneServletContextListener instead of MembraneServlet.");
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) BaseLocationXmlWebApplicationContext(com.predic8.membrane.servlet.config.spring.BaseLocationXmlWebApplicationContext) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 62 with Router

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

the class QuickstartRESTTest method doit.

@Test
public void doit() throws IOException, InterruptedException {
    File baseDir = getExampleDir("quickstart-rest");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        String result = getAndAssert200("http://localhost:2000/restnames/name.groovy?name=Pia");
        assertContains("Italy", result);
        AssertUtils.closeConnections();
        new ProxiesXmlUtil(new File(baseDir, "proxies.xml")).updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "\r\n" + "       <serviceProxy name=\"names\" port=\"2000\">\r\n" + "         <path isRegExp=\"true\">/(rest)?names.*</path>\r\n" + "         <rewriter>\r\n" + "           <map from=\"/names/(.*)\" to=\"/restnames/name\\.groovy\\?name=$1\" />\r\n" + "         </rewriter>\r\n" + "         <statisticsCSV file=\"log.csv\" />\r\n" + "         <response>\r\n" + "           <regExReplacer regex=\"\\s*,\\s*&lt;\" replace=\"&lt;\" />\r\n" + "           <transform xslt=\"restnames.xsl\" />\r\n" + "         </response>\r\n" + "         <target host=\"thomas-bayer.com\" port=\"80\" />\r\n" + "       </serviceProxy>\r\n" + "     \r\n" + "       <serviceProxy name=\"Console\" port=\"9000\">\r\n" + "         <basicAuthentication>\r\n" + "           <user name=\"alice\" password=\"membrane\" />\r\n" + "         </basicAuthentication>			\r\n" + "         <adminConsole />\r\n" + "       </serviceProxy>	\r\n" + "     </router>\r\n" + "</spring:beans>", sl);
        result = getAndAssert200("http://localhost:2000/names/Pia");
        assertContains("Italy, Spain", result);
        assertContainsNot(",<", result);
        String csvLog = FileUtils.readFileToString(new File(baseDir, "log.csv"));
        assertContains("Pia", csvLog);
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "alice", "membrane");
        result = getAndAssert200("http://localhost:9000/admin/");
        assertContains("ServiceProxies", result);
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) ProxiesXmlUtil(com.predic8.membrane.examples.ProxiesXmlUtil) File(java.io.File) Test(org.junit.Test)

Example 63 with Router

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

the class AbstractProxy method init.

/**
 * Called after parsing is complete and this has been added to the object tree (whose root is Router).
 */
public final void init(Router router) throws Exception {
    this.router = router;
    try {
        init();
        for (Interceptor i : interceptors) i.init(router);
        active = true;
    } catch (Exception e) {
        if (!router.isRetryInit())
            throw e;
        log.error("", e);
        active = false;
        error = e.getMessage();
    }
}
Also used : Interceptor(com.predic8.membrane.core.interceptor.Interceptor)

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