Search in sources :

Example 6 with WSDLParser

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

Example 7 with WSDLParser

use of com.predic8.wsdl.WSDLParser 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();
    parser.setResourceResolver(new SSLTrustedExternalResolver());
    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) SSLTrustedExternalResolver(io.irontest.core.SSLTrustedExternalResolver) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

WSDLParser (com.predic8.wsdl.WSDLParser)7 Definitions (com.predic8.wsdl.Definitions)5 WSDLParserContext (com.predic8.wsdl.WSDLParserContext)4 Schema (com.predic8.schema.Schema)2 RequestTemplateCreator (com.predic8.wstool.creator.RequestTemplateCreator)2 SOARequestCreator (com.predic8.wstool.creator.SOARequestCreator)2 MarkupBuilder (groovy.xml.MarkupBuilder)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 SSLParser (com.predic8.membrane.core.config.security.SSLParser)1 ResourceRetrievalException (com.predic8.membrane.core.resolver.ResourceRetrievalException)1 Binding (com.predic8.wsdl.Binding)1 BindingOperation (com.predic8.wsdl.BindingOperation)1 Port (com.predic8.wsdl.Port)1 Service (com.predic8.wsdl.Service)1 Types (com.predic8.wsdl.Types)1 SSLTrustedExternalResolver (io.irontest.core.SSLTrustedExternalResolver)1 WSDLBinding (io.irontest.models.WSDLBinding)1