Home - Programming - Java: Struts2 REST

A while back I started working on a REST project in Java. Then I got sidetracked by life and found myself finally coming back to it months later. So knowing that I've got too much going on to fart around with complex setup and steep learning curves, I decided to hunt for something that used as much of my existing knowledge as possible.

Enter Struts2 REST.

I have done some serious rocket science with Struts 1, and just as Struts 2 was coming out I put it aside to take a small pivot in my career. So it's something I know and love as an easy way to get a server-dominated web application up and runly quickly and easily. I downloaded the latest version of Eclipse into a VM, search for some examples, skimmed a couple of tutorials, and with only a few days of aggravation I got a simple REST resource online. And in the process I learned that this was definitely not what I wanted to use.

Struts 2 is slightly different animal than Struts 1, although it's not a hugely different experience setting it up and getting it running. What messed me up was trying to get the REST plug-in installed and functioning, to get Eclipse to properly deploy it, and then to get it to call my REST resource code. Having cleared those hurdles, and after playing with it a bit, I started to realize I'd made some bad assumptions.

The Struts 2 REST plug-in is only capable of a few basic operations, and it breaks REST by allowing verbs in the URL. You can't specify which columns you want to retrieve, nor can you pass in filter information to narrow the search. I mean, you might be able to sneak something by in the HTTP headers, but I haven't seen yet where the request information is exposed to my controller class. And there's no way to define subresources, consume ETags, do pagination, specify a sort order, etc.

Sometimes working with a bad solution at least informs the search for the next solution. Now I have a pretty good idea of what to search for, and based on that search pulled the docs for Spring Boot, RESTEasy, and a few others. And decided to just go with vanilla JAX-RS for now.

So the lastest challenge is getting Eclipse to let me do development using JAX-RS. I have come at it from 10 different directions, but my VM with Eclipse in it just can't seem to activate the JAX-RS stuff. Something to do with loading the Application subclass as the servlet. I'm pretty sure, based on all I've read on the 'net, that it's set up correctly, but there appears to be a problem with it.

The struggle continues...


Todd Grigsby