Package com.google.walkaround.util.server.servlet

Examples of com.google.walkaround.util.server.servlet.BadRequestException


    String code = requireParameter(req, "code");
    String state = requireParameter(req, "state");
    log.info("code=" + code + ", state=" + state);
    String[] split = state.split(" ");
    if (split.length != 2) {
      throw new BadRequestException("state格式错误: " + state);
    }
    OAuthCredentials credentials;
    try {
      credentials = oAuthProviderHelp.exchangeCodeForToken(split[0], code);
    } catch (IOException e) {
View Full Code Here


      throws IOException, ServletException {
    if (!userCtx.get().isUserAdmin()) {
      log.severe("Admin page requested by non-admin user: "
          + (userCtx.get().hasParticipantId() ? userCtx.get().getParticipantId()
              : "(not logged in)"));
      throw new BadRequestException();
    }
    filterChain.doFilter(request, response);
  }
View Full Code Here

      throw new NeedNewOAuthTokenException("POST with no OAuth credentials: " + userContext);
    }
    try {
      xsrfHelper.verify(XSRF_ACTION, requireParameter(req, "token"));
    } catch (XsrfTokenExpiredException e) {
      throw new BadRequestException(e);
    } catch (InvalidSecurityTokenException e) {
      throw new BadRequestException(e);
    }
    String action = requireParameter(req, "action");
    if ("findwaves".equals(action) || "findandimport".equals(action)) {
      SourceInstance instance =
          sourceInstanceFactory.parseUnchecked(requireParameter(req, "instance"));
      // Rather than enqueueing just one interval 2008-01-01 to 2013-01-01, we
      // split that interval into random parts.  See the note on randomization
      // in FindRemoteWavesProcessor.
      log.info("Enqueueing find waves tasks");
      @Nullable ImportSettings autoImportSettings;
      if ("findwaves".equals(action)) {
        autoImportSettings = null;
      } else {
        autoImportSettings = new ImportSettingsGsonImpl();
        autoImportSettings.setSynthesizeHistory(!preserveHistory);
        if ("private".equals(requireParameter(req, "sharingmode"))) {
          autoImportSettings.setSharingMode(ImportSharingMode.PRIVATE);
        } else if ("shared".equals(requireParameter(req, "sharingmode"))) {
          autoImportSettings.setSharingMode(ImportSharingMode.SHARED);
        } else if ("privateunlessparticipant".equals(requireParameter(req, "sharingmode"))) {
          autoImportSettings.setSharingMode(ImportSharingMode.PRIVATE_UNLESS_PARTICIPANT);
        } else {
          throw new BadRequestException("Bad sharingmode");
        }
      }
      enqueueTasks(findProcessor.get().makeRandomTasksForInterval(instance,
            DaysSinceEpoch.fromYMD(2008, 1, 1),
            DaysSinceEpoch.fromYMD(2013, 1, 1),
            autoImportSettings));
    } else if ("importwavelet".equals(action)) {
      SourceInstance instance =
          sourceInstanceFactory.parseUnchecked(requireParameter(req, "instance"));
      WaveId waveId = WaveId.deserialise(requireParameter(req, "waveid"));
      WaveletId waveletId = WaveletId.deserialise(requireParameter(req, "waveletid"));
      ImportWaveletTask task = new ImportWaveletTaskGsonImpl();
      task.setInstance(instance.serialize());
      task.setWaveId(waveId.serialise());
      task.setWaveletId(waveletId.serialise());
      ImportSettings settings = new ImportSettingsGsonImpl();
      if ("private".equals(requireParameter(req, "sharingmode"))) {
        settings.setSharingMode(ImportSettings.ImportSharingMode.PRIVATE);
      } else if ("shared".equals(requireParameter(req, "sharingmode"))) {
        settings.setSharingMode(ImportSettings.ImportSharingMode.SHARED);
      } else {
        throw new BadRequestException("Unexpected import sharing mode");
      }
      settings.setSynthesizeHistory(!preserveHistory);
      task.setSettings(settings);
      @Nullable String existingSlobIdToIgnore = optionalParameter(req, "ignoreexisting", null);
      if (existingSlobIdToIgnore != null) {
        task.setExistingSlobIdToIgnore(existingSlobIdToIgnore);
      }
      final ImportTaskPayload payload = new ImportTaskPayloadGsonImpl();
      payload.setImportWaveletTask(task);
      log.info("Enqueueing import task for " + waveId
          + "; synthesizeHistory=" + task.getSettings().getSynthesizeHistory());
      enqueueTasks(ImmutableList.of(payload));
    } else if ("canceltasks".equals(action)) {
      log.info("Cancelling all tasks for " + userId);
      try {
        new RetryHelper().run(new RetryHelper.VoidBody() {
          @Override public void run() throws RetryableFailure, PermanentFailure {
            CheckedTransaction tx = datastore.get().beginTransaction();
            try {
              if (perUserTable.get().deleteAllTasks(tx, userId)) {
                tx.commit();
              }
            } finally {
              tx.close();
            }
          }
        });
      } catch (PermanentFailure e) {
        throw new IOException("Failed to delete tasks", e);
      }
    } else if ("forgetwaves".equals(action)) {
      log.info("Forgetting all waves for " + userId);
      try {
        new RetryHelper().run(new RetryHelper.VoidBody() {
          @Override public void run() throws RetryableFailure, PermanentFailure {
            CheckedTransaction tx = datastore.get().beginTransaction();
            try {
              if (perUserTable.get().deleteAllWaves(tx, userId)) {
                tx.commit();
              }
            } finally {
              tx.close();
            }
          }
        });
      } catch (PermanentFailure e) {
        throw new IOException("Failed to delete tasks", e);
      }
    } else {
      throw new BadRequestException("Unknown action: " + action);
    }
    // TODO(ohler): Send 303, not 302.  See
    // http://en.wikipedia.org/wiki/Post/Redirect/Get .
    resp.sendRedirect(req.getServletPath());
  }
