コード例 #1
0
  private Response.ResponseBuilder evaluateIfNoneMatch(
      EntityTag eTag, Set<? extends EntityTag> matchingTags, boolean isGetOrHead) {
    if (isGetOrHead) {
      if (matchingTags == MatchingEntityTag.ANY_MATCH) {
        // 304 Not modified
        return Response.notModified(eTag);
      }

      // The weak comparison function may be used to compare entity tags
      if (matchingTags.contains(eTag)
          || matchingTags.contains(new EntityTag(eTag.getValue(), !eTag.isWeak()))) {
        // 304 Not modified
        return Response.notModified(eTag);
      }
    } else {
      // The strong comparison function must be used to compare the entity
      // tags. Thus if the entity tag of the entity is weak then matching
      // of entity tags in the If-None-Match header should fail if the
      // HTTP method is not GET or not HEAD.
      if (eTag.isWeak()) {
        return null;
      }

      if (matchingTags == MatchingEntityTag.ANY_MATCH || matchingTags.contains(eTag)) {
        // 412 Precondition Failed
        return Response.status(Response.Status.PRECONDITION_FAILED);
      }
    }

    return null;
  }
コード例 #2
0
  @GET
  @Path("/start")
  public synchronized Response startOrderProcessor() {
    if (theMan.justChillin()) {
      System.out.println("INFO -- Starting things up");

      theMan.makeThingsHappen();

      return Response.ok().build();
    } else return Response.notModified().build();
  }
コード例 #3
0
ファイル: AccountResource.java プロジェクト: pkdevboxy/osee
 /**
  * Deletes the account
  *
  * @return response
  * @response.representation.200.doc account status set to active
  * @response.representation.304.doc account active status not modified
  */
 @DELETE
 @RolesAllowed(SystemRoles.ROLES_ADMINISTRATOR)
 public Response deleteAccount() {
   ResponseBuilder builder;
   boolean modified = accountOps.deleteAccount(accountId);
   if (modified) {
     builder = Response.ok();
   } else {
     builder = Response.notModified();
   }
   return builder.build();
 }
コード例 #4
0
  public Response updateCustomer(Customer customer) {
    System.out.println("----invoking updateCustomer, Customer name is: " + customer.getName());
    Customer c = customers.get(customer.getId());
    Response r;
    if (c != null) {
      customers.put(customer.getId(), customer);
      r = Response.ok().build();
    } else {
      r = Response.notModified().build();
    }

    return r;
  }
コード例 #5
0
 @PUT
 @Path("/students/")
 public Response updateStudent(Student s) {
   System.out.println("entered inside the updatecustomer methd for customer" + s.getId());
   Student x = Students.get(s.getId());
   Response r;
   if (x != null) {
     Students.put(s.getId(), s);
     r = Response.ok().build();
   } else {
     r = Response.notModified().build();
   }
   return r;
 }
コード例 #6
0
  private Response.ResponseBuilder evaluateIfModifiedSince(
      long lastModified, String ifModifiedSinceHeader) {
    try {
      long ifModifiedSince = HttpHeaderReader.readDate(ifModifiedSinceHeader).getTime();
      if (roundDown(lastModified) <= ifModifiedSince) {
        // 304 Not modified
        return Response.notModified();
      }
    } catch (ParseException ex) {
      // Ignore the header if parsing error
    }

    return null;
  }
コード例 #7
0
  /**
   * Grants read / write permissions for a task to the specified user. <br>
   * <br>
   * <div style='border-left: solid 5px #999999; border-radius: 10px; padding: 6px;'>
   * <strong>Required permissions:</strong>
   *
   * <ul>
   *   <li>Admin permissions
   * </ul>
   *
   * </div>
   *
   * @summary Grant task permissions to user
   * @param taskId <strong>REQUIRED</strong> Unique id that identifies the task.
   * @param topologyName <strong>REQUIRED</strong> Name of the topology where the task is submitted.
   * @param username <strong>REQUIRED</strong> Permissions are granted to the account with this
   *     unique username
   * @return Status code indicating whether the operation was successful or not.
   */
  @POST
  @Path("{taskId}/permit")
  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @ReturnType("java.lang.Void")
  public Response grantPermissions(
      @PathParam("topologyName") String topologyName,
      @PathParam("taskId") String taskId,
      @FormParam("username") String username) {

    if (taskId != null && topologyName != null) {
      grantPermissionsForTask(taskId, username);
      return Response.ok().build();
    }
    return Response.notModified().build();
  }
コード例 #8
0
  public Response deleteCustomer(String id) {
    System.out.println("----invoking deleteCustomer, Customer id is: " + id);
    long idNumber = Long.parseLong(id);
    Customer c = customers.get(idNumber);

    Response r;
    if (c != null) {
      r = Response.ok().build();
      customers.remove(idNumber);
    } else {
      r = Response.notModified().build();
    }

    return r;
  }
コード例 #9
0
  @DELETE
  @Path("/students/{id}/")
  public Response deleteStudent(@PathParam("id") String id) {
    System.out.println("Entered inside delete student method for id" + id);
    Response r;
    long sid = Long.parseLong(id);
    Student s = Students.get(sid);
    if (s != null) {
      r = Response.ok().build();
      Students.remove(sid);

    } else {
      r = Response.notModified().build();
    }
    return r;
  }
コード例 #10
0
ファイル: RestAppDataServer.java プロジェクト: CherifSy/pwm
  @GET
  @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
  @Path("/client")
  public Response doGetAppClientData(
      @QueryParam("pageUrl") String pageUrl,
      @PathParam(value = "eTagUri") final String eTagUri,
      @Context HttpServletRequest request,
      @Context HttpServletResponse response)
      throws PwmUnrecoverableException, IOException, ChaiUnavailableException {
    final int maxCacheAgeSeconds = 60 * 5;
    final RestRequestBean restRequestBean;
    try {
      restRequestBean =
          RestServerHelper.initializeRestRequest(
              request, response, ServicePermissions.PUBLIC, null);
    } catch (PwmUnrecoverableException e) {
      return RestResultBean.fromError(e.getErrorInformation()).asJsonResponse();
    }

    final String eTagValue =
        makeClientEtag(
            restRequestBean.getPwmApplication(), restRequestBean.getPwmSession(), request);

    // check the incoming header;
    final String ifNoneMatchValue = request.getHeader("If-None-Match");

    if (ifNoneMatchValue != null
        && ifNoneMatchValue.equals(eTagValue)
        && eTagValue.equals(eTagUri)) {
      return Response.notModified().build();
    }

    response.setHeader("ETag", eTagValue);
    response.setDateHeader("Expires", System.currentTimeMillis() + (maxCacheAgeSeconds * 1000));
    response.setHeader("Cache-Control", "public, max-age=" + maxCacheAgeSeconds);

    final AppData appData =
        makeAppData(
            restRequestBean.getPwmApplication(),
            restRequestBean.getPwmSession(),
            request,
            response,
            pageUrl);
    final RestResultBean restResultBean = new RestResultBean();
    restResultBean.setData(appData);
    return restResultBean.asJsonResponse();
  }
コード例 #11
0
  @DELETE
  @Path("/customers/{id}/")
  public Response deleteCustomer(@PathParam("id") String id) {
    long idNumber = Long.parseLong(id);
    Customer c = customers.get(idNumber);

    Response r;
    if (c != null) {
      r = Response.ok().build();
      customers.remove(idNumber);
    } else {
      r = Response.notModified().build();
    }
    if (idNumber == currentId.get()) {
      currentId.decrementAndGet();
    }
    return r;
  }
コード例 #12
0
  /**
   * Submits a Task for execution. Each Task execution is associated with a specific plugin.
   *
   * <p><strong>Write permissions required</strong>.
   *
   * @summary Submit Task
   * @param task <strong>REQUIRED</strong> Task to be executed. Should contain links to input data,
   *     either in form of cloud-records or cloud-datasets.
   * @param topologyName <strong>REQUIRED</strong> Name of the topology where the task is submitted.
   * @return URI with information about the submitted task execution.
   */
  @POST
  @Consumes({MediaType.APPLICATION_JSON})
  @PreAuthorize("hasPermission(#topologyName,'" + TOPOLOGY_PREFIX + "', write)")
  @Path("/")
  public Response submitTask(
      DpsTask task, @PathParam("topologyName") String topologyName, @Context UriInfo uriInfo) {

    LOGGER.info("Submiting task");

    if (task != null) {
      submitService.submitTask(task, topologyName);
      grantPermissionsForTask(task.getTaskId() + "");
      String createdTaskUrl = buildTaskUrl(uriInfo, task, topologyName);
      try {
        LOGGER.info("Task submitted succesfully");
        return Response.created(new URI(createdTaskUrl)).build();
      } catch (URISyntaxException e) {
        LOGGER.error("Task submition failed");
        e.printStackTrace();
        return Response.serverError().build();
      }
    }
    return Response.notModified().build();
  }
