Search in sources :

Example 1 with Binding

use of com.predic8.wsdl.Binding in project irontest by zheng-wang.

the class WSDLResource method getWSDLBindings.

@GET
@Path("/{wsdlUrl}/bindings")
public List<WSDLBinding> getWSDLBindings(@PathParam("wsdlUrl") String wsdlUrl) throws UnsupportedEncodingException {
    List<WSDLBinding> result = new ArrayList<WSDLBinding>();
    WSDLParser parser = new WSDLParser();
    Definitions definition = parser.parse(wsdlUrl);
    for (Binding binding : definition.getBindings()) {
        List<String> operationNames = new ArrayList<String>();
        for (BindingOperation operation : binding.getOperations()) {
            operationNames.add(operation.getName());
        }
        result.add(new WSDLBinding(binding.getName(), operationNames));
    }
    return result;
}
Also used : WSDLBinding(io.irontest.models.WSDLBinding) Binding(com.predic8.wsdl.Binding) BindingOperation(com.predic8.wsdl.BindingOperation) WSDLBinding(io.irontest.models.WSDLBinding) Definitions(com.predic8.wsdl.Definitions) ArrayList(java.util.ArrayList) WSDLParser(com.predic8.wsdl.WSDLParser) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with Binding

use of com.predic8.wsdl.Binding 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 3 with Binding

use of com.predic8.wsdl.Binding in project carbon-business-process by wso2.

the class HTRenderingApiImpl method createSoapTemplate.

/**
 * Function to create response message template
 *
 * @param SrcWsdl   source wsld : wsdl file path or url
 * @param portType  callback port type
 * @param operation callback operation name
 * @param binding   callback binding
 * @return DOM element of response message template
 * @throws IOException  If error occurred while parsing string xml to Dom element
 * @throws SAXException If error occurred while parsing string xml to Dom element
 */
private static Element createSoapTemplate(String SrcWsdl, String portType, String operation, String binding) throws IOException, SAXException {
    WSDLParser parser = new WSDLParser();
    // BPS-677
    int fileLocationPrefixIndex = SrcWsdl.indexOf(HumanTaskConstants.FILE_LOCATION_FILE_PREFIX);
    if (SrcWsdl.indexOf(HumanTaskConstants.FILE_LOCATION_FILE_PREFIX) != -1) {
        SrcWsdl = SrcWsdl.substring(fileLocationPrefixIndex + HumanTaskConstants.FILE_LOCATION_FILE_PREFIX.length());
    }
    Definitions wsdl = parser.parse(SrcWsdl);
    StringWriter writer = new StringWriter();
    // SOAPRequestCreator constructor: SOARequestCreator(Definitions, Creator, MarkupBuilder)
    SOARequestCreator creator = new SOARequestCreator(wsdl, new RequestTemplateCreator(), new MarkupBuilder(writer));
    // creator.createRequest(PortType name, Operation name, Binding name);
    creator.createRequest(portType, operation, binding);
    Element outGenMessageDom = DOMUtils.stringToDOM(writer.toString());
    Element outMsgElement = null;
    NodeList nodes = outGenMessageDom.getElementsByTagNameNS(outGenMessageDom.getNamespaceURI(), "Body").item(0).getChildNodes();
    if (nodes != null) {
        for (int i = 0; i < nodes.getLength(); i++) {
            if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
                outMsgElement = (Element) nodes.item(i);
                break;
            }
        }
    }
    if (outMsgElement != null) {
        // convert element to string and back to element to remove Owner Document
        return DOMUtils.stringToDOM(DOMUtils.domToString(outMsgElement));
    }
    return null;
}
Also used : RequestTemplateCreator(com.predic8.wstool.creator.RequestTemplateCreator) StringWriter(java.io.StringWriter) Definitions(com.predic8.wsdl.Definitions) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) MarkupBuilder(groovy.xml.MarkupBuilder) WSDLParser(com.predic8.wsdl.WSDLParser) SOARequestCreator(com.predic8.wstool.creator.SOARequestCreator)

Aggregations

Definitions (com.predic8.wsdl.Definitions)3 Binding (com.predic8.wsdl.Binding)2 WSDLParser (com.predic8.wsdl.WSDLParser)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 Mapping (com.predic8.membrane.core.interceptor.administration.Mapping)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 Service (com.predic8.wsdl.Service)1 RequestTemplateCreator (com.predic8.wstool.creator.RequestTemplateCreator)1 SOARequestCreator (com.predic8.wstool.creator.SOARequestCreator)1 MarkupBuilder (groovy.xml.MarkupBuilder)1 WSDLBinding (io.irontest.models.WSDLBinding)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1