Example #1
0
  /**
   * Construct.
   *
   * @param location The key identifying the client window to which this courier delivers updates.
   * @param elementId The key identifying the element on the Portal Page that would need a courier
   *     delivered message when things change.
   */
  public ObservingCourier(String location, String elementId) {
    m_deliveryId = SessionManager.getCurrentSession().getId() + location;
    m_elementId = elementId;
    m_location = location;

    // "inject" a CourierService
    m_courierService = org.sakaiproject.courier.cover.CourierService.getInstance();
  }
Example #2
0
  /**
   * Respond to access requests.
   *
   * @param req The servlet request.
   * @param res The servlet response.
   * @throws ServletException.
   * @throws IOException.
   */
  protected void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    // support two "/" separated parameters [1] and [2]) - both get presence updated, the first is
    // the address for delivery (second optional)
    String[] parts = req.getPathInfo().split("/");

    if ((parts.length == 2) || (parts.length == 3)) {
      String placementId = parts[1];

      // if we are in a newly created session where we had an invalid (presumed timed out) session
      // in the request,
      // send script to cause a sakai top level redirect
      if (ThreadLocalManager.get(SessionManager.CURRENT_INVALID_SESSION) != null) {
        String loggedOutUrl = ServerConfigurationService.getLoggedOutUrl();
        if (M_log.isDebugEnabled())
          M_log.debug("sending top redirect: " + placementId + " : " + loggedOutUrl);
        sendTopRedirect(res, loggedOutUrl);
      } else {
        String requestUserId = req.getParameter("userId");
        Session session = sessionManager.getCurrentSession();

        if (requestUserId == null || requestUserId.equals(session.getUserId())) {
          // compute our courier delivery address: this placement in this session
          String deliveryId = session.getId() + placementId;

          // find all deliveries for the requested deivery address
          List deliveries = CourierService.getDeliveries(deliveryId);

          // see if any DeliveryProviders have deliveries
          List<DeliveryProvider> providers = CourierService.getDeliveryProviders();
          if (providers != null) {
            List<Delivery> moreDeliveries = new ArrayList<Delivery>();
            for (DeliveryProvider provider : providers) {
              List<Delivery> d = provider.getDeliveries(session.getId(), placementId);
              if (d != null && !d.isEmpty()) {
                moreDeliveries.addAll(d);
              }
            }
            if (moreDeliveries.isEmpty()) {
              // use deliveries
            } else if (deliveries.isEmpty()) {
              deliveries = moreDeliveries;
            } else {
              // both lists have deliveries, so add moreDeliveries to deliveries
              deliveries.addAll(moreDeliveries);
            }
          }

          // form the reply
          sendDeliveries(res, deliveries);

          // refresh our presence at the location (placement)
          if (M_log.isDebugEnabled()) M_log.debug("setting presence: " + placementId);
          PresenceUpdater.setPresence(placementId);

          // register another presence if present
          if (parts.length == 3) {
            String secondPlacementId = parts[2];
            if (M_log.isDebugEnabled())
              M_log.debug("setting second presence: " + secondPlacementId);
            PresenceUpdater.setPresence(secondPlacementId);
          }
        } else {
          // This courier request was not meant for this user (i.e., session), so we won't honour it
          M_log.debug(
              "out-of-session courier request: requestUserId="
                  + requestUserId
                  + " session user="******"bad courier request: " + req.getPathInfo());
      sendDeliveries(res, new Vector());
    }
  }