4

How do you integrate or create a REST web-application? I saw this plugin struts rest-plugin but the documentation does not provide any running example.

Are there any alternatives in using REST with Struts2 or maybe another REST plug in for Struts2? I googled another framework that supports REST and I saw spring framework. Is there anyway I can merge Spring frameworks rest with Struts2 rest if so how?

Roman C
  • 49,761
  • 33
  • 66
  • 176
user962206
  • 15,637
  • 61
  • 177
  • 270

3 Answers3

2

Spring supports Struts 1 and 2 and Java Faces. It also has its own web MVC frame that's a big improvement on all of them, in my opinion.

Whether you're doing it from Spring services or Struts Action classes, you just need to invoke REST or SOAP clients that call your REST or SOAP services to fulfill the use case. You really just need a good client library.

REST is easy - any HTTP client will do.

SOAP clients can be had from Apache or Spring.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • 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 RESTful services using RESTEasy in my application ? – r.bhardwaj Feb 26 '15 at 07:32
  • Deploy REST services on JBOSS and add the client calls either as AJAX in your JSPs or orchestrated by your Struts Action classes. No examples, sorry. – duffymo Feb 26 '15 at 10:18
  • I have added REST service and I want my service to extract the ActionForm object by interacting with it's Action class. My Action class contains all the business logic in the execute method. How can I extract the details of ActionForm object in the REST service? – r.bhardwaj Mar 16 '15 at 09:26
  • This is a very bad idea. Your REST service should not know or care about Struts or ActionForms. Rethink this. REST uses HTTP verbs: GET, PUT, POST, DELETE and works with HTTP parameters. That's it. No ActionForm, no Struts. – duffymo Mar 16 '15 at 11:40
2

Take a look at these examples on how to build a REST application with Struts2 (and the REST plugin):

example1

example2

Atropo
  • 12,231
  • 6
  • 49
  • 62
1

yes you can integrate it all, see my blog post, it has detailed description and a code example which shows exactly how to make this all work together, from zero to production.

TheZuck
  • 3,513
  • 2
  • 29
  • 36
  • one more thing do, if my website is ajaxified if I select a remote link will the url change without reloading the whole page? – user962206 Dec 21 '12 at 11:59
  • Ajax does not change the page url, it only loads additional content/data "in the background" instead of having to reload the page to change the page content. The code in my blog post also has jquery integrated for ajax by the way. – TheZuck Dec 21 '12 at 19:35