Search in sources :

Example 6 with ServletInfo

use of org.apache.felix.http.base.internal.runtime.ServletInfo in project felix by apache.

the class ErrorPageRegistryTest method createServletHandler.

private static ServletHandler createServletHandler(final long id, final int ranking, final String... codes) throws InvalidSyntaxException {
    final ServletInfo si = createServletInfo(id, ranking, codes);
    final ExtServletContext ctx = mock(ExtServletContext.class);
    final Servlet servlet = mock(Servlet.class);
    return new HttpServiceServletHandler(ctx, si, servlet);
}
Also used : ServletInfo(org.apache.felix.http.base.internal.runtime.ServletInfo) ExtServletContext(org.apache.felix.http.base.internal.context.ExtServletContext) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) Servlet(javax.servlet.Servlet)

Example 7 with ServletInfo

use of org.apache.felix.http.base.internal.runtime.ServletInfo in project felix by apache.

the class HandlerRegistryTest method testAddRemoveServlet.

@Test
public void testAddRemoveServlet() throws Exception {
    registry.init();
    final FailedDTOHolder holder = new FailedDTOHolder();
    final ServletContextDTO dto = new ServletContextDTO();
    dto.serviceId = HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID;
    dto.servletDTOs = new ServletDTO[0];
    Servlet servlet = Mockito.mock(Servlet.class);
    final ServletInfo info = new ServletInfo("foo", "/foo", Collections.<String, String>emptyMap());
    ServletHandler handler = new HttpServiceServletHandler(null, info, servlet);
    assertTrue(registry.getRuntimeInfo(dto, holder));
    assertEquals("Precondition", 0, dto.servletDTOs.length);
    registry.getRegistry(handler.getContextServiceId()).registerServlet(handler);
    Mockito.verify(servlet, Mockito.times(1)).init(Mockito.any(ServletConfig.class));
    assertTrue(registry.getRuntimeInfo(dto, holder));
    assertEquals(1, dto.servletDTOs.length);
    assertEquals(info.getServiceId(), dto.servletDTOs[0].serviceId);
    final ServletInfo info2 = new ServletInfo("bar", "/bar", Collections.<String, String>emptyMap());
    ServletHandler handler2 = new HttpServiceServletHandler(null, info2, Mockito.mock(Servlet.class));
    registry.getRegistry(handler.getContextServiceId()).registerServlet(handler2);
    assertTrue(registry.getRuntimeInfo(dto, holder));
    assertEquals(2, dto.servletDTOs.length);
    final ServletInfo info3 = new ServletInfo("zar", "/foo", Collections.<String, String>emptyMap());
    ServletHandler handler3 = new HttpServiceServletHandler(null, info3, Mockito.mock(Servlet.class));
    registry.getRegistry(handler.getContextServiceId()).registerServlet(handler3);
    assertTrue(registry.getRuntimeInfo(dto, holder));
    assertEquals(2, dto.servletDTOs.length);
    assertEquals(1, holder.failedServletDTOs.size());
    registry.shutdown();
}
Also used : ServletInfo(org.apache.felix.http.base.internal.runtime.ServletInfo) ServletHandler(org.apache.felix.http.base.internal.handler.ServletHandler) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) FailedDTOHolder(org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) ServletConfig(javax.servlet.ServletConfig) Servlet(javax.servlet.Servlet) Test(org.junit.Test)

Example 8 with ServletInfo

use of org.apache.felix.http.base.internal.runtime.ServletInfo in project felix by apache.

the class ServletRegistryTest method createServletHandler.

private static ServletHandler createServletHandler(final long id, final int ranking, final String... paths) throws InvalidSyntaxException {
    final ServletInfo si = createServletInfo(id, ranking, paths);
    final ExtServletContext ctx = mock(ExtServletContext.class);
    final Servlet servlet = mock(Servlet.class);
    return new HttpServiceServletHandler(ctx, si, servlet);
}
Also used : ServletInfo(org.apache.felix.http.base.internal.runtime.ServletInfo) ExtServletContext(org.apache.felix.http.base.internal.context.ExtServletContext) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) Servlet(javax.servlet.Servlet)

Example 9 with ServletInfo

use of org.apache.felix.http.base.internal.runtime.ServletInfo in project felix by apache.

the class ServletRegistryTest method createServletInfo.

private static ServletInfo createServletInfo(final long id, final int ranking, final String... paths) throws InvalidSyntaxException {
    final BundleContext bCtx = mock(BundleContext.class);
    when(bCtx.createFilter(Matchers.anyString())).thenReturn(null);
    final Bundle bundle = mock(Bundle.class);
    when(bundle.getBundleContext()).thenReturn(bCtx);
    final ServiceReference<Servlet> ref = mock(ServiceReference.class);
    when(ref.getBundle()).thenReturn(bundle);
    when(ref.getProperty(Constants.SERVICE_ID)).thenReturn(id);
    when(ref.getProperty(Constants.SERVICE_RANKING)).thenReturn(ranking);
    when(ref.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN)).thenReturn(paths);
    when(ref.getPropertyKeys()).thenReturn(new String[0]);
    final ServletInfo si = new ServletInfo(ref);
    return si;
}
Also used : ServletInfo(org.apache.felix.http.base.internal.runtime.ServletInfo) Bundle(org.osgi.framework.Bundle) Servlet(javax.servlet.Servlet) BundleContext(org.osgi.framework.BundleContext)

Example 10 with ServletInfo

use of org.apache.felix.http.base.internal.runtime.ServletInfo in project felix by apache.

the class FailureStateHandlerTest method testAddRemoveNoContext.

@Test
public void testAddRemoveNoContext() {
    final ServletInfo info = new ServletInfo("test", "/test", Collections.<String, String>emptyMap());
    final FailureStateHandler handler = new FailureStateHandler();
    handler.addFailure(info, DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
    final FailedDTOHolder holder = new FailedDTOHolder();
    handler.getRuntimeInfo(holder);
    assertEquals(1, holder.failedServletDTOs.size());
    assertEquals(DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, holder.failedServletDTOs.get(0).failureReason);
    holder.failedServletDTOs.clear();
    handler.remove(info);
    handler.getRuntimeInfo(holder);
    assertEquals(0, holder.failedServletDTOs.size());
}
Also used : ServletInfo(org.apache.felix.http.base.internal.runtime.ServletInfo) FailedDTOHolder(org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder) Test(org.junit.Test)

Aggregations

ServletInfo (org.apache.felix.http.base.internal.runtime.ServletInfo)12 Servlet (javax.servlet.Servlet)5 ExtServletContext (org.apache.felix.http.base.internal.context.ExtServletContext)4 HttpServiceServletHandler (org.apache.felix.http.base.internal.handler.HttpServiceServletHandler)4 HashMap (java.util.HashMap)3 ServletHandler (org.apache.felix.http.base.internal.handler.ServletHandler)3 FailedDTOHolder (org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder)3 Test (org.junit.Test)3 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ServletException (javax.servlet.ServletException)2 FilterInfo (org.apache.felix.http.base.internal.runtime.FilterInfo)2 ListenerInfo (org.apache.felix.http.base.internal.runtime.ListenerInfo)2 ResourceInfo (org.apache.felix.http.base.internal.runtime.ResourceInfo)2 Bundle (org.osgi.framework.Bundle)2 BundleContext (org.osgi.framework.BundleContext)2 FailedResourceDTO (org.osgi.service.http.runtime.dto.FailedResourceDTO)2 FailedServletDTO (org.osgi.service.http.runtime.dto.FailedServletDTO)2 IOException (java.io.IOException)1