use of com.twinsoft.convertigo.engine.requesters.InternalRequester in project convertigo by convertigo.
the class ConnectorEditorPartWrap method runRequestable.
private void runRequestable(final String projectName, final Map<String, String[]> parameters) {
if (!Engine.isStartFailed && Engine.isStarted) {
parameters.put(Parameter.Project.getName(), new String[] { projectName });
new Thread(new Runnable() {
@Override
public void run() {
try {
InternalHttpServletRequest request;
if (session == null) {
request = new InternalHttpServletRequest();
session = request.getSession();
} else {
request = new InternalHttpServletRequest(session);
}
new InternalRequester(GenericUtils.<Map<String, Object>>cast(parameters), request).processRequest();
} catch (Exception e) {
// logException(e, "Failed to run the requestable of project " + projectName);
}
}
}).start();
} else {
// logInfo("Cannot run the requestable of project " + projectName + ", the embedded tomcat is not correctly started.");
}
}
use of com.twinsoft.convertigo.engine.requesters.InternalRequester in project convertigo by convertigo.
the class SequenceEditorPartWrap method runRequestable.
private void runRequestable(final String projectName, final Map<String, String[]> parameters) {
if (!Engine.isStartFailed && Engine.isStarted) {
parameters.put(Parameter.Project.getName(), new String[] { projectName });
new Thread(new Runnable() {
@Override
public void run() {
try {
InternalHttpServletRequest request;
if (session == null) {
request = new InternalHttpServletRequest();
session = request.getSession();
} else {
request = new InternalHttpServletRequest(session);
}
new InternalRequester(GenericUtils.<Map<String, Object>>cast(parameters), request).processRequest();
} catch (Exception e) {
// logException(e, "Failed to run the requestable of project " + projectName);
}
}
}).start();
} else {
// logInfo("Cannot run the requestable of project " + projectName + ", the embedded tomcat is not correctly started.");
}
}
use of com.twinsoft.convertigo.engine.requesters.InternalRequester 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.requesters.InternalRequester in project convertigo by convertigo.
the class Sequence method getSessionId.
public String getSessionId() {
String sessionId = null;
try {
// Case of internal requester
if (context.httpSession == null) {
try {
InternalRequester requester = (InternalRequester) context.requestedObject.requester;
Map<String, String[]> request = GenericUtils.cast(requester.inputData);
sessionId = request.get(Parameter.SessionId.getName())[0];
Engine.logBeans.debug("Sequence session ID (internal requester case): " + sessionId);
} catch (Exception e) {
// Exception case
sessionId = context.contextID.substring(0, context.contextID.indexOf("_"));
Engine.logBeans.debug("Sequence session ID (internal requester case, but with exception): " + sessionId);
Engine.logBeans.debug(e.getMessage());
}
} else // Case of servlet requester
{
sessionId = context.httpSession.getId();
Engine.logBeans.debug("Sequence session ID (servlet requester case): " + sessionId);
}
} catch (Exception e) {
Engine.logBeans.error("Unable to retrieve sessionID of sequence", e);
}
return sessionId;
}
use of com.twinsoft.convertigo.engine.requesters.InternalRequester in project convertigo by convertigo.
the class Project method executeAutoStartSequences.
public static void executeAutoStartSequences(final String projectName) {
try {
final Project p = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
if (p != null) {
for (final Sequence sequence : p.getSequencesList()) {
if (sequence.isAutoStart()) {
Engine.execute(() -> {
try {
Map<String, String[]> parameters = new HashMap<String, String[]>();
parameters.put(Parameter.Project.getName(), new String[] { projectName });
parameters.put(Parameter.Sequence.getName(), new String[] { sequence.getName() });
InternalHttpServletRequest request = new InternalHttpServletRequest();
InternalRequester requester = new InternalRequester(GenericUtils.<Map<String, Object>>cast(parameters), request);
requester.processRequest();
} catch (Exception e) {
Engine.logEngine.error("Failed to execute the auto start sequence \"" + sequence.getQName() + "\"", e);
}
});
}
}
}
} catch (Exception e) {
Engine.logEngine.error("Failed to execute auto start sequences for project \"" + projectName + "\"", e);
}
}
Aggregations