Java Code Examples for org.springframework.mock.web.MockRequestDispatcher

Following code examples demonstrate how to use org.springframework.mock.web.MockRequestDispatcher from spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.mock.web.MockRequestDispatcher and various code implementation of this class.
Example 1
Project : spring-framework Source File : TestApplicationContext.java View Source Code on GitHub

                    public RequestDispatcher getNamedDispatcher(String path) {
                            if ("default".equalsIgnoreCase(path)) {
                                    return new MockRequestDispatcher(path);
                            } else {
                                    return super.getRequestDispatcher(path);
                            }
                    }
			
Example 2
Project : spring-framework Source File : RequestDispatcherImpl.java View Source Code on GitHub

	public void forward(ServletRequest request, ServletResponse response) {
		Assert.notNull(request, "Request must not be null");
		Assert.notNull(response, "Response must not be null");
		if (response.isCommitted()) {
			throw new IllegalStateException("Cannot perform forward - response is already committed");
		}
		MockHttpServletResponse resp = getMockHttpServletResponse(response);
		resp.setForwardedUrl(this.resource);
		PathMatchingResourcePatternResolver resl = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
		try {
			Resource res = resl
					.getResource("classpath:static" + (resource.charAt(0) == '/' ? resource : '/' + resource));
			if (res != null) {
				StreamUtils.copy(res.getInputStream(), resp.getOutputStream());
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (logger.isDebugEnabled()) {
			logger.debug("MockRequestDispatcher: forwarding to [" + this.resource + "]");
		}
	}