Exemplo n.º 1
0
  public void testExportSystemView1() throws Exception {
    Node nd = m_session.getRootNode().addNode("foo");

    nd.setProperty("stringprop", "Barba<papa>");

    nd.setProperty("binaryprop", new ByteArrayInputStream("Barbabinary".getBytes()));

    nd.setProperty(
        "multiprop",
        new Value[] {
          m_session.getValueFactory().createValue("pimpim&"),
          m_session.getValueFactory().createValue("poppop\"")
        });
    m_session.save();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    m_session.exportSystemView("/", out, false, false);

    String s = out.toString("UTF-8");

    System.out.println(s);
    assertTrue("Barbapapa wrong", s.indexOf("Barba&lt;papa&gt;") != -1);
    assertTrue("pim wrong", s.indexOf("pimpim&amp;") != -1);
    assertTrue("pop wrong", s.indexOf("poppop&quot;") != -1);
  }
 public synchronized void setOwner(long id, Object owner) throws SessionExpiredException {
   SessionImpl session = sessionsById.get(id);
   if (session == null) {
     throw new KeeperException.SessionExpiredException();
   }
   session.owner = owner;
 }
 public synchronized boolean touchSession(long sessionId, int timeout) {
   if (LOG.isTraceEnabled()) {
     ZooTrace.logTraceMessage(
         LOG,
         ZooTrace.CLIENT_PING_TRACE_MASK,
         "SessionTrackerImpl --- Touch session: 0x"
             + Long.toHexString(sessionId)
             + " with timeout "
             + timeout);
   }
   SessionImpl s = sessionsById.get(sessionId);
   if (s == null) {
     return false;
   }
   long expireTime = roundToInterval(System.currentTimeMillis() + timeout);
   if (s.tickTime >= expireTime) {
     // Nothing needs to be done
     return true;
   }
   SessionSet set = sessionSets.get(s.tickTime);
   if (set != null) {
     set.sessions.remove(s);
   }
   s.tickTime = expireTime;
   set = sessionSets.get(s.tickTime);
   if (set == null) {
     set = new SessionSet();
     sessionSets.put(expireTime, set);
   }
   set.sessions.add(s);
   return true;
 }
Exemplo n.º 4
0
  public OperationsImpl(final SessionImpl session, final Class<T> persistentClass) {
    this.persistentClass = checkNotNull(persistentClass);

    this.session = checkNotNull(session);

    this.metadata = session.getSessionFactory().getClassMetadata(persistentClass);

    entryCache = new TypeSafeCache<>(persistentClass, session.getCache());
  }
 public synchronized void checkSession(long sessionId, Object owner)
     throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException {
   SessionImpl session = sessionsById.get(sessionId);
   if (session == null) {
     throw new KeeperException.SessionExpiredException();
   }
   if (session.owner == null) {
     session.owner = owner;
   } else if (session.owner != owner) {
     throw new KeeperException.SessionMovedException();
   }
 }
Exemplo n.º 6
0
  /**
   * Creates a new session. The provided object factory, authentication provider and cache instance
   * override the values in the session parameters if they are not <code>null</code>.
   *
   * @param parameters a {@code Map} of name/value pairs with parameters for the session
   * @param objectFactory an object factory instance
   * @param authenticationProvider an authentication provider instance
   * @param cache a cache instance
   * @param typeDefCache a type definition cache instance
   * @return a {@link Session} connected to the CMIS repository
   * @throws CmisBaseException if the connection could not be established
   * @see SessionParameter
   */
  public Session createSession(
      Map<String, String> parameters,
      ObjectFactory objectFactory,
      AuthenticationProvider authenticationProvider,
      Cache cache,
      TypeDefinitionCache typeDefCache) {
    SessionImpl session =
        new SessionImpl(parameters, objectFactory, authenticationProvider, cache, typeDefCache);
    session.connect();

    return session;
  }
Exemplo n.º 7
0
 @Override
 public org.splash.messaging.Session createSession()
     throws NetworkException, MessagingException, TimeoutException {
   synchronized (_lock) {
     if (_closed.get()) {
       throw new MessagingException("Connection is closed");
     }
     Session ssn = _connection.session();
     SessionImpl session = new SessionImpl(this, ssn);
     _sessions.put(ssn, session);
     session.init();
     return session;
   }
 }
