use of javax.ws.rs.core.CacheControl in project jersey by jersey.
the class CacheControlProvider method fromString.
@Override
public CacheControl fromString(String header) {
throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.CACHE_CONTROL_IS_NULL());
try {
HttpHeaderReader reader = HttpHeaderReader.newInstance(header);
CacheControl cacheControl = new CacheControl();
// defaults to true
cacheControl.setNoTransform(false);
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);
}
}
use of javax.ws.rs.core.CacheControl in project jersey by jersey.
the class CacheControlImplTest method checkRoundTrip.
private void checkRoundTrip(String s) {
CacheControlProvider p = new CacheControlProvider();
CacheControl cc1 = p.fromString(s);
CacheControl cc2 = p.fromString(cc1.toString());
cc2.toString();
cc1.equals(cc2);
try {
assertEquals(cc1, cc2);
} catch (RuntimeException ex) {
throw ex;
}
}
use of javax.ws.rs.core.CacheControl in project jersey by jersey.
the class CacheControlImplTest method testToString.
@Test
public void testToString() {
CacheControlProvider p = new CacheControlProvider();
CacheControl instance = new CacheControl();
instance.setNoCache(true);
String expResult = "no-cache, no-transform";
String result = p.toString(instance);
assertEquals(expResult, result);
instance.setNoStore(true);
expResult = "no-cache, no-store, no-transform";
result = p.toString(instance);
assertEquals(expResult, result);
instance.setPrivate(true);
expResult = "private, no-cache, no-store, no-transform";
result = p.toString(instance);
assertEquals(expResult, result);
instance.getPrivateFields().add("Fred");
expResult = "private=\"Fred\", no-cache, no-store, no-transform";
result = p.toString(instance);
assertEquals(expResult, result);
instance.getPrivateFields().add("Bob");
expResult = "private=\"Fred, Bob\", no-cache, no-store, no-transform";
result = p.toString(instance);
assertEquals(expResult, result);
instance = new CacheControl();
instance.getCacheExtension().put("key1", "value1");
expResult = "no-transform, key1=value1";
result = p.toString(instance);
assertEquals(expResult, result);
instance.getCacheExtension().put("key1", "value1 with spaces");
expResult = "no-transform, key1=\"value1 with spaces\"";
result = p.toString(instance);
assertEquals(expResult, result);
instance.setNoStore(true);
expResult = "no-store, no-transform, key1=\"value1 with spaces\"";
result = p.toString(instance);
assertEquals(expResult, result);
instance = new CacheControl();
instance.getCacheExtension().put("key1", null);
expResult = "no-transform, key1";
result = p.toString(instance);
assertEquals(expResult, result);
}
use of javax.ws.rs.core.CacheControl in project graylog2-server by Graylog2.
the class WebInterfaceAssetsResource method getResponse.
private Response getResponse(Request request, String filename, URL resourceUrl, boolean fromPlugin) throws IOException, URISyntaxException {
final Date lastModified;
final InputStream stream;
final HashCode hashCode;
switch(resourceUrl.getProtocol()) {
case "file":
final File file = new File(resourceUrl.toURI());
lastModified = new Date(file.lastModified());
stream = new FileInputStream(file);
hashCode = Files.hash(file, Hashing.sha256());
break;
case "jar":
final URI uri = resourceUrl.toURI();
final FileSystem fileSystem = fileSystemCache.getUnchecked(uri);
final java.nio.file.Path path = fileSystem.getPath(pluginPrefixFilename(fromPlugin, filename));
final FileTime lastModifiedTime = java.nio.file.Files.getLastModifiedTime(path);
lastModified = new Date(lastModifiedTime.toMillis());
stream = resourceUrl.openStream();
hashCode = Resources.asByteSource(resourceUrl).hash(Hashing.sha256());
break;
default:
throw new IllegalArgumentException("Not a JAR or local file: " + resourceUrl);
}
final EntityTag entityTag = new EntityTag(hashCode.toString());
final Response.ResponseBuilder response = request.evaluatePreconditions(lastModified, entityTag);
if (response != null) {
return response.build();
}
final String contentType = firstNonNull(mimeTypes.getContentType(filename), MediaType.APPLICATION_OCTET_STREAM);
final CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge((int) TimeUnit.DAYS.toSeconds(365));
cacheControl.setNoCache(false);
cacheControl.setPrivate(false);
return Response.ok(stream).header(HttpHeaders.CONTENT_TYPE, contentType).tag(entityTag).cacheControl(cacheControl).lastModified(lastModified).build();
}
use of javax.ws.rs.core.CacheControl in project oxAuth by GluuFederation.
the class ClientInfoRestWebServiceImpl method requestClientInfo.
public Response requestClientInfo(String accessToken, String authorization, SecurityContext securityContext) {
if (authorization != null && !authorization.isEmpty() && authorization.startsWith("Bearer ")) {
accessToken = authorization.substring(7);
}
log.debug("Attempting to request Client Info, Access token = {}, Is Secure = {}", new Object[] { accessToken, securityContext.isSecure() });
Response.ResponseBuilder builder = Response.ok();
if (!ClientInfoParamsValidator.validateParams(accessToken)) {
builder = Response.status(400);
builder.entity(errorResponseFactory.getErrorAsJson(ClientInfoErrorResponseType.INVALID_REQUEST));
} else {
AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(accessToken);
if (authorizationGrant == null) {
builder = Response.status(400);
builder.entity(errorResponseFactory.getErrorAsJson(ClientInfoErrorResponseType.INVALID_TOKEN));
} else {
CacheControl cacheControl = new CacheControl();
cacheControl.setPrivate(true);
cacheControl.setNoTransform(false);
cacheControl.setNoStore(true);
builder.cacheControl(cacheControl);
builder.header("Pragma", "no-cache");
builder.entity(getJSonResponse(authorizationGrant.getClient(), authorizationGrant.getScopes()));
}
}
return builder.build();
}
Aggregations