5

I am currently working on a web application that is based on Strtus2, Spring, open JPA and LDAP.

Now client wants us to develop RESTful api for this system so that other websites or application can integrate with it.

This task has been assigned to me and I clearly have no idea from where to start.

I have done my research and found out that, there is a plugin struts2-rest and for Spring there are several different ways.

More to that most of the example I have been seen are using Maven, but our project does not use that.

So, I just need a direction to start this thing.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Raddix
  • 113
  • 2
  • 9
  • 1
    This is OT. BTW, you're not forced to use something related to Struts2. Just stick with Java EE standards (JAX RS), if you can. – Andrea Ligios Apr 11 '17 at 17:16
  • 1
    @AndreaLigios This seems to be the best one, thanks for the help will try this out. – Raddix Apr 12 '17 at 17:38

1 Answers1

8

In Struts2 you can implement RESTful api via struts2-rest-plugin. The starting point is REST Plugin.

Setting Up

Assuming you have a normal Struts 2 application, all you need to do for this REST demo is to add the following two plugins:

Struts 2 Rest Plugin
Struts 2 Convention Plugin

Note, you can download the jars for these plugins from Maven Central Configuration ( struts.xml )

Just dropping the plugin's into your application may not produce exactly the desired effect. There are a couple of considerations. The first consideration is whether you want to have any non-RESTful URL's coexisting with your RESTful URL's. We'll show two configurations. The first assumes all you want to do is REST. The second assumes you want to keep other non-RESTful URL's alive in the same Struts 2 application.


In the Home of Struts2 docs you'll find everything necessary to start developing Struts2 application.

Resources:

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • 1
    Thanks for the answer. Just tried it out and after adding 4 libraries the web application is not working correctly. For every action I am hitting, I am getting exception and when I checked the logs, I saw that all the methods got a .index() suffix in them. I mean the server is thinking that, the method is not execute().index() instead of execute(). Any idea what to do with that ? – Raddix Apr 12 '17 at 17:41
  • @Raddix I suggest you to download a working project from the official site, and try to run it in your environment. – Roman C Apr 13 '17 at 12:11
  • Just did sorry for not doing that earlier. – Raddix Nov 11 '17 at 17:07