[Minor] added cache mode setting for rest http header (defaults to
no-cache)
This commit is contained in:
parent
e44775f30b
commit
e39df60247
|
@ -20,6 +20,7 @@ import java.text.MessageFormat;
|
|||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.StrolchComponent;
|
||||
import li.strolch.rest.filters.AccessControlResponseFilter;
|
||||
import li.strolch.rest.filters.HttpCacheResponseFilter;
|
||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||
|
||||
import org.glassfish.jersey.server.ServerProperties;
|
||||
|
@ -35,6 +36,7 @@ public class RestfulStrolchComponent extends StrolchComponent {
|
|||
private static final String PARAM_CORS_ORIGIN = "corsOrigin"; //$NON-NLS-1$
|
||||
private static final String PARAM_REST_LOGGING = "restLogging"; //$NON-NLS-1$
|
||||
private static final String PARAM_REST_LOGGING_ENTITY = "restLoggingEntity"; //$NON-NLS-1$
|
||||
private static final String PARAM_HTTP_CACHE_MODE = "httpCacheMode"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Allowed values:
|
||||
|
@ -69,6 +71,7 @@ public class RestfulStrolchComponent extends StrolchComponent {
|
|||
private String corsOrigin;
|
||||
private boolean restLogging;
|
||||
private boolean restLoggingEntity;
|
||||
private String cacheMode;
|
||||
|
||||
/**
|
||||
* @param container
|
||||
|
@ -140,6 +143,10 @@ public class RestfulStrolchComponent extends StrolchComponent {
|
|||
String msg = "Set restLogging={0} with logEntities={1} restTracing={2} with threshold={3}"; //$NON-NLS-1$
|
||||
logger.info(MessageFormat.format(msg, this.restLogging, this.restLoggingEntity, this.restTracing,
|
||||
this.restTracingThreshold));
|
||||
|
||||
// set http cache mode
|
||||
this.cacheMode = configuration.getString(PARAM_HTTP_CACHE_MODE, HttpCacheResponseFilter.NO_CACHE);
|
||||
logger.info("HTTP header cache mode is set to {}",cacheMode);
|
||||
|
||||
super.initialize(configuration);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package li.strolch.rest.filters;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Priority;
|
||||
import javax.ws.rs.Priorities;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.container.ContainerResponseContext;
|
||||
import javax.ws.rs.container.ContainerResponseFilter;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
@Priority(Priorities.HEADER_DECORATOR)
|
||||
public class HttpCacheResponseFilter implements ContainerResponseFilter {
|
||||
|
||||
public static final String NO_CACHE = "no-cache"; //$NON-NLS-1$
|
||||
|
||||
private static String cacheMode = NO_CACHE;
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
|
||||
throws IOException {
|
||||
|
||||
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
|
||||
headers.add(HttpHeaders.CACHE_CONTROL, cacheMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cacheMode
|
||||
*/
|
||||
public static String getCacheMode() {
|
||||
return cacheMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cacheMode
|
||||
* the cacheMode to set
|
||||
*/
|
||||
public static void setCacheMode(String cacheMode) {
|
||||
HttpCacheResponseFilter.cacheMode = cacheMode;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue