Java Reference
In-Depth Information
A user will now only be able to invoke the updateCustomer() method once per day.
The last thing we have to do is initialize our deployment. Our Application class needs to
change a little bit to enable this:
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 >();
public
public ShoppingApplication ()
{
singletons . add ( new
new CustomerResource ());
HashMap < String , String > userSecretMap = new
new HashMap < String , String >();
userSecretMap . put ( "bburke" , "geheim" );
singletons . add ( new
new OneTimePasswordAuthenticator ( userSecretMap ));
singletons . add ( new
new PerDayAuthorizer ());
}
@Override
public
public Set < Object > getSingletons ()
{
return
return singletons ;
}
}
The ShoppingApplication class populates the user-secret map that must be used to con-
struct the singleton OneTimePasswordAuthenticator instance. The PerDayAuthorizer
class is also a singleton and instantiated by this constructor.
The client code
The first thing we do on the client side is to implement a ClientRequestFilter that sets up
the Authorization header that will be sent to the server:
src/main/java/com/restfully/shop/features/OneTimePasswordGenerator.java
public
public class
class OneTimePasswordGenerator
OneTimePasswordGenerator implements
implements ClientRequestFilter
{
protected
protected String user ;
protected
protected String secret ;
public
public OneTimePasswordGenerator ( String user , String secret )
{
this
this . user = user ;
Search WWH ::




Custom Search