Nirmal Gamage
Nirmal Gamage

Reputation: 177

How to manage many number of parameters for a same url with jersey-servlet

I am developing a REST API which has about 20 services. All are HTTP GET requests with same URL with different parameters for different services. All together there are about 100 parameters for the entire API. I am using Jersey library for the API.Is there any better way to manage these huge number of parameters?

    @GET
    @Path("/processMessage")
    @Produces({MediaType.APPLICATION_XML})
    public Response processMessage(
          @QueryParam("a") String a,
          @QueryParam("b") String b,
          @QueryParam("c") String c,
          @QueryParam("d") String d,
          @QueryParam("e") String e,
          @QueryParam("f") String f,
          @QueryParam("g") String g,
          @QueryParam("h") String h,
          @QueryParam("h") String z,
  )
}

`

Upvotes: 1

Views: 119

Answers (1)

Ori Marko
Ori Marko

Reputation: 58892

Get all parameters using UriInfo:

public Response processMessage(@Context UriInfo uriInfo) {
     MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); 

Or as a field:

@Context
UriInfo uriInfo;

An instance of UriInfo can be injected as field or method parameter using the @Context annotation. UriInfo provides access to application and request URI information

Upvotes: 2

Related Questions