use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class RequestableObject method run.
/**
* Initializes all common things for transaction and launch
* the execution of the core transaction.
*
* @param requester the calling requester.
* @param context the associated context.
*
* @return the resulting DOM of the transaction.
*/
public Document run(Requester requester, Context context) throws EngineException {
fireRequestableEvent(RequestableObject.EVENT_REQUESTABLE_STARTED);
try {
this.requester = requester;
this.context = context;
this.score = 0;
context.cacheControl = this.isClientCachable() ? "true" : "false";
context.outputDocument = requester.createDOM(getEncodingCharSet());
Element outputDocumentRootElement = context.outputDocument.createElement("document");
context.outputDocument.appendChild(outputDocumentRootElement);
outputDocumentRootElement.setAttribute("project", context.projectName);
outputDocumentRootElement.setAttribute("sequence", context.sequenceName);
outputDocumentRootElement.setAttribute("connector", context.connectorName);
outputDocumentRootElement.setAttribute("transaction", context.transactionName);
if (context.lang != null && context.lang.length() != 0) {
outputDocumentRootElement.setAttribute("lang", context.lang);
}
int maxNbCurrentWorkerThreads = Integer.parseInt(EnginePropertiesManager.getProperty(PropertyName.DOCUMENT_THREADING_MAX_WORKER_THREADS));
if (nbCurrentWorkerThreads >= maxNbCurrentWorkerThreads)
throw new EngineException("No more available worker thread (" + maxNbCurrentWorkerThreads + ")");
Engine.logContext.debug("(RequestableObject) Start of the thread for the requested object '" + getName() + "' (" + context.contextID + ")");
workerThreadCreationStatistic = context.statistics.start(EngineStatistics.WORKER_THREAD_START);
runningThread = new RequestableThread();
runningThread.start();
try {
synchronized (Engine.theApp) {
// modification of the worker threads counter
if (runningThread.engineId == Engine.startStopDate)
nbCurrentWorkerThreads++;
}
boolean hasBeenInterrupted = false;
do {
try {
synchronized (runningThread) {
long lTime = System.currentTimeMillis();
long haveToWait;
while (runningThread.bContinue) {
if (getResponseTimeout() <= 0) {
Engine.logContext.trace("(RequestableObject) Waiting for requested object response during 60s...");
haveToWait = 60000;
runningThread.wait(60000);
} else if (Engine.isStudioMode()) {
// Studio context => ~infinite responseTimeout
Engine.logContext.trace("(RequestableObject) Waiting for requested object response during infinite timeout (24 hours) because of Studio context execution...");
haveToWait = 1000 * 60 * 60 * 24;
runningThread.wait(1000 * 60 * 60 * 24);
} else {
Engine.logContext.trace("(RequestableObject) Waiting for requested object response during " + getResponseTimeout() + "s");
haveToWait = getResponseTimeout() * 1000;
runningThread.wait(getResponseTimeout() * 1000);
}
Engine.logContext.trace("(RequestableObject) End of wait(), runningThread.bContinue=" + runningThread.bContinue);
if (runningThread.bContinue) {
if (System.currentTimeMillis() - lTime > haveToWait) {
// Cleans up before stopping
cleanup();
// Stops thread
if (EnginePropertiesManager.getProperty(PropertyName.DOCUMENT_THREADING_USE_STOP_METHOD).equalsIgnoreCase("true")) {
ThreadUtils.stopThread(runningThread);
Engine.logContext.error("(RequestableObject) Stopping the thread for the requested object '" + getName() + "' because of timeout expiration");
} else {
runningThread.bContinue = false;
Engine.logContext.error("(RequestableObject) Request for stopping the thread for the requested object '" + getName() + "' because of timeout expiration");
}
TransactionTimeoutException e = new TransactionTimeoutException("The requested object '" + getName() + "' has been interrupted because it did not terminate quickly enough.");
throw e;
} else
Engine.logContext.trace("(RequestableObject) Spurious wakup , keep waiting");
}
}
}
} catch (InterruptedException e) {
Engine.logContext.warn("(RequestableObject) InterruptedException while waiting for requested object response; retrying wait()");
hasBeenInterrupted = true;
}
} while (hasBeenInterrupted && runningThread.bContinue);
} finally {
synchronized (Engine.theApp) {
// modification of the worker threads counter
if (runningThread.engineId == Engine.startStopDate)
nbCurrentWorkerThreads--;
}
}
// An exception has been thrown ?
if (runningThread.exception != null)
if (runningThread.exception instanceof EngineException)
throw (EngineException) runningThread.exception;
else
throw new EngineException("An unexpected error has occured while the execution of the requested object '" + getName() + "'.", runningThread.exception);
outputDocumentRootElement.setAttribute("generated", Calendar.getInstance(Locale.getDefault()).getTime().toString());
Engine.logContext.debug("(RequestableObject) End of the thread for the requested object '" + getName() + "'");
/*
* If we have a status node , this means that we are in async mode.
* As the outputDocument has been used to return the status, the outputdocument will be appended to the status.
*
* In this case, We have to :
* 1) delete JOB tags in status
* 2) add as child node to outputDocumentRootElement the follwing sibling (the real data)
* 3) replace status with outputDocumentRootElement.
*
if (context.isAsync) {
NodeList nl = context.outputDocument.getElementsByTagName("status");
if (nl.getLength() != 0) {
nl.item(0).removeChild(nl.item(0).getFirstChild()); // remove "job" tag, now firstChild is the real data
Node node = outputDocumentRootElement.getOwnerDocument().importNode(nl.item(0).getFirstChild(), true);
outputDocumentRootElement.appendChild(node);
node = context.outputDocument.importNode(outputDocumentRootElement, true);
context.outputDocument.removeChild(nl.item(0));
context.outputDocument.appendChild(node);
}
}
*/
} finally {
fireRequestableEvent(RequestableObject.EVENT_REQUESTABLE_FINISHED);
this.context = null;
this.requester = null;
this.runningThread = null;
this.scope = null;
}
return context.outputDocument;
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class RequestableObject 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;
}
try {
NodeList childNodes = element.getElementsByTagName("wsdltype");
int len = childNodes.getLength();
if (len > 0) {
Node childNode = childNodes.item(0);
Node cdata = XMLUtils.findChildNode(childNode, Node.CDATA_SECTION_NODE);
if (cdata != null) {
wsdlType = cdata.getNodeValue();
Engine.logBeans.trace("(Requestable) Requestable.configure() : wsdltype has been successfully set");
} else {
Engine.logBeans.trace("(Requestable) Requestable.configure() : wsdltype is empty");
}
}
} catch (Exception e) {
throw new EngineException("Unable to configure the WSDL types of the requestable \"" + getName() + "\".", e);
}
try {
// Convert the publicMethod property to new semantic (accessibility)
if (VersionUtils.compare(version, "6.1.2") < 0) {
boolean publicMethod = (Boolean) XMLUtils.findPropertyValue(element, "publicMethod");
if (publicMethod) {
setAccessibility(Accessibility.Public);
} else {
setAccessibility(Accessibility.Hidden);
}
hasChanged = true;
Engine.logBeans.warn("[RequestableObject] The object \"" + getName() + "\" has been updated to version 6.1.2; publicMethod=" + publicMethod + "; accessibility=" + accessibility);
}
} catch (Exception e) {
throw new EngineException("Unable to migrate the accessibility for requestable \"" + getName() + "\".", e);
}
if (VersionUtils.compare(version, "4.6.0") < 0) {
// Backup wsdlTypes to file
try {
backupWsdlTypes(element);
if (!wsdlType.equals("")) {
wsdlType = "";
hasChanged = true;
Engine.logBeans.warn("[RequestableObject] Successfully backup wsdlTypes for requestable \"" + getName() + "\" (v 4.6.0)");
} else {
Engine.logBeans.warn("[RequestableObject] Empty wsdlTypes for requestable \"" + getName() + "\", none backup done (v 4.6.0)");
}
} catch (Exception e) {
Engine.logBeans.error("[RequestableObject] Could not backup wsdlTypes for requestable \"" + getName() + "\" (v 4.6.0)", e);
}
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class RequestableStep method stepExecute.
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
if (super.stepExecute(javascriptContext, scope)) {
try {
request = new HashMap<String, Object>();
try {
prepareForRequestable(javascriptContext, scope);
} catch (Exception e) {
Engine.logBeans.error("An error occured while preparing transaction step \"" + RequestableStep.this.getName() + "\"", e);
xmlHttpDocument = ConvertigoError.get(e).buildErrorDocument(sequence.getRequester(), sequence.context, false);
flushDocument();
return true;
}
if (bInternalInvoke) {
Engine.logBeans.debug("(RequestableStep) Internal invoke requested");
InternalRequester internalRequester = new InternalRequester(request, sequence.context.httpServletRequest);
LogParameters logParameters = sequence.context.logParameters;
Object result = internalRequester.processRequest();
// MDC log parameters must return to their original values, because
// the internal requester has been executed on the same thread as us.
Log4jHelper.mdcSet(logParameters);
if (result != null) {
xmlHttpDocument = (Document) result;
// if (Engine.isStudioMode()) {
// ((Sequence)sequence.getOriginal()).fireDataChanged(new SequenceEvent(this, result));
// }
// else {
// sequence.fireDataChanged(new SequenceEvent(this, result));
// }
((Sequence) sequence.getOriginal()).fireDataChanged(new SequenceEvent(this, result));
flushDocument();
}
} else {
Engine.logBeans.debug("(RequestableStep) requesting : " + method.getURI());
byte[] result = executeMethod();
Engine.logBeans.debug("(RequestableStep) Total read bytes: " + ((result != null) ? result.length : 0));
if (result != null) {
makeDocument(result);
if (Engine.isStudioMode()) {
((Sequence) sequence.getOriginal()).fireDataChanged(new SequenceEvent(this, result));
} else {
sequence.fireDataChanged(new SequenceEvent(this, result));
}
flushDocument();
}
}
} catch (Exception e) {
setErrorStatus(true);
Engine.logBeans.error("An error occured while invoking transaction step \"" + RequestableStep.this.getName() + "\"", e);
} finally {
if (!bInternalInvoke && (method != null))
method.releaseConnection();
}
return true;
}
}
return false;
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class ScreenClass method getOrder.
/**
* Get representation of order for quick sort of a given database object.
*/
@Override
public Object getOrder(Object object) throws EngineException {
if (object instanceof Criteria) {
List<Long> ordered = orderedCriterias.get(0);
long time = ((Criteria) object).priority;
if (ordered.contains(time))
return (long) ordered.indexOf(time);
else
throw new EngineException("Corrupted criterias for screenclass \"" + getName() + "\". Criteria \"" + ((Criteria) object).getName() + "\" with priority \"" + time + "\" isn't referenced anymore.");
} else if (object instanceof ExtractionRule) {
List<Long> ordered = orderedExtractionRules.get(0);
long time = ((ExtractionRule) object).priority;
if (ordered.contains(time))
return (long) ordered.indexOf(time);
else
throw new EngineException("Corrupted extraction rules for screenclass \"" + getName() + "\". Extraction rule \"" + ((ExtractionRule) object).getName() + "\" with priority \"" + time + "\" isn't referenced anymore.");
} else
return super.getOrder(object);
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class Sequence method createDOM.
public Document createDOM() throws EngineException {
Document doc = null;
try {
if (requester == null)
doc = new DefaultRequester().createDomWithNoXMLDeclaration(getEncodingCharSet());
else
doc = ((GenericRequester) requester).createDomWithNoXMLDeclaration(getEncodingCharSet());
Element rootElement = doc.createElement("document");
doc.appendChild(rootElement);
} catch (Exception e) {
}
return doc;
}
Aggregations