Search in sources :

Example 1 with RequestableEngineEvent

use of com.twinsoft.convertigo.engine.RequestableEngineEvent in project convertigo by convertigo.

the class SequenceEditorPartWrap method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromSequence = false;
    if (event instanceof RequestableEngineEvent) {
        RequestableEngineEvent requestableEvent = (RequestableEngineEvent) event;
        String sequenceName = requestableEvent.getSequenceName();
        if (sequenceName != null) {
            if (sequenceName.equals(sequence.getName()) && requestableEvent.getProjectName().equals(sequence.getProject().getName())) {
                isSourceFromSequence = true;
            }
        }
    } else if (event instanceof EngineEvent) {
        Object ob = ((EngineEvent) event).getSource();
        if (ob instanceof Step) {
            try {
                String projectName = ((Step) ob).getProject().getName();
                String sequenceName = ((Step) ob).getSequence().getName();
                if (sequenceName.equals(sequence.getName()) && projectName.equals(sequence.getProject().getName())) {
                    isSourceFromSequence = true;
                }
            } catch (Exception e) {
            }
        }
    }
    return isSourceFromSequence;
}
Also used : RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EventObject(java.util.EventObject) Step(com.twinsoft.convertigo.beans.core.Step)

Example 2 with RequestableEngineEvent

use of com.twinsoft.convertigo.engine.RequestableEngineEvent in project convertigo by convertigo.

