/**
  * This returns a proxy to the requested session bean.
  *
  * @param string $lookupName The lookup name for the requested session bean
  * @param string $sessionId  The session-ID if available
  *
  * @return \AppserverIo\RemoteMethodInvocation\RemoteObjectInterface The proxy instance
  */
 public function lookupProxy($lookupName, $sessionId = null)
 {
     // initialize the remote method call parser and the session storage
     $sessions = new ArrayList();
     // initialize the local context connection
     $connection = new DoctrineLocalContextConnection();
     $connection->injectSessions($sessions);
     $connection->injectApplication($this->getApplication());
     // initialize the context session
     $session = $connection->createContextSession();
     // check if we've a HTTP session ID passed
     if ($sessionId == null) {
         // simulate a unique session ID
         $session->setSessionId(SessionUtils::generateRandomString());
     } else {
         // else, set the passed session ID
         $session->setSessionId($sessionId);
     }
     // lookup and return the requested remote bean instance
     return $session->createInitialContext()->lookup($lookupName);
 }
Beispiel #2
0
 /**
  * Returns the session for this request.
  *
  * @param boolean $create TRUE to create a new session, else FALSE
  *
  * @return null|\AppserverIo\Psr\Servlet\Http\HttpSessionInterface The session instance
  *
  * @throws \Exception
  */
 public function getSession($create = false)
 {
     // load the proposed session-ID and name
     $id = $this->getProposedSessionId();
     $sessionName = $this->getRequestedSessionName();
     // if no session has already been load, initialize the session manager
     /** @var \AppserverIo\Appserver\ServletEngine\SessionManagerInterface $manager */
     $manager = $this->getSessionManager();
     // if no session manager was found, we don't support sessions
     if ($manager == null) {
         return;
     }
     // find or create a new session (if flag has been set)
     $session = $manager->find($id);
     // if we can't find a session or session has been expired and we want to create a new one
     if ($session == null && $create === true) {
         // check if a session ID has been specified
         if ($id == null) {
             // if not, generate a unique one
             $id = SessionUtils::generateRandomString();
         }
         // create a new session and register ID in request
         $session = $manager->create($id, $sessionName);
     }
     // if we can't find a session and we should NOT create one, return nothing
     if ($create === false && $session == null) {
         return;
     }
     // if we can't find a session although we SHOULD create one, we throw an exception
     if ($create === true && $session == null) {
         throw new \Exception('Can\'t create a new session!');
     }
     // initialize the session wrapper
     $wrapper = new SessionWrapper();
     $wrapper->injectSession($session);
     $wrapper->injectRequest($this);
     // return the found session
     return $wrapper;
 }
 /**
  * Finally this method does the lookup for the passed resource identifier
  * using the also passed connection.
  *
  * @param \AppserverIo\Psr\Naming\ResourceIdentifier              $resourceIdentifier The identifier for the requested bean
  * @param \AppserverIo\RemoteMethodInvocation\ConnectionInterface $connection         The connection we use for loading the bean
  * @param string                                                  $sessionId          The session-ID, necessary for lookup stateful session beans
  *
  * @return object The been proxy instance
  */
 protected function doLookup(ResourceIdentifier $resourceIdentifier, ConnectionInterface $connection, $sessionId = null)
 {
     // initialize the context session
     $session = $connection->createContextSession();
     // check if we've a HTTP session ID passed
     if ($sessionId == null) {
         // simulate a unique session ID
         $session->setSessionId(SessionUtils::generateRandomString());
     } else {
         // else, set the passed session ID
         $session->setSessionId($sessionId);
     }
     // check if we've a HTTP servlet request that may contain a session
     if ($servletRequest = $this->getServletRequest()) {
         $session->injectServletRequest($servletRequest);
     }
     // load the class name from the resource identifier => that is the path information
     $className = $resourceIdentifier->getClassName();
     // lookup and return the requested remote bean instance
     return $session->createInitialContext()->lookup($className);
 }
 /**
  * Generates and propagates a new session ID and transfers all existing data
  * to the new session.
  *
  * @return string The new session ID
  * @throws \AppserverIo\Psr\Servlet\IllegalStateException
  */
 public function renewId()
 {
     // create a new session ID
     $this->setId(SessionUtils::generateRandomString());
     // load the session manager
     $sessionManager = $this->getContext()->search('SessionManagerInterface');
     // attach this session with the new ID
     $sessionManager->attach($this->getSession());
     // create a new cookie with the session values
     $cookie = new HttpCookie($this->getName(), $this->getId(), $this->getLifetime(), $this->getMaximumAge(), $this->getDomain(), $this->getPath(), $this->isSecure(), $this->isHttpOnly());
     // add the cookie to the response
     $this->getRequest()->setRequestedSessionId($this->getId());
     $this->getResponse()->addCookie($cookie);
     // return the new session ID
     return $this->getId();
 }