I'm writing integration tests using MockMvc, and I'm wondering if there's a way to load servlet mappings from web.xml (which normally shouldn't matter).
I have a custom HandlerInteceptor
that matches the request URI (from HttpServletRequest
) against a template (using AntPathMatcher
).
In web.xml, I define servlet mappings like this (with a corresponding mobile-context.xml):
<servlet-mapping>
<servlet-name>mobileServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
So when a controller defines a mapping like "/operation"
, requests should really be made to "/services/operation"
. My custom HandlerInterceptor
matches URI requests against a template like "/**/services/{operationName}/**"
.
My application works perfectly on Tomcat. However, in @ContextConfiguration, I can only specify mobile-context.xml since web.xml is not a spring config file. Thus, MockMvc only allows me to make requests to "/operation"
and not "/services/operation"
, causing my HandlerInterceptor
to throw an exception.
Is there any way to get MockMvc to register the servlet mappings, or any clever ways around this? Thanks in advance.
Edit:
A similar question here suggests what I need is not possible, but I don't have permission to change the source code, so I can't modify the template or the HandlerInterceptor
.