Search in sources :

Example 16 with Context

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

the class RequestableObject method includeInScope.

public static Object includeInScope(org.mozilla.javascript.Context cx, Scriptable thisObj, Object[] args, Function funObj) {
    Object res = Scriptable.NOT_FOUND;
    if (args.length < 1) {
        return res;
    }
    String path = (String) args[0];
    Context context = (Context) ((NativeJavaObject) thisObj.get("context", thisObj)).unwrap();
    Project project = context.project;
    File js = new File(project.getDirPath(), path);
    if (js.exists()) {
        try {
            res = RhinoUtils.evalCachedJavascript(cx, thisObj, FileUtils.readFileToString(js, "UTF-8"), path, 1, null);
        } catch (IOException e) {
            Engine.logBeans.warn("Cannot include '" + js + "' because of a read failure!", e);
        }
    } else {
        Engine.logBeans.warn("Cannot include '" + js + "' because it doesn't exist!");
    }
    return res;
}
Also used : Context(com.twinsoft.convertigo.engine.Context) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) FunctionObject(org.mozilla.javascript.FunctionObject) IOException(java.io.IOException) File(java.io.File)

Example 17 with Context

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

the class Sequence method removeTransactionContexts.

protected void removeTransactionContexts(String contextName) {
    if (Engine.isEngineMode()) {
        if (useSameJSessionForSteps()) {
            String sessionID = getSessionId();
            for (int i = 0; i < stepContextNames.size(); i++) {
                String ctxName = (String) stepContextNames.get(i);
                if (ctxName.startsWith(contextName)) {
                    String contextID = sessionID + "_" + contextName;
                    Context ctx = Engine.theApp.contextManager.get(contextID);
                    if (ctx != null && ctx.transaction != null) {
                        if (contextName.startsWith("Container-")) {
                            // Only remove context automatically named
                            if (Engine.logBeans.isDebugEnabled())
                                Engine.logBeans.debug("(Sequence) Removing transaction's context \"" + contextID + "\"");
                            Engine.theApp.contextManager.remove(contextID);
                        } else {
                            if (Engine.logBeans.isDebugEnabled())
                                Engine.logBeans.debug("(Sequence) Keeping transaction's context \"" + contextID + "\"");
                        }
                    }
                }
            }
        }
    }
}
Also used : Context(com.twinsoft.convertigo.engine.Context)

Example 18 with Context

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

