jQuery in Action, 3rd edition
The moose likes Web Services and the fly likes REST Web Service - Dynamic Query Parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "REST Web Service - Dynamic Query Parameters" Watch "REST Web Service - Dynamic Query Parameters" New topic

REST Web Service - Dynamic Query Parameters

Aravamudhan Vijayaraghavan

Joined: Sep 20, 2012
Posts: 1
I have a requirement to send dynamic query parameters to REST web service GET method [as shown below].

host:port/app?field1=XXX&value1=VVV&field2=XXX&value2=XXX ....

The consumer can send parameters up to fieldn and valuen. Each field maps to the value.

With this type of requirement, I can't code a finite set of QueryParams on the server side method.

Is there any type of REST library that supports this? I checked RESTEasy and Jersey, and they both don't seem to support this [as far as I checked].

William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

That is not true REST.

You can do that easily with a servlet in the which the Request object gives you a collection of parameters and attributes.

True REST would look like:

GET host:port/app/field1value/field2value/fieldnvalue

but would be quite difficult to implement knowing that you can have any number of fields(n)


GET host:port/app/field1=XXX&value1=VVV&field2=XXX&value2=XXX


then in method (Been a while, may need to check Syntax)

William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

FYI: Quote from another site:

JAX-RS simply isn’t meant for the type of flexibility you’re describing… I’d probably stick with a servlet in the case you describe. Also, if you need the kind of flexibility you’re describing from an “interface” standpoint, then HTTP headers and query parameters seem much more friendly than path params

William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Since you're new.. Welcome, and I'm feeling generous.

This is a simple JAX-RS RESTful webservice that does what you want. I encourage you to read through it and understand.
Pacakge names have been changed to protect the innocent, and I will not help you deploy it to your JEE container.
The framework is JAX-RS.



Now, once deployed correctly, entering this URL in browser: http://localhost:8080/jboss7webapp/rest/app/a=1&b=2&c=3&d=4

There you have it.. Good luck,

Sachin Pachari
Ranch Hand

Joined: Jan 16, 2012
Posts: 56

hi guys,

i am new to this whole web service, i am stuck with this JAXRS project where i have to integrate my EJB with the Service and i am not able to @Inject or @EJB, everytime i try to inject, i get a Null Pointer Exeption, i have been Searching in google to solve this issue,

i have tried all the possible solutions. like adding @Stateless, adding Beans.xml to my META-INF and also configuring RestEasy CDI Injector Factory in my Web.xml

But no use, i am using JBoss AS 7.0, i keep on getting null pointer, is it even possible to inject any object into my (JAX-RS) Web Services ?? Someone please help me, i have been stuck in this point for more than a week. Someone Please Explain me clearly about this.

Any Kind of help is welcome.

Thanks & Regards,
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Sachin, You should really have started a new thread for this question.

Copy your text, start a new thread, then come back and delete this post.

You'll get more help that way!

I agree. Here's the link: http://aspose.com/file-tools
subject: REST Web Service - Dynamic Query Parameters
It's not a secret anymore!