Package com.google.wave.api

Examples of com.google.wave.api.InvalidRequestException


  public void testDeserializationFailsSafely() throws Exception {
    when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE);
    when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenReturn(RETURNED_OPERATION);
    when(serializer.deserializeOperations(RETURNED_OPERATION)).thenThrow(
        new InvalidRequestException("Invalid Request"));

    List<OperationRequest> operations =
        connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION);
    assertTrue("Expected no operations to be returned", operations.isEmpty());
  }
View Full Code Here


  public void testExecuteOperationsSetsErrorOnInvalidRequestException() throws Exception {
    String operationId = "op1";
    OperationRequest operation = new OperationRequest("wavelet.create", operationId);

    OperationService service =
        mock(OperationService.class, new ThrowsException(new InvalidRequestException("")));
    when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service);

    OperationUtil.executeOperation(operation, operationRegistry, context, ALEX);

    assertTrue("Expected one response", context.getResponses().size() == 1);
View Full Code Here

    try {
      targetParticipant = ParticipantId.of(paramParticipant);
    } catch (InvalidParticipantAddress e) {
      String message = "Target ParticipantId " + paramParticipant + " is not " + "valid";
      LOG.info(message);
      throw new InvalidRequestException(message);
    }

    String rootBlipId = ConversationUtil.getRootBlipId(conversation);

    // Create generic event (defined by operation type) that will be processed
    // by the context.
    Event event;

    // Set up participant containers.
    List<String> participantsAdded = Lists.newArrayList();
    List<String> participantsRemoved = Lists.newArrayList();

    OperationType type = OperationUtil.getOperationType(operation);
    switch (type) {
      case WAVELET_ADD_PARTICIPANT_NEWSYNTAX:
        // Make sure targetParticipant is not already member.
        if (conversation.getParticipantIds().contains(targetParticipant)) {
          String message = targetParticipant.getAddress() + " is already a " + "member of wavelet";
          LOG.info(message);
          throw new InvalidRequestException(message, operation);
        }

        // Add participant to conversation and send event.
        conversation.addParticipant(targetParticipant);
        participantsAdded.add(targetParticipant.getAddress());
        event =
            new WaveletParticipantsChangedEvent(null, null, participant.getAddress(),
                System.currentTimeMillis(), rootBlipId, participantsAdded, participantsRemoved);
        break;
      case WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX:
        // Make sure targetParticipant is already member.
        if (!conversation.getParticipantIds().contains(targetParticipant)) {
          // Not a member, throw invalid request.
          String message = targetParticipant.getAddress() + " is not a " + "member of wavelet";
          LOG.info(message);
          throw new InvalidRequestException(message, operation);
        }

        // Remove participant and send event.
        conversation.removeParticipant(targetParticipant);
        participantsRemoved.add(targetParticipant.getAddress());
View Full Code Here

      attachmentId =  AttachmentId.deserialise(OperationUtil.<String>getRequiredParameter(operation,
          ParamsProperty.ATTACHMENT_ID));
      attachmentData = OperationUtil.<RawAttachmentData>getRequiredParameter(operation,
          ParamsProperty.ATTACHMENT_DATA);
    } catch (InvalidIdException ex) {
      throw new InvalidRequestException("Invalid id", operation, ex);
    }
    try {
      attachmentService.storeAttachment(attachmentId, new ByteArrayInputStream(attachmentData.getData()),
        WaveletName.of(waveId, waveletId), attachmentData.getFileName(), ParticipantId.of(attachmentData.getCreator()));
    } catch (InvalidParticipantAddress ex) {
      throw new InvalidRequestException("Invalid participant " + attachmentData.getCreator(), operation, ex);
    } catch (IOException ex) {
      LOG.severe("Store attachment", ex);
      context.constructErrorResponse(operation, ex.toString());
      return;
    }
