dev@jersey.java.net

Re: MatrixParam help?

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 31 Oct 2007 15:13:48 -0400

On Oct 31, 2007, at 2:59 PM, Ayub Khan wrote:
>
> I tried http://localhost:8080/CustomerDB/resources/hello3?name=test
>
For a matrix param you need ';' rather than '?' in the above URL. It
looks like you did that in your first post though.

Marc.


> The result is same
>
> <b>Hello null</b>
>
> I guess Matrix Param annotation is just ignored for following code
>
> @HttpMethod("GET")
> @ProduceMime("application/xml")
> public String getXml(@MatrixParam("name") String name) {
> return "<?xml version='1.0' encoding='UTF-8'?>\n<b>Hello
> "+name+"</b>";
> }
>>
>> I just did a quick check by modifying the SimpleServlet example
>> and adding a matrix parameter:
>>
>> public InputStream doGet(@MatrixParam("name") String name) {
>> System.out.println(name);
>> return this.getClass().getResourceAsStream("index.html");
>> }
>>
>> and it worked fine with or without a matrix parameter present on
>> the URI.
>>
>> What is the source code for the class whose name is the value of
>> the servlet init-parameter webresourceclass ?
> This file WebResources.java is attached.
>>
>> IIRC Matrix parameters are not supported by the WADL generation.
>>
>> Paul.
> Thanks
> Ayub
>>
>> Ayub Khan wrote:
>>> Hi Paul,
>>>
>>> With 0.4ea jersey available in REST modules of NB6.0 trunk.
>>>
>>> I was trying MatrixParam annotation.
>>>
>>>
>>> /**
>>> * Retrieves representation of an instance of
>>> hello.HelloWorldResource
>>> * @return an instance of java.lang.String
>>> */
>>> @HttpMethod("GET")
>>> @ProduceMime("application/xml")
>>> public String getXml(@MatrixParam("name") String name) {
>>> return "<?xml version='1.0' encoding='UTF-8'?>\n<b>Hello
>>> "+name+"</b>";
>>> }
>>>
>>> After deploying the app, if I try the URL http://localhost:8080/
>>> CustomerDB/resources/hello3;name=test
>>> I get 404 error on the browser.
>>>
>>> Also checked the wadl, it does not have a param element
>>> (I was expecting this element also to have a style="matrix"
>>> attribute) for the resource hello3.
>>>
>>> application.wadl
>>> ---------------------
>>> ...
>>> <resource path="hello3">
>>> <method name="GET">
>>> <request>
>>> <representation/>
>>> </request>
>>> <response>
>>> <representation mediaType="application/xml"/>
>>> </response>
>>> </method>
>>> ...
>>> ----------------------
>>>
>>>
>>> Can you please provide a sample and how to test it.
>>>
>>> Thanks
>>> Ayub
>>>
>>> --------------------------------------------------------------------
>>> -
>>> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>>>
>>
>
> package webresources;
>
> import com.sun.ws.rest.api.core.DefaultResourceConfig;
>
>
> /**
> * This class was generated.
> *
> * It is used to declare the set of root resource classes.
> *
> */
> public class WebResources
> extends DefaultResourceConfig
> {
>
>
> /**
> * Declare the set of root resource classes.
> *
> */
> public WebResources() {
> getResourceClasses().add
> (customerdb.service.DiscountCodesResource.class);
> getResourceClasses().add
> (customerdb.service.HelloWorldResource.class);
> getResourceClasses().add
> (customerdb.service.DapperSearchResource.class);
> getResourceClasses().add
> (customerdb.service.HelloWorldResource2.class);
> getResourceClasses().add
> (customerdb.service.CustomersResource.class);
> getResourceClasses().add
> (customerdb.service.HelloWorldResource1.class);
> getResourceClasses().add
> (customerdb.service.HelloWorldResource3.class);
> getResourceClasses().add
> (com.sun.ws.rest.wadl.resource.WadlResource.class);
> getFeatures().put
> ("com.sun.ws.rest.config.feature.NormalizeURI", false);
> getFeatures().put
> ("com.sun.ws.rest.config.feature.IgnoreMatrixParams", false);
> getFeatures().put
> ("com.sun.ws.rest.config.feature.CanonicalizeURIPath", false);
> getFeatures().put
> ("com.sun.ws.rest.config.feature.Redirect", false);
> }
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.