Search in sources :

Example 1 with Session

use of com.twinsoft.api.Session in project convertigo by convertigo.

the class WebClippingServletRequester method coreProcessRequest.

@Override
protected Object coreProcessRequest() throws Exception {
    try {
        if (context.getConnector() != null) {
            if (context.getConnector() instanceof HtmlConnector) {
                HtmlConnector connector = (HtmlConnector) context.getConnector();
                if (bDirty) {
                    return Boolean.toString(connector.getHtmlParser().getDomDirty(context)).getBytes();
                } else {
                    HttpServletRequest request = (HttpServletRequest) inputData;
                    String webURL = request.getQueryString();
                    String contentType = null;
                    if (webURL == null) {
                        Engine.logEngine.debug("(WebClippingServletRequester) no webURL !!! return empty result");
                        return new byte[0];
                    }
                    // TODO: q&d fix #419 [Invalid URI error if ressource image to get contains "\"] ; may be include it in httpClient ?
                    webURL = webURL.replace('\\', '/');
                    Engine.logEngine.trace("(WebClippingServletRequester) weburl is " + webURL);
                    InputStream is = bCache ? cache.getResource(webURL) : null;
                    if (is == null) {
                        String charset = null;
                        byte[] data = null;
                        synchronized (context) {
                            connector.sUrl = webURL;
                            if (context.requestedObject == null) {
                                context.requestedObject = connector.getDefaultTransaction();
                                context.transaction = (HtmlTransaction) context.requestedObject;
                                context.requestedObject.createRequestableThread();
                            }
                            // save old context headers
                            String exContentType = context.contentType;
                            Header[] exHeaders = context.getResponseHeaders();
                            data = connector.getData(context);
                            contentType = context.contentType;
                            charset = connector.getCharset();
                            // restore old context headers
                            context.contentType = exContentType;
                            context.setResponseHeaders(exHeaders);
                            Engine.logEngine.trace("(WebClippingServletRequester) contentType is " + contentType);
                            Engine.logEngine.trace("(WebClippingServletRequester) charset is " + charset);
                        }
                        request.setAttribute("convertigo.charset", charset);
                        data = rewriteCSS(data, webURL, contentType, charset);
                        is = new ByteArrayInputStream(data);
                        if (bCache) {
                            CacheEntry c = cache.storeResponse(webURL, data);
                            c.contentLength = data.length;
                            c.contentType = contentType;
                        }
                    } else {
                        contentType = cache.getCacheEntry(webURL).contentType;
                    }
                    request.setAttribute("convertigo.contentType", contentType);
                    byte[] data = new byte[is.available()];
                    is.read(data);
                    is.close();
                    return data;
                }
            } else if (context.getConnector() instanceof JavelinConnector && bDirty) {
                Session session = Engine.theApp.sessionManager.getSession(context.contextID);
                if (session != null) {
                    return Boolean.toString(session.isSomethingChange());
                }
            }
        }
    } catch (EngineException e) {
        Engine.logEngine.error("Error", e);
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Header(org.apache.commons.httpclient.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EngineException(com.twinsoft.convertigo.engine.EngineException) CacheEntry(com.twinsoft.convertigo.engine.proxy.cache.CacheEntry) Session(com.twinsoft.api.Session) HttpSession(javax.servlet.http.HttpSession)

Example 2 with Session

use of com.twinsoft.api.Session 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

Session (com.twinsoft.api.Session)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)1 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)1 Transaction (com.twinsoft.convertigo.beans.core.Transaction)1 Role (com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role)1 Context (com.twinsoft.convertigo.engine.Context)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 CacheEntry (com.twinsoft.convertigo.engine.proxy.cache.CacheEntry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Header (org.apache.commons.httpclient.Header)1 Element (org.w3c.dom.Element)1