Exemplo n.º 8
0
  /** Makes sure nobody tampers with root node UUID. */
  public void testRootUUID() throws Exception {
    Node nd = m_session.getRootNode();

    assertTrue("uuid missing", nd.hasProperty("jcr:uuid"));

    assertEquals("uuid value", "93b885ad-fe0d-3089-8df6-34904fd59f71", nd.getUUID());
  }
  public void send(
      Destination destination, Message message, int deliveryMode, int priority, long timeToLive)
      throws JMSException {
    if (message == null) {
      throw new MessageFormatException(Messages.getString("MessageProducerImpl_0")); // $NON-NLS-1$
    }

    // message.setJMSMessageID(MessageId.create());
    message.setJMSDestination(destination);
    message.setJMSTimestamp(new Date().getTime());
    message.setJMSPriority(priority);

    if (timeToLive > 0) {
      message.setJMSExpiration(System.currentTimeMillis() + timeToLive);
    } else {
      message.setJMSExpiration(0);
    }

    if (destination instanceof JMSTemporaryDestination) {
      message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    } else {
      message.setJMSDeliveryMode(deliveryMode);
    }

    session.sendMessage(message);
  }
Exemplo n.º 10
0
  public void dispatchMessage() {
    MessageListener listener = messageListener;
    if (listener != null) {
      MessageImpl message = messages.poll();
      if (message == null) {
        OM.LOG.warn(Messages.getString("MessageConsumerImpl.1")); // $NON-NLS-1$
        return;
      }

      try {
        listener.onMessage(message);
        if (!session.getTransacted()
            && session.getAcknowledgeMode() != Session.CLIENT_ACKNOWLEDGE) {
          session.acknowledgeMessages(this);
        }
      } catch (RuntimeException ex) {
        OM.LOG.warn(ex);
      }
    }
  }
Exemplo n.º 11
0
  public void testMove() throws Exception {
    Node nd = m_session.getRootNode().addNode("source");
    nd = nd.addNode("tobemoved");
    nd.setProperty("test", 20);
    nd = nd.addNode("childprop");
    nd.setProperty("test2", "foo");

    nd = m_session.getRootNode().addNode("dest");

    m_session.save();

    m_session.move("/source/tobemoved", "/dest/newnode");

    assertTrue("node", m_session.hasNode("/dest/newnode"));
    assertEquals("prop", 20, m_session.getRootNode().getProperty("dest/newnode/test").getLong());
  }
Exemplo n.º 12
0
  public void tearDown() throws Exception {
    m_session.logout();

    super.tearDown();
  }
Exemplo n.º 13
0
 public void setMessageListener(MessageListener listener) {
   messageListener = listener;
   if (messageListener != null) {
     session.addWork(this);
   }
 }
Exemplo n.º 14
0
 public void handleServerMessage(MessageImpl message) {
   messages.add(message);
   if (messageListener != null) {
     session.addWork(this);
   }
 }
Exemplo n.º 15
0
  @Override
  public Session createSession(
      final HttpServerExchange serverExchange, final SessionConfig config) {
    if (evictionQueue != null) {
      if (expireOldestUnusedSessionOnMax) {
        while (sessions.size() >= maxSize && !evictionQueue.isEmpty()) {

          String key = evictionQueue.poll();
          UndertowLogger.REQUEST_LOGGER.debugf("Removing session %s as max size has been hit", key);
          SessionImpl toRemove = sessions.get(key);
          if (toRemove != null) {
            toRemove.invalidate(
                null, SessionListener.SessionDestroyedReason.TIMEOUT); // todo: better reason
          }
        }
      } else if (sessions.size() >= maxSize) {
        if (statisticsEnabled) {
          rejectedSessionCount.incrementAndGet();
        }
        throw UndertowMessages.MESSAGES.tooManySessions(maxSize);
      }
    }
    if (config == null) {
      throw UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig();
    }
    String sessionID = config.findSessionId(serverExchange);
    int count = 0;
    while (sessionID == null) {
      sessionID = sessionIdGenerator.createSessionId();
      if (sessions.containsKey(sessionID)) {
        sessionID = null;
      }
      if (count++ == 100) {
        // this should never happen
        // but we guard against pathalogical session id generators to prevent an infinite loop
        throw UndertowMessages.MESSAGES.couldNotGenerateUniqueSessionId();
      }
    }
    Object evictionToken;
    if (evictionQueue != null) {
      evictionToken = evictionQueue.offerLastAndReturnToken(sessionID);
    } else {
      evictionToken = null;
    }
    if (statisticsEnabled) {
      createdSessionCount.incrementAndGet();
    }
    final SessionImpl session =
        new SessionImpl(
            this,
            sessionID,
            config,
            serverExchange.getIoThread(),
            serverExchange.getConnection().getWorker(),
            evictionToken,
            defaultSessionTimeout);
    sessions.put(sessionID, session);
    config.setSessionId(serverExchange, session.getId());
    session.lastAccessed = System.currentTimeMillis();
    session.bumpTimeout();
    sessionListeners.sessionCreated(session, serverExchange);
    serverExchange.putAttachment(NEW_SESSION, session);
    return session;
  }