This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Jersey to annotate EJB methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Jersey to annotate EJB methods" Watch "Jersey to annotate EJB methods" New topic
Author

Jersey to annotate EJB methods

Vinit Parakh
Greenhorn

Joined: Oct 20, 2011
Posts: 21
hello,

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 the EJB methods from that servlet.

Problem :
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 ....??

Thanking you,
Vectors.

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I don't understand the problem. You'd use Jersey annotations on the methods that should handle the WS calls, and those methods would in turn call the EJBs, just like the servlets did before.

What are you trying to achieve by using Jersey annotations on EJBs (which would be a case of mixing model and view layer, so you should not be doing that anyway) ?
Vinit Parakh
Greenhorn

Joined: Oct 20, 2011
Posts: 21
hey thanks Tim Moores,

Appreciate your quick response.

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?

Thankyou,
Vectors.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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 http://www.coderanch.com/how-to/java/WebServicesFaq page about the benefits of REST in general.
Vinit Parakh
Greenhorn

Joined: Oct 20, 2011
Posts: 21
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.

Thankyou,
Vectors.

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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.
 
jQuery in Action, 2nd edition
 
subject: Jersey to annotate EJB methods
 
Similar Threads
Problem with JERSEY and JAX-RS
JSP & Servlets : How do detect THE MAIN cause of error ?
@RolesAllowed, @PermitAll, etc Servlet . with Tomcat JDBC Realm
question abt web.xml file