Search in sources :

Example 36 with Router

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

the class ServiceInvocationTest method createRouter.

private HttpRouter createRouter() throws Exception {
    HttpRouter router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(createFirstRule());
    router.getRuleManager().addProxyAndOpenPortIfNew(createServiceRule());
    router.getTransport().getInterceptors().add(router.getTransport().getInterceptors().size() - 1, new MockInterceptor("transport-log"));
    router.init();
    return router;
}
Also used : MockInterceptor(com.predic8.membrane.core.interceptor.MockInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 37 with Router

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

the class RewriteInterceptorIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    interceptor = new RewriteInterceptor();
    interceptor.getMappings().add(new Mapping("/blz-service\\?wsdl", "/axis2/services/BLZService?wsdl", null));
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3006), "thomas-bayer.com", 80);
    rule.getInterceptors().add(interceptor);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
}
Also used : Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 38 with Router

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

the class REST2SOAPInterceptorIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3004), "www.thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    REST2SOAPInterceptor rest2SoapInt = new REST2SOAPInterceptor();
    rest2SoapInt.setMappings(getMappings());
    rule.getInterceptors().add(rest2SoapInt);
    router.init();
}
Also used : Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 39 with Router

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

the class MyApplication method main.

public static void main(String[] args) throws Exception {
    System.out.println("Starting up");
    // create a new service proxy that listens on port 8080 and has a target to localhost:2001
    ServiceProxy sp = createServiceProxy();
    // create an enclosing WebSocket interceptor to add our own Logging interceptor to it
    WebSocketInterceptor ws = new WebSocketInterceptor();
    ws.getInterceptors().add(new MyWebSocketLogInterceptor());
    // attach the WebSocket interceptor to the service proxy
    sp.getInterceptors().add(ws);
    // add the service proxy to a new router instance and start it
    HttpRouter router = new HttpRouter();
    router.add(sp);
    router.init();
    System.out.println("Starting finished - Waiting for WebSocket communication");
}
Also used : ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) WebSocketInterceptor(com.predic8.membrane.core.interceptor.tunnel.WebSocketInterceptor) MyWebSocketLogInterceptor(com.predic8.membrane.core.interceptor.websocket.custom.MyWebSocketLogInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 40 with Router

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

the class TestServiceInterceptor method init.

@Override
public void init(final Router router) throws Exception {
    super.init(router);
    wi.init(router);
    Rule r = router.getParentProxy(this);
    if (r instanceof AbstractServiceProxy) {
        final Path path = ((AbstractServiceProxy) r).getPath();
        if (path != null) {
            if (path.isRegExp())
                throw new Exception("<testService> may not be used together with <path isRegExp=\"true\">.");
            final String keyPath = path.getValue();
            final String name = URLUtil.getName(router.getUriFactory(), keyPath);
            wi.setPathRewriter(new PathRewriter() {

                @Override
                public String rewrite(String path2) {
                    try {
                        if (path2.contains("://")) {
                            path2 = new URL(new URL(path2), keyPath).toString();
                        } else {
                            Matcher m = RELATIVE_PATH_PATTERN.matcher(path2);
                            path2 = m.replaceAll("./" + name + "?");
                        }
                    } catch (MalformedURLException e) {
                    }
                    return path2;
                }
            });
        }
    }
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) Path(com.predic8.membrane.core.config.Path) MalformedURLException(java.net.MalformedURLException) PathRewriter(com.predic8.membrane.core.ws.relocator.Relocator.PathRewriter) Matcher(java.util.regex.Matcher) Rule(com.predic8.membrane.core.rules.Rule) MalformedURLException(java.net.MalformedURLException) SAXParseException(org.xml.sax.SAXParseException) URL(java.net.URL)

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