the class SequenceEditorPart method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromSequence = false;
    if (event instanceof RequestableEngineEvent) {
        RequestableEngineEvent requestableEvent = (RequestableEngineEvent) event;
        String sequenceName = requestableEvent.getSequenceName();
        if (sequenceName != null) {
            if (sequenceName.equals(sequence.getName()) && requestableEvent.getProjectName().equals(sequence.getProject().getName())) {
                isSourceFromSequence = true;
            }
        }
    } else if (event instanceof EngineEvent) {
        Object ob = ((EngineEvent) event).getSource();
        if (ob instanceof Step) {
            try {
                String projectName = ((Step) ob).getProject().getName();
                String sequenceName = ((Step) ob).getSequence().getName();
                if (sequenceName.equals(sequence.getName()) && projectName.equals(sequence.getProject().getName())) {
                    isSourceFromSequence = true;
                }
            } catch (Exception e) {
            }
        }
    }
    return isSourceFromSequence;
}
Also used : RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EventObject(java.util.EventObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Step(com.twinsoft.convertigo.beans.core.Step) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

Example 3 with RequestableEngineEvent

use of com.twinsoft.convertigo.engine.RequestableEngineEvent in project convertigo by convertigo.

the class GenericRequester method processRequest.

@Override
public final Object processRequest(Object inputData) throws Exception {
    if (Engine.theApp == null)
        throw new EngineException("Unable to process the request: the Convertigo engine is not started!");
    Object result = null;
    boolean needRetry;
    boolean addStatistics = false;
    try {
        do {
            needRetry = false;
            this.inputData = inputData;
            context = getContext();
            Engine.logContext.debug("[" + getName() + "] Locking the working semaphore...");
            synchronized (context) {
                // #4910 : case of queued sequences, renew the context
                if (context.removalRequired()) {
                    context.requireRemoval(false);
                    Engine.theApp.contextManager.remove(context);
                }
                if (context.isDestroying) {
                    needRetry = true;
                    continue;
                }
                context.waitingRequests++;
                Engine.logContext.debug("[" + getName() + "] Working semaphore locked (" + context.waitingRequests + " requests(s) pending) [" + context.hashCode() + "]");
                // Update log4j context infos
                Log4jHelper.mdcInit(context);
                long uniqueRequestID = System.currentTimeMillis() + (long) (Math.random() * 1261440000000L);
                Log4jHelper.mdcPut(mdcKeys.UID, Long.toHexString(uniqueRequestID));
                Log4jHelper.mdcPut(mdcKeys.ContextID, context.contextID);
                Log4jHelper.mdcPut(mdcKeys.Project, context.projectName);
                Log4jHelper.mdcPut(mdcKeys.ClientIP, context.remoteAddr);
                if (inputData instanceof HttpServletRequest) {
                    HttpServletRequest request = (HttpServletRequest) inputData;
                    String deviceUUID = request.getParameter(Parameter.DeviceUUID.getName());
                    if (deviceUUID != null) {
                        Log4jHelper.mdcPut(mdcKeys.UUID, deviceUUID);
                        Engine.logContext.debug("[" + getName() + "] request from device UUID: '" + deviceUUID + "' with user agent '" + request.getHeader(HeaderName.UserAgent.value()) + "'");
                    }
                }
                Engine.logContext.trace("[" + getName() + "] start");
                context.statistics.clearLatestDurations();
                String t = context.statistics.start(EngineStatistics.REQUEST);
                try {
                    if ((context.isAsync) && (JobManager.jobExists(context.contextID))) {
                        Engine.logContext.debug("[" + getName() + "] Context is async and job is running, do not initialize context");
                    } else {
                        Engine.logContext.trace("[" + getName() + "] Context is not async and no job are running");
                        initContext(context);
                        if (context.sequenceName != null)
                            Log4jHelper.mdcPut(mdcKeys.Sequence, context.sequenceName);
                        if (context.transactionName != null) {
                            Log4jHelper.mdcPut(mdcKeys.Connector, context.connectorName);
                            Log4jHelper.mdcPut(mdcKeys.Transaction, context.transactionName);
                        }
                        context.updateUserInLog();
                    }
                    result = coreProcessRequest();
                    result = getTranslator().buildOutputData(context, result);
                } finally {
                    if (context != null) {
                        context.statistics.stop(t);
                        // Bugfix for #853 (Tomcat looses parameters without any explanation)
                        // Remove the request and session references from the context
                        // Moved here by #2254
                        Engine.logContext.trace("Bugfix #853, #2254");
                        Engine.logContext.trace("context=" + context);
                        Engine.logContext.trace("Removing request and session objects from the context");
                        if (context.requestedObject != null) {
                            addStatistics = context.requestedObject.getAddStatistics();
                        }
                        context.clearRequest();
                    }
                }
            }
        } while (needRetry);
    } finally {
        if (context != null) {
            String stats = null;
            if (Engine.logStatistics.isInfoEnabled()) {
                stats = context.statistics.printStatistics();
                Engine.logStatistics.info("Statistics:\n" + stats);
            }
            String s = EnginePropertiesManager.getProperty(EnginePropertiesManager.PropertyName.DOCUMENT_INCLUDE_STATISTICS);
            boolean bStatistics = (s.equalsIgnoreCase("true"));
            if (bStatistics) {
                result = addStatisticsAsText(stats, result);
            }
            if (addStatistics) {
                // Requestable data statistics
                addStatisticsAsData(result);
            }
            if (result instanceof Document) {
                Engine.theApp.fireDocumentGenerated(new RequestableEngineEvent((Document) result, context.projectName, context.sequenceName, context.connectorName));
            }
            context.waitingRequests--;
            Engine.logContext.debug("[" + getName() + "] Working semaphore released (" + context.waitingRequests + " request(s) pending) [" + context.hashCode() + "]");
        }
        Engine.logContext.debug("[" + getName() + "] end of request");
        // Remove all MDC values for clean release of the thread
        Log4jHelper.mdcClear();
    }
    return result;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Document(org.w3c.dom.Document)

Example 4 with RequestableEngineEvent

use of com.twinsoft.convertigo.engine.RequestableEngineEvent in project convertigo by convertigo.

the class ConnectorEditorPart method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromConnector = false;
    if (event instanceof RequestableEngineEvent) {
        RequestableEngineEvent requestableEvent = (RequestableEngineEvent) event;
        String connectorName = requestableEvent.getConnectorName();
        if (connectorName != null) {
            if (connectorName.equals(connector.getName()) && requestableEvent.getProjectName().equals(connector.getProject().getName())) {
                isSourceFromConnector = true;
            }
        }
    } else if (event instanceof EngineEvent) {
        Object ob = ((EngineEvent) event).getSource();
        if (ob instanceof DatabaseObject) {
            try {
                String projectName = ((DatabaseObject) ob).getProject().getName();
                String connectorName = ((DatabaseObject) ob).getConnector().getName();
                if (connectorName.equals(connector.getName()) && projectName.equals(connector.getProject().getName())) {
                    isSourceFromConnector = true;
                }
            } catch (Exception e) {
            }
        }
    }
    return isSourceFromConnector;
}
Also used : RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) EventObject(java.util.EventObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

Example 5 with RequestableEngineEvent

use of com.twinsoft.convertigo.engine.RequestableEngineEvent in project convertigo by convertigo.

the class ConnectorEditorPartWrap method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromConnector = false;
    if (event instanceof RequestableEngineEvent) {
        RequestableEngineEvent requestableEvent = (RequestableEngineEvent) event;
        String connectorName = requestableEvent.getConnectorName();
        if (connectorName != null) {
            if (connectorName.equals(connector.getName()) && requestableEvent.getProjectName().equals(connector.getProject().getName())) {
                isSourceFromConnector = true;
            }
        }
    } else if (event instanceof EngineEvent) {
        Object ob = ((EngineEvent) event).getSource();
        if (ob instanceof DatabaseObject) {
            try {
                String projectName = ((DatabaseObject) ob).getProject().getName();
                String connectorName = ((DatabaseObject) ob).getConnector().getName();
                if (connectorName.equals(connector.getName()) && projectName.equals(connector.getProject().getName())) {
                    isSourceFromConnector = true;
                }
            } catch (Exception e) {
            }
        }
    }
    return isSourceFromConnector;
}
Also used : RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) EventObject(java.util.EventObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Aggregations

RequestableEngineEvent (com.twinsoft.convertigo.engine.RequestableEngineEvent)5 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)4 EngineEvent (com.twinsoft.convertigo.engine.EngineEvent)4 EventObject (java.util.EventObject)4 Step (com.twinsoft.convertigo.beans.core.Step)2 IOException (java.io.IOException)2 JSONException (org.codehaus.jettison.json.JSONException)2 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 KeyExpiredException (com.twinsoft.convertigo.engine.KeyExpiredException)1 MaxCvsExceededException (com.twinsoft.convertigo.engine.MaxCvsExceededException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Document (org.w3c.dom.Document)1