0

I'm relatively new to REST api designing. So If i'm wrong please correct me. I'm trying to add rest services for a struts application. The current code has poor design. So my first challenge is to segregate the java code in such a manner it can be utilized by both Struts action classes and the rest api(using jersey or resteasy).Currently what I have decided to to build a thin layer of Java api. Communication to this api will be simply by using Java beans. All db calls and service calls will be hidden under this layer. Since they are simple POJO it can be utilized both by REST for and for action form's in struts. I haven't implemented it, its just my idea of doing it. I have no idea if this is the right way to approach the problem.Please give suggestion's on how deal with this problem in a better manner.

I don't want to integrate Struts and Rest together i.e. It's not going to happen that Struts is getting called from REST or other way round.

Rahul Borkar
  • 2,742
  • 3
  • 24
  • 38

1 Answers1

1

RestEasy works perfectly fine with any Servlet Container with whatever other framework. So This works well without any explicit configuration.

Rahul Borkar
  • 2,742
  • 3
  • 24
  • 38
  • My application uses Struts 1.2 and JBoss 6.1. Can you guide me to any working example or any other useful resource to integrate RESTEasy with my application ? – r.bhardwaj Feb 26 '15 at 05:25
  • I have added REST service(using RESTEasy) with my Struts application. My Struts Action class contains all the business logic in the execute method. Now, I want my service to extract the ActionForm object details by interacting with the Action class. How to achieve this ? – r.bhardwaj Mar 16 '15 at 09:34
  • Major issue you will face is to get request and response objects, have a look at @Context annotation of REST. This autobinds the request and response objects with struts request and response. When you have both of above you can directly call execute or ActionForm's methods. – Rahul Borkar Mar 16 '15 at 09:54
  • You meant of using Context HttpServletResponse response and Context HttpServletRequest request as web service parameters. But how can I bind it with Struts Action request, response ? – r.bhardwaj Mar 16 '15 at 12:51
  • If you have existing struts application running. You just need to create your Resteasy class in same application with @context for implicit objects. 1. You might need to configure Resteasy on different URL. 2. Go to Struts Application URL first, this will internally create request and response objects in that context 3. After this, go to RestEasy URL and check, you will find request and response objects with values. – Rahul Borkar Mar 17 '15 at 11:51
  • Yes I have application running with huge code and all the business logic handled through Actions. Also, as you have mentioned I had configured Resteasy service on different url. I want my service to act as layer above the Actions. Basically, I would like to have flow as: Web service call -> Web service layer -> Struts Backend(with Actions and Forms). I used RestEasy **ClientRequest** to call Action like this: ClientRequest clientRequest = new ClientRequest(http://localhost:8080/StrutsApp/struts.do); I want to retrieve the ActionForm object somehow to access the form getters. – r.bhardwaj Mar 23 '15 at 06:23