2

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);
Community
  • 1
  • 1
wonza
  • 302
  • 1
  • 4
  • 15
  • Could you please post the whole stacktrace message? Seems that your mocked request requires a `ServletContext` as well. Also, the link you've posted is not exactly what you want/need because that code is executed in an application server, while yours is running elsewhere. – Luiggi Mendoza Oct 05 '15 at 19:25
  • The only part you're missing is this: java.lang.NullPointerException and then my code. Added the rest in now though. – wonza Oct 05 '15 at 19:48
  • Do you have the chance to use an other rendering engine: velocity or freemarker for example? – Ralph Oct 05 '15 at 19:58
  • It depends.. we don't want to change the JSP template at all, as it's huge and would take a lot of work. Plus we want the same file to work from both places. – wonza Oct 05 '15 at 20:04

0 Answers0