View Full Code Here

    ConnectResult result;
    try {
      result = storeSelector.get(session.getStoreType()).getSlobStore()
          .reconnect(session.getObjectId(), session.getClientId());
    } catch (SlobNotFoundException e) {
      throw new BadRequestException("Object not found or access denied", e);
    } catch (AccessDeniedException e) {
      throw new BadRequestException("Object not found or access denied", e);
    }
    log.info("connect " + session + ": " + result);

    ConnectResponseGsonImpl response = sessionHelper.createConnectResponse(session, result);
View Full Code Here

        // javadoc doesn't mention this) and this case doesn't (even though it
        // could).
        result.put("error", "Too many concurrent connections");
      }
    } catch (SlobNotFoundException e) {
      throw new BadRequestException("Object not found or access denied", e);
    } catch (AccessDeniedException e) {
      throw new BadRequestException("Object not found or access denied", e);
    } catch (NumberFormatException nfe) {
      throw new BadRequestException("Parse error", nfe);
    }

    resp.setContentType("application/json");
    ServletUtil.writeJsonResult(resp.getWriter(), result.toString());
  }
View Full Code Here

  public SlobFacilities get(String storeType) {
    Provider<SlobFacilities> provider = facilities.get(storeType);
    if (provider != null) {
      return provider.get();
    }
    throw new BadRequestException("Unknown store type: " + storeType);
  }
View Full Code Here

    final StableUserId userId = new StableUserId(requireParameter(req, USER_ID_HEADER));
    final long taskId;
    try {
      taskId = Long.parseLong(requireParameter(req, TASK_ID_HEADER));
    } catch (NumberFormatException e) {
      throw new BadRequestException("Bad task id");
    }
    log.info("userId=" + userId + ", taskId=" + taskId);

    authHelper.serve(
        new ServletAuthHelper.ServletBody() {
View Full Code Here

    MutateResult res;
    try {
      res = storeSelector.get(session.getStoreType()).getSlobStore().mutateObject(mutateRequest);
    } catch (SlobNotFoundException e) {
      throw new BadRequestException("Object not found or access denied", e);
    } catch (AccessDeniedException e) {
      throw new BadRequestException("Object not found or access denied", e);
    }

    resp.setContentType("application/json");
    ServletUtil.writeJsonResult(resp.getWriter(),
        ServletUtil.getSubmitDeltaResultJson(res.getResultingVersion()));
View Full Code Here

    try {
      inner(req, resp);
    } catch (JSONException e) {
      throw new Error(e);
    } catch (SlobNotFoundException e) {
      throw new BadRequestException("Object not found or access denied", e);
    } catch (AccessDeniedException e) {
      throw new BadRequestException("Object not found or access denied", e);
    }
  }
View Full Code Here

        endVersion = null;
      } else {
        endVersion = Long.parseLong(endVersionString);
      }
    } catch (NumberFormatException nfe) {
      throw new BadRequestException(nfe);
    }

    SlobId objectId = session.getObjectId();
    SlobStore store = storeSelector.get(session.getStoreType()).getSlobStore();
    JSONObject result = new JSONObject();
View Full Code Here

TOP

Related Classes of com.google.walkaround.util.server.servlet.BadRequestException

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.