Examples of EventMessageBundle


Examples of com.google.wave.api.impl.EventMessageBundle

   * @param req the HTTP request.
   * @param resp the HTTP response.
   */
  private void processRpc(HttpServletRequest req, HttpServletResponse resp) {
    // Deserialize and process the incoming events.
    EventMessageBundle events = null;
    try {
      events = deserializeEvents(req);
    } catch (IOException e) {
      resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR);
      return;
    }

    // Append robot.notifyCapabilitiesHash operation before processing the
    // events.
    OperationQueue operationQueue = events.getWavelet().getOperationQueue();
    operationQueue.appendOperation(OperationType.ROBOT_NOTIFY_CAPABILITIES_HASH,
        Parameter.of(ParamsProperty.CAPABILITIES_HASH, version));

    // Call the robot event handlers.
    processEvents(events);
View Full Code Here

Examples of com.google.wave.api.impl.EventMessageBundle

   */
  private EventMessageBundle deserializeEvents(HttpServletRequest req) throws IOException {
    String json = readRequestBody(req);
    LOG.info("Incoming events: " + json);

    EventMessageBundle bundle = SERIALIZER.fromJson(json, EventMessageBundle.class);

    if (bundle.getRpcServerUrl() == null) {
      throw new IllegalArgumentException("RPC server URL is not set in the event bundle.");
    }

    // Get the OAuth credentials for the given RPC server URL.
    ConsumerData consumerDataObj = consumerData.get(bundle.getRpcServerUrl());
    if (consumerDataObj == null && !isUnsignedRequestsAllowed()) {
      throw new IllegalArgumentException("No consumer key is found for the RPC server URL: " +
          bundle.getRpcServerUrl());
    }

    // Validates the request.
    if (consumerDataObj != null) {
      try {
View Full Code Here

Examples of com.google.wave.api.impl.EventMessageBundle

   * @param req the HTTP request.
   * @param resp the HTTP response.
   */
  private void processRpc(HttpServletRequest req, HttpServletResponse resp) {
    // Deserialize and process the incoming events.
    EventMessageBundle events = null;
    try {
      events = deserializeEvents(req);
    } catch (IOException e) {
      resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR);
      return;
    }

    // Append robot.notifyCapabilitiesHash operation before processing the
    // events.
    OperationQueue operationQueue = events.getWavelet().getOperationQueue();
    operationQueue.notifyRobotInformation(WaveService.PROTOCOL_VERSION, version);

    // Call the robot event handlers.
    processEvents(events);

View Full Code Here

Examples of com.google.wave.api.impl.EventMessageBundle

   */
  private EventMessageBundle deserializeEvents(HttpServletRequest req) throws IOException {
    String json = readRequestBody(req);
    LOG.info("Incoming events: " + json);

    EventMessageBundle bundle = SERIALIZER.fromJson(json, EventMessageBundle.class);

    if (bundle.getRpcServerUrl() == null) {
      throw new IllegalArgumentException("RPC server URL is not set in the event bundle.");
    }

    if (!isUnsignedRequestsAllowed()) {
      if (!waveService.hasConsumerData(bundle.getRpcServerUrl())) {
        throw new IllegalArgumentException("No consumer key is found for the RPC server URL: " +
            bundle.getRpcServerUrl());
      }

      // Validates the request.
      try {
        @SuppressWarnings("unchecked")
        Map<String, String[]> parameterMap = req.getParameterMap();
        waveService.validateOAuthRequest(req.getRequestURL().toString(), parameterMap,
            json, bundle.getRpcServerUrl());
      } catch (OAuthException e) {
        throw new IllegalArgumentException("Error validating OAuth request", e);
      }
    }
    return bundle;
View Full Code Here

Examples of com.google.wave.api.impl.EventMessageBundle

      throws InvalidRequestException {
    OpBasedWavelet wavelet = context.openWavelet(operation, participant);
    ObservableConversation conversation =
        context.openConversation(operation, participant).getRoot();

    EventMessageBundle messages =
        mapWaveletToMessageBundle(context.getConverter(), participant, wavelet, conversation);

    String rootBlipId = ConversationUtil.getRootBlipId(conversation);
    String message = OperationUtil.getOptionalParameter(operation, ParamsProperty.MESSAGE);

    WaveletFetchedEvent event =
        new WaveletFetchedEvent(null, null, participant.getAddress(), System.currentTimeMillis(),
            message, rootBlipId, messages.getWaveletData(), messages.getBlipData(),
            messages.getThreads(), null, null);

    context.processEvent(operation, event);
  }
View Full Code Here

Examples of com.google.wave.api.impl.EventMessageBundle

   * @param wavelet the wavelet to put in the bundle.
   * @param conversation the conversation to put in the bundle.
   */
  private EventMessageBundle mapWaveletToMessageBundle(EventDataConverter converter,
      ParticipantId participant, Wavelet wavelet, Conversation conversation) {
    EventMessageBundle messages = new EventMessageBundle(participant.getAddress(), "");
    WaveletData waveletData = converter.toWaveletData(wavelet, conversation, messages);
    messages.setWaveletData(waveletData);
    ContextResolver.addAllBlipsToEventMessages(messages, conversation, wavelet, converter);
    return messages;
  }
View Full Code Here

Examples of com.google.wave.api.impl.EventMessageBundle

        return;
      }
    }

    RobotCapabilities capabilities = account.getCapabilities();
    EventMessageBundle messages =
        eventGenerator.generateEvents(wavelet, capabilities.getCapabilitiesMap(),
            converterManager.getEventDataConverter(capabilities.getProtocolVersion()));

    if (messages.getEvents().isEmpty()) {
      // No events were generated, we are done
      LOG.info(robotName + ": no events were generated");
      return;
    }
View Full Code Here

Examples of com.google.wave.api.impl.EventMessageBundle

   *        WaveletData and BlipData.
   * @returns true if an event was generated, false otherwise
   */
  public EventMessageBundle generateEvents(WaveletAndDeltas waveletAndDeltas,
      Map<EventType, Capability> capabilities, EventDataConverter converter) {
    EventMessageBundle messages = new EventMessageBundle(robotName.toEmailAddress(), "");
    ObservableWaveletData snapshot =
        WaveletDataUtil.copyWavelet(waveletAndDeltas.getSnapshotBeforeDeltas());
    isEventProcessingSuspended = !snapshot.getParticipants().contains(robotId);

    if (robotName.hasProxyFor()) {
      // This robot is proxying so set the proxy field.
      messages.setProxyingFor(robotName.getProxyFor());
    }

    // Sending any operations will cause an exception.
    OpBasedWavelet wavelet =
        new OpBasedWavelet(snapshot.getWaveId(), snapshot,
            // This doesn't thrown an exception, the sinks will
            new BasicWaveletOperationContextFactory(null),
            ParticipationHelper.DEFAULT, SilentOperationSink.VOID, SilentOperationSink.VOID);

    ObservableConversation conversation = getRootConversation(wavelet);

    if (conversation == null) {
      return messages;
    }

    // Start listening
    EventGeneratingConversationListener conversationListener =
        new EventGeneratingConversationListener(conversation, capabilities, messages, robotName);
    conversation.addListener(conversationListener);
    EventGeneratingWaveletListener waveletListener =
        new EventGeneratingWaveletListener(capabilities);
    wavelet.addListener(waveletListener);

    Map<String, EventGeneratingDocumentHandler> docHandlers = Maps.newHashMap();
    try {
      for (TransformedWaveletDelta delta : waveletAndDeltas.getDeltas()) {
        // TODO(ljvderijk): Set correct timestamp and hashed version once
        // wavebus sends them along
        long timestamp = 0L;
        conversationListener.deltaBegin(delta.getAuthor(), timestamp);

        for (WaveletOperation op : delta) {
          // Check if we need to attach a doc handler.
          if ((op instanceof WaveletBlipOperation)) {
            attachDocHandler(conversation, op, docHandlers, capabilities, messages,
                delta.getAuthor(), timestamp);
          }
          op.apply(snapshot);
        }
        conversationListener.deltaEnd();
      }
    } catch (OperationException e) {
      throw new IllegalStateException("Operation failed to apply when generating events", e);
    } finally {
      conversation.removeListener(conversationListener);
      wavelet.removeListener(waveletListener);
      for (EventGeneratingDocumentHandler docHandler : docHandlers.values()) {
        docHandler.doc.removeListener(docHandler);
      }
    }

    if (messages.getEvents().isEmpty()) {
      // No events found, no need to resolve contexts
      return messages;
    }

    // Resolve the context of the bundle now that all events have been
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.