mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
fxi missing contextPath for ForwardingPushStateDispatchers
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package sonia.scm;
|
package sonia.scm;
|
||||||
|
|
||||||
|
import sonia.scm.util.HttpUtil;
|
||||||
|
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -14,7 +16,8 @@ import java.io.IOException;
|
|||||||
public class ForwardingPushStateDispatcher implements PushStateDispatcher {
|
public class ForwardingPushStateDispatcher implements PushStateDispatcher {
|
||||||
@Override
|
@Override
|
||||||
public void dispatch(HttpServletRequest request, HttpServletResponse response, String uri) throws IOException {
|
public void dispatch(HttpServletRequest request, HttpServletResponse response, String uri) throws IOException {
|
||||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.html");
|
String path = HttpUtil.append(request.getContextPath(), "index.html");
|
||||||
|
RequestDispatcher dispatcher = request.getRequestDispatcher(path);
|
||||||
try {
|
try {
|
||||||
dispatcher.forward(request, response);
|
dispatcher.forward(request, response);
|
||||||
} catch (ServletException e) {
|
} catch (ServletException e) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class ForwardingPushStateDispatcherTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDispatch() throws ServletException, IOException {
|
public void testDispatch() throws ServletException, IOException {
|
||||||
|
when(request.getContextPath()).thenReturn("");
|
||||||
when(request.getRequestDispatcher("/index.html")).thenReturn(requestDispatcher);
|
when(request.getRequestDispatcher("/index.html")).thenReturn(requestDispatcher);
|
||||||
|
|
||||||
dispatcher.dispatch(request, response, "/something");
|
dispatcher.dispatch(request, response, "/something");
|
||||||
@@ -40,8 +41,19 @@ public class ForwardingPushStateDispatcherTest {
|
|||||||
verify(requestDispatcher).forward(request, response);
|
verify(requestDispatcher).forward(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDispatchWithContextPath() throws ServletException, IOException {
|
||||||
|
when(request.getContextPath()).thenReturn("/scm");
|
||||||
|
when(request.getRequestDispatcher("/scm/index.html")).thenReturn(requestDispatcher);
|
||||||
|
|
||||||
|
dispatcher.dispatch(request, response, "/something");
|
||||||
|
|
||||||
|
verify(requestDispatcher).forward(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IOException.class)
|
@Test(expected = IOException.class)
|
||||||
public void testWrapServletException() throws ServletException, IOException {
|
public void testWrapServletException() throws ServletException, IOException {
|
||||||
|
when(request.getContextPath()).thenReturn("");
|
||||||
when(request.getRequestDispatcher("/index.html")).thenReturn(requestDispatcher);
|
when(request.getRequestDispatcher("/index.html")).thenReturn(requestDispatcher);
|
||||||
doThrow(ServletException.class).when(requestDispatcher).forward(request, response);
|
doThrow(ServletException.class).when(requestDispatcher).forward(request, response);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user