Spring MockMVC inject mockHttpServletRequest when not in method signature Spring MockMVC inject mockHttpServletRequest when not in method signature spring spring

Spring MockMVC inject mockHttpServletRequest when not in method signature


You can add a RequestPostProcessor. Which you can then pass in to the mockmvc stuff by using the with() method.

mockMvc().perform(  fileUpload("/upload")  .file(FileFactory.stringContent("myFile"))  .with(new RequestPostProcessor() {     public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {       request.setRemoteAddr("12345");        return request;    }}));

Something like that should work.