the class List method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    HttpSession currentSession = request.getSession();
    Element rootElement = document.getDocumentElement();
    Element connectionsListElement = document.createElement("connections");
    rootElement.appendChild(connectionsListElement);
    Element sessionsListElement = document.createElement("sessions");
    rootElement.appendChild(sessionsListElement);
    Element contextsInUseElement = document.createElement("contextsInUse");
    contextsInUseElement.setTextContent("" + Math.max(0, Engine.theApp.contextManager.getNumberOfContexts()));
    rootElement.appendChild(contextsInUseElement);
    Element contextsNumberElement = document.createElement("contextsNumber");
    contextsNumberElement.setTextContent("" + EnginePropertiesManager.getProperty(PropertyName.CONVERTIGO_MAX_CONTEXTS));
    rootElement.appendChild(contextsNumberElement);
    Element sessionsInUseElement = document.createElement("sessionsInUse");
    sessionsInUseElement.setTextContent("" + HttpSessionListener.countSessions());
    rootElement.appendChild(sessionsInUseElement);
    Element sessionsIsOverflowElement = document.createElement("sessionsIsOverflow");
    sessionsIsOverflowElement.setTextContent(KeyManager.isOverflow(Session.EmulIDSE) ? "true" : "false");
    rootElement.appendChild(sessionsIsOverflowElement);
    Element sessionsNumberElement = document.createElement("sessionsNumber");
    sessionsNumberElement.setTextContent("" + Math.max(0, KeyManager.getMaxCV(Session.EmulIDSE)));
    rootElement.appendChild(sessionsNumberElement);
    Element threadsInUseElement = document.createElement("threadsInUse");
    threadsInUseElement.setTextContent("" + Math.max(0, com.twinsoft.convertigo.beans.core.RequestableObject.nbCurrentWorkerThreads));
    rootElement.appendChild(threadsInUseElement);
    Element threadsNumberElement = document.createElement("threadsNumber");
    threadsNumberElement.setTextContent(EnginePropertiesManager.getProperty(PropertyName.DOCUMENT_THREADING_MAX_WORKER_THREADS));
    rootElement.appendChild(threadsNumberElement);
    Element httpTimeoutElement = document.createElement("httpTimeout");
    httpTimeoutElement.setTextContent(formatTime(currentSession.getMaxInactiveInterval()));
    rootElement.appendChild(httpTimeoutElement);
    long now = System.currentTimeMillis();
    Collection<Context> contexts = null;
    String sessionToFilter = request.getParameter("session");
    if (StringUtils.isNotBlank(sessionToFilter)) {
        HttpSession session = HttpSessionListener.getHttpSession(sessionToFilter);
        if (session != null) {
            contexts = Engine.theApp.contextManager.getContexts(session);
        }
    }
    if (contexts == null) {
        contexts = Engine.theApp.contextManager.getContexts();
    }
    for (Context context : contexts) {
        String authenticatedUser = null;
        try {
            authenticatedUser = context.getAuthenticatedUser();
        } catch (Exception e) {
            Engine.logAdmin.trace("connection.List failed to get the authenticated user: " + e);
        }
        com.twinsoft.api.Session apiSession = Engine.theApp.sessionManager.getSession(context.contextID);
        boolean bConnected = ((apiSession != null) && apiSession.isConnected());
        Element connectionElement = document.createElement("connection");
        connectionElement.setAttribute("connected", Boolean.toString(bConnected));
        connectionElement.setAttribute("contextName", context.contextID);
        connectionElement.setAttribute("project", context.projectName);
        connectionElement.setAttribute("connector", context.connectorName);
        connectionElement.setAttribute("requested", (context.requestedObject instanceof Transaction) ? context.transactionName : context.sequenceName);
        connectionElement.setAttribute("status", (context.requestedObject == null || context.requestedObject.runningThread == null ? "finished" : (context.requestedObject.runningThread.bContinue ? "in progress" : "finished")) + "(" + context.waitingRequests + ")");
        connectionElement.setAttribute("user", authenticatedUser == null ? "" : authenticatedUser);
        connectionElement.setAttribute("contextCreationDate", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(context.creationTime)));
        connectionElement.setAttribute("lastContextAccessDate", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(context.lastAccessTime)));
        try {
            connectionElement.setAttribute("contextInactivityTime", formatTime((now - context.lastAccessTime) / 1000) + " / " + formatTime(Engine.theApp.databaseObjectsManager.getOriginalProjectByName(context.projectName).getContextTimeout()));
        } catch (Exception e) {
        // TODO: document = DOMUtils.handleError(e); << USELESS
        }
        connectionElement.setAttribute("clientComputer", context.remoteHost + " (" + context.remoteAddr + "), " + context.userAgent);
        connectionsListElement.appendChild(connectionElement);
    }
    if (!"false".equals(request.getParameter("sessions"))) {
        for (HttpSession session : HttpSessionListener.getSessions()) {
            Element sessionElement = document.createElement("session");
            java.util.List<Context> ctxs = Engine.theApp.contextManager.getContexts(session);
            sessionElement.setAttribute("sessionID", session.getId());
            sessionElement.setAttribute("authenticatedUser", SessionAttribute.authenticatedUser.string(session));
            sessionElement.setAttribute("contexts", Integer.toString(ctxs == null ? 0 : ctxs.size()));
            sessionElement.setAttribute("clientIP", SessionAttribute.clientIP.string(session));
            sessionElement.setAttribute("deviceUUID", SessionAttribute.deviceUUID.string(session));
            sessionElement.setAttribute("lastSessionAccessDate", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(session.getLastAccessedTime())));
            sessionElement.setAttribute("sessionInactivityTime", formatTime((now - session.getLastAccessedTime()) / 1000) + " / " + formatTime(session.getMaxInactiveInterval()));
            Role[] r = (Role[]) session.getAttribute(SessionKey.ADMIN_ROLES.toString());
            sessionElement.setAttribute("adminRoles", Integer.toString(r == null ? 0 : r.length));
            if (session == currentSession) {
                sessionElement.setAttribute("isCurrentSession", "true");
            }
            Set<HttpServletRequest> set = SessionAttribute.fullSyncRequests.get(session);
            sessionElement.setAttribute("isFullSyncActive", Boolean.toString(set != null && !set.isEmpty()));
            sessionsListElement.appendChild(sessionElement);
        }
    }
}
Also used : Context(com.twinsoft.convertigo.engine.Context) Session(com.twinsoft.api.Session) HttpSession(javax.servlet.http.HttpSession) Element(org.w3c.dom.Element) Date(java.util.Date) Role(com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role) HttpServletRequest(javax.servlet.http.HttpServletRequest) Transaction(com.twinsoft.convertigo.beans.core.Transaction)

Aggregations

Context (com.twinsoft.convertigo.engine.Context)18 HttpSession (javax.servlet.http.HttpSession)4 EngineException (com.twinsoft.convertigo.engine.EngineException)3 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)2 CertificateManager (com.twinsoft.convertigo.engine.CertificateManager)2 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HostConfiguration (org.apache.commons.httpclient.HostConfiguration)2 HttpState (org.apache.commons.httpclient.HttpState)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 AuthScope (org.apache.commons.httpclient.auth.AuthScope)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 Protocol (org.apache.commons.httpclient.protocol.Protocol)2 Session (com.twinsoft.api.Session)1 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)1 ProxyHttpConnector (com.twinsoft.convertigo.beans.connectors.ProxyHttpConnector)1 Project (com.twinsoft.convertigo.beans.core.Project)1