Search in sources :

Example 26 with Rule

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

the class ServiceInvocationTest method createFirstRule.

private ServiceProxy createFirstRule() {
    ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost", Request.METHOD_POST, "*", 3016), "thomas-bayer.com", 80);
    rule.setTargetURL("service:log");
    rule.getInterceptors().add(new MockInterceptor("process"));
    return rule;
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) MockInterceptor(com.predic8.membrane.core.interceptor.MockInterceptor)

Example 27 with Rule

use of com.predic8.membrane.core.rules.Rule 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 28 with Rule

use of com.predic8.membrane.core.rules.Rule 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 29 with Rule

use of com.predic8.membrane.core.rules.Rule 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)

Example 30 with Rule

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

the class HeaderFilterInterceptor method handleMessage.

private void handleMessage(Message msg) {
    if (msg == null)
        return;
    Header h = msg.getHeader();
    if (h == null)
        return;
    for (HeaderField hf : h.getAllHeaderFields()) for (Rule r : rules) if (r.matches(hf.getHeaderName().toString())) {
        switch(r.getAction()) {
            case REMOVE:
                log.debug("Removing HTTP header " + hf.getHeaderName().toString());
                h.remove(hf);
                break;
            case KEEP:
                break;
        }
        break;
    }
}
Also used : Header(com.predic8.membrane.core.http.Header) HeaderField(com.predic8.membrane.core.http.HeaderField)

Aggregations

Rule (com.predic8.membrane.core.rules.Rule)29 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)15 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)13 HttpRouter (com.predic8.membrane.core.HttpRouter)11 Before (org.junit.Before)8 IRuleChangeListener (com.predic8.membrane.core.model.IRuleChangeListener)6 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)6 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)5 Exchange (com.predic8.membrane.core.exchange.Exchange)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)2 HeaderField (com.predic8.membrane.core.http.HeaderField)2 MockInterceptor (com.predic8.membrane.core.interceptor.MockInterceptor)2 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)2 IExchangesStoreListener (com.predic8.membrane.core.model.IExchangesStoreListener)2 NullRule (com.predic8.membrane.core.rules.NullRule)2 SOAPProxy (com.predic8.membrane.core.rules.SOAPProxy)2 StringWriter (java.io.StringWriter)2 CacheBuilder (com.google.common.cache.CacheBuilder)1