use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class WhiteboardManager method getRuntimeInfo.
public RegistryRuntime getRuntimeInfo() {
final FailedDTOHolder failedDTOHolder = new FailedDTOHolder();
final Collection<ServletContextDTO> contextDTOs = new ArrayList<>();
// get sort list of context handlers
final List<WhiteboardContextHandler> contextHandlerList = new ArrayList<>();
synchronized (this.contextMap) {
for (final List<WhiteboardContextHandler> list : this.contextMap.values()) {
if (!list.isEmpty()) {
contextHandlerList.add(list.get(0));
}
}
this.failureStateHandler.getRuntimeInfo(failedDTOHolder);
}
Collections.sort(contextHandlerList);
for (final WhiteboardContextHandler handler : contextHandlerList) {
final ServletContextDTO scDTO = ServletContextDTOBuilder.build(handler.getContextInfo(), handler.getSharedContext(), -1);
if (registry.getRuntimeInfo(scDTO, failedDTOHolder)) {
contextDTOs.add(scDTO);
}
}
final List<PreprocessorDTO> preprocessorDTOs = new ArrayList<>();
final List<PreprocessorHandler> localHandlers = this.preprocessorHandlers;
for (final PreprocessorHandler handler : localHandlers) {
preprocessorDTOs.add(PreprocessorDTOBuilder.build(handler.getPreprocessorInfo(), -1));
}
return new RegistryRuntime(failedDTOHolder, contextDTOs, preprocessorDTOs);
}
use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class ErrorPageRegistryTest method testRangeRegistrationOverlay.
@Test
public void testRangeRegistrationOverlay() throws InvalidSyntaxException {
final ErrorPageRegistry reg = new ErrorPageRegistry();
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
final ServletHandler handler4 = createServletHandler(1L, 0, "4xx");
final ServletHandler handler = createServletHandler(2L, 10, "404", "403");
reg.addServlet(handler4);
reg.addServlet(handler);
// check DTO
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
// a 4xx is only registered as failure DTO if overlayed by a 4xx!
// -> no failure in this case
assertEquals(0, holder.failedErrorPageDTOs.size());
final Set<Long> codes4 = new HashSet<Long>();
for (final long c : dto.errorPageDTOs[1].errorCodes) {
assertTrue(c >= 400 && c < 500);
codes4.add(c);
}
assertEquals(98, codes4.size());
assertFalse(codes4.contains(404L));
assertFalse(codes4.contains(403L));
assertEquals(2, dto.errorPageDTOs[0].errorCodes.length);
final Set<Long> codes = new HashSet<Long>();
for (final long c : dto.errorPageDTOs[0].errorCodes) {
assertTrue(c >= 403 && c < 405);
codes.add(c);
}
assertEquals(2, codes.size());
}
use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class ErrorPageRegistryTest method testSingleErrorPage.
@Test
public void testSingleErrorPage() throws InvalidSyntaxException, ServletException {
final ErrorPageRegistry reg = new ErrorPageRegistry();
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
// empty reg
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertEmpty(dto, holder);
// register error page
final ServletHandler h1 = createServletHandler(1L, 0, "404", "java.io.IOException");
reg.addServlet(h1);
verify(h1.getServlet()).init(Matchers.any(ServletConfig.class));
// one entry in reg
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertNull(dto.resourceDTOs);
assertNull(dto.servletDTOs);
assertNotNull(dto.errorPageDTOs);
assertEquals(1, dto.errorPageDTOs.length);
assertEquals(1L, dto.errorPageDTOs[0].serviceId);
assertEquals(1, dto.errorPageDTOs[0].errorCodes.length);
assertEquals(404, dto.errorPageDTOs[0].errorCodes[0]);
assertEquals(1, dto.errorPageDTOs[0].exceptions.length);
assertEquals("java.io.IOException", dto.errorPageDTOs[0].exceptions[0]);
assertTrue(holder.failedErrorPageDTOs.isEmpty());
// test error handling
assertNotNull(reg.get(new IOException(), 404));
assertNotNull(reg.get(new RuntimeException(), 404));
assertNotNull(reg.get(new IOException(), 500));
assertNotNull(reg.get(new FileNotFoundException(), 500));
assertNull(reg.get(new RuntimeException(), 500));
// remove servlet
final Servlet s = h1.getServlet();
reg.removeServlet(h1.getServletInfo(), true);
verify(s).destroy();
// empty again
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertEmpty(dto, holder);
}
use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class ErrorPageRegistryTest method testSimpleHiding.
@Test
public void testSimpleHiding() throws InvalidSyntaxException, ServletException {
final ErrorPageRegistry reg = new ErrorPageRegistry();
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
// check DTO
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertEmpty(dto, holder);
// register error pages
final ServletHandler h1 = createServletHandler(1L, 0, "404", "java.io.IOException");
reg.addServlet(h1);
final ServletHandler h2 = createServletHandler(2L, 10, "404", "some.other.Exception");
reg.addServlet(h2);
verify(h1.getServlet()).init(Matchers.any(ServletConfig.class));
verify(h2.getServlet()).init(Matchers.any(ServletConfig.class));
// two entries in DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertNull(dto.resourceDTOs);
assertNull(dto.servletDTOs);
assertNotNull(dto.errorPageDTOs);
assertEquals(2, dto.errorPageDTOs.length);
assertEquals(0, dto.errorPageDTOs[1].errorCodes.length);
assertEquals(1, dto.errorPageDTOs[0].errorCodes.length);
assertEquals(404, dto.errorPageDTOs[0].errorCodes[0]);
assertEquals(1, dto.errorPageDTOs[1].exceptions.length);
assertEquals(1, dto.errorPageDTOs[0].exceptions.length);
assertEquals("java.io.IOException", dto.errorPageDTOs[1].exceptions[0]);
assertEquals("some.other.Exception", dto.errorPageDTOs[0].exceptions[0]);
assertEquals(1, holder.failedErrorPageDTOs.size());
assertEquals(1L, holder.failedErrorPageDTOs.get(0).serviceId);
assertEquals(1, holder.failedErrorPageDTOs.get(0).errorCodes.length);
assertEquals(404, holder.failedErrorPageDTOs.get(0).errorCodes[0]);
assertEquals(0, holder.failedErrorPageDTOs.get(0).exceptions.length);
assertEquals(DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, holder.failedErrorPageDTOs.get(0).failureReason);
// remove second page
final Servlet s2 = h2.getServlet();
reg.removeServlet(h2.getServletInfo(), true);
verify(s2).destroy();
// one entry in DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertNull(dto.resourceDTOs);
assertNull(dto.servletDTOs);
assertNotNull(dto.errorPageDTOs);
assertEquals(1, dto.errorPageDTOs.length);
assertEquals(1, dto.errorPageDTOs[0].errorCodes.length);
assertEquals(404, dto.errorPageDTOs[0].errorCodes[0]);
assertEquals(1, dto.errorPageDTOs[0].exceptions.length);
assertEquals("java.io.IOException", dto.errorPageDTOs[0].exceptions[0]);
assertTrue(holder.failedErrorPageDTOs.isEmpty());
// test error handling
assertNotNull(reg.get(new IOException(), 404));
assertNotNull(reg.get(new RuntimeException(), 404));
assertNotNull(reg.get(new IOException(), 500));
assertNotNull(reg.get(new FileNotFoundException(), 500));
assertNull(reg.get(new RuntimeException(), 500));
// remove first page
final Servlet s1 = h1.getServlet();
reg.removeServlet(h1.getServletInfo(), true);
verify(s1).destroy();
// empty again
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertEmpty(dto, holder);
}
use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class EventListenerRegistryTest method testSingleFilter.
@Test
public void testSingleFilter() throws InvalidSyntaxException, ServletException {
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
// check DTO
reg.getRuntimeInfo(dto, holder.failedFilterDTOs);
assertEmpty(dto, holder);
// register filter
final FilterHandler h1 = createFilterHandler(1L, 0, "/foo");
reg.addFilter(h1);
verify(h1.getFilter()).init(Matchers.any(FilterConfig.class));
// one entry in DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedFilterDTOs);
assertTrue(holder.failedFilterDTOs.isEmpty());
assertNotNull(dto.filterDTOs);
assertEquals(1, dto.filterDTOs.length);
assertEquals(1, dto.filterDTOs[0].patterns.length);
assertEquals("/foo", dto.filterDTOs[0].patterns[0]);
// remove filter
final Filter f = h1.getFilter();
reg.removeFilter(h1.getFilterInfo(), true);
verify(f).destroy();
// empty again
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedFilterDTOs);
assertEmpty(dto, holder);
}
Aggregations