use of com.twinsoft.convertigo.engine.ConvertigoError in project convertigo by convertigo.
the class XmlHttpTransaction method makeDocument.
@Override
public void makeDocument(byte[] httpData) throws Exception {
Engine.logBeans.trace("makeDocument : " + getEncodingCharSet());
Charset charset = XMLUtils.getEncoding(httpData, Charset.forName(xmlEncoding));
String sdata = new String(httpData, charset);
sdata = sdata.replaceFirst("[\\d\\D]*?<", "<");
Engine.logBeans.trace("makeDocument afternewString: " + sdata);
Document xmlHttpDocument = requester.parseDOM(sdata);
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("makeDocument after parseDom: " + XMLUtils.prettyPrintDOM(xmlHttpDocument));
// Replace SOAP fault by an c8o error element
if (isErrorOnSoapFault()) {
Element soapFaultElement = null;
soapFaultElement = getSoapFaultElement(xmlHttpDocument);
if (soapFaultElement != null) {
String sfm = getSoapFaultMessage(soapFaultElement);
ConvertigoException ex = new ConvertigoException("The Web Service returned a SOAP Fault", new SOAPException(sfm));
ConvertigoError err = ConvertigoError.initError(ErrorType.Project, ex);
Document errDocument = err.buildErrorDocument(getRequester(), context);
Node error = context.outputDocument.importNode(errDocument.getDocumentElement().getFirstChild(), true);
context.outputDocument.getDocumentElement().appendChild(error);
return;
}
}
if (getAllowDownloadAttachment()) {
Element attachmentInfo = (Element) XPathAPI.selectSingleNode(context.outputDocument, "/document/AttachmentInfo");
if (attachmentInfo != null) {
NodeList nl = XPathAPI.selectNodeList(attachmentInfo, "attachment");
for (int i = 0; i < nl.getLength(); i++) {
Element attachment = (Element) nl.item(i);
String cid = attachment.getAttribute("cid");
if (StringUtils.isNotBlank(cid)) {
Element include = (Element) XPathAPI.selectSingleNode(xmlHttpDocument, "//*[local-name()='Include' and @href='" + cid + "']");
if (include != null) {
include.appendChild(xmlHttpDocument.importNode(attachment, true));
XMLUtils.removeNode(attachment);
}
}
}
if (XPathAPI.selectSingleNode(attachmentInfo, "attachment") == null) {
XMLUtils.removeNode(attachmentInfo);
}
}
}
// Removes soap elements if needed
if (isIgnoreSoapEnveloppe()) {
Element soapBodyResponseElement = null;
soapBodyResponseElement = getSoapBodyResponseElement(xmlHttpDocument.getDocumentElement());
if (soapBodyResponseElement != null) {
NamedNodeMap attributes = ((Element) soapBodyResponseElement.getParentNode()).getAttributes();
NodeList childNodes = soapBodyResponseElement.getChildNodes();
int len = childNodes.getLength();
Node child, node;
for (int i = 0; i < len; i++) {
node = childNodes.item(i);
if (node instanceof Element) {
// child = importNodeWithNoPrefix(context.outputDocument, node, true);
child = context.outputDocument.importNode(node, true);
// add envelope attributes (e.g namespace declarations to avoid unbound prefixes for XSL transformation)
for (int j = 0; j < attributes.getLength(); j++) {
Node attr = attributes.item(j);
((Element) child).setAttributeNode((Attr) context.outputDocument.importNode(attr, true));
}
context.outputDocument.getDocumentElement().appendChild(child);
}
}
} else {
XMLUtils.copyDocument(xmlHttpDocument, context.outputDocument);
}
} else
// Normal case
XMLUtils.copyDocument(xmlHttpDocument, context.outputDocument);
}
use of com.twinsoft.convertigo.engine.ConvertigoError in project convertigo by convertigo.
the class XMLErrorStep method createStepNodeValue.
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
try {
String sCode, eMessage, eDetails;
int eCode = (sCode = code.getSingleString(this)) == null ? -1 : sCode.equals("") ? -1 : Integer.parseInt(sCode);
eMessage = (eMessage = message.getSingleString(this)) == null ? "" : eMessage;
eDetails = (eDetails = details.getSingleString(this)) == null ? "" : eDetails;
ConvertigoError err = ConvertigoError.initError(eCode, ErrorType.Project, new StepException(eMessage, eDetails));
err.appendOutputNodes(stepNode, getSequence().context, false);
try {
Element exception = (Element) stepNode.getElementsByTagName("exception").item(0);
stepNode.replaceChild(doc.createElement("exception"), exception);
Element stacktrace = (Element) stepNode.getElementsByTagName("stacktrace").item(0);
stepNode.replaceChild(doc.createElement("stacktrace"), stacktrace);
} catch (Exception e) {
}
} catch (Exception e) {
setErrorStatus(true);
Engine.logBeans.error("An error occured while generating values from XMLErrorStep", e);
// throw new EngineException("Unable to generate XMLErrorStep",e);
}
}
Aggregations