CacheControl cc = new CacheControl(); cc.setMaxAge(600);
@GET @Produces(MediaType.APPLICATION_JSON) public Response getGeoJsonIsochrone() throws Exception { SimpleFeatureCollection contourFeatures = makeContourFeatures(computeIsochrone()); StringWriter writer = new StringWriter(); FeatureJSON fj = new FeatureJSON(); fj.writeFeatureCollection(contourFeatures, writer); CacheControl cc = new CacheControl(); cc.setMaxAge(3600); cc.setNoCache(false); return Response.ok().entity(writer.toString()).cacheControl(cc).build(); }
@GET @Path("/tile/{layer}/{z}/{x}/{y}.{ext}") @Produces("image/*") public Response tileGet() throws Exception { // Re-use analyst Envelope2D env = SlippyTile.tile2Envelope(x, y, z); TileRequest tileRequest = new TileRequest(env, 256, 256); Router router = otpServer.getRouter(routerId); BufferedImage image = router.tileRendererManager.renderTile(tileRequest, layer); MIMEImageFormat format = new MIMEImageFormat("image/" + ext); ByteArrayOutputStream baos = new ByteArrayOutputStream(image.getWidth() * image.getHeight() / 4); ImageIO.write(image, format.type, baos); CacheControl cc = new CacheControl(); cc.setMaxAge(3600); cc.setNoCache(false); return Response.ok(baos.toByteArray()).type(format.toString()).cacheControl(cc).build(); }
private static Response generateStreamingGeotiffResponse(final GridCoverage2D coverage) { StreamingOutput streamingOutput = new StreamingOutput() { public void write(OutputStream outStream) { try { long t0 = System.currentTimeMillis(); GeoTiffWriteParams wp = new GeoTiffWriteParams(); wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType("LZW"); ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); new GeoTiffWriter(outStream).write(coverage, (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1])); //new GeoTiffWriter(outStream).write(coverage, null); //wasn't this line writing twice and trashing compressed version? long t1 = System.currentTimeMillis(); LOG.debug("wrote geotiff in {}msec", t1-t0); } catch (Exception e) { LOG.error("exception while preparing geotiff : {}", e.getMessage()); throw new WebApplicationException(e); } } }; CacheControl cc = new CacheControl(); cc.setMaxAge(3600); cc.setNoCache(false); return Response.ok(streamingOutput) .type("image/geotiff") .cacheControl(cc) .build(); }
public static Response generateStreamingImageResponse( final BufferedImage image, final MIMEImageFormat format) { if (image == null) { LOG.warn("response image is null"); } StreamingOutput streamingOutput = new StreamingOutput() { public void write(OutputStream outStream) { try { long t0 = System.currentTimeMillis(); ImageIO.write(image, format.type, outStream); long t1 = System.currentTimeMillis(); LOG.debug("wrote image in {}msec", (int)(t1-t0)); } catch (Exception e) { LOG.error("exception while preparing image : {}", e.getMessage()); throw new WebApplicationException(e); } } }; CacheControl cc = new CacheControl(); cc.setMaxAge(3600); cc.setNoCache(false); return Response.ok(streamingOutput) .type(format.toString()) .cacheControl(cc) .build(); }
final CacheControl cacheControl = new CacheControl(); cacheControl.setMaxAge((int) TimeUnit.DAYS.toSeconds(365)); cacheControl.setNoCache(false);
/** * Edit the response headers to indicating no caching. * * @param response response * @return builder */ protected ResponseBuilder noCache(final ResponseBuilder response) { final CacheControl cacheControl = new CacheControl(); cacheControl.setPrivate(true); cacheControl.setNoCache(true); cacheControl.setNoStore(true); return response.cacheControl(cacheControl); }
CacheControl cacheControl = new CacheControl(); cacheControl.setNoTransform(true); cacheControl.setPrivate(true);
CacheControl cacheControl = new CacheControl(); cacheControl.setNoTransform(true); cacheControl.setPrivate(true);
@Override public CacheControl fromString(String header) { throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.CACHE_CONTROL_IS_NULL()); try { HttpHeaderReader reader = HttpHeaderReader.newInstance(header); CacheControl cacheControl = new CacheControl(); cacheControl.setNoTransform(false); // defaults to true while (reader.hasNext()) { readDirective(cacheControl, reader); if (reader.hasNextSeparator(',', true)) { reader.nextSeparator(','); } } return cacheControl; } catch (ParseException pe) { throw new IllegalArgumentException( "Error parsing cache control '" + header + "'", pe); } }
@Override public CacheControl fromString(String header) { throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.CACHE_CONTROL_IS_NULL()); try { HttpHeaderReader reader = HttpHeaderReader.newInstance(header); CacheControl cacheControl = new CacheControl(); cacheControl.setNoTransform(false); // defaults to true while (reader.hasNext()) { readDirective(cacheControl, reader); if (reader.hasNextSeparator(',', true)) { reader.nextSeparator(','); } } return cacheControl; } catch (ParseException pe) { throw new IllegalArgumentException( "Error parsing cache control '" + header + "'", pe); } }
CacheControlledResponseFilter(CacheControl control) { final javax.ws.rs.core.CacheControl cacheControl = new javax.ws.rs.core.CacheControl(); cacheControl.setPrivate(control.isPrivate()); cacheControl.setNoCache(control.noCache()); cacheControl.setNoStore(control.noStore()); cacheControl.setNoTransform(control.noTransform()); cacheControl.setMustRevalidate(control.mustRevalidate()); cacheControl.setProxyRevalidate(control.proxyRevalidate()); cacheControl.setMaxAge((int) control.maxAgeUnit().toSeconds(control.maxAge())); cacheControl.setSMaxAge((int) control.sharedMaxAgeUnit() .toSeconds(control.sharedMaxAge())); if (control.immutable()) { cacheControl.setMaxAge(ONE_YEAR_IN_SECONDS); } cacheResponseHeader = cacheControl.toString(); }
private StatusResponseBuilder(Response.Status status) { this(status, new CacheControl()); }
CacheControl cc = new CacheControl(); cc.setNoCache(true);
private CacheControl cacheControlNoStore() { CacheControl cacheControl = new CacheControl(); cacheControl.setNoStore(true); return cacheControl; }
protected CacheControl initCacheControl(NoCache value) { CacheControl cacheControl = new CacheControl(); cacheControl.setNoCache(true); cacheControl.setNoTransform(false); for (String field : value.fields()) cacheControl.getNoCacheFields().add(field); return cacheControl; } }
CacheControl cc = new CacheControl(); cc.setNoTransform(true); cc.setMustRevalidate(false);
CacheControl cc = new CacheControl(); cc.setMaxAge(entry.getExpirationInSeconds()); if (builder != null)
protected CacheControl initCacheControl(Cache methodCached) { CacheControl cacheControl = new CacheControl(); if (methodCached.isPrivate()) { cacheControl.setPrivate(true); } if (methodCached.maxAge() > -1) { cacheControl.setMaxAge(methodCached.maxAge()); } if (methodCached.sMaxAge() > -1) { cacheControl.setSMaxAge(methodCached.sMaxAge()); } cacheControl.setMustRevalidate((methodCached.mustRevalidate())); cacheControl.setNoStore((methodCached.noStore())); cacheControl.setNoTransform((methodCached.noTransform())); cacheControl.setProxyRevalidate(methodCached.proxyRevalidate()); cacheControl.setNoCache(methodCached.noCache()); return cacheControl; }
protected CacheControl initCacheControl(NoCache value) { CacheControl cacheControl = new CacheControl(); cacheControl.setNoCache(true); cacheControl.setNoTransform(false); for (String field : value.fields()) cacheControl.getNoCacheFields().add(field); return cacheControl; } }