On Sep 9, 2010, at 7:54 PM, Saavedra, Gisella wrote:
> Paul,
>
> some of my parameters might not be String. So, I take from what you
> say that this pattern only works for strings.
>
Yes, since they are encoded as strings on the wire. You would need to
tell Jersey what parameters can be decoded into what Java types.
@FormParam can do that for you, if you know what the parameter names
are.
An alternative is to write your own message body reader for processing
form parameters that supports the Java type you require.
Paul.
>
> -----Original Message-----
> From: Paul Sandoz [mailto:Paul.Sandoz_at_oracle.com]
> Sent: Thursday, September 09, 2010 3:55 AM
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] MultiValuedMap & variable number of parameters
>
> Hi,
>
> You need to use a the type MultivaluedMap<String, String>, as in the
> following:
>
> @POST
> @Path("/peer/{eventGkey}")
> @Consumes("application/x-www-form-urlencoded")
> @Produces("application/octet-stream")
> public Response
> invokePeerActionWithParams(@PathParam("eventGkey") Long inEventGkey,
> MultivaluedMap<String, String> inFormParams) {
> ...
> }
>
> Paul.
>
>
> On Sep 9, 2010, at 2:27 AM, Saavedra, Gisella wrote:
>
>> I have a map of values (form parameters) which vary. basically what
>> I am saying is that the REST service should only care a bout a
>> Map<String,Object> paramters.
>>
>> I am doing a POST with one PathParam, and the rest are form
>> parameters (count is variable).
>>
>>
>> I do the following at the client:
>>
>> MultivaluedMap data = new
>> StringKeyObjectValueIgnoreCaseMultivaluedMap();
>> for (Map.Entry<String,Serializable> param :
>> inParams.entrySet()) {
>> data.add(param.getKey(), param.getValue());
>> }
>>
>> WebResource res =
>>
>> RESTUtils.prepareWebResource(nodeURL,
>> EventConsts.URI_COMPONENT_EVENT, configProperties)
>> .path(inEventGkey.toString());
>> ClientResponse resp =
>> res
>> .type
>> (MediaType
>> .APPLICATION_FORM_URLENCODED
>> ).accept(MediaType.APPLICATION_OCTET_STREAM_TYPE)
>> .header
>> (EventConsts.URI_HEADER_USER_ID, inUserContext.getUserId())
>> .post(ClientResponse.class, data);
>>
>>
>> The URL generated is: http://10.40.4.99:8280/sandbox/rest/componentEvent/peer/28
>>
>> My service does not seem to find the right combination of type/
>> reader. This is the code:
>> @POST
>> @Path("/peer/{eventGkey}")
>> @Consumes("application/x-www-form-urlencoded")
>> @Produces("application/octet-stream")
>> public Response
>> invokePeerActionWithParams(@PathParam("eventGkey") Long inEventGkey,
>> MultivaluedMap<String, Object> inFormParams) {
>> ...
>> }
>>
>>
>> Should I be using something different than the MultiValuedMap? Or
>> else. The REST server tells me that it cannot find a reader for
>> type = javax.ws.rs.core.MultivaluedMap
>> FromProvider. isReadable(Class<?> type, Type genericType,
>> Annotation[] annotations, MediaType mediaType) returns false.
>>
>> I get this error:
>> A message body reader for Java class
>> javax.ws.rs.core.MultivaluedMap, and Java type
>> javax.ws.rs.core.MultivaluedMap<java.lang.String, java.lang.Object>,
>> and MIME media type application/x-www-form-urlencoded was not found.
>> --
>>
>>
>> Any help is appreciated. Thanks.
>>
>> - CONFIDENTIAL-
>>
>> This email and any files transmitted with it are confidential, and
>> may also be legally privileged. If you are not the intended
>> recipient, you may not review, use, copy, or distribute this
>> message. If you receive this email in error, please notify the
>> sender immediately by reply email and then delete this email.
>