Search in sources :

Example 41 with Port

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

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)9 Test (org.junit.Test)7 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)6 StringWriter (java.io.StringWriter)6 Exchange (com.predic8.membrane.core.exchange.Exchange)5 Rule (com.predic8.membrane.core.rules.Rule)5 Process2 (com.predic8.membrane.examples.Process2)5 File (java.io.File)5 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)4 HttpRouter (com.predic8.membrane.core.HttpRouter)3 Request (com.predic8.membrane.core.http.Request)3 Response (com.predic8.membrane.core.http.Response)3 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Definitions (com.predic8.wsdl.Definitions)3 Port (com.predic8.wsdl.Port)3 ArrayList (java.util.ArrayList)3 EtcdNodeInformation (com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation)2 IPortChangeListener (com.predic8.membrane.core.model.IPortChangeListener)2 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)2