View Full Code Here

      waveId = ApiIdSerializer.instance().deserialiseWaveId(
          OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID));
      waveletId = ApiIdSerializer.instance().deserialiseWaveletId(
          OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID));
    } catch (InvalidIdException ex) {
      throw new InvalidRequestException("Invalid id", operation, ex);
    }
    waveId = WaveId.of(waveDomain, waveId.getId());
    waveletId = WaveletId.of(waveDomain, waveletId.getId());
    List<byte[]> history =
        OperationUtil.getRequiredParameter(operation, ParamsProperty.RAW_DELTAS);
    WaveletName waveletName = WaveletName.of(waveId, waveletId);
    long importedFromVersion = -1;
    if (!history.isEmpty()) {
      CommittedWaveletSnapshot waveletSnapshot;
      try {
        waveletSnapshot = waveletProvider.getSnapshot(waveletName);
      } catch (WaveServerException ex) {
        LOG.info("Get wavelet snapshot", ex);
        context.constructErrorResponse(operation, ex.toString());
        return;
      }
      for (byte[] deltaBytes : history) {
        ProtocolWaveletDelta delta;
        try {
          delta = ProtocolWaveletDelta.parseFrom(deltaBytes);
        } catch (InvalidProtocolBufferException ex) {
          throw new InvalidRequestException("Parse delta", operation, ex);
        }
        long currentVersion = 0;
        if (waveletSnapshot != null) {
          currentVersion = waveletSnapshot.snapshot.getVersion();
        }
        if (currentVersion == delta.getHashedVersion().getVersion()) {
          if (importedFromVersion == -1) {
            importedFromVersion = currentVersion;
          }
          ProtocolWaveletDelta newDelta;
          try {
            newDelta = setVersionHash(delta, waveletSnapshot, waveletName);
          } catch (InvalidParticipantAddress ex) {
            throw new InvalidRequestException("Convert delta", operation, ex);
          }
          final StringBuffer error = new StringBuffer();
          waveletProvider.submitRequest(waveletName, newDelta,
              new WaveletProvider.SubmitRequestListener() {
View Full Code Here

      // TODO(anorth): Remove this round-trip when the API instead talks about
      // opaque conversation ids, and doesn't use legacy id serialization.
      conversationId = WaveletBasedConversation.idFor(
          ApiIdSerializer.instance().deserialiseWaveletId(waveletId));
    } catch (InvalidIdException e) {
      throw new InvalidRequestException("Invalid conversation id", operation, e);
    }
    ObservableConversation conversation = conversationView.getConversation(conversationId);

    OperationType type = OperationUtil.getOperationType(operation);
    switch (type) {
View Full Code Here

    String parentBlipId = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_ID);
    ConversationBlip parentBlip = context.getBlip(conversation, parentBlipId);

    Integer index = OperationUtil.getRequiredParameter(operation, ParamsProperty.INDEX);
    if (index <= 0) {
      throw new InvalidRequestException(
          "Can't inline a blip on position <= 0, got " + index, operation);
    }

    ApiView view = new ApiView(parentBlip.getContent(), wavelet);
    int xmlLocation = view.transformToXmlOffset(index);
View Full Code Here

    // view.locateElement will tell where the element actually is.
    ApiView view = new ApiView(parentBlip.getContent(), wavelet);
    int elementApiLocation = view.locateElement(element);

    if (elementApiLocation == -1) {
      throw new InvalidRequestException("Requested element not found", operation);
    }

    // Insert just after the requested element
    int xmlLocation = view.transformToXmlOffset(elementApiLocation + 1);
View Full Code Here

      waveId = ApiIdSerializer.instance().deserialiseWaveId(
        OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID));
      waveletId = ApiIdSerializer.instance().deserialiseWaveletId(
        OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID));
    } catch (InvalidIdException ex) {
      throw new InvalidRequestException("Invalid id", operation, ex);
    }
    WaveletName waveletName = WaveletName.of(waveId, waveletId);
    CommittedWaveletSnapshot snapshot = context.getWaveletSnapshot(waveletName, participant);
    WaveletSnapshot protoSnapshot = SnapshotSerializer.serializeWavelet(snapshot.snapshot, snapshot.snapshot.getHashedVersion());
    WaveletSnapshotProtoImpl protoSnapshotImpl = new WaveletSnapshotProtoImpl(protoSnapshot);
View Full Code Here

    AttachmentId attachmentId;
    try {
      attachmentId =  AttachmentId.deserialise(OperationUtil.<String>getRequiredParameter(operation,
          ParamsProperty.ATTACHMENT_ID));
    } catch (InvalidIdException ex) {
      throw new InvalidRequestException("Invalid id", operation, ex);
    }
    AttachmentMetadata meta;
    byte[] data;
    try {
      meta = attachmentService.getMetadata(attachmentId);
View Full Code Here

TOP

Related Classes of com.google.wave.api.InvalidRequestException

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.