Search in sources :

Example 21 with Interceptor

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

the class AdminPageBuilder method createInterceptorVisualization.

private void createInterceptorVisualization(Interceptor i, int columnSpan, String id, boolean noMarginTop) {
    td().style("padding:0px;");
    if (columnSpan > 1)
        colspan("" + columnSpan);
    if (i == null) {
        div().style("padding:2px 5px; margin: 10px; width: 299px;");
        raw(" ");
        end();
    } else {
        String shortDescription = i.getShortDescription();
        String longDescription = i.getLongDescription();
        boolean same = longDescription.equals(shortDescription);
        if (!TextUtil.isValidXMLSnippet(shortDescription)) {
            shortDescription = StringEscapeUtils.escapeHtml(shortDescription).replace("\n", "<br/>");
            if (same)
                longDescription = shortDescription;
        }
        if (!same && !TextUtil.isValidXMLSnippet(longDescription)) {
            longDescription = StringEscapeUtils.escapeHtml(longDescription).replace("\n", "<br/>");
        }
        shortDescription = shortDescription.replaceAll("\"/admin", "\"" + relativeRootPath + "/admin");
        longDescription = longDescription.replaceAll("\"/admin", "\"" + relativeRootPath + "/admin");
        String did = "d" + id;
        div().id(did).style("border: 1px solid black; padding:8px 5px; margin: 10px;overflow-x: auto; background-color: #FFC04F;" + (columnSpan == 1 ? "width: 299px;" : "width: 630px;") + (noMarginTop ? "margin-top: 0px;" : ""));
        String iid = "i" + id;
        div().id("i" + id);
        createHelpIcon(i, id);
        if (shortDescription.length() > 0 && !longDescription.equals(shortDescription)) {
            createExpandIcon(i, id);
        }
        end();
        createShowIconsScript(did, iid);
        div().classAttr("name");
        text(i.getDisplayName());
        end();
        if (shortDescription.length() > 0) {
            div().style("padding-top: 4px;");
            String sid = "s" + id;
            div().id(sid);
            raw(shortDescription);
            if (!longDescription.equals(shortDescription)) {
                String aid = "a" + id;
                String lid = "l" + id;
                String eid = "e" + id;
                String cid = "c" + id;
                a().id(aid).href("#").text("...").end();
                end();
                div().id(lid).style("margin: 0px;");
                raw(longDescription);
                end();
                script();
                raw("jQuery(document).ready(function() {\r\n" + "  jQuery(\"#" + eid + "\").css('cursor', 'pointer');\r\n" + "  jQuery(\"#" + cid + "\").css('cursor', 'pointer');\r\n" + "  jQuery(\"#" + lid + "\").hide();\r\n" + "  jQuery(\"#" + cid + "\").hide();\r\n" + "  jQuery(\"#" + eid + "\").click(function()\r\n" + "  {\r\n" + "    jQuery(\"#" + sid + "\").hide();\r\n" + "    jQuery(\"#" + lid + "\").slideToggle(500);\r\n" + "    jQuery(\"#" + eid + "\").hide();\r\n" + "    jQuery(\"#" + cid + "\").show();\r\n" + "  });\r\n" + "  jQuery(\"#" + aid + "\").click(function()\r\n" + "  {\r\n" + "    jQuery(\"#" + sid + "\").hide();\r\n" + "    jQuery(\"#" + lid + "\").slideToggle(500);\r\n" + "    jQuery(\"#" + eid + "\").hide();\r\n" + "    jQuery(\"#" + cid + "\").show();\r\n" + "  });\r\n" + "  jQuery(\"#" + cid + "\").click(function()\r\n" + "  {\r\n" + "    jQuery(\"#" + sid + "\").show();\r\n" + "    jQuery(\"#" + lid + "\").slideToggle(500);\r\n" + "    jQuery(\"#" + cid + "\").hide();\r\n" + "    jQuery(\"#" + eid + "\").show();\r\n" + "  });\r\n" + "});\r\n" + "</script>\r\n" + "\r\n" + "");
            }
            end();
            end();
        }
        end();
    }
    end();
}
Also used : URLParamUtil.createQueryString(com.predic8.membrane.core.util.URLParamUtil.createQueryString)

