Hi Gabo

Hi Sergey,

> You don't need to put @PathParam-annotate inidividual fileds in a
bean like SearchFilter, just having proprty setters
> will do.

As soon as I remove the empty @PathParam, I get the premature end of file 
exception:

Not sure about this one - but I didn't suggest removing the empty 
@PathParam(""), it should still be

@Path({foo}/{bar})
someMethod(@PathParam("") SearchFilter filer)

as it indicates to the runtime that individual path segments need to be injected as properties into a SearchFilter bean. What I was saying was that you don't need @PathParam annotations inside SearchFilter which I noticed in your original example.

Where/how should I put the @DefaultValue for @PathParam? Note that the method parameter is a java object. I annotated my method as @Path("/search/{whereCondition}/{sortString}/{startingRow}/{lastRow}") which forces me to access the page as is.

I'm not sure I understand but let me try.

If you do requests like "GET /search/someCondition" you'd still like the method 
annotated with the
@Path("/search/{whereCondition}/{sortString}/{startingRow}/{lastRow} be invoked, and as no sortString/startingRow/lastRow are available, you'd like default values for sortString/etc injected into SearchFilter ?

If yes - then it's not possible at the JAX-RS level, you'd need to have a 
seperate method to start with say just
@Path("/search/{whereCondition}") and handle default values at the SearchFilter bean level, that is, if no value has been injected then assume some default value for a given property.

A JAX-RS compliant approach is to have all your path variables as method 
parameters, like this
getIt(@DefaultValue("bar") @PathParam("whereCondition"), ....)

but obviously it makes a signature more brittle/verbose.

Or do you have something else in mind ?


Could I have some sample on injecting via QueryParams? I have tried adding @QueryParam to all the setters of SearchFilter object while having the method annotated as follows:

@GET
@Path("/search")
@ProduceMime("application/xml")
public Accounts getList(
       @QueryParam("")
       SearchFilter sf
       ) {


This looks correct.
Here's fragment from my test :

public static class CustomerBean {
private String a;
private Long b;
public void setA(String aString) {
this.a = aString;
}
public void setB(Long bLong) {
this.b = bLong;
}
public String getA() {
return a;
}
public Long getB() {
return b;
}
}

public class Customer {
public void testQueryBean(@QueryParam("") CustomerBean cb){}
}

testcode :

messageImpl.put(Message.QUERY_STRING, "a=aValue&b=123");
...
assertEquals("aValue", cb.getA());
assertEquals(new Long(123), cb.getB());


so if you have a query variable named 'a' then you need to have a setA(...) method. Note, no @QueryParam annotations on the CustomerBean class.

I think using a query can be better if you'd like to avoid having multiple 
methods.

Hope it helps, Sergey

Again, my thanks.

Gabo

Reply via email to