Hi Jason - I'm not sure if @param is an option given your new
approach. But one way to accomplish what you're after is to sub-class
your own WadlGenerator, and then add it to any existing WadlGenerator
implementations you've already configured in your WadlGeneratorConfig
(via generator call). Based on the example at
http://wikis.sun.com/display/Jersey/HowToConfigureExtendedWADL, your
WadlGeneratorConfig might look like below. Note the class passed into
that last generator call. I attached the source for it (check out the
createRequest method). It's just a simple bare bones example (only
adds one of the params) but should give you a good starting point if
you choose this approach.
public class SampleWadlGeneratorConfig extends WadlGeneratorConfig {
@Override
public List<WadlGeneratorDescription> configure() {
return generator( WadlGeneratorApplicationDoc.class )
.prop( "applicationDocsStream", "application-doc.xml" )
.generator( WadlGeneratorGrammarsSupport.class )
.prop( "grammarsStream", "application-grammars.xml" )
.generator( WadlGeneratorResourceDocSupport.class )
.prop( "resourceDocStream", "resourcedoc.xml" )
.generator( SampleQueryParamWadlGeneratorSupport.class )
.descriptions();
}
}
Sample WADL fragment using SampleQueryParamWadlGeneratorSupport:
<ns2:resource path="theOldWay">
<ns2:method name="GET" id="theOldWay">
<ns2:request>
<ns2:param
xmlns:xs="
http://www.w3.org/2001/XMLSchema" type="xs:string"
style="query" name="regionCode"/>
<ns2:param
xmlns:xs="
http://www.w3.org/2001/XMLSchema" type="xs:string"
style="query" name="customerCode"/>
<ns2:param
xmlns:xs="
http://www.w3.org/2001/XMLSchema" type="xs:int"
style="query" name="pageSize"/>
<ns2:param
xmlns:xs="
http://www.w3.org/2001/XMLSchema" type="xs:int"
style="query" name="page"/>
</ns2:request>
<ns2:response>
<ns2:representation mediaType="application/xml"/>
</ns2:response>
</ns2:method>
</ns2:resource>
<ns2:resource path="theNewWay">
<ns2:method name="GET" id="theNewWay">
<ns2:request>
<ns2:param
type="xs:string" style="query" name="regionCode"
xmlns:xs="
http://www.w3.org/2001/XMLSchema"/>
</ns2:request>
<ns2:response>
<ns2:representation mediaType="application/xml"/>
</ns2:response>
</ns2:method>
</ns2:resource>
On Mon, Jan 10, 2011 at 8:26 PM, Jason Erickson <jerickson_at_factorlab.com> wrote:
> I have some web services that require quite a few options for query parameters. Rather than have a long list of @QueryParam parameters and then manually setting them to a criteria object I've created, I thought I would use UriInfo and get the MultivaluedMap from getQueryParameters, then pass that MultivaluedMap to a constructor (or a setter) for my criteria object.
>
> So here's a concrete example. In my old method:
>
> @GET
> public Item[] getItems(@QueryParam String regionCode, @QueryParam String customerCode, @QueryParam Integer pageSize, @QueryParam Integer page) {
> ItemCriteria criteria = new ItemCriteria();
> criteria.setRegionCode(regionCode);
> criteria.setCustomerCode(customerCode);
> criteria.setPageSize(pageSize);
> criteria.setPage(page);
> return itemDao.getItemsByCriteria(criteria);
> }
>
> Replace that with:
> @GET
> public Item[] getItems(@Context UriInfo ui) {
> ItemCriteria criteria = new ItemCriteria(ui.getQueryParameters());
> return itemDao.getItemsByCriteria(criteria);
> }
>
> It works great, and I can do a lot with unit tests that I would have otherwise probably had to do with integration tests. The problem is that I don't get to use @param javadoc comments to produce my extended WADL anymore. I can just manually format all of the expected parameters, but is there a way to do this that I'm missing?
>
>
>