Reputation: 13789
I'm currently adding rest services for a struts application.The struts that we use is 1.x .I came to know that rest plugin is only supported for struts2 and that too the plugin is not fully restful. In such a case, is rest plugin a good choice? Is it worth moving from Struts 1.x to 2 for rest plugin support? I googled about this topic and I could find very few resources on this topic.It would be really helpful to know how other have added rest services to their app.
Resources I have found:
The code in the second link is a bit bloated and won't scale for migrating a large Struts 1.x application.I have thought about using jersey but i have no idea how to use it along with struts 1.x .May be i'm doing it all wrong.If any one has some idea on developing restful apps please help.
Upvotes: 1
Views: 9593
Reputation: 450
Using Jersey with struts 1 is good idea to implement Rest nature in project.
Few Easy steps we can implement jersey in struts 1
Below jars are compatible with java 8
Modify web.xml
and new servlet mapping
<servlet>
<servlet-name>Rest</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.myorg.rest.controllers</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Rest</servlet-name>
<url-pattern>/rest/v1/*</url-pattern>
</servlet-mapping>
Now we can write rest controller and access it via ajax call
Upvotes: 0
Reputation: 118691
Well, I'd move on to Struts 2 simply because Struts 1 is awful, but that's me.
Jersey will slot in quite handily alongside a Struts 1 app.
It is configured simply in web.xml, it will share the same session state with your Struts app, and doesn't really conflict at all.
Any logic pre-existing in your Struts app can be readily reused and repurposed with the most basic of refactoring. Worst you'd have to do is yank it out of the Struts actions (though they're pretty generic on their own, you may be able to use them directly).
Also, all the standard Servlet stuff will work fine with Jersey, like Filters and Sessions and what not. Since a lot of folks use Filters for security or setting up persistence and such, it should Just Work behind that existing infrastructure.
Just fire it up and put it in parallel and you should be good to go.
Upvotes: 3