Search in sources :

Example 41 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class GroovyInterceptor method logGroovyException.

private void logGroovyException(Flow flow, Exception e) {
    try {
        ServiceProxy sp = getRule();
        log.error("Exception in Groovy script in service proxy '" + sp.getName() + "' on port " + sp.getPort() + " with path " + (sp.getPath() != null ? sp.getPath().getValue() : "*"));
        if (flow != null)
            log.error("Flow: " + flow.name());
        else
            log.error("There is possibly a syntax error in the groovy script (compilation error)");
    } catch (NoSuchElementException e2) {
    // ignore - logging should not break anything
    } finally {
        e.printStackTrace();
    }
}
Also used : ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) NoSuchElementException(java.util.NoSuchElementException)

Example 42 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class DefaultConfigTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getMembraneHome();
    File proxies = new File(baseDir, "conf/proxies.xml");
    File proxiesFull = new File(baseDir, "conf/proxies-full-sample.xml");
    replaceInFile(proxies, "9000", "2003");
    replaceInFile(proxiesFull, "9000", "2003");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        setupHTTPAuthentication("localhost", 2003, "admin", "membrane");
        assertContains("Membrane Service Proxy Administration", getAndAssert200("http://localhost:2003/admin/"));
        ProxiesXmlUtil pxu = new ProxiesXmlUtil(proxies);
        pxu.updateWith(FileUtils.readFileToString(proxiesFull), sl);
        setupHTTPAuthentication("localhost", 2001, "admin", "membrane");
        assertContains("Routing Configuration", getAndAssert200("http://localhost:2001/static/proxies.xml"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) ProxiesXmlUtil(com.predic8.membrane.examples.ProxiesXmlUtil) AssertUtils.replaceInFile(com.predic8.membrane.test.AssertUtils.replaceInFile) File(java.io.File) Test(org.junit.Test)

Example 43 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class CBRTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("cbr");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        String result = postAndAssert200("http://localhost:2000/shop", FileUtils.readFileToString(new File(baseDir, "order.xml")));
        assertContains("Normal order received.", result);
        result = postAndAssert200("http://localhost:2000/shop", FileUtils.readFileToString(new File(baseDir, "express.xml")));
        assertContains("Express order received.", result);
        result = postAndAssert200("http://localhost:2000/shop", FileUtils.readFileToString(new File(baseDir, "import.xml")));
        assertContains("Order contains import items.", result);
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 44 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class LoadBalancerBasic1Test method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-basic-1");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:4000/"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:4001/"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:4002/"));
        addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4000);
        addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4001);
        Thread.sleep(1000);
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        getAndAssert(204, "http://localhost:9010/clustermanager/up?host=localhost&port=4002");
        AssertUtils.assertContains("localhost:4002", getAndAssert200("http://localhost:9000/admin/clusters/show?cluster=Default"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 45 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class LoadBalancerClient2Test method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-client-2");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
    AssertUtils.replaceInFile(new File(base, "lb-client-secured.proxies.xml"), "8080", "3023");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:4000/"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:4001/"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:4002/"));
        addNodeViaScript(base, "localhost", 4000);
        Thread.sleep(1000);
        assertNodeStatus(getAndAssert200("http://localhost:9000/admin/clusters/show?cluster=Default"), "localhost", 4000, "UP");
        addNodeViaScript(base, "localhost", 4001);
        addNodeViaScript(base, "localhost", 4002);
        Thread.sleep(100);
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        removeNodeViaScript(base, "localhost", 4000);
        Thread.sleep(100);
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
    } finally {
        sl.killScript();
    }
    sl = new Process2.Builder().in(base).script("service-proxy-secured").waitForMembrane().start();
    try {
        // 1 indicates failure
        controlNodeViaScript(1, base, "up", "localhost", 4000);
        File propFile = new File(base, "client.properties");
        writeStringToFile(propFile, readFileToString(propFile).replace("#", ""));
        Thread.sleep(1000);
        addNodeViaScript(base, "localhost", 4000);
        Thread.sleep(1000);
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "admin");
        AssertUtils.assertContains("localhost:4000", getAndAssert200("http://localhost:9000/admin/clusters/show?cluster=Default"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)39 Process2 (com.predic8.membrane.examples.Process2)35 File (java.io.File)29 StringWriter (java.io.StringWriter)5 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)4 Rule (com.predic8.membrane.core.rules.Rule)4 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 HttpRouter (com.predic8.membrane.core.HttpRouter)3 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)3 BufferLogger (com.predic8.membrane.examples.util.BufferLogger)3 SubstringWaitableConsoleEvent (com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent)3 Definitions (com.predic8.wsdl.Definitions)3 Port (com.predic8.wsdl.Port)3 Service (com.predic8.wsdl.Service)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Exchange (com.predic8.membrane.core.exchange.Exchange)2 Request (com.predic8.membrane.core.http.Request)2 Response (com.predic8.membrane.core.http.Response)2