Search in sources :

Example 6 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class AbstractHttpTransaction method configure.

@Override
public void configure(Element element) throws Exception {
    super.configure(element);
    String version = element.getAttribute("version");
    if (version == null) {
        String s = XMLUtils.prettyPrintDOM(element);
        EngineException ee = new EngineException("Unable to find version number for the database object \"" + getName() + "\".\nXML data: " + s);
        throw ee;
    }
    if (VersionUtils.compare(version, "3.1.8") < 0) {
        NodeList properties = element.getElementsByTagName("property");
        Element propValue = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "httpVariables");
        XMLVector<XMLVector<Long>> httpVariables = null;
        Node xmlNode = null;
        NodeList nl = propValue.getChildNodes();
        int len_nl = nl.getLength();
        for (int j = 0; j < len_nl; j++) {
            xmlNode = nl.item(j);
            if (xmlNode.getNodeType() == Node.ELEMENT_NODE) {
                httpVariables = GenericUtils.cast(XMLUtils.readObjectFromXml((Element) xmlNode));
                continue;
            }
        }
        XMLVector<XMLVector<Long>> orderedVariables = getOrderedVariables();
        int len = orderedVariables.size();
        XMLVector<Long> line;
        for (int i = 0; i < len; i++) {
            line = orderedVariables.get(i);
            if (httpVariables.size() > 0) {
                line.add(httpVariables.get(i).get(1));
                line.add(httpVariables.get(i).get(2));
            }
        }
        hasChanged = true;
        Engine.logBeans.warn("[HttpTransaction] The object \"" + getName() + "\" has been updated to version 3.1.8");
    }
    try {
        Node node = XPathAPI.selectSingleNode(element, "property[@name='httpVerb']/java.lang.Integer/@value");
        if (node != null) {
            httpVerb = HttpMethodType.values()[Integer.parseInt(node.getNodeValue())];
            hasChanged = true;
            Engine.logBeans.warn("[HttpTransaction] The object \"" + getName() + "\" has been updated to use the new 'httpVerb' format");
        }
    } catch (Throwable t) {
    // ignore migration errors
    }
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 7 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class CicsTransaction method getXMLMap.

private Element getXMLMap(Document doc, String eltName, XMLVector<XMLVector<Object>> v, boolean bExpand) {
    Element root = null, parent = null, node = null, last = null;
    String xPath = "";
    if (doc != null) {
        int curlevel = 0;
        root = doc.createElement(eltName);
        if (v != null) {
            Enumeration<XMLVector<Object>> rows = v.elements();
            while (rows.hasMoreElements()) {
                XMLVector<Object> row = rows.nextElement();
                String sLevel = (String) row.get(0);
                String sName = (String) row.get(1);
                String sOccurs = (String) row.get(2);
                String sBytes = ((Integer) row.get(3)).toString();
                String sFormat = (String) row.get(4);
                String sPicture = (String) row.get(5);
                String sDefault = (String) row.get(6);
                int level = Integer.parseInt(sLevel, 10);
                if (level > 0) {
                    node = doc.createElement(sName);
                    node.setAttribute("level", sLevel);
                    if (!sOccurs.equalsIgnoreCase(""))
                        node.setAttribute("occurs", sOccurs);
                    if (!sPicture.equalsIgnoreCase(""))
                        node.setAttribute("picture", sPicture);
                    if (!sBytes.equalsIgnoreCase(""))
                        node.setAttribute("bytes", sBytes);
                    if (!sFormat.equalsIgnoreCase(""))
                        node.setAttribute("format", sFormat);
                    if (!sDefault.equalsIgnoreCase(""))
                        node.setAttribute("default", sDefault);
                    if (curlevel == 0)
                        parent = root;
                    else if (level < curlevel) {
                        curlevel = level;
                        do {
                            parent = (Element) last.getParentNode();
                            try {
                                level = Integer.parseInt((parent.getAttribute("level")), 10);
                            } catch (NumberFormatException e) {
                                level = 0;
                            }
                            last = parent;
                        } while (level >= curlevel);
                        level = curlevel;
                    } else if (level == curlevel) {
                        parent = (Element) last.getParentNode();
                    } else {
                        parent = last;
                    }
                    if (parent != null) {
                        // set xpath attribute relative to root element in description map
                        xPath = parent.getAttribute("relxpath") + "/" + sName;
                        if (!sOccurs.equalsIgnoreCase("")) {
                            node.setAttribute("occurence", "1");
                            xPath = xPath + "[1]";
                        }
                        node.setAttribute("relxpath", xPath);
                        parent.appendChild(node);
                        last = node;
                        curlevel = level;
                    }
                }
            }
        }
    }
    if (root != null) {
        if (bExpand)
            expandXMLMap(root);
    }
    return root;
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Element(org.w3c.dom.Element)

Example 8 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class DefaultInternalTranslator method addParameterObject.

private void addParameterObject(Document doc, Node parentItem, String parameterName, Object parameterObject) {
    if (parameterObject instanceof NativeJavaObject) {
        parameterObject = ((NativeJavaObject) parameterObject).unwrap();
    }
    if (parameterObject.getClass().isArray()) {
        int len = Array.getLength(parameterObject);
        for (int i = 0; i < len; i++) {
            Object o = Array.get(parameterObject, i);
            if (o != null) {
                addParameterObject(doc, parentItem, parameterName, o);
            }
        }
    } else if (parameterObject instanceof Node) {
        Node node = (Node) parameterObject;
        Element item = doc.createElement("variable");
        item.setAttribute("name", parameterName);
        if (bStrictMode) {
            // append full structured node
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                item.appendChild(doc.importNode(node, true));
            } else {
                item.setAttribute("value", node.getNodeValue());
            }
        } else {
            // append only child nodes for a structured node
            if (node.getNodeType() == Node.TEXT_NODE) {
                item.setAttribute("value", node.getNodeValue());
            } else {
                NodeList nl = node.getChildNodes();
                if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) {
                    item.setAttribute("value", nl.item(0).getNodeValue());
                } else {
                    node = doc.importNode(node, true);
                    nl = node.getChildNodes();
                    while (nl.getLength() > 0) {
                        item.appendChild(node.removeChild(nl.item(0)));
                    }
                }
            }
        }
        parentItem.appendChild(item);
    } else if (parameterObject instanceof NodeList) {
        NodeList nl = (NodeList) parameterObject;
        int len = nl.getLength();
        if (bStrictMode) {
            Element item = doc.createElement("variable");
            item.setAttribute("name", parameterName);
            for (int i = 0; i < len; i++) {
                Node node = nl.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    item.appendChild(doc.importNode(node, true));
                } else {
                    item.setAttribute("value", node.getNodeValue());
                }
            }
            parentItem.appendChild(item);
        } else {
            for (int i = 0; i < len; i++) {
                addParameterObject(doc, parentItem, parameterName, nl.item(i));
            }
        }
    } else if (parameterObject instanceof XMLVector) {
        XMLVector<Object> values = GenericUtils.cast(parameterObject);
        for (Object object : values) {
            addParameterObject(doc, parentItem, parameterName, object);
        }
    } else if (parameterObject instanceof List) {
        List<Object> list = GenericUtils.cast(parameterObject);
        for (Object object : list) {
            addParameterObject(doc, parentItem, parameterName, object);
        }
    } else {
        Element item = doc.createElement("variable");
        item.setAttribute("name", parameterName);
        item.setAttribute("value", parameterObject.toString());
        parentItem.appendChild(item);
    }
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) NodeList(org.w3c.dom.NodeList) List(java.util.List) NativeJavaObject(org.mozilla.javascript.NativeJavaObject)

Example 9 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class SourcePickerViewWrap method sourceSelected.

@Override
public void sourceSelected(StepSourceEventWrap stepSourceEvent) {
    sourcePicker.getTwsDomTree().removeAll();
    sourcePicker.getXpathEvaluator().removeAnchor();
    sourcePicker.getXpathEvaluator().setXpathText("");
    DatabaseObject dbo = (DatabaseObject) stepSourceEvent.getSource();
    String xpath = stepSourceEvent.getXPath();
    String priority = "" + dbo.priority;
    XMLVector<String> stepSourceDefinition = new XMLVector<String>();
    stepSourceDefinition.add(priority);
    stepSourceDefinition.add(xpath);
    sourcePicker.setStepSourceDefinition(stepSourceDefinition);
    selectedDbo = dbo;
    fillHelpContent();
    sourcePicker.displayTargetWsdlDom(dbo);
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 10 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class WsReference method createSoapTransaction.

private static XmlHttpTransaction createSoapTransaction(XmlSchema xmlSchema, WsdlInterface iface, WsdlOperation operation, Project project, HttpConnector httpConnector) throws ParserConfigurationException, SAXException, IOException, EngineException {
    XmlHttpTransaction xmlHttpTransaction = null;
    WsdlRequest request;
    String requestXml;
    String transactionName, comment;
    String operationName;
    if (operation != null) {
        comment = operation.getDescription();
        try {
            comment = (comment.equals("") ? operation.getBindingOperation().getDocumentationElement().getTextContent() : comment);
        } catch (Exception e) {
        }
        operationName = operation.getName();
        transactionName = StringUtils.normalize("C" + operationName);
        xmlHttpTransaction = new XmlHttpTransaction();
        xmlHttpTransaction.bNew = true;
        xmlHttpTransaction.setHttpVerb(HttpMethodType.POST);
        xmlHttpTransaction.setName(transactionName);
        xmlHttpTransaction.setComment(comment);
        // Set encoding (UTF-8 by default)
        xmlHttpTransaction.setEncodingCharSet("UTF-8");
        xmlHttpTransaction.setXmlEncoding("UTF-8");
        // Ignore SOAP elements in response
        xmlHttpTransaction.setIgnoreSoapEnveloppe(true);
        // Adds parameters
        XMLVector<XMLVector<String>> parameters = new XMLVector<XMLVector<String>>();
        XMLVector<String> xmlv;
        xmlv = new XMLVector<String>();
        xmlv.add(HeaderName.ContentType.value());
        xmlv.add(MimeType.TextXml.value());
        parameters.add(xmlv);
        xmlv = new XMLVector<String>();
        xmlv.add("Host");
        xmlv.add(httpConnector.getServer());
        parameters.add(xmlv);
        xmlv = new XMLVector<String>();
        xmlv.add("SOAPAction");
        // fix #4215 - SOAPAction header must be empty
        xmlv.add("");
        parameters.add(xmlv);
        xmlv = new XMLVector<String>();
        xmlv.add("user-agent");
        xmlv.add("Convertigo EMS " + Version.fullProductVersion);
        parameters.add(xmlv);
        xmlHttpTransaction.setHttpParameters(parameters);
        QName qname = null;
        boolean bRPC = false;
        String style = operation.getStyle();
        if (style.toUpperCase().equals("RPC"))
            bRPC = true;
        // Set SOAP response element
        if (bRPC) {
            try {
                MessagePart[] parts = operation.getDefaultResponseParts();
                if (parts.length > 0) {
                    String ename = parts[0].getName();
                    if (parts[0].getPartType().name().equals("CONTENT")) {
                        MessagePart.ContentPart mpcp = (MessagePart.ContentPart) parts[0];
                        qname = mpcp.getSchemaType().getName();
                        if (qname != null) {
                            // response is based on an element defined with a type
                            // operationResponse element name; element name; element type
                            String responseQName = operationName + "Response;" + ename + ";" + "{" + qname.getNamespaceURI() + "}" + qname.getLocalPart();
                            xmlHttpTransaction.setResponseElementQName(responseQName);
                        }
                    }
                }
            } catch (Exception e) {
            }
        } else {
            try {
                qname = operation.getResponseBodyElementQName();
                if (qname != null) {
                    QName refName = new QName(qname.getNamespaceURI(), qname.getLocalPart());
                    xmlHttpTransaction.setXmlElementRefAffectation(new XmlQName(refName));
                }
            } catch (Exception e) {
            }
        }
        // Create request/response
        request = operation.addNewRequest("Test" + transactionName);
        requestXml = operation.createRequest(true);
        request.setRequestContent(requestXml);
        // responseXml = operation.createResponse(true);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document requestDoc = db.parse(new InputSource(new StringReader(requestXml)));
        // Document responseDoc = db.parse(new InputSource(new StringReader(responseXml)));
        Element enveloppe = requestDoc.getDocumentElement();
        String soapenvNamespace = enveloppe.getNamespaceURI();
        // Retrieve variables
        Element header = (Element) requestDoc.getDocumentElement().getElementsByTagNameNS(soapenvNamespace, "Header").item(0);
        Element body = (Element) requestDoc.getDocumentElement().getElementsByTagNameNS(soapenvNamespace, "Body").item(0);
        // System.out.println(XMLUtils.prettyPrintDOM(requestDoc));
        // Extract variables
        List<RequestableHttpVariable> variables = new ArrayList<RequestableHttpVariable>();
        extractSoapVariables(xmlSchema, variables, header, null, false, null);
        extractSoapVariables(xmlSchema, variables, body, null, false, null);
        // Serialize request/response into template xml files
        String projectName = project.getName();
        String connectorName = httpConnector.getName();
        String templateDir = Engine.projectDir(projectName) + "/soap-templates/" + connectorName;
        File dir = new File(templateDir);
        if (!dir.exists())
            dir.mkdirs();
        String requestTemplateName = "/soap-templates/" + connectorName + "/" + xmlHttpTransaction.getName() + ".xml";
        String requestTemplate = Engine.PROJECTS_PATH + "/" + projectName + requestTemplateName;
        xmlHttpTransaction.setRequestTemplate(requestTemplateName);
        saveTemplate(requestDoc, requestTemplate);
        // Adds variables
        for (RequestableHttpVariable variable : variables) {
            // System.out.println("adding "+ variable.getName());
            xmlHttpTransaction.add(variable);
        }
        xmlHttpTransaction.hasChanged = true;
    }
    return xmlHttpTransaction;
}
Also used : InputSource(org.xml.sax.InputSource) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) MessagePart(com.eviware.soapui.model.iface.MessagePart) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) WsdlRequest(com.eviware.soapui.impl.wsdl.WsdlRequest) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) File(java.io.File)

Aggregations

XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)51 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)18 EngineException (com.twinsoft.convertigo.engine.EngineException)15 Element (org.w3c.dom.Element)15 IOException (java.io.IOException)10 NodeList (org.w3c.dom.NodeList)8 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)7 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)6 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)6 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)6 Shell (org.eclipse.swt.widgets.Shell)6 Step (com.twinsoft.convertigo.beans.core.Step)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ArrayList (java.util.ArrayList)5 Document (org.w3c.dom.Document)5 Block (com.twinsoft.convertigo.beans.core.Block)4 Sequence (com.twinsoft.convertigo.beans.core.Sequence)4 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)4 TestCase (com.twinsoft.convertigo.beans.core.TestCase)4 Variable (com.twinsoft.convertigo.beans.core.Variable)4