com.guicedee.guicedservlets.services.mocks.MockRequestDispatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-servlets Show documentation
Show all versions of guiced-servlets Show documentation
An integration library for Servlets in the Guiced Injection Framework
package com.guicedee.guicedservlets.services.mocks;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import java.io.IOException;
public class MockRequestDispatcher
implements RequestDispatcher
{
/**
* The resource path to dispatch to.
*/
private String resourcePath;
/**
* Constructs a new RequestDispatcher instance for the specified
* resourcePath.
*
* @param resourcePath
* the resource path to dispatch to
*/
public MockRequestDispatcher(String resourcePath)
{
this.resourcePath = resourcePath;
}
/**
* This method stores the dispatcher's resourcePath on the request.
*
* The resourcePath can later be retrieved by calling
* {@link MockRequest#getForward()}
*
* @param request
* the servlet request
* @param response
* the servlet response
*
* @throws jakarta.servlet.ServletException
* if the response was already
* committed
* @throws java.io.IOException
* if the target resource throws this exception
*/
@Override
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
MockRequest mockRequest = new MockRequest();
mockRequest.setForward(resourcePath);
}
/**
* This method stores the dispatcher's resourcePath on the request.
*
* The resourcePath can be retrieved by calling
* {@link MockRequest#getIncludes()}
*
* @param request
* the servlet request
* @param response
* the servlet response
*
* @throws jakarta.servlet.ServletException
* if the response was already
* committed
* @throws java.io.IOException
* if the target resource throws this exception
*/
@Override
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
MockRequest mockRequest = new MockRequest();
mockRequest.addInclude(resourcePath);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy