Search in sources :

Example 31 with Service

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

the class WebServiceExplorerInterceptor method getPortsByLocation.

private List<Port> getPortsByLocation(Service service, Port port) {
    String location = port.getAddress().getLocation();
    if (location == null)
        throw new IllegalArgumentException("Location not set for port in WSDL.");
    final List<Port> ports = new ArrayList<Port>();
    for (Port p : service.getPorts()) if (location.equals(p.getAddress().getLocation()))
        ports.add(p);
    return ports;
}
Also used : Port(com.predic8.wsdl.Port) ArrayList(java.util.ArrayList)

Example 32 with Service

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

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

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

the class IndexInterceptor method handleRequest.

@Override
public Outcome handleRequest(final Exchange exc) throws Exception {
    StringWriter sw = new StringWriter();
    new Html(sw) {

        {
            html();
            head();
            title().text(Constants.PRODUCT_NAME + ": Service Proxies").end();
            style();
            raw("<!--\r\n" + "body { font-family: sans-serif; }\r\n" + "h1 { font-size: 24pt; }\r\n" + "td, th { border: 1px solid black; padding: 0pt 10pt; }\r\n" + "table { border-collapse: collapse; }\r\n" + ".help { margin-top:20pt; color:#AAAAAA; padding:1em 0em 0em 0em; font-size:10pt; }\r\n" + ".footer { color:#AAAAAA; padding:0em 0em; font-size:10pt; }\r\n" + ".footer a { color:#AAAAAA; }\r\n" + ".footer a:hover { color:#000000; }\r\n" + "-->");
            end();
            end();
            body();
            h1().text("Service Proxies").end();
            List<ServiceInfo> services = getServices(exc);
            if (services.isEmpty())
                p().text("There are no services defined.").end();
            else
                createIndexTable(services, exc.getHandler() instanceof HttpServerHandler);
            p().classAttr("help").text("The hyperlinks might not work due to semantics which is not known to " + Constants.PRODUCT_NAME + ".").end();
            p().classAttr("footer").raw(Constants.HTML_FOOTER).end();
            end();
            end();
        }

        private void createIndexTable(List<ServiceInfo> services, boolean showSSL) {
            table().cellspacing("0").cellpadding("0").border("" + 1);
            tr();
            th().text("Name").end();
            th().text("Virtual Host").end();
            th().text("Port").end();
            th().text("Path").end();
            if (showSSL)
                th().text("SSL").end();
            end();
            for (ServiceInfo ri : services) {
                tr();
                td();
                if (ri.url != null && !"POST".equals(ri.method)) {
                    a().href(ri.url);
                    text(ri.name);
                    end();
                } else {
                    text(ri.name);
                }
                end();
                td().raw(ri.host).end();
                td().raw(ri.port).end();
                td().raw(ri.path).end();
                if (showSSL)
                    td().raw(ri.ssl ? "yes" : "").end();
                end();
            }
            end();
        }
    };
    exc.setResponse(Response.ok(sw.toString()).build());
    return Outcome.RETURN;
}
Also used : StringWriter(java.io.StringWriter) Html(com.googlecode.jatl.Html) ArrayList(java.util.ArrayList) List(java.util.List) HttpServerHandler(com.predic8.membrane.core.transport.http.HttpServerHandler)

Example 35 with Service

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

the class LoadBalancingWithClusterManagerTest method nodesTest.

@Test
public void nodesTest() throws Exception {
    node1 = new HttpRouter();
    node2 = new HttpRouter();
    node3 = new HttpRouter();
    DummyWebServiceInterceptor service1 = startNode(node1, 2000);
    DummyWebServiceInterceptor service2 = startNode(node2, 3000);
    DummyWebServiceInterceptor service3 = startNode(node3, 4000);
    startLB();
    sendNotification("up", 2000);
    sendNotification("up", 3000);
    // goes to service one
    assertEquals(200, post("/getBankwithSession555555.xml"));
    assertEquals(1, service1.getCount());
    assertEquals(0, service2.getCount());
    // goes to service 1 again
    assertEquals(200, post("/getBankwithSession555555.xml"));
    assertEquals(2, service1.getCount());
    assertEquals(0, service2.getCount());
    // goes to service 2
    assertEquals(200, post("/getBankwithSession444444.xml"));
    assertEquals(2, service1.getCount());
    assertEquals(1, service2.getCount());
    sendNotification("down", 2000);
    // goes to service 2 because service 1 is down
    assertEquals(200, post("/getBankwithSession555555.xml"));
    assertEquals(2, service1.getCount());
    assertEquals(2, service2.getCount());
    sendNotification("up", 4000);
    assertEquals(0, service3.getCount());
    // goes to service 3
    assertEquals(200, post("/getBankwithSession666666.xml"));
    assertEquals(2, service1.getCount());
    assertEquals(2, service2.getCount());
    assertEquals(1, service3.getCount());
    // goes to service 2
    assertEquals(200, post("/getBankwithSession555555.xml"));
    // goes to service 2
    assertEquals(200, post("/getBankwithSession444444.xml"));
    // goes to service 3
    assertEquals(200, post("/getBankwithSession666666.xml"));
    assertEquals(2, service1.getCount());
    assertEquals(4, service2.getCount());
    assertEquals(2, service3.getCount());
}
Also used : HttpRouter(com.predic8.membrane.core.HttpRouter) DummyWebServiceInterceptor(com.predic8.membrane.core.services.DummyWebServiceInterceptor) Test(org.junit.Test)

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