Skip to content

Commit

Permalink
handle exception case
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 19, 2024
1 parent c07b8b9 commit 3f9e092
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHtt
requestDispatcher.include(request, response);
}
else {
String referrer = request.getHeader("Referrer");
log.error("Unable to dispatch proxy request for {} referrer={}", request.getRequestURI(), referrer);
throw new ServletException("No Content");
throw new ServletException("No Request Dispatcher.");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
*/
package io.wcm.handler.commons.servlets.impl;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;

import org.apache.sling.api.SlingHttpServletRequest;
Expand Down Expand Up @@ -102,4 +104,15 @@ void testComplexUrl() throws Exception {
verifyNoMoreInteractions(response);
}

@Test
void testNoRequestDispatcher() throws Exception {
HtxPageExtensionMapper underTest = context.registerInjectActivateService(new HtxPageExtensionMapper(), "enabled", true);

when(request.getRequestDispatcher(anyString())).thenReturn(null);

assertThrows(ServletException.class, () -> {
underTest.doGet(request, response);
});
}

}

0 comments on commit 3f9e092

Please sign in to comment.