Search in sources :

Example 16 with Mapping

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.

the class WebServiceExplorerInterceptor method createSOAPUIResponse.

@Mapping("(?!.*operation)([^?]*)")
public Response createSOAPUIResponse(QueryParameter params, final String relativeRootPath, final Exchange exc) throws Exception {
    try {
        final String myPath = router.getUriFactory().create(exc.getRequestURI()).getPath();
        final Definitions w = getParsedWSDL();
        final Service service = getService(w);
        final Port port = SOAPProxy.selectPort(service.getPorts(), portName);
        final List<Port> ports = getPortsByLocation(service, port);
        StringWriter sw = new StringWriter();
        new StandardPage(sw, service.getName()) {

            @Override
            protected void createContent() {
                h1().text("Service Proxy: " + service.getName()).end();
                p();
                text("Target Namespace: " + w.getTargetNamespace());
                br().end();
                String wsdlLink = getClientURL(exc) + "?wsdl";
                text("WSDL: ").a().href(wsdlLink).text(wsdlLink).end();
                end();
                for (PortType pt : w.getPortTypes()) {
                    h2().text("Port Type: " + pt.getName()).end();
                    Documentation d = pt.getDocumentation();
                    if (d != null) {
                        p().text("Documentation: " + d.toString()).end();
                    }
                }
                Binding binding = port.getBinding();
                PortType portType = binding.getPortType();
                List<Operation> bindingOperations = getOperationsByBinding(w, binding);
                if (bindingOperations.isEmpty())
                    p().text("There are no operations defined.").end();
                else
                    createOperationsTable(w, bindingOperations, binding, portType);
                h2().text("Virtual Endpoint").end();
                p().a().href(getClientURL(exc)).text(getClientURL(exc)).end().end();
                h2().text("Target Endpoints").end();
                if (service.getPorts().isEmpty())
                    p().text("There are no endpoints defined.").end();
                else
                    createEndpointTable(service.getPorts(), ports);
            }

            private void createOperationsTable(Definitions w, List<Operation> bindingOperations, Binding binding, PortType portType) {
                table().cellspacing("0").cellpadding("0").border("" + 1);
                tr();
                th().text("Operation").end();
                th().text("Input").end();
                th().text("Output").end();
                end();
                for (Operation o : bindingOperations) {
                    tr();
                    td();
                    if ("HTTP".equals(getProtocolVersion(binding))) {
                        text(o.getName());
                    } else {
                        String link = myPath + "/operation/" + binding.getName() + "/" + portType.getName() + "/" + o.getName();
                        a().href(link).text(o.getName()).end();
                    }
                    end();
                    td();
                    for (Part p : o.getInput().getMessage().getParts()) text(p.getElement().getName());
                    end();
                    td();
                    for (Part p : o.getOutput().getMessage().getParts()) text(p.getElement().getName());
                    end();
                    end();
                }
                end();
            }

            private void createEndpointTable(List<Port> ports, List<Port> matchingPorts) {
                table().cellspacing("0").cellpadding("0").border("" + 1);
                tr();
                th().text("Port Name").end();
                th().text("Protocol").end();
                th().text("URL").end();
                end();
                for (Port p : ports) {
                    tr();
                    td().text(p.getName()).end();
                    td().text(getProtocolVersion(p.getBinding())).end();
                    td().text(p.getAddress().getLocation()).end();
                    td();
                    if (matchingPorts.contains(p))
                        text("*");
                    end();
                    end();
                }
                end();
                p().small().text("* available through this proxy").end().end();
            }
        };
        return Response.ok(sw.toString()).build();
    } catch (IllegalArgumentException e) {
        log.error("", e);
        return Response.internalServerError().build();
    }
}
Also used : Binding(com.predic8.wsdl.Binding) Definitions(com.predic8.wsdl.Definitions) Port(com.predic8.wsdl.Port) Documentation(com.predic8.wsdl.Documentation) Service(com.predic8.wsdl.Service) Operation(com.predic8.wsdl.Operation) StringWriter(java.io.StringWriter) Part(com.predic8.wsdl.Part) ArrayList(java.util.ArrayList) List(java.util.List) PortType(com.predic8.wsdl.PortType) Mapping(com.predic8.membrane.core.interceptor.administration.Mapping)

Example 17 with Mapping

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.

the class AdminRESTInterceptor method getProxies.

