Search in sources :

Example 1 with Operation

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

the class QuickstartSOAPTest method doit.

@Test
public void doit() throws IOException, InterruptedException {
    File baseDir = getExampleDir("quickstart-soap");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        ProxiesXmlUtil pxu = new ProxiesXmlUtil(new File(baseDir, "proxies.xml"));
        pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "	\r\n" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        String endpoint = "http://localhost:2000/MyBLZService";
        String result = getAndAssert200(endpoint + "?wsdl");
        assertContains("wsdl:documentation", result);
        // assert that rewriting did take place
        assertContains("localhost:2000/MyBLZService", result);
        result = AssertUtils.postAndAssert200(endpoint, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + "   <soapenv:Header/>\r\n" + "   <soapenv:Body>\r\n" + "      <blz:getBank>\r\n" + "         <blz:blz>37050198</blz:blz>\r\n" + "      </blz:getBank>\r\n" + "   </soapenv:Body>\r\n" + "</soapenv:Envelope>");
        assertContains("Sparkasse", result);
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        result = getAndAssert200("http://localhost:9000/admin/");
        result.contains("BLZService");
        String invalidRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + "   <soapenv:Header/>\r\n" + "   <soapenv:Body>\r\n" + "      <blz:getBank>\r\n" + "         <blz:blz>37050198</blz:blz>\r\n" + "         <foo />\r\n" + "      </blz:getBank>\r\n" + "   </soapenv:Body>\r\n" + "</soapenv:Envelope>";
        result = postAndAssert(500, endpoint, invalidRequest);
        assertContains(".java:", result);
        AssertUtils.closeConnections();
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "	\r\n" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = postAndAssert(500, endpoint, invalidRequest);
        assertContainsNot(".java:", result);
        AssertUtils.closeConnections();
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "	\r\n" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "		<validator/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = postAndAssert(400, endpoint, invalidRequest);
        assertContains("Validation failed", result);
        result = getAndAssert200("http://localhost:9000/admin/service-proxy/show?name=BLZService%3A2000");
        result.contains("1 of 1 messages have been invalid");
        result = getAndAssert200(endpoint);
        assertContains("Target Namespace", result);
        result = getAndAssert200(endpoint + "/operation/BLZServiceSOAP11Binding/BLZServicePortType/getBank");
        assertContains("blz&gt;?XXX?", result);
        AssertUtils.closeConnections();
        pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "	\r\n" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "		<validator/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"2000\">\r\n" + "		<index />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = getAndAssert200("http://localhost:2000");
        assertContains("/MyBLZService", result);
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) ProxiesXmlUtil(com.predic8.membrane.examples.ProxiesXmlUtil) File(java.io.File) Test(org.junit.Test)

Example 2 with Operation

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

the class TestServiceInterceptor method handleOperation.

private Response handleOperation(Element operation, boolean soap11) {
    if (!operation.getNamespaceURI().equals("http://thomas-bayer.com/blz/"))
        throw new AssertionError("Unknown operation namespace.");
    if (operation.getLocalName().equals("getBank")) {
        NodeList children = operation.getChildNodes();
        Element param = null;
        for (int i = 0; i < children.getLength(); i++) {
            if (children.item(i) instanceof Text) {
                String text = ((Text) children.item(i)).getNodeValue();
                for (int j = 0; j < text.length(); j++) if (!Character.isWhitespace(text.charAt(j)))
                    throw new AssertionError("Found non-whitespace text.");
                continue;
            }
            if (!(children.item(i) instanceof Element))
                throw new AssertionError("Non-element child of <Body> found: " + children.item(i).getNodeName() + ".");
            param = (Element) children.item(i);
        }
        if (param == null)
            throw new AssertionError("No parameter child of operation element found.");
        if (!param.getNamespaceURI().equals("http://thomas-bayer.com/blz/") || !param.getLocalName().equals("blz"))
            throw new AssertionError("Unknown parameter element.");
        children = param.getChildNodes();
        if (children.getLength() != 1)
            throw new AssertionError("Parameter element has children.length != 1");
        if (!(children.item(0) instanceof Text))
            throw new AssertionError("Parameter element has non-text child.");
        Text text = (Text) children.item(0);
        String blz = text.getNodeValue();
        return getBank(blz, soap11);
    } else {
        throw new AssertionError("Unknown operation.");
    }
}
Also used : NodeList(org.w3c.dom.NodeList) MCElement(com.predic8.membrane.annot.MCElement) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Example 3 with Operation

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

