Search in sources :

Example 6 with Operation

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

the class TestServiceInterceptor method handleSOAP12.

private Response handleSOAP12(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.SOAP12_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, false);
}
Also used : MCElement(com.predic8.membrane.annot.MCElement) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text)

Example 7 with Operation

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

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

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