Search in sources :

Example 1 with InternalRequester

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.");
    }
}
Also used : InternalHttpServletRequest(com.twinsoft.convertigo.engine.requesters.InternalHttpServletRequest) InternalRequester(com.twinsoft.convertigo.engine.requesters.InternalRequester) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with InternalRequester

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.");
    }
}
Also used : InternalHttpServletRequest(com.twinsoft.convertigo.engine.requesters.InternalHttpServletRequest) InternalRequester(com.twinsoft.convertigo.engine.requesters.InternalRequester) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with InternalRequester

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;
}
Also used : LogParameters(com.twinsoft.convertigo.engine.LogParameters) InternalRequester(com.twinsoft.convertigo.engine.requesters.InternalRequester) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) URIException(org.apache.commons.httpclient.URIException) EngineException(com.twinsoft.convertigo.engine.EngineException) TransformerException(javax.xml.transform.TransformerException) ConnectionException(com.twinsoft.convertigo.beans.connectors.ConnectionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 4 with InternalRequester

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;
}
Also used : InternalRequester(com.twinsoft.convertigo.engine.requesters.InternalRequester) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 5 with InternalRequester

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);
    }
}
Also used : InternalHttpServletRequest(com.twinsoft.convertigo.engine.requesters.InternalHttpServletRequest) HashMap(java.util.HashMap) InternalRequester(com.twinsoft.convertigo.engine.requesters.InternalRequester) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

InternalRequester (com.twinsoft.convertigo.engine.requesters.InternalRequester)10 EngineException (com.twinsoft.convertigo.engine.EngineException)7 HashMap (java.util.HashMap)6 InternalHttpServletRequest (com.twinsoft.convertigo.engine.requesters.InternalHttpServletRequest)4 IOException (java.io.IOException)3 StringTokenizer (java.util.StringTokenizer)3 Document (org.w3c.dom.Document)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 ConnectionException (com.twinsoft.convertigo.beans.connectors.ConnectionException)1 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 UrlMapping (com.twinsoft.convertigo.beans.core.UrlMapping)1 UrlMappingParameter (com.twinsoft.convertigo.beans.core.UrlMappingParameter)1 DataContent (com.twinsoft.convertigo.beans.core.UrlMappingParameter.DataContent)1 UrlMappingResponse (com.twinsoft.convertigo.beans.core.UrlMappingResponse)1 AbstractConvertigoJob (com.twinsoft.convertigo.beans.scheduler.AbstractConvertigoJob)1