.tag(entityTag) .cacheControl(cacheControl) .lastModified(lastModified) .build();
public Response.ResponseBuilder ifUnmodifiedSince(String strDate, Date lastModified) { Date date = DateUtil.parseDate(strDate); if (date.getTime() >= lastModified.getTime()) { return null; } return Response.status(SC_PRECONDITION_FAILED).lastModified(lastModified); }
@GET @Path("/sample") @Produces(MediaType.APPLICATION_JSON) public Response getSample(@Context Request request) throws ParseException { Date lastUpdate = format.parse("2016-02-01 00:00:00.123"); Response.ResponseBuilder responseBuilder = request.evaluatePreconditions(lastUpdate); if (responseBuilder == null) { responseBuilder = Response.ok("Significantly big payload "); } return responseBuilder.lastModified(lastUpdate).build(); }
@POST @Produces(MediaType.APPLICATION_JSON) @Path("import-path-mappings") @ApiOperation(value = "Import path mappings from a page", notes = "User must have the MANAGE_APPLICATION permission to use this service") @ApiResponses({ @ApiResponse(code = 201, message = "Path mappings successfully imported", response = ApiEntity.class), @ApiResponse(code = 500, message = "Internal server error")}) @Permissions({ @Permission(value = RolePermission.API_DEFINITION, acls = RolePermissionAction.UPDATE) }) public Response importPathMappingsFromPage(@PathParam("api") String api, @QueryParam("page") @NotNull String page) { final ApiEntity apiEntity = (ApiEntity) get(api).getEntity(); ApiEntity updatedApi = apiService.importPathMappingsFromPage(apiEntity, page); return Response .ok(updatedApi) .tag(Long.toString(updatedApi.getUpdatedAt().getTime())) .lastModified(updatedApi.getUpdatedAt()) .build(); }
@GET public Response get(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch, @HeaderParam(HttpHeaders.IF_MODIFIED_SINCE) Date ifModifiedSince) { // Check the ETags to see if the resource has changed... if (ifNoneMatch != null) { for (String eTag : ETAG_SPLITTER.split(ifNoneMatch)) { if ("*".equals(eTag) || ETAG.equals(EntityTag.valueOf(eTag))) { return NOT_MODIFIED; } } } // Check the last modification time if (ifModifiedSince != null && ifModifiedSince.after(LAST_MODIFIED)) { return NOT_MODIFIED; } return Response.ok().lastModified(LAST_MODIFIED).tag(ETAG).type(CONTENT_TYPE).entity(FAVICON).build(); } }
public ResponseBuilder getProfileBuilder(Profile profile , UriInfo info) { try { Response.ResponseBuilder ok = Response.ok(profile.getProfileDocument()); List<ProfileAssociation> profileAssociationsByProfileSid = profileAssociationsDao.getProfileAssociationsByProfileSid(profile.getSid()); for (ProfileAssociation assoc : profileAssociationsByProfileSid) { LinkHeader composeLink = composeLink(assoc.getTargetSid(), info); ok.header(LINK_HEADER, composeLink.toString()); } ok.header(LINK_HEADER, composeSchemaLink(info)); String profileStr = profile.getProfileDocument();// IOUtils.toString(profile.getProfileDocument(), PROFILE_ENCODING); ok.entity(profileStr); ok.lastModified(profile.getDateUpdated()); ok.type(PROFILE_CONTENT_TYPE); return ok; } catch (Exception ex) { logger.debug("getting profile", ex); return Response.serverError().entity(ex.getMessage()); } }
@POST @Produces(MediaType.APPLICATION_JSON) @Path("import-path-mappings") @ApiOperation(value = "Import path mappings from a page", notes = "User must have the MANAGE_APPLICATION permission to use this service") @ApiResponses({ @ApiResponse(code = 201, message = "Path mappings successfully imported", response = ApiEntity.class), @ApiResponse(code = 500, message = "Internal server error")}) @Permissions({ @Permission(value = RolePermission.API_DEFINITION, acls = RolePermissionAction.UPDATE) }) public Response importPathMappingsFromPage(@PathParam("api") String api, @QueryParam("page") @NotNull String page) { final ApiEntity apiEntity = (ApiEntity) get(api).getEntity(); ApiEntity updatedApi = apiService.importPathMappingsFromPage(apiEntity, page); return Response .ok(updatedApi) .tag(Long.toString(updatedApi.getUpdatedAt().getTime())) .lastModified(updatedApi.getUpdatedAt()) .build(); }
private Response getClassification(String classId, Function<MCRCategoryDAO, MCRCategory> categorySupplier) { MCRCategoryDAO categoryDAO = MCRCategoryDAOFactory.getInstance(); Date lastModified = getLastModifiedDate(classId, categoryDAO); Optional<Response> cachedResponse = MCRRestUtils.getCachedResponse(request.getRequest(), lastModified); if (cachedResponse.isPresent()) { return cachedResponse.get(); } MCRCategory classification = categorySupplier.apply(categoryDAO); if (classification == null) { throw new NotFoundException(); } return Response.ok() .entity(classification.isClassification() ? MCRClass.getClassification(classification) : MCRClassCategory.getInstance(classification)) .lastModified(lastModified) .build(); }
@GET @Path("/{id}") @Produces({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response get(@PathParam("id") String id) { DOMAIN entity = getRepository().get(id); if (entity == null) { return Response.status(Status.NOT_FOUND).type(getMediaType()).build(); } return Response.ok(getConverter().from(uriInfo, entity)) .type(getMediaType()) .lastModified(entity.getLastModified()) .build(); }
@GET @Path("version") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Operation(description = "get MyCoRe version information", responses = { @ApiResponse(content = @Content(schema = @Schema(implementation = GitInfo.class))) }, tags = MCRRestUtils.TAG_MYCORE_ABOUT) public Response getVersion() { Optional<Response> cachedResponse = MCRRestUtils.getCachedResponse(request, INIT_TIME); return cachedResponse.orElseGet( () -> Response.ok(new GitInfo(MCRCoreVersion.getVersionProperties())).lastModified(INIT_TIME).build()); }
public static ResponseBuilder addLastModifiedAndETagIfAvailable(final ResponseBuilder responseBuilder, final Version version) { if (version != null && version.getTime() != null) { final Date time = version.getTime(); responseBuilder.lastModified(time); responseBuilder.tag(asETag(time)); } return responseBuilder; }
public Response.ResponseBuilder ifUnmodifiedSince(String strDate, Date lastModified) { Date date = DateUtil.parseDate(strDate); if (date.getTime() >= lastModified.getTime()) { return null; } return Response.status(SC_PRECONDITION_FAILED).lastModified(lastModified); }
public static Response.ResponseBuilder addLastModifiedAndETagIfAvailable( final Response.ResponseBuilder responseBuilder, final Version version) { if (version != null && version.getTime() != null) { final Date time = version.getTime(); responseBuilder.lastModified(time); responseBuilder.tag(asETag(time)); } return responseBuilder; }
public Response.ResponseBuilder ifUnmodifiedSince(String strDate, Date lastModified) { Date date = DateUtil.parseDate(strDate); if (date.getTime() >= lastModified.getTime()) { return null; } return Response.status(HttpResponseCodes.SC_PRECONDITION_FAILED).lastModified(lastModified); }
private Response buildTaskCompletedResponse(final TaskDescriptor<IndexCommandResult> task) throws ExecutionException, InterruptedException { final IndexCommandResult result = task.getResult(); if (result.isSuccessful()) { return Response.ok(ReindexBean.fromTaskDescriptor(task)).lastModified(task.getFinishedTimestamp()).build(); } else { return Response.serverError().entity(result.getErrorCollection()).cacheControl(never()).build(); } }
public static ResponseBuilder addLastModifiedAndETagIfAvailable(final ResponseBuilder responseBuilder, final Version version) { if (version != null && version.getTime() != null) { final Date time = version.getTime(); responseBuilder.lastModified(time); responseBuilder.tag("" + time); } return responseBuilder; }
public Response.ResponseBuilder ifUnmodifiedSince(String strDate, Date lastModified) { Date date = DateUtil.parseDate(strDate); if (date.getTime() >= lastModified.getTime()) { return null; } return Response.status(HttpResponseCodes.SC_PRECONDITION_FAILED).lastModified(lastModified); }
private static Response response(String response, String type, Date lastModified) { byte[] responseBytes = response.getBytes(StandardCharsets.UTF_8); String mimeType = type + "; charset=UTF-8"; CacheControl cacheControl = new CacheControl(); cacheControl.setNoTransform(false); cacheControl.setMaxAge(0); return Response.ok(responseBytes, mimeType).lastModified(lastModified) .header("Content-Length", responseBytes.length) .cacheControl(cacheControl).build(); }
public Response.ResponseBuilder ifUnmodifiedSince(String strDate, Date lastModified) { Date date = DateUtil.parseDate(strDate); if (date.getTime() >= lastModified.getTime()) { return null; } return Response.status(HttpResponseCodes.SC_PRECONDITION_FAILED).lastModified(lastModified); }
public Response.ResponseBuilder ifUnmodifiedSince(String strDate, Date lastModified) { Date date = DateUtil.parseDate(strDate); if (date.getTime() >= lastModified.getTime()) { return null; } return Response.status(SC_PRECONDITION_FAILED).lastModified(lastModified); }