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

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2815664

Reply via email to