• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

REST Web Service - Dynamic Query Parameters

 
Aravamudhan Vijayaraghavan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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].

Thanks.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

*or*

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

@Path("app")

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



WP
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


WP
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Model:


Service:


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


There you have it.. Good luck,

WP
 
Sachin Pachari
Ranch Hand
Posts: 56
Eclipse IDE Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Sachin
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

WP
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic