Search in sources :

Example 6 with MarkupBuilder

use of groovy.xml.MarkupBuilder 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 MarkupBuilder

use of groovy.xml.MarkupBuilder in project groovy-core by groovy.

the class ServletBinding method lazyInit.

private void lazyInit() {
    if (initialized)
        return;
    initialized = true;
    HttpServletResponse response = (HttpServletResponse) super.getVariable("response");
    ServletOutput output = new ServletOutput(response);
    super.setVariable("out", output.getWriter());
    super.setVariable("sout", output.getOutputStream());
    MarkupBuilder builder = new MarkupBuilder(output.getWriter());
    builder.setExpandEmptyElements(true);
    super.setVariable("html", builder);
    try {
        Class jsonBuilderClass = this.getClass().getClassLoader().loadClass("groovy.json.StreamingJsonBuilder");
        Constructor writerConstructor = jsonBuilderClass.getConstructor(Writer.class);
        super.setVariable("json", writerConstructor.newInstance(output.getWriter()));
    } catch (Throwable t) {
        t.printStackTrace();
    }
    // bind forward method
    MethodClosure c = new MethodClosure(this, "forward");
    super.setVariable("forward", c);
    // bind include method
    c = new MethodClosure(this, "include");
    super.setVariable("include", c);
    // bind redirect method
    c = new MethodClosure(this, "redirect");
    super.setVariable("redirect", c);
}
Also used : Constructor(java.lang.reflect.Constructor) HttpServletResponse(javax.servlet.http.HttpServletResponse) MarkupBuilder(groovy.xml.MarkupBuilder) MethodClosure(org.codehaus.groovy.runtime.MethodClosure)

Aggregations

MarkupBuilder (groovy.xml.MarkupBuilder)7 StringWriter (java.io.StringWriter)4 RequestTemplateCreator (com.predic8.wstool.creator.RequestTemplateCreator)3 SOARequestCreator (com.predic8.wstool.creator.SOARequestCreator)3 Definitions (com.predic8.wsdl.Definitions)2 WSDLParser (com.predic8.wsdl.WSDLParser)2 Constructor (java.lang.reflect.Constructor)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MethodClosure (org.codehaus.groovy.runtime.MethodClosure)2 SOAPOperationInfo (io.irontest.models.teststep.SOAPOperationInfo)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1