Supporting REST via Spring Roo in #SAPNWCloud: A lazy developer’s challenge
I remember reading a blog from Dagfinn Parnas entitled “Exposing a REST API from #SAPNWCloud” in which he describes how to create an application on NetWeaver Cloud that supports REST.
Although Dagfinn used Apache Jersey, there was still a great of development work that was necessary.
A Challenge
I thought to myself – I like a challenge – what about trying to create the same app without any Java coding.
I used Spring Roo and used these commands:
project –topLevelPackage net.rhirsch.test –projectName restpoc
persistence setup –provider ECLIPSELINK –database HYPERSONIC_IN_MEMORY
entity jpa –class ~.domain.FeedEntry –testAutomatically
field string –fieldName senderName –sizeMax 50
field string –fieldName senderEmail
field boolean –fieldName isComment
field string –fieldName parent
field date –fieldName timeCreated –type java.util.Date
field string –fieldName feedText
json add –class ~.domain.FeedEntry
web mvc setup
web mvc all –package ~.controller
web mvc json add –jsonObject ~.domain.FeedEntry –class ~.controller.FeedEntryController
nwcloud enable-deploy
nwcloud enable-jpa
quit
I changed the nwcloud.properties file to contain my properties
I then used maven to deploy the application to the NetWeaver Cloud:
mvn -Dmaven.test.skip=true package nwcloud:deploy nwcloud:start
The Results
A nice web User Interface.
I also got a working REST interface:
The generated REST interface is a bit flaky but it works.
Conclusion
Motto: Never underestimate the power of Spring Roo + NetWeaver Cloud.
JSON, REST, Persistence, WebUI in 16 lines of Roo code and a few maven commands.
Dagfinn’s application is probably a better foundation for a real app but for a quick prototype – nothing beats Roo.
Wow, really impressed. Putting "Learn more about SpringRoo" on my todo list.
Thanks for sharing!
It took a lot of time trying out different combinations in Roo to get both the web UI and the REST / JSON to work.
Roo can do a lot more but you need to play with it
D.
Roo is nice although I am always afraid how I can fix it if "something" does not work in the myriad of hidden functionality.
Reminds me on JBoss Seam where you can also generate everything using seamgen. Much programming work is done automatically but then you get inconsistencies through new releases and then you have real trouble at your hand...
Now it would be nice if you could switch the UI easily to SAP UI5. I bet this is somewhere in planning, what do you think?
EDIT: Now I also found your other blog First tests with Spring Roo to create #SAPNWCloud apps which I should have been reading before...