Example 22 with Interceptor

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

the class BasicAuthenticationInterceptorIntegrationTest method setup.

@Before
public void setup() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3001), "thomas-bayer.com", 80);
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    BasicAuthenticationInterceptor interceptor = new BasicAuthenticationInterceptor();
    List<User> users = new ArrayList<User>();
    users.add(new User("admin", "admin"));
    interceptor.setUsers(users);
    router.addUserFeatureInterceptor(interceptor);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) User(com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ArrayList(java.util.ArrayList) Rule(com.predic8.membrane.core.rules.Rule) Before(org.junit.Before)

Example 23 with Interceptor

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

the class ClusterNotificationInterceptorTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3002), "thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    interceptor = new ClusterNotificationInterceptor();
    router.addUserFeatureInterceptor(interceptor);
    lbi = new LoadBalancingInterceptor();
    lbi.setName("Default");
    Rule rule2 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3003), "thomas-bayer.com", 80);
    router.getRuleManager().addProxyAndOpenPortIfNew(rule2);
    rule2.getInterceptors().add(lbi);
    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 24 with Interceptor

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

the class FormValidationInterceptorTest method testValidation.

@Test
public void testValidation() throws Exception {
    FormValidationInterceptor interceptor = new FormValidationInterceptor();
    interceptor.init(new HttpRouter());
    Field article = new Field();
    article.setName("article");
    article.setRegex("banana|apple");
    Field amount = new Field();
    amount.setName("amount");
    amount.setRegex("\\d+");
    List<Field> fields = new ArrayList<Field>();
    fields.add(amount);
    fields.add(article);
    interceptor.setFields(fields);
    Exchange exc = getExchange("/buy?article=pizza&amount=five");
    assertEquals(Outcome.ABORT, interceptor.handleRequest(exc));
    assertEquals(400, exc.getResponse().getStatusCode());
    exc = getExchange("/buy?article=pizza&amount=2");
    assertEquals(Outcome.ABORT, interceptor.handleRequest(exc));
    assertEquals(400, exc.getResponse().getStatusCode());
    exc = getExchange("/buy?article=banana&amount=five");
    assertEquals(Outcome.ABORT, interceptor.handleRequest(exc));
    assertEquals(400, exc.getResponse().getStatusCode());
    exc = getExchange("/buy?article=banana&amount=5");
    assertEquals(Outcome.CONTINUE, interceptor.handleRequest(exc));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Field(com.predic8.membrane.core.interceptor.formvalidation.FormValidationInterceptor.Field) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 25 with Interceptor

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

Aggregations

Interceptor (com.predic8.membrane.core.interceptor.Interceptor)11 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)6 Test (org.junit.Test)6 HttpRouter (com.predic8.membrane.core.HttpRouter)5 Rule (com.predic8.membrane.core.rules.Rule)5 Before (org.junit.Before)5 Exchange (com.predic8.membrane.core.exchange.Exchange)4 ArrayList (java.util.ArrayList)4 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 ResolverMap (com.predic8.membrane.core.resolver.ResolverMap)3 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)3 Response (com.predic8.membrane.core.http.Response)2 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)2 DispatchingInterceptor (com.predic8.membrane.core.interceptor.DispatchingInterceptor)2 HTTPClientInterceptor (com.predic8.membrane.core.interceptor.HTTPClientInterceptor)2 RuleMatchingInterceptor (com.predic8.membrane.core.interceptor.RuleMatchingInterceptor)2 UserFeatureInterceptor (com.predic8.membrane.core.interceptor.UserFeatureInterceptor)2 AccessControlInterceptor (com.predic8.membrane.core.interceptor.acl.AccessControlInterceptor)2 User (com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User)2 RequestInterceptor (com.predic8.membrane.core.interceptor.flow.RequestInterceptor)2