コード例 #13
0
  @Override
  public void handleMessage(Message message) throws Fault {

    if (checkETagSkipList(
        message.get(Message.PATH_INFO).toString(),
        message.get(Message.HTTP_REQUEST_METHOD).toString())) {
      log.info("Skipping ETagInInterceptor for URI : " + message.get(Message.PATH_INFO).toString());
      return;
    }

    OperationResourceInfo operationResource =
        message.getExchange().get(OperationResourceInfo.class);
    Map<String, List<String>> headers = CastUtils.cast((Map) message.get(Message.PROTOCOL_HEADERS));
    List<Object> arguments = MessageContentsList.getContentsList(message);
    try {
      Class aClass =
          Class.forName(operationResource.getMethodToInvoke().getDeclaringClass().getName());
      Method aClassMethod =
          aClass.getMethod(
              operationResource.getMethodToInvoke().getName() + RestApiConstants.GET_LAST_UPDATED,
              operationResource.getMethodToInvoke().getParameterTypes());
      Object o = aClass.newInstance();
      String lastUpdatedTime = String.valueOf(aClassMethod.invoke(o, arguments.toArray()));
      if (message.get(Message.HTTP_REQUEST_METHOD).equals(RestApiConstants.GET)) {
        if (!Objects.equals(lastUpdatedTime, "null")) {
          String eTag = ETagGenerator.getETag(lastUpdatedTime);
          if (headers.containsKey(HttpHeaders.IF_NONE_MATCH)) {
            String headerValue = headers.get(HttpHeaders.IF_NONE_MATCH).get(0);
            if (Objects.equals(eTag, headerValue)) {
              Response response = Response.notModified(eTag).build();
              message.getExchange().put(Response.class, response);
              return;
            }
          }
          message.getExchange().put(RestApiConstants.ETAG, eTag);
        }
      }
      /*
      If the request method is a PUT or a DELETE and the If-Match header is given then the ETag value for the
      resource and the header value will be compared and if they do not match then the flow will be terminated
      with 412 PRECONDITION FAILED
       */
      if (((RestApiConstants.PUT.equals(message.get(Message.HTTP_REQUEST_METHOD))
              || RestApiConstants.DELETE.equals(message.get(Message.HTTP_REQUEST_METHOD))))
          && headers.containsKey(HttpHeaders.IF_MATCH)) {
        String ifMatchHeaderValue;
        ifMatchHeaderValue = String.valueOf(headers.get(HttpHeaders.IF_MATCH).get(0));
        if (!Objects.equals(lastUpdatedTime, "null")) {
          String eTag = ETagGenerator.getETag(lastUpdatedTime);
          if (!Objects.equals(ifMatchHeaderValue, eTag)) {
            Response response = Response.status(Response.Status.PRECONDITION_FAILED).build();
            message.getExchange().put(Response.class, response);
          }
        }
      }
    } catch (ClassNotFoundException
        | NoSuchMethodException
        | IllegalAccessException
        | InvocationTargetException
        | InstantiationException e) {
      if (log.isDebugEnabled()) {
        log.debug(
            " Error while retrieving the ETag Resource timestamps due to " + e.getMessage(), e);
      }
    }
  }
コード例 #14
0
 @Override
 public Response toResponse(Exception exception) {
   exception.printStackTrace();
   return Response.notModified().build();
 }
コード例 #15
0
ファイル: NodeService.java プロジェクト: faireprogram/CS549
 private Response responseNull() {
   return Response.notModified().header(Time.TIME_STAMP, Time.advanceTime()).build();
 }