Search in sources :

Example 21 with Service

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

the class XMLValidationTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("validation" + File.separator + "xml");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        String url = "http://localhost:2000/";
        postAndAssert(200, url, readFileToString(new File(baseDir, "year.xml")));
        postAndAssert(400, url, readFileToString(new File(baseDir, "invalid-year.xml")));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) File(java.io.File) Test(org.junit.Test)

Example 22 with Service

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

the class DynamicAdminPageInterceptor method handleServiceProxyShowRequest.

@Mapping("/admin/service-proxy/show/?(\\?.*)?")
public Response handleServiceProxyShowRequest(final Map<String, String> params, final String relativeRootPath) throws Exception {
    final StringWriter writer = new StringWriter();
    final AbstractServiceProxy rule = (AbstractServiceProxy) RuleUtil.findRuleByIdentifier(router, params.get("name"));
    return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {

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

        @Override
        protected String getTitle() {
            return super.getTitle() + " " + rule.toString() + " ServiceProxy";
        }

        @Override
        protected void createTabContent() throws Exception {
            h1().text(rule.toString() + " ServiceProxy").end();
            script().raw("$(function() {\r\n" + "					$( \"#subtab\" ).tabs();\r\n" + "				});").end();
            div().id("subtab");
            ul();
            li().a().href("#tab1").text("Visualization").end(2);
            li().a().href("#tab2").text("Statistics").end(2);
            // li().a().href("#tab3").text("XML Configuration").end(2);
            end();
            div().id("tab1");
            createServiceProxyVisualization(rule, relativeRootPath);
            end();
            div().id("tab2");
            createStatusCodesTable(rule.getStatisticsByStatusCodes());
            br();
            createButton("View Messages", "calls", null, createQueryString("proxy", rule.toString()));
            end();
            end();
        }
    }.createPage());
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) StringWriter(java.io.StringWriter)

Example 23 with Service

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

the class ApiManagementConfiguration method parsePolicies.

private Map<String, Policy> parsePolicies(Map<String, Object> yaml) {
    Map<String, Policy> result = new HashMap<String, Policy>();
    Object policies = yaml.get("policies");
    if (policies == null) {
        log.warn("No policies in policy file");
        return result;
    }
    List<Object> yamlPolicies = (List<Object>) policies;
    for (Object yamlPolicyObj : yamlPolicies) {
        if (yamlPolicyObj == null) {
            continue;
        }
        LinkedHashMap<String, Object> yamlPolicy = (LinkedHashMap<String, Object>) yamlPolicyObj;
        for (Object polObj : yamlPolicy.values()) {
            if (polObj == null) {
                continue;
            }
            LinkedHashMap<String, Object> yamlPolicyDef = (LinkedHashMap<String, Object>) polObj;
            Policy policy = new Policy();
            Object name = yamlPolicyDef.get("id");
            if (name == null) {
                log.warn("Policy object found, but no \"id\" field");
                continue;
            }
            String policyName = (String) name;
            policy.setName(policyName);
            Object serviceProxiesObj = yamlPolicyDef.get("serviceProxy");
            if (serviceProxiesObj == null) {
                log.warn("Policy object found, but no service proxies specified ");
                continue;
            }
            List<String> serviceProxyNames = (List<String>) serviceProxiesObj;
            for (String sp : serviceProxyNames) {
                policy.getServiceProxies().add(sp);
            }
            // Optionals like rateLimit/quota etc. follow
            Object rateLimitObj = yamlPolicyDef.get("rateLimit");
            if (rateLimitObj != null) {
                LinkedHashMap<String, Object> rateLimitData = (LinkedHashMap<String, Object>) rateLimitObj;
                RateLimit rateLimit = new RateLimit();
                int requests = parseInteger(rateLimitData.get("requests"), RateLimit.REQUESTS_DEFAULT);
                int interval = parseInteger(rateLimitData.get("interval"), RateLimit.INTERVAL_DEFAULT);
                rateLimit.setRequests(requests);
                rateLimit.setInterval(interval);
                policy.setRateLimit(rateLimit);
            }
            Object quotaObj = yamlPolicyDef.get("quota");
            if (quotaObj != null) {
                LinkedHashMap<String, Object> quota = (LinkedHashMap<String, Object>) quotaObj;
                Object quotaSizeObj = quota.get("size");
                long quotaNumber = getQuotaNumber(quotaSizeObj);
                int quotaInterval = parseInteger(quota.get("interval"), Quota.INTERVAL_DEFAULT);
                Quota q = new Quota();
                q.setSize(quotaNumber);
                q.setInterval(quotaInterval);
                policy.setQuota(q);
            }
            parseUnauthenticatedField(yamlPolicyDef, policy);
            result.put(policyName, policy);
        }
    }
    return result;
}
Also used : Policy(com.predic8.membrane.core.interceptor.apimanagement.policy.Policy) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RateLimit(com.predic8.membrane.core.interceptor.apimanagement.policy.RateLimit) Quota(com.predic8.membrane.core.interceptor.apimanagement.policy.Quota)

Example 24 with Service

use of com.predic8.wsdl.Service 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)

Example 25 with Service

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

the class AdminPageBuilder method createStreamPumpsTable.

protected void createStreamPumpsTable() throws UnsupportedEncodingException {
    table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display", "id", "stream-pumps-table");
    thead();
    tr();
    createThs("Name", "Service Proxy", "Creation Time", "Active Time", "Transferred Bytes");
    end();
    end();
    tbody();
    for (StreamPump p : router.getStatistics().getStreamPumpStats().getStreamPumps()) {
        tr().style("text-align: right;");
        td().style("text-align:left;").text(p.getName()).end();
        createTds(p.getServiceProxyName(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(p.getCreationTime()), // TODO: Pretty Print with library
        (System.currentTimeMillis() - p.getCreationTime()) / 1000 + " seconds", "" + p.getTransferredBytes());
        end();
    }
    end();
    end();
}
Also used : StreamPump(com.predic8.membrane.core.transport.http.StreamPump) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Test (org.junit.Test)39 Process2 (com.predic8.membrane.examples.Process2)35 File (java.io.File)29 StringWriter (java.io.StringWriter)5 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)4 Rule (com.predic8.membrane.core.rules.Rule)4 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 HttpRouter (com.predic8.membrane.core.HttpRouter)3 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)3 BufferLogger (com.predic8.membrane.examples.util.BufferLogger)3 SubstringWaitableConsoleEvent (com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent)3 Definitions (com.predic8.wsdl.Definitions)3 Port (com.predic8.wsdl.Port)3 Service (com.predic8.wsdl.Service)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Exchange (com.predic8.membrane.core.exchange.Exchange)2 Request (com.predic8.membrane.core.http.Request)2 Response (com.predic8.membrane.core.http.Response)2