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);
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations