Search in sources :

Example 6 with Port

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

the class QuickstartSOAPTest method doit.

@Test
public void doit() throws IOException, InterruptedException {
    File baseDir = getExampleDir("quickstart-soap");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        ProxiesXmlUtil pxu = new ProxiesXmlUtil(new File(baseDir, "proxies.xml"));
        pxu.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" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        String endpoint = "http://localhost:2000/MyBLZService";
        String result = getAndAssert200(endpoint + "?wsdl");
        assertContains("wsdl:documentation", result);
        // assert that rewriting did take place
        assertContains("localhost:2000/MyBLZService", result);
        result = AssertUtils.postAndAssert200(endpoint, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + "   <soapenv:Header/>\r\n" + "   <soapenv:Body>\r\n" + "      <blz:getBank>\r\n" + "         <blz:blz>37050198</blz:blz>\r\n" + "      </blz:getBank>\r\n" + "   </soapenv:Body>\r\n" + "</soapenv:Envelope>");
        assertContains("Sparkasse", result);
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        result = getAndAssert200("http://localhost:9000/admin/");
        result.contains("BLZService");
        String invalidRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + "   <soapenv:Header/>\r\n" + "   <soapenv:Body>\r\n" + "      <blz:getBank>\r\n" + "         <blz:blz>37050198</blz:blz>\r\n" + "         <foo />\r\n" + "      </blz:getBank>\r\n" + "   </soapenv:Body>\r\n" + "</soapenv:Envelope>";
        result = postAndAssert(500, endpoint, invalidRequest);
        assertContains(".java:", result);
        AssertUtils.closeConnections();
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        pxu.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" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = postAndAssert(500, endpoint, invalidRequest);
        assertContainsNot(".java:", result);
        AssertUtils.closeConnections();
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        pxu.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" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "		<validator/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = postAndAssert(400, endpoint, invalidRequest);
        assertContains("Validation failed", result);
        result = getAndAssert200("http://localhost:9000/admin/service-proxy/show?name=BLZService%3A2000");
        result.contains("1 of 1 messages have been invalid");
        result = getAndAssert200(endpoint);
        assertContains("Target Namespace", result);
        result = getAndAssert200(endpoint + "/operation/BLZServiceSOAP11Binding/BLZServicePortType/getBank");
        assertContains("blz&gt;?XXX?", result);
        AssertUtils.closeConnections();
        pxu.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" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "		<validator/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"2000\">\r\n" + "		<index />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = getAndAssert200("http://localhost:2000");
        assertContains("/MyBLZService", 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 7 with Port

use of com.predic8.wsdl.Port 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;
}
Also used : RuleKey(com.predic8.membrane.core.rules.RuleKey) Rule(com.predic8.membrane.core.rules.Rule)

Example 8 with Port

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

the class DynamicAdminPageInterceptor method handleNodeSessionsRequest.

@Mapping("/admin/node/sessions/?(\\?.*)?")
public Response handleNodeSessionsRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
    StringWriter writer = new StringWriter();
    return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {

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

        @Override
        protected void createTabContent() throws Exception {
            h2().text("Node " + params.get("host") + ":" + params.get("port")).end();
            h3().text("Sessions").end();
            createSessionsTable(BalancerUtil.lookupBalancer(router, getBalancerParam(params)).getSessionsByNode(params.get("cluster"), new Node(params.get("host"), Integer.parseInt(params.get("port")))));
        }
    }.createPage());
}
Also used : StringWriter(java.io.StringWriter) Node(com.predic8.membrane.core.interceptor.balancer.Node)

Example 9 with Port

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

the class EtcdRegistryApiConfig method publishToEtcd.

private boolean publishToEtcd() {
    String baseKey = baseKeyPrefix + membraneId;
    EtcdResponse respPublishApiUrl = EtcdRequest.create(url, baseKey, "/apiconfig").setValue("url", "").sendRequest();
    if (!respPublishApiUrl.is2XX()) {
        System.out.println(respPublishApiUrl.getBody());
        return false;
    }
    EtcdResponse respPublishApiFingerprint = EtcdRequest.create(url, baseKey, "/apiconfig").setValue("fingerprint", "").sendRequest();
    if (!respPublishApiFingerprint.is2XX()) {
        System.out.println(respPublishApiFingerprint.getBody());
        return false;
    }
    EtcdNodeInformation adminConsole = findAdminConsole();
    EtcdResponse respPublishEndpointName = EtcdRequest.create(url, baseKey, "/endpoint").setValue("name", adminConsole.getName()).sendRequest();
    if (!respPublishEndpointName.is2XX()) {
        System.out.println(respPublishEndpointName.getBody());
        return false;
    }
    EtcdResponse respPublishEndpointHost = EtcdRequest.create(url, baseKey, "/endpoint").setValue("host", adminConsole.getTargetHost()).sendRequest();
    if (!respPublishEndpointHost.is2XX()) {
        System.out.println(respPublishEndpointHost.getBody());
        return false;
    }
    EtcdResponse respPublishEndpointPort = EtcdRequest.create(url, baseKey, "/endpoint").setValue("port", adminConsole.getTargetPort()).sendRequest();
    if (!respPublishEndpointPort.is2XX()) {
        System.out.println(respPublishEndpointPort.getBody());
        return false;
    }
    return true;
}
Also used : EtcdNodeInformation(com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation) EtcdResponse(com.predic8.membrane.core.cloud.etcd.EtcdResponse)

Example 10 with Port

use of com.predic8.wsdl.Port 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.");
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) AdminConsoleInterceptor(com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) EtcdNodeInformation(com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation) Router(com.predic8.membrane.core.Router) Rule(com.predic8.membrane.core.rules.Rule) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) AdminConsoleInterceptor(com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor)

Aggregations

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)9 Test (org.junit.Test)7 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)6 StringWriter (java.io.StringWriter)6 Exchange (com.predic8.membrane.core.exchange.Exchange)5 Rule (com.predic8.membrane.core.rules.Rule)5 Process2 (com.predic8.membrane.examples.Process2)5 File (java.io.File)5 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)4 HttpRouter (com.predic8.membrane.core.HttpRouter)3 Request (com.predic8.membrane.core.http.Request)3 Response (com.predic8.membrane.core.http.Response)3 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Definitions (com.predic8.wsdl.Definitions)3 Port (com.predic8.wsdl.Port)3 ArrayList (java.util.ArrayList)3 EtcdNodeInformation (com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation)2 IPortChangeListener (com.predic8.membrane.core.model.IPortChangeListener)2 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)2