Hi,
I forgot to answer the question in relation to HTTP POST data. One
solution is to have an abstract class that has the post method:
public abstract class Poster {
@POST public void post(...) {
}
abstract void processPost(...)
}
@Path("/")
public class MyPoster extends Poster {
void processPost(...) {
}
}
Tis frustrating in Java that there is no concept of a trait (i.e. to
support multiple inheritance) like there is in Scala, then this pattern
would be more flexible. But! of course you can use Scala with Jersey if
you wish :-) although i have not tested with traits...
Paul.
Paul Sandoz wrote:
> Hi ks,
>
> If you have a hierarchical relationship in the URI path for a user-based
> URIs and sub-resources you can use constructors and sub-locators:
>
> @Path("{user})
> public class User {
> public User(@PathParam("user") String user) {
> // get user information from DB
> }
>
> @Path("sub")
> public Object getSubResource() {
> return new SubResource(... pass in user information here ...);
> }
> }
>
> This does impose a certain style of development via the use of
> per-request life cycle and sub-locators, but you can see how useful
> using constructors can be sometimes for keeping things DRYer.
>
> I suspect using an IoC framework it may be possible to avoid the passing
> of information to constructors of sub-resources.
>
> Another solution is to have all user-based resources extend a common
> abstract class the constructor of which gets user the required information.
>
> I am definitely interested in alternative ideas/ways of managing this.
>
> Paul.
> KSChan wrote:
>> Hi,
>>
>> I would like to know is there any ways to preprocess the data when
>> invoking the web service?
>>
>> For example, if I have a web service to obtain USER ID from DB with a
>> LOGIN NAME and PASSWORD; could I preprocess the data before the
>> invocation of the method defined in the resource? The preprocessing is
>> aimed as preventing SQL injection for "all" resource so that I won't
>> need to process the data every time.
>>
>> ks.
>>
>> --
>> I, have a dream. I want to make my dream come true.
>>
>> http://mr.kschan.googlepages.com
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109