users@jersey.java.net

Re: [Jersey] MultiValuedMap & variable number of parameters

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Thu, 9 Sep 2010 12:54:37 +0200

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.