I refer to this post How to manually render Spring MVC view to html? , which does almost exactly what I require. However, I'm running outside of a web container and need to use the same template that's been used within my web application. Which means I don't have a valid HttpServletRequest. I've tried create a MockHttpServletRequest but get a null pointer:
java.lang.NullPointerException
at org.springframework.web.context.support.WebApplicationObjectSupport.getServletContext(WebApplicationObjectSupport.java:128)
at org.springframework.web.servlet.view.JstlView.exposeHelpers(JstlView.java:135)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:142)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at com.e.afw.commons.service.ProcessService.getEmailBody(ProcessService.java:616)
at com.e.afw.commons.service.ProcessService.processRequest(ProcessService.java:187)
at com.api.spring.management.CheckRN.checkRequests(CheckRN.java:99)
at com.api.spring.management.CheckRN.main(CheckRN.java:63)
Just to add a little more detail, here's what I've tried so far for the request:
final MockServletContext servletContext = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, servletContext);