Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98f00b2
commit 296847e
Showing
10 changed files
with
885 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
jaxrs/resteasy-client/src/main/java/org/jboss/resteasy/client/jaxrs/cache/BrowserCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.jboss.resteasy.client.jaxrs.cache; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> | ||
* @version $Revision: 1 $ | ||
*/ | ||
public interface BrowserCache | ||
{ | ||
public static class Header implements Serializable | ||
{ | ||
private static final long serialVersionUID = 4145981086454860081L; | ||
|
||
private String name; | ||
private String value; | ||
|
||
public Header(String name, String value) | ||
{ | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
public String getValue() | ||
{ | ||
return value; | ||
} | ||
} | ||
|
||
public static interface Entry | ||
{ | ||
MultivaluedMap<String, String> getHeaders(); | ||
|
||
boolean expired(); | ||
|
||
Header[] getValidationHeaders(); | ||
|
||
byte[] getCached(); | ||
|
||
MediaType getMediaType(); | ||
} | ||
|
||
Entry getAny(String key); | ||
|
||
Entry get(String key, MediaType accept); | ||
|
||
Entry put(String key, MediaType mediaType, MultivaluedMap<String, String> headers, byte[] cached, int expires, String etag, String lastModified); | ||
|
||
Entry remove(String key, MediaType type); | ||
|
||
void clear(); | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...teasy-client/src/main/java/org/jboss/resteasy/client/jaxrs/cache/BrowserCacheFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jboss.resteasy.client.jaxrs.cache; | ||
|
||
import javax.ws.rs.client.Configuration; | ||
import javax.ws.rs.client.Feature; | ||
|
||
/** | ||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> | ||
* @version $Revision: 1 $ | ||
*/ | ||
public class BrowserCacheFeature implements Feature | ||
{ | ||
protected BrowserCache cache; | ||
|
||
public BrowserCache getCache() | ||
{ | ||
return cache; | ||
} | ||
|
||
public void setCache(BrowserCache cache) | ||
{ | ||
this.cache = cache; | ||
} | ||
|
||
@Override | ||
public boolean onEnable(Configuration configuration) | ||
{ | ||
if (cache == null) cache = new LightweightBrowserCache(); | ||
configuration.setProperty(BrowserCache.class.getName(), cache); | ||
configuration.register(new CacheInterceptor(cache)); | ||
return true; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
jaxrs/resteasy-client/src/main/java/org/jboss/resteasy/client/jaxrs/cache/CacheEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package org.jboss.resteasy.client.jaxrs.cache; | ||
|
||
import org.jboss.resteasy.client.jaxrs.cache.BrowserCache.Entry; | ||
import org.jboss.resteasy.client.jaxrs.cache.BrowserCache.Header; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import java.io.Serializable; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class CacheEntry implements Entry, Serializable | ||
{ | ||
private static final long serialVersionUID = -1922521972113619372L; | ||
private final String mediaType; | ||
private final byte[] cached; | ||
private final int expires; | ||
private final long timestamp = System.currentTimeMillis(); | ||
private final MultivaluedMap<String, String> headers; | ||
private Header[] validationHeaders = {}; | ||
private final String key; | ||
private Map extendedProperties = new ConcurrentHashMap(); | ||
|
||
public CacheEntry(String key, MultivaluedMap<String, String> headers, byte[] cached, int expires, String etag, String lastModified, MediaType mediaType) | ||
{ | ||
this.key = key; | ||
this.cached = cached; | ||
this.expires = expires; | ||
this.mediaType = mediaType.toString(); | ||
this.headers = headers; | ||
|
||
if (etag != null || lastModified != null) | ||
{ | ||
if (etag != null && lastModified != null) | ||
{ | ||
validationHeaders = new Header[2]; | ||
validationHeaders[0] = new Header("If-Modified-Since", lastModified); | ||
validationHeaders[1] = new Header("If-None-Match", etag); | ||
} | ||
else if (etag != null) | ||
{ | ||
validationHeaders = new Header[1]; | ||
validationHeaders[0] = new Header("If-None-Match", etag); | ||
} | ||
else if (lastModified != null) | ||
{ | ||
validationHeaders = new Header[1]; | ||
validationHeaders[0] = new Header("If-Modified-Since", lastModified); | ||
} | ||
|
||
} | ||
} | ||
|
||
public String getKey() | ||
{ | ||
return key; | ||
} | ||
|
||
public MultivaluedMap<String, String> getHeaders() | ||
{ | ||
return headers; | ||
} | ||
|
||
public boolean expired() | ||
{ | ||
return System.currentTimeMillis() - timestamp >= expires * 1000; | ||
} | ||
|
||
public Header[] getValidationHeaders() | ||
{ | ||
return validationHeaders; | ||
} | ||
|
||
public byte[] getCached() | ||
{ | ||
return cached; | ||
} | ||
|
||
public MediaType getMediaType() | ||
{ | ||
return MediaType.valueOf(mediaType); | ||
} | ||
|
||
public void addExtendedProperty(Serializable key, Serializable value) | ||
{ | ||
extendedProperties.put(key, value); | ||
} | ||
|
||
public Object getExtendedProperty(Serializable key) | ||
{ | ||
return extendedProperties.get(key); | ||
} | ||
} |
Oops, something went wrong.