Package com.webobjects.appserver

Examples of com.webobjects.appserver.WOSession


  /**
   * Sets distribution enabled on new sessions
   * @param n a session created notification
   */
  public void enableSessionDistribution(NSNotification n) {
    WOSession session = (WOSession) n.object();
    session.setDistributionEnabled(true);
  }
View Full Code Here


  @Override
  public WOSession removeSessionWithID(String s) {
    EOEditingContext ec = ERXEC.newEditingContext();
    ERSessionInfo info = ERSessionInfo.clazz.objectMatchingKeyAndValue(ec, ERSessionInfo.SESSION_ID_KEY, s);
    if(info != null) {
      WOSession session = info.session();
      info.delete();
      ec.saveChanges();
      return session;
    }
    return null;
View Full Code Here

    return info == null || info.expirationDate().getTime() < System.currentTimeMillis()?null:info.session();
  }

  @Override
  public void saveSessionForContext(WOContext context) {
    WOSession session = context.session();
    EOEditingContext ec = ERXEC.newEditingContext();
    ERSessionInfo info = ERSessionInfo.clazz.objectMatchingKeyAndValue(ec, ERSessionInfo.SESSION_ID_KEY, session.sessionID());
    if(info == null) {
      info = ERSessionInfo.clazz.createAndInsertObject(ec);
      info.setSessionID(session.sessionID());
    }
    NSTimestamp expires = new NSTimestamp(System.currentTimeMillis() + session.timeOutMillis());
    info.setExpirationDate(expires);
    try {
      /*
       * An error here can later hang the instance when the session is restored.
       * If the session fails to archive, delete it.
       */
      info.archiveDataFromSession(session);
    } catch (Exception e) {
      log.error("Error archiving session! Deleting session.");
      ERXApplication app = ERXApplication.erxApplication();
      NSMutableDictionary extraInfo = app.extraInformationForExceptionInContext(e, context);
      app.reportException(e, context, extraInfo);
      /*
       * If the session info is new, just don't save it.
       * Otherwise, we need to delete the session.
       */
      if(!info.isNewObject()) {
        removeSessionWithID(session.sessionID());
      }
      return;
    }
    ec.saveChanges();
  }
View Full Code Here

    }
    NSDelayedCallbackCenter.defaultCenter().eventEnded();
  }

  public void sessionDidCreate(NSNotification notification) {
    WOSession session = (WOSession) notification.object();
    WORequest request = session.context().request();
    Conversation conversation = InstantMessengerAdaptor.conversation(request);
    if (conversation != null) {
      conversation.setSessionID(session.sessionID());
    }
  }
View Full Code Here

  }

  /** Overridden to check the sessions */
  @Override
  public WOSession createSessionForRequest(WORequest worequest) {
    WOSession wosession = super.createSessionForRequest(worequest);
    if (wosession != null && useSessionStoreDeadlockDetection()) {
      _sessions.put(wosession.sessionID(), new SessionInfo(null));
    }
    return wosession;
  }
View Full Code Here

  /** Overridden to check the sessions */
  @Override
  public void saveSessionForContext(WOContext wocontext) {
    if (useSessionStoreDeadlockDetection()) {
      WOSession wosession = wocontext._session();
      if (wosession != null) {
        String sessionID = wosession.sessionID();
        SessionInfo sessionInfo = _sessions.get(sessionID);
        if (sessionInfo == null) {
          log.error("Check-In of session that was not checked out, most likely diue to an exception in session.awake(): " + sessionID);
        }
        else {
View Full Code Here

  public WOSession restoreSessionWithID(String sessionID, WOContext wocontext) {
    if(sessionID != null && ERXSession.session() != null && sessionID.equals(ERXSession.session().sessionID())) {
      // AK: I have no idea how this can happen
      throw new IllegalStateException("Trying to check out a session twice in one RR loop: " + sessionID);
    }
    WOSession session = null;
    if (useSessionStoreDeadlockDetection()) {
      SessionInfo sessionInfo = _sessions.get(sessionID);
      if (sessionInfo != null) {
        throw new IllegalStateException(sessionInfo.exceptionMessageForCheckout(wocontext));
      }
      session = super.restoreSessionWithID(sessionID, wocontext);
      if (session != null) {
        _sessions.put(session.sessionID(), new SessionInfo(wocontext));
      }
    }
    else {
      session = super.restoreSessionWithID(sessionID, wocontext);
    }
View Full Code Here

      String msg = context().request().stringFormValueForKey("m");
      if (logger == null) {
        logger = AjaxRemoteLogging.class.getSimpleName();
      }
      // trigger session loading if present
      WOSession existing = existingSession();
      Logger log = Logger.getLogger(logger);
      if ("fatal".equalsIgnoreCase(level)) {
        log.fatal(msg);
      }
      else if ("error".equalsIgnoreCase(level)) {
View Full Code Here

          if (sessionId == null && input.has(sessionIdKey)) {
            sessionId = input.getString(sessionIdKey);
          }
        }
        context._setRequestSessionID(sessionId);
        WOSession session = null;
        if (context._requestSessionID() != null) {
          session = WOApplication.application().restoreSessionWithID(sessionId, context);
        }
        if (session != null) {
          session.awake();
        }
        try {
          JSONComponentCallback componentCallback = null;
         
          WODynamicURL url = request._uriDecomposed();
          String requestHandlerPath = url.requestHandlerPath();
          JSONRPCBridge jsonBridge;
          if (requestHandlerPath != null && requestHandlerPath.length() > 0) {
            String componentNameAndInstance = requestHandlerPath;
            String componentInstance;
            String componentName;
            int slashIndex = componentNameAndInstance.indexOf('/');
            if (slashIndex == -1) {
              componentName = componentNameAndInstance;
              componentInstance = null;
            }
            else {
              componentName = componentNameAndInstance.substring(0, slashIndex);
              componentInstance = componentNameAndInstance.substring(slashIndex + 1);
            }

            if (session == null) {
              session = context.session();
            }

            String bridgesKey = (componentInstance == null) ? "_JSONGlobalBridges" : "_JSONInstanceBridges";
            Map<String, JSONRPCBridge> componentBridges = (Map<String, JSONRPCBridge>) session.objectForKey(bridgesKey);
            if (componentBridges == null) {
              int limit = ERXProperties.intForKeyWithDefault((componentInstance == null) ? "er.ajax.json.globalBacktrackCacheSize" : "er.ajax.json.backtrackCacheSize", WOApplication.application().pageCacheSize());
              componentBridges = new LRUMap<String, JSONRPCBridge>(limit);
              session.setObjectForKey(componentBridges, bridgesKey);
            }
            jsonBridge = componentBridges.get(componentNameAndInstance);
            if (jsonBridge == null) {
              Class componentClass = _NSUtilities.classWithName(componentName);
              JSONComponent component;
              if (JSONComponent.class.isAssignableFrom(componentClass)) {
                component = (JSONComponent) _NSUtilities.instantiateObject(componentClass, new Class[] { WOContext.class }, new Object[] { context }, true, false);
              }
              else {
                throw new SecurityException("There is no JSON component named '" + componentName + "'.");
              }
              jsonBridge = createBridgeForComponent(component, componentName, componentInstance, componentBridges);
            }
           
            componentCallback = new JSONComponentCallback(context);
            jsonBridge.registerCallback(componentCallback, WOContext.class);
          }
          else {
            jsonBridge = _sharedBridge;
          }

          try {
            output = jsonBridge.call(new Object[] { request, response, context }, input);
          }
          finally {
            if (componentCallback != null) {
              jsonBridge.unregisterCallback(componentCallback, WOContext.class);
            }
          }

          if (context._session() != null) {
            WOSession contextSession = context._session();
            // If this is a new session, then we have to force it to be a cookie session
            if (sessionId == null) {
              boolean storesIDsInCookies = contextSession.storesIDsInCookies();
              try {
                contextSession.setStoresIDsInCookies(true);
                contextSession._appendCookieToResponse(response);
              }
              finally {
                contextSession.setStoresIDsInCookies(storesIDsInCookies);
              }
            }
            else {
              contextSession._appendCookieToResponse(response);
            }
          }
          response.appendContentString(output.toString());
          response._finalizeInContext(context);
          response.disableClientCaching();
View Full Code Here

  public Object resolveArg(Object obj) throws LocalArgResolveException {
    if (!(obj instanceof WOContext)) {
      throw new LocalArgResolveException("Invalid context.");
    }
    WOSession session = ((WOContext) obj).session();
    return session.valueForKey("JSONRPCBridge");
  }
View Full Code Here

TOP

Related Classes of com.webobjects.appserver.WOSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.