Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public Object aroundReadFrom(final ReaderInterceptorContext context) throws IOEx
}
final MultivaluedMap<String, String> responseHeaders = context.getHeaders();
final String cacheControlHeader = responseHeaders.getFirst(HttpHeaders.CACHE_CONTROL);
if (cacheControlHeader == null) {
return context.proceed();
}
final CacheControl cacheControl = CacheControl.valueOf(cacheControlHeader);

byte[] cachedBytes = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;

public class ClientCacheTest {
Expand Down Expand Up @@ -203,6 +204,25 @@ public void testGetJaxbBookCacheByValue() {
}
}

@Test
public void testGetNonCacheBook() {
try (CacheControlFeature feature = new CacheControlFeature()) {
final WebTarget base = ClientBuilder.newBuilder().register(feature).build().target(ADDRESS);
final Invocation.Builder cached =
setAsLocal(base.request("text/xml")).header(HttpHeaders.CACHE_CONTROL, "public");
final Response r = cached.get();
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
final Book b1 = r.readEntity(Book.class);
assertEquals("JNonCache", b1.getName());
assertNotNull(b1.getId());
waitABit();
final Response r2 = cached.get();
final Book b2 = r2.readEntity(Book.class);
assertNotEquals(b1, b2);
assertEquals(b1.getName(), b2.getName());
}
}

private static Invocation.Builder setAsLocal(final Invocation.Builder client) {
WebClient.getConfig(client).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
return client;
Expand Down Expand Up @@ -232,6 +252,14 @@ public Response getJaxbBook() {
b.setName("JCache");
return Response.ok(b).tag("123").cacheControl(CacheControl.valueOf("max-age=50000")).build();
}
@GET
@Produces("text/xml")
public Response getNonCacheBook() {
Book b = new Book();
b.setId(System.currentTimeMillis());
b.setName("JNonCache");
return Response.ok(b).tag("123").build();
}
}
@XmlRootElement
public static class Book implements Serializable {
Expand Down
Loading