Search in sources :

Example 1 with XmlQName

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

the class XmlHttpTransaction method generateWsdlType.

@Override
public String generateWsdlType(Document document) throws Exception {
    XmlQName xmlQName = getXmlElementRefAffectation();
    String reqn = getResponseElementQName();
    if (!reqn.equals("") || !xmlQName.isEmpty()) {
        // String opName = getName()+"Response", eltName = "response", eltType = "xsd:string";
        // boolean useRef = true;
        // int index, index2;
        // if ((index = reqn.indexOf(";")) != -1) {
        // useRef = false;
        // opName = reqn.substring(0, index);
        // if ((index2 = reqn.indexOf(";", index+1)) != -1) {
        // eltName = reqn.substring(index+1,index2);
        // eltType = reqn.substring(index2+1);
        // }
        // }
        // 
        // String prefix = getXsdTypePrefix();
        // String xsdType = "";
        // xsdType += "<xsd:complexType name=\""+ prefix + getName() +"Response" +"\" >\n";
        // xsdType += "  <xsd:sequence>\n";
        // if (useRef)
        // xsdType += "    <xsd:element ref=\""+ reqn +"\"/>\n";
        // else {
        // xsdType += "    <xsd:element name=\""+ opName +"\">\n";
        // xsdType += "      <xsd:complexType>\n";
        // xsdType += "        <xsd:sequence>\n";
        // xsdType += "          <xsd:element name=\""+ eltName +"\" type=\""+ eltType +"\"/>\n";
        // xsdType += "        </xsd:sequence>\n";
        // xsdType += "      </xsd:complexType>\n";
        // xsdType += "    </xsd:element>\n";
        // }
        // xsdType += "  </xsd:sequence>\n";
        // xsdType += "</xsd:complexType>\n";
        String xsdType = "<xsd:complexType name=\"" + getXsdResponseElementName() + "\" />\n";
        try {
            XmlSchema xmlSchema = createSchema();
            XmlSchemaComplexType cType = (XmlSchemaComplexType) xmlSchema.getTypeByName(getXsdResponseTypeName());
            xsdType = cType.toString("xsd", 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return xsdType;
    }
    return super.generateWsdlType(document);
}
Also used : XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) SOAPException(javax.xml.soap.SOAPException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException)

Example 2 with XmlQName

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

the class XmlHttpTransaction method getXmlSchemaObject.

@SuppressWarnings("unused")
@Override
public XmlSchemaInclude getXmlSchemaObject(XmlSchemaCollection collection, XmlSchema schema) {
    XmlQName xmlQName = getXmlElementRefAffectation();
    String reqn = getResponseElementQName();
    if (!xmlQName.isEmpty() || !reqn.equals("")) {
        long timeStart = System.currentTimeMillis();
        XmlSchemaInclude xmlSchemaInclude = new XmlSchemaInclude();
        XmlSchema transactionSchema = createSchema();
        if (transactionSchema != null) {
            // Transformer transformer = TransformerFactory.newInstance().newTransformer();
            // transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            // transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
            // transformer.transform(new DOMSource(transactionSchema.getSchemaDocument()), new StreamResult(System.out));
            xmlSchemaInclude.setSchema(transactionSchema);
        }
        long timeStop = System.currentTimeMillis();
        // System.out.println("Schema for \"" + getName() + "\" | Times >> total : " + (timeStop - timeStart) + " ms");
        return xmlSchemaInclude;
    } else {
        return super.getXmlSchemaObject(collection, schema);
    }
}
Also used : XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaInclude(org.apache.ws.commons.schema.XmlSchemaInclude)

Example 3 with XmlQName

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

the class XmlHttpTransaction method extractXsdType.

@Override
protected String extractXsdType(Document document) throws Exception {
    XmlQName xmlQName = getXmlElementRefAffectation();
    String reqn = getResponseElementQName();
    if (!reqn.equals("") || !xmlQName.isEmpty())
        return generateWsdlType(document);
    return super.extractXsdType(document);
}
Also used : XmlQName(com.twinsoft.convertigo.beans.common.XmlQName)

Example 4 with XmlQName

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

the class WsReference method createHttpVariable.

private static RequestableHttpVariable createHttpVariable(boolean multi, String variableName, QName schemaTypeName) throws EngineException {
    RequestableHttpVariable httpVariable = (multi ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable());
    httpVariable.setName(variableName);
    httpVariable.setDescription(variableName);
    httpVariable.setWsdl(Boolean.TRUE);
    httpVariable.setPersonalizable(Boolean.FALSE);
    httpVariable.setCachedKey(Boolean.TRUE);
    httpVariable.setHttpMethod("POST");
    httpVariable.setHttpName(variableName.toUpperCase());
    httpVariable.setXmlTypeAffectation(new XmlQName(schemaTypeName));
    httpVariable.bNew = true;
    return httpVariable;
}
Also used : XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable)

Example 5 with XmlQName

use of com.twinsoft.convertigo.beans.common.XmlQName 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

XmlQName (com.twinsoft.convertigo.beans.common.XmlQName)16 QName (javax.xml.namespace.QName)6 EngineException (com.twinsoft.convertigo.engine.EngineException)5 XmlSchema (org.apache.ws.commons.schema.XmlSchema)4 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)4 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)4 XmlHttpTransaction (com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction)3 File (java.io.File)3 IOException (java.io.IOException)3 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)3 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)3 Document (org.w3c.dom.Document)3 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)2 Connector (com.twinsoft.convertigo.beans.core.Connector)2 Transaction (com.twinsoft.convertigo.beans.core.Transaction)2 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)2 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)2 StringReader (java.io.StringReader)2 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)2 InputSource (org.xml.sax.InputSource)2