cancel
Showing results for 
Search instead for 
Did you mean: 

How do I change the Spring MVC servlet mapping for only the Activiti REST endpoints?

mjustin
Champ in-the-making
Champ in-the-making
I am working on an application where we are using Spring Boot and Activiti REST version 5.17.0 (using spring-boot-starter-rest-api).  As the application already has REST endpoints of its own, we would like to put the Activiti REST endpoints in a separate path, e.g.

I want my existing REST endpoints to be unchanged, e.g. "www.example.com:1234/myAppNameHere/myResource/1234".  However, I cannot figure out how to configure this.

I was able to achieve this in another application using Activiti 5.14 with its Restlet functionality by configuring the web.xml file:

<servlet>  
  <servlet-name>RestletServlet</servlet-name> 
  <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
  <init-param>
    <param-name>org.restlet.application</param-name>
    <param-value>my.organization.appname.MyAppActivitiRestApplication</param-value>
  </init-param>
</servlet>

<servlet-mapping>
  <servlet-name>RestletServlet</servlet-name>
  <url-pattern>/bpm-rest/*</url-pattern>
</servlet-mapping>

However, I am unsure how I would duplicate this functionality with the Spring Boot/Spring MVC configuration.  I asked a similar question a while back (http://forums.activiti.org/comment/26977), when I was attempting to upgrade my other application to Activiti 5.16.4.  In that thread I was advised that I could change the servlet mapping "by overriding the WebConfigurer class".  However, I do not see a class with that name in either Activiti or Spring MVC.  There is one in Spring Boot under "org.springframework.boot.test", but I suspect that's not the one being referred to.

In short, how do I configure the Activiti 5.17.0 Spring MVC REST endpoints to use a separate sub-path of my application from my application endpoints?
4 REPLIES 4

jim1
Champ on-the-rise
Champ on-the-rise
The REST API request are handled by the Spring dispatcher servlet, so you just need to change the servlet mapping for this.
The quickest way to do this is to add the following entry to your applications properties file:

server.servletPath=/my_path/

mjustin
Champ in-the-making
Champ in-the-making
I believe this doesn't solve my problem, as won't this change all Spring MVC paths (including my own), and not just the REST API paths?

jbarrez
Star Contributor
Star Contributor
One option is to have a custom DispatcherServletCOnfiguration (like we have in activiti-rest-webapp) that you map onto a different url

raedius
Champ in-the-making
Champ in-the-making
@jarrez I have this same use case, could you elaborate on your proposed solution?

I've looked at the DispatcherServletConfiguration in the rest module but I don't see how I would use it to add a prefix to the activiti rest endpoints. I see that you are providing your own RequestMappingHandlerMapping object but it appears to collect all @RequestMapping methods not just the Activiti ones. Even if I could filter the mappings to just the Activiti mappings how would I map them to a different path prefix?

Thanks for any help you can give