Java Reference
In-Depth Information
the HTTP response with a max age of 500 seconds. Let's also take a look at how these
classes are registered:
src/main/java/com/restfully/shop/services/ShoppingApplication.java
@ApplicationPath
(
"/services"
)
public
public class
class
ShoppingApplication
ShoppingApplication
extends
extends
Application
{
private
private
Set
<
Object
>
singletons
=
new
new
HashSet
<
Object
>();
private
private
Set
<
Class
<?>>
classes
=
new
new
HashSet
<
Class
<?>>();
public
public
ShoppingApplication
()
{
singletons
.
add
(
new
new
CustomerResource
());
classes
.
add
(
MaxAgeFeature
.
class
);
}
@Override
public
public
Set
<
Class
<?>>
getClasses
()
{
return
return
classes
;
}
@Override
public
public
Set
<
Object
>
getSingletons
()
{
return
return
singletons
;
}
}
Notice that we only register the
MaxAgeFeature
class. This class handles the registration of
the
CacheControlFilter
if the JAX-RS method is annotated with
@MaxAge
.
The Client Code
The client code hasn't changed much from other examples. We first start off by creating a
Customer
on the server. We then do a GET request to get the customer, checking for the
Cache-Control
header generated by the
CacheControlFilter
on the server side:
src/test/java/com/restfully/shop/test/CustomerResourceTest.java
...
System
.
out
.
println
(
"*** GET Created Customer **"
);
response
=
client
.
target
(
location
).
request
().
get
();
CacheControl cc
=
CacheControl
.
valueOf
(