dev@jsr311.java.net

Re: JSR311: taking the POJO injection idea further

From: Dhanji R. Prasanna <dhanji_at_gmail.com>
Date: Tue, 19 Feb 2008 13:01:32 -0800

I agree with Marc, these suggestions are starting to look very much like
SpringMVC now.
I think our core focus ought to remain stateless programming, mapping HTTP
methods to Java methods. And HTTP resources to Java resources (i.e.
classes).

Dhanji.

On Feb 19, 2008 11:56 AM, Bill Burke <bburke_at_redhat.com> wrote:

>
>
> Marc Hadley wrote:
> > On Feb 19, 2008, at 1:15 PM, Bill Burke wrote:
> >
> >> I just showed you an example where IAGNI, so I fail to see your point.
> >
> > Your example could easily be covered by the existing stuff we have:
>
> Then why do we have @HeaderParam or @QueryParam? or even Providers?
> They could be built easily using Httpheaders, UriInfo, and InputStream
> respectively. i.e.
>
> //_at_HttpParam("foo")
> public String get(@HttpContext HttpHeaders)
> {
> int foo = Integer.valueOf(httpHeaders.get("foo"));
> }
>
> //_at_QueryParam("foo")
> public String get(@HttpContext UriInfo info) {
> int foo = Integer.valueOf(info.getQueryParameters().getFirst("foo"));
> }
>
> //provider replacement
> public void put(InputStream is) {
> MyPojo pojo = new MyPojo(is);
> }
>
>
> Why do we even need JAX-RS for that matter? We could easily use the
> Servlet specification instead?
>
>
> The answer? JAX-RS is a convenience spec.
>
> >
> > GET http://host.com/customerdb/;first=Bill;last=Burke;ssn=444-44-4444
> >
> > @Path("/customerdb/{customerid}")
> > @GET
> > public String get(@MatrixParam("first") String firstName,
> > @MatrixParam("last") String lastName, ...) {...}
> >
>
> Your method declaration starts to get REALLY long. What if I need a few
> Pathparam, header params or even cookie params? Gets even longer if I
> want @DefaultValues
>
>
> > or
> >
> > @Path("/customerdb/{customerid}")
> > @GET
> > public String get() {
> > CustomerPK c = new CustomerPK(uriInfo.getMatrixParameters());
> > ...
> > }
> >
>
> Well, there is no uriInfo.getMatrixParameters() and get() needs an
> @HttpContext UriInfo. Let's see what's simpler though:
>
> public String get(@PathParam("customerid") CustomerPK pk) {
> }
>
> public class CustomerPK {
> @MatrixParam String first;
> @MatrixParam String last;
> @MatrixParam int ssn;
> }
>
> vs.
>
> public String get(@PathParam("customerid") PathSegment segment) {
> CustomerPK pk = new CustomerPK(segment.getMatrixParameters());
> }
>
> public class CustomerPK {
>
> public CustomerPK(MultivaluedMap<String, String> matrix) {
> first = matrix.getFirst("first");
> last = matrix.getFirst("last");
> ssn = Integer.valueOf(matrix.getFirst("ssn"));
> }
> }
>
> You're not saving a crazy alot of code here, but you are saving some,
> and it looks more readable. These savings can be compounded if you
> start reusing these mapped pojos in different methods and resources.
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>
>