Thanks Thierry.
I have a handful of methods that depend on the raw value of a custom
ChallengeScheme. It doesn't seem that Restlet will extract this value on the
fly as in:
@Get
public Representation getAttributes(ChallengeResponse token) {
// do stuff with token.
}
Right?
If not, what would you recommend for the following? I have a ClientResource in
the internals of my API that connects to a session provisioner. I have a
ServerResource that the user of my public API connects to which in turn
connects to the ClientResource. I have both the ClientResource and the
ServerResource implementing a common interface as in:
public interface Session {
@Post
abstract Representation createSession(Form form);
@Get
abstract Representation getAttributes(String token);
@Put
abstract void validateSessionToken(String token);
@Delete
abstract void logout(String token);
}
Right now, the ServerResource gets the raw value of the custom
ChallengeResponse and then calls the corresponding ClientResource method
passing the token in as a string. So like this:
public final class SessionImpl extends ServerResource implements Session {
//…
public Representation getAttributes(String token) {
Representation rep;
Rep = clientResource.
getAttributes(getChallengeResponse().getRawValue());
return rep;
}
//…
}
public final class SessionProvisionerProxy extends ClientResource implements
Session {
//…
public Representation getAttributes(String token) {
Representation rep;
rep = getAttributesFromSessionProvisioner(token);
return rep;
}
//…
}
This works fine, mind you, but I was wondering if there is a better design
practice I should be following here since the ServerResource doesn't know what
the "String token" is (?).
From: Thierry Boileau
<[email protected]<mailto:[email protected]>>
Reply-To: discuss
<[email protected]<mailto:[email protected]>>
Date: Thu, 11 Aug 2011 06:52:15 -0500
To: "[email protected]<mailto:[email protected]>"
<[email protected]<mailto:[email protected]>>
Subject: Re: Spring inject a Form constructed using the requestEntity
Hello Paul,
But how do I inject the Form into my ServerResource object in the Spring
context file since it won't have what it needs (namely the requestEntity) to
get instantiated until after the POST gets called?
I think there is no need to inject Form or request entity into server resources.
You can use Spring to configure your application and its sets of so called
"routes" (basically a route is a "uri template/resource" pair).
Then, the framework is in charge to transmit the request (and its entity, its
header, etc) to the new instance of ServerResource : in the sample code that
you provided, there is no need to explicitely call the "getRequestEntity()"
method, because the "entity" parameter is already the request's entity :
@Post
public Representation doPost(Representation entity) {
Form form = new Form(entity);
// do stuff with the parameters in the form
}
I would like also add that each request is handled by a brand new instance of
class ServerResource (I mean : subclass of).
You can also rely on the "content negotiation" feature. Based on the
characteristics of the request, this feature chooses the right method to invoke
with the right parameters : handleForm(Form),
handleRepresentation(Representation), etc
You can define several annotated method :
@Post
public Representation handleForm(Form form) {
// do stuff with the parameters in the form
}
@Post("xml")
public Representation handleXml(Representation entity) {
// parse the xml entity and do stuff
}
@Post("json")
public Representation handleJson(Representation entity) {
// parse the json entity and do stuff
}
This may explain Tim's suggestion.
Best regards,
Thierry Boileau
This message and any included attachments are intended only for the addressee.
The information contained in this message is confidential and may constitute
proprietary or non-public information under international, federal, or state
laws. Unauthorized forwarding, printing, copying, distribution, or use of such
information is strictly prohibited and may be unlawful. If you are not the
addressee, please promptly delete this message and notify the sender of the
delivery error by e-mail.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2815791