the class TestServiceInterceptor method handleSOAP11.

private Response handleSOAP11(Element envelope) {
    Element body = null;
    NodeList children = envelope.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i) instanceof Text) {
            String text = ((Text) children.item(i)).getNodeValue();
            for (int j = 0; j < text.length(); j++) if (!Character.isWhitespace(text.charAt(j)))
                throw new AssertionError("Found non-whitespace text.");
            continue;
        }
        if (!(children.item(i) instanceof Element))
            throw new AssertionError("Non-element child of <Envelope> found: " + children.item(i).getNodeName() + ".");
        Element item = (Element) children.item(i);
        if (!item.getNamespaceURI().equals(Constants.SOAP11_NS))
            throw new AssertionError("Non-SOAP child element of <Envelope> found.");
        if (item.getLocalName().equals("Body"))
            body = item;
    }
    if (body == null)
        throw new AssertionError("No SOAP <Body> found.");
    children = body.getChildNodes();
    Element operation = null;
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i) instanceof Text) {
            String text = ((Text) children.item(i)).getNodeValue();
            for (int j = 0; j < text.length(); j++) if (!Character.isWhitespace(text.charAt(j)))
                throw new AssertionError("Found non-whitespace text.");
            continue;
        }
        if (!(children.item(i) instanceof Element))
            throw new AssertionError("Non-element child of <Body> found: " + children.item(i).getNodeName() + ".");
        operation = (Element) children.item(i);
    }
    if (operation == null)
        throw new AssertionError("No SOAP <Body> found.");
    return handleOperation(operation, true);
}
Also used : MCElement(com.predic8.membrane.annot.MCElement) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text)

Example 4 with Operation

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

the class WebServiceExplorerInterceptor method createOperationResponse.

@Mapping("[^?]*/operation/([^/?]+)/([^/?]+)/([^/?]+)")
public Response createOperationResponse(QueryParameter params, String relativeRootPath) throws Exception {
    try {
        final String bindingName = params.getGroup(1);
        final String portName = params.getGroup(2);
        final String operationName = params.getGroup(3);
        final Definitions w = getParsedWSDL();
        final Service service = getService(w);
        StringWriter sw = new StringWriter();
        new StandardPage(sw, null) {

            @Override
            protected void createContent() {
                h1().text("Service Proxy for " + service.getName());
                h2().text("Operation: " + operationName).end();
                h3().text("Sample Request").end();
                pre().text(generateSampleRequest(portName, operationName, bindingName, w)).end();
            }
        };
        return Response.ok(sw.toString()).build();
    } catch (IllegalArgumentException e) {
        log.error("", e);
        return Response.internalServerError().build();
    }
}
Also used : StringWriter(java.io.StringWriter) Definitions(com.predic8.wsdl.Definitions) Service(com.predic8.wsdl.Service) Mapping(com.predic8.membrane.core.interceptor.administration.Mapping)

Example 5 with Operation

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

Aggregations

Definitions (com.predic8.wsdl.Definitions)4 Element (org.w3c.dom.Element)4 NodeList (org.w3c.dom.NodeList)4 MCElement (com.predic8.membrane.annot.MCElement)3 StringWriter (java.io.StringWriter)3 Text (org.w3c.dom.Text)3 Mapping (com.predic8.membrane.core.interceptor.administration.Mapping)2 Binding (com.predic8.wsdl.Binding)2 Service (com.predic8.wsdl.Service)2 WSDLParser (com.predic8.wsdl.WSDLParser)2 ArrayList (java.util.ArrayList)2 Process2 (com.predic8.membrane.examples.Process2)1 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)1 BindingOperation (com.predic8.wsdl.BindingOperation)1 Documentation (com.predic8.wsdl.Documentation)1 Operation (com.predic8.wsdl.Operation)1 Part (com.predic8.wsdl.Part)1 Port (com.predic8.wsdl.Port)1 PortType (com.predic8.wsdl.PortType)1 RequestTemplateCreator (com.predic8.wstool.creator.RequestTemplateCreator)1