I am having a problem using Jersey. This the scenario : Right now i am using doGet and doPost methods to hit the servlet and then call theEJB methods from that servlet.
1. We are planning to shift to Jersey....but now to annotate the methods....its not possible to annotate the EJB methods since it is a EJB project and i dont have any web.xml to map the servelt.
2. Now, even if I make a Dynamic web project (Which has a web.xml and would allow me to annotate the functions using jersey), I am not able to run my existing EJB project.
Isnt there any way possible to use jersey to annotate EJB methods ....??
I am sorry but i am actually a newbie to Jersey. What i know is instead of writing the doGet and the doPost methods i can directly annotate @Post or @Get over my function definition. But as you pointed out....what i am trying to do is completely wrong (annotate the EJB methods wusing Jersey).
But i have 2 things to ask :
1. How do i use Jersey then? Right now i am just calling the EJB methods directly from the doPost method as soon as the Client hits the servlet.
2. Apart from the developers point of view, what is the advantage of using Jersey?
If you have never created a WS using Jersey I'd suggest to start with some simple services before actually using it in your project. Searching for "introduction jax-rs jersey" or some such terms should find numerous articles and other helpful resources along with example code. Jersey runs fine in a servlet container such as Tomcat. You might also want to read some of the articles linked in the https://coderanch.com/how-to/java/WebServicesFaq page about the benefits of REST in general.
I have created basic webservices before...but i dont get in mycase where i just need to call the EJB methods from the doPost method of the servlet. How does it matter if i create a webservice and call those methods using Jersey or iuse the same doPost method?. Arent the two processes similar. I can understand the importance when i annotate the actual function definition, but which is not the case.
How does it matter if i create a webservice and call those methods using Jersey or iuse the same doPost method?
If you ask that question then that suggests that you have not yet fully grokked RESTful WS, or how the JAX-RS API can make life easier for you. It may very well be that using any REST library is overkill. If there's only a single call, and you think that it works just fine using a servlet's doPost method, then that's probably true.
Java-based REST libraries (like Jersey) are built on top of servlets, so there isn't anything they can do that raw servlets can't do, either. I think it's very convenient to use a @Path annotation to determine which method gets called when a particular URL is accessed, without having to write the code to dissect the URL myself, though. And to use @PathParam and@HeaderParam to access effortlessly the parameters of the call. Or to return JSON from my Java objects simply by using a @Produces annotation. And so on. Note that these are JAX-RS features, not REST features in general.
If the WS will ever grow to have more methods, you'll quickly see the benefits of using JAX-RS for creating maintainable code; trust me on this.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop