How to change REST service URIs?

Posted by Tim Kuehn on 05-Dec-2016 15:36

11.6.3 linux REST, Classic Appserver, tomcat 7

I've got a situation where each REST service of a project was deployed as an individual war file, with the resulting URI looking like so:

http://hostname/servicename/rest/servicename/method/etc.

This URI structure can't easily be changed. 

What I'm looking to do is automate the current REST service deploy process using restgen / restman. These tools allow me to specify a list of services that go in a war file like so: service1:service2:service3:service4. If I do this with a project SomeProject, and then use that project name to construct the war file name (ie SomeProject.war), the URIs after deployment would look like this:

http://hostname/SomeProject/rest/servicename1/method/etc.

http://hostname/SomeProject/rest/servicename2/method/etc.

http://hostname/SomeProject/rest/servicename3/method/etc.

This URI structure would break many things if it was implemented. 

One option I could pursue would be to generate a .war file for each service and give that war file the target service's name. This would preserve the existing URI structure on deploy at the cost of extra overhead to maintain and deploy each .war file.

What I would prefer to do would be to alter a mapping somewhere in tomcat that would redirect requests from the current URI structure to the new all-services-in-one-project/warfile structure. 

ie 

http://hostname/servicename1/rest/servicename1/method/etc.

would be redirected to 

http://hostname/SomeProject/rest/servicename1/method/etc.

Tomcat has a 'rewrite' valve that looks like it'd do what I want:

https://tomcat.apache.org/tomcat-8.0-doc/rewrite.html

Has anyone else successfully accomplished this goal?

Posted by Peter Judge on 07-Dec-2016 12:24

I would definitely expect it to (that’s it’s job, after all :)
 
 

All Replies

Posted by Peter Judge on 06-Dec-2016 08:18

Tim,
 
What naming scheme are you looking for?
 

Posted by danielb on 06-Dec-2016 20:01

We haven't done it with Tomcat rewrite, but we have just deployed a REST API using Classic WebSpeed and IIS URL Rewrite rules.

For example

localhost/.../customers

would be rewritten internally to be

localhost/.../handler.p

Posted by Tim Kuehn on 07-Dec-2016 12:01

Peter - the requirements have changed and I don't need this any more - however I'm still curious if a tomcat rewrite valve would enable me to redirect

   http://hostname/servicename1/rest/servicename1/method/etc

to

    http://hostname/SomeProject/rest/servicename1/method/etc.

Tim 

Posted by Peter Judge on 07-Dec-2016 12:24

I would definitely expect it to (that’s it’s job, after all :)
 

This thread is closed