@Mapping("/admin/rest/proxies(/?\\?.*)?")
public Response getProxies(final QueryParameter params, String relativeRootPath) throws Exception {
    final List<AbstractServiceProxy> proxies = getServiceProxies();
    if ("order".equals(params.getString("sort"))) {
        if (params.getString("order", "asc").equals("desc"))
            Collections.reverse(proxies);
    } else {
        Collections.sort(proxies, ComparatorFactory.getAbstractServiceProxyComparator(params.getString("sort", "name"), params.getString("order", "asc")));
    }
    final int offset = params.getInt("offset", 0);
    int max = params.getInt("max", proxies.size());
    final List<AbstractServiceProxy> paginated = proxies.subList(offset, Math.min(offset + max, proxies.size()));
    return json(new JSONContent() {

        public void write(JsonGenerator gen) throws Exception {
            gen.writeStartObject();
            gen.writeArrayFieldStart("proxies");
            int i = offset;
            if (params.getString("order", "asc").equals("desc"))
                i = proxies.size() - i + 1;
            for (AbstractServiceProxy p : paginated) {
                gen.writeStartObject();
                gen.writeNumberField("order", i += params.getString("order", "asc").equals("desc") ? -1 : 1);
                gen.writeStringField("name", p.toString());
                gen.writeBooleanField("active", p.isActive());
                if (!p.isActive())
                    gen.writeStringField("error", p.getErrorState());
                gen.writeNumberField("listenPort", p.getKey().getPort());
                gen.writeStringField("virtualHost", p.getKey().getHost());
                gen.writeStringField("method", p.getKey().getMethod());
                gen.writeStringField("path", p.getKey().getPath());
                gen.writeStringField("targetHost", p.getTargetHost());
                gen.writeNumberField("targetPort", p.getTargetPort());
                gen.writeNumberField("count", p.getCount());
                gen.writeObjectFieldStart("actions");
                if (!isReadOnly()) {
                    gen.writeStringField("delete", "/admin/service-proxy/delete?name=" + URLEncoder.encode(RuleUtil.getRuleIdentifier(p), "UTF-8"));
                }
                if (!p.isActive())
                    gen.writeStringField("start", "/admin/service-proxy/start?name=" + URLEncoder.encode(RuleUtil.getRuleIdentifier(p), "UTF-8"));
                gen.writeEndObject();
                gen.writeEndObject();
            }
            gen.writeEndArray();
            gen.writeNumberField("total", proxies.size());
            gen.writeEndObject();
        }
    });
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) JSONContent(com.predic8.membrane.core.interceptor.rest.JSONContent) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) SQLException(java.sql.SQLException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) IOException(java.io.IOException)

Example 18 with Mapping

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.

the class AdminRESTInterceptor method getRaw.

@Mapping("/admin/rest/exchanges/(-?\\d+)/(response|request)/raw")
public Response getRaw(QueryParameter params, String relativeRootPath) throws Exception {
    AbstractExchange exc = router.getExchangeStore().getExchangeById(params.getGroupInt(1));
    if (exc == null) {
        return Response.notFound().build();
    }
    Message msg = params.getGroup(2).equals("response") ? exc.getResponse() : exc.getRequest();
    if (msg == null) {
        return Response.noContent().build();
    }
    // TODO uses body.toString that doesn't handle different encodings than utf-8
    return Response.ok().contentType(MimeType.TEXT_PLAIN_UTF8).body(msg.toString()).build();
}
Also used : Message(com.predic8.membrane.core.http.Message) AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange)

Example 19 with Mapping

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.

the class AdminRESTInterceptor method getClients.

@Mapping("/admin/rest/clients(/?\\?.*)?")
public Response getClients(QueryParameter params, String relativeRootPath) throws Exception {
    final List<? extends ClientStatistics> clients = getRouter().getExchangeStore().getClientStatistics();
    Collections.sort(clients, ComparatorFactory.getClientStatisticsComparator(params.getString("sort", "name"), params.getString("order", "asc")));
    int offset = params.getInt("offset", 0);
    int max = params.getInt("max", clients.size());
    final int total = clients.size();
    final List<? extends ClientStatistics> paginated = clients.subList(offset, Math.min(offset + max, clients.size()));
    return json(new JSONContent() {

        public void write(JsonGenerator gen) throws Exception {
            gen.writeStartObject();
            gen.writeArrayFieldStart("clients");
            for (ClientStatistics s : paginated) {
                gen.writeStartObject();
                gen.writeStringField("name", s.getClient());
                gen.writeNumberField("count", s.getCount());
                gen.writeNumberField("min", s.getMinDuration());
                gen.writeNumberField("max", s.getMaxDuration());
                gen.writeNumberField("avg", s.getAvgDuration());
                gen.writeEndObject();
            }
            gen.writeEndArray();
            gen.writeNumberField("total", total);
            gen.writeEndObject();
        }
    });
}
Also used : JSONContent(com.predic8.membrane.core.interceptor.rest.JSONContent) ClientStatistics(com.predic8.membrane.core.exchangestore.ClientStatistics) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) SQLException(java.sql.SQLException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) IOException(java.io.IOException)

Example 20 with Mapping

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleProxySaveRequest.

@Mapping("/admin/proxy/save/?(\\?.*)?")
public Response handleProxySaveRequest(Map<String, String> params, String relativeRootPath) throws Exception {
    if (readOnly)
        return createReadOnlyErrorResponse();
    log.debug("adding proxy rule");
    log.debug("name: " + params.get("name"));
    log.debug("port: " + params.get("port"));
    Rule r = new ProxyRule(new ProxyRuleKey(Integer.parseInt(params.get("port")), null));
    r.setName(params.get("name"));
    router.getRuleManager().addProxyAndOpenPortIfNew(r);
    return respond(getProxyPage(params, relativeRootPath));
}
Also used : ProxyRule(com.predic8.membrane.core.rules.ProxyRule) ProxyRuleKey(com.predic8.membrane.core.rules.ProxyRuleKey) ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Aggregations

StringWriter (java.io.StringWriter)7 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)5 Rule (com.predic8.membrane.core.rules.Rule)5 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 Message (com.predic8.membrane.core.http.Message)4 JSONContent (com.predic8.membrane.core.interceptor.rest.JSONContent)4 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)4 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 HttpRouter (com.predic8.membrane.core.HttpRouter)3 Mapping (com.predic8.membrane.core.interceptor.administration.Mapping)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)3 Header (com.predic8.membrane.core.http.Header)2 Node (com.predic8.membrane.core.interceptor.balancer.Node)2 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)2 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)2 URLParamUtil.createQueryString (com.predic8.membrane.core.util.URLParamUtil.createQueryString)2 Definitions (com.predic8.wsdl.Definitions)2