users@jersey.java.net

Re: [Jersey] several QueryParams ?

From: Felipe Gaścho <fgaucho_at_gmail.com>
Date: Wed, 9 Sep 2009 15:36:10 +0200

I finally adopted this:

        @POST
        @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
        public PujInstitutionEntity update(@QueryParam("acronym") String acronym,
                        @QueryParam("name") String name,
                        @QueryParam("website") String website,
                        @QueryParam("logo") String logo,
                        @QueryParam("email") String email,
                        @QueryParam("contact") String contact,
                        @QueryParam("phone") String phone) {
                PujInstitutionEntity institution = facade.read(
                                PujInstitutionEntity.class, acronym);
                if (name != null) {
                        institution.setContact(validateNull(name));
                }
                if (website != null) {
                        institution.setContact(validateNull(website));
                }
                if (logo != null) {
                        institution.setContact(validateNull(logo));
                }
                if (contact != null) {
                        institution.setContact(validateNull(contact));
                }
                if (phone != null) {
                        institution.setContact(validateNull(phone));
                }
                return facade.update(institution);
        }

        private String validateNull(String param) {
                if (param.equalsIgnoreCase(EntityFacadeConstants.PARAM_START)) {
                        return null;
                } else {
                        return param;
                }
        }


2009/9/9 Felipe Gaścho <fgaucho_at_gmail.com>:
> very nice.. now I am here thinking about validation, if Jersey will
> detect an invalid parameter if it is not declared in the method.. and
> then perhaps it is a good idea to type a bit more :)
>
> On Wed, Sep 9, 2009 at 3:13 PM, Herak Sen<HSen_at_vertrax.com> wrote:
>> Hi ,
>>
>>
>> You can use the UriInfo to get the query params.
>>
>>
>>        @POST
>>        @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
>>        public PujInstitutionEntity update(@Context UriInfo uriInfo) {
>>
>>                        MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
>>                        String name = queryParams.getFirst("name ");
>>
>>                        // .. code here----
>>
>>        }
>>
>> Hope this helps
>>
>> Herak
>>
>> -----Original Message-----
>> From: Felipe Gaścho [mailto:fgaucho_at_gmail.com]
>> Sent: Wednesday, September 09, 2009 9:04 AM
>> To: users_at_jersey.dev.java.net
>> Subject: [Jersey] several QueryParams ?
>>
>> is there a more reasonable way of receive a set of query parameters
>> than enumerating them in the method signature?
>>
>>        @POST
>>        @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
>>        public PujInstitutionEntity update(@QueryParam("name") String acronym,
>>                        @QueryParam("name") String name,
>>                        @QueryParam("name") String website,
>>                        @QueryParam("name") String logo, @QueryParam("name") String email,
>>                        @QueryParam("name") String contact, @QueryParam("name") String phone) {
>>
>>                // .. code here----
>>        }
>>
>> --
>> Looking for a client application for this service:
>> http://fgaucho.dyndns.org:8080/footprint-service/wadl
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
>
>
> --
> Looking for a client application for this service:
> http://fgaucho.dyndns.org:8080/footprint-service/wadl
>



-- 
Looking for a client application for this service:
http://fgaucho.dyndns.org:8080/footprint-service/wadl