Search in sources :

Example 36 with Rule

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

the class HeaderFilterInterceptorTest method doit.

@Test
public void doit() throws Exception {
    Exchange exc = new Exchange(null);
    exc.setResponse(Response.ok().header("a", "b").header("c", "d").header("c", "d2").header("e", "f").build());
    HeaderFilterInterceptor fhi = new HeaderFilterInterceptor();
    fhi.setRules(Lists.newArrayList(new Rule[] { // implicitly set by Response.ok()
    new Rule("Server", Action.REMOVE), new Rule("a", Action.KEEP), new Rule("c.*", Action.REMOVE) }));
    fhi.handleResponse(exc);
    HeaderField[] h = exc.getResponse().getHeader().getAllHeaderFields();
    assertEquals(3, h.length);
    assertEquals("Content-Length", h[0].getHeaderName().toString());
    assertEquals("a", h[1].getHeaderName().toString());
    assertEquals("e", h[2].getHeaderName().toString());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) HeaderField(com.predic8.membrane.core.http.HeaderField) Rule(com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule) Test(org.junit.Test)

Example 37 with Rule

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

the class RegExReplaceInterceptorTest method testReplace.

@Test
public void testReplace() throws Exception {
    router = Router.init("src/test/resources/regex-monitor-beans.xml");
    Rule serverRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3009), "www.predic8.de", 80);
    router.getRuleManager().addProxyAndOpenPortIfNew(serverRule);
    router.init();
    try {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod("http://localhost:3009");
        method.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8);
        method.setRequestHeader(Header.SOAP_ACTION, "");
        assertEquals(200, client.executeMethod(method));
        assertTrue(new String(method.getResponseBody()).contains("Membrane RegEx Replacement Is Cool"));
    } finally {
        router.shutdown();
    }
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Rule(com.predic8.membrane.core.rules.Rule) Test(org.junit.Test)

Example 38 with Rule

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

the class AccessControlInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    router = new HttpRouter();
    interceptor = new AccessControlInterceptor();
    interceptor.setFile("classpath:/acl/acl.xml");
    Rule rule4000 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 4000), "oio.de", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule4000);
    router.addUserFeatureInterceptor(interceptor);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) Before(org.junit.Before)

Example 39 with Rule

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

the class MethodTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 4000), "oio.de", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) Before(org.junit.Before)

Example 40 with Rule

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

the class ReadRulesWithInterceptorsConfigurationTest method testRuleInterceptorSize.

@Test
public void testRuleInterceptorSize() throws Exception {
    Rule rule = rules.get(0);
    assertEquals(1, rule.getInterceptors().size());
}
Also used : Rule(com.predic8.membrane.core.rules.Rule) Test(org.junit.Test)

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