@Test public void scansForJaxRsComponentsAndCreatesApplication() throws Exception { when(servletContext.getInitParameter("org.everrest.scan.components")).thenReturn("true"); EverrestServletContextInitializer everrestServletContextInitializer = new EverrestServletContextInitializer(servletContext); Application application = everrestServletContextInitializer.getApplication(); assertEquals(scannedClasses, application.getClasses()); }
public Application getApplication() { Application application = null; String applicationFQN = getParameter(JAXRS_APPLICATION); boolean scan = getBoolean(EVERREST_SCAN_COMPONENTS, false); if (applicationFQN != null) { if (scan) { String msg = "Scan of JAX-RS components is disabled cause to specified 'javax.ws.rs.Application'."; LOG.warn(msg); } try { Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(applicationFQN); application = (Application)cl.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } else if (scan) { application = new Application() { @Override public Set<Class<?>> getClasses() { return new LinkedHashSet<>(ComponentFinder.findComponents()); } }; } return application; }
EverrestServletContextInitializer { public Application getApplication() { Application application = null; String applicationFQN = getParameter(JAXRS_APPLICATION); boolean scan = getBoolean(EVERREST_SCAN_COMPONENTS, false); if (applicationFQN != null) { if (scan) { String msg = "Scan of JAX-RS components is disabled cause to specified 'javax.ws.rs.Application'."; LOG.warn(msg); } try { Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(applicationFQN); application = (Application)cl.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } else if (scan) { application = new Application() { @Override public Set<Class<?>> getClasses() { return new LinkedHashSet<>(ComponentFinder.findComponents()); } }; } return application; } }
EverrestServletContextInitializer { public Application getApplication() { Application application = null; String applicationFQN = getParameter(JAXRS_APPLICATION); boolean scan = getBoolean(EVERREST_SCAN_COMPONENTS, false); if (applicationFQN != null) { if (scan) { String msg = "Scan of JAX-RS components is disabled cause to specified 'javax.ws.rs.Application'."; LOG.warn(msg); } try { Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(applicationFQN); application = (Application)cl.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } else if (scan) { application = new Application() { @Override public Set<Class<?>> getClasses() { return new LinkedHashSet<>(ComponentFinder.findComponents()); } }; } return application; } EverrestServletContextInitializer(ServletContext servletContext); }
EverrestServletContextInitializer { public Application getApplication() { Application application = null; String applicationFQN = getParameter(JAXRS_APPLICATION); boolean scan = getBoolean(EVERREST_SCAN_COMPONENTS, false); if (applicationFQN != null) { if (scan) { String msg = "Scan of JAX-RS components is disabled cause to specified 'javax.ws.rs.Application'."; LOG.warn(msg); } try { Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(applicationFQN); application = (Application)cl.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } else if (scan) { application = new Application() { @Override public Set<Class<?>> getClasses() { return new LinkedHashSet<>(ComponentFinder.findComponents()); } }; } return application; } EverrestServletContextInitializer(ServletContext servletContext); Application getApplication(); EverrestConfiguration createConfiguration(); RequestHandler createRequestHandler(); RequestDispatcher createRequestDispatcher(); ResourceBinder createResourceBinder(); DependencySupplier getDependencySupplier(); ProviderBinder createProviderBinder(); EverrestProcessor createEverrestProcessor(); }
EverrestServletContextInitializer { public Application getApplication() { Application application = null; String applicationFQN = getParameter(JAXRS_APPLICATION); boolean scan = getBoolean(EVERREST_SCAN_COMPONENTS, false); if (applicationFQN != null) { if (scan) { String msg = "Scan of JAX-RS components is disabled cause to specified 'javax.ws.rs.Application'."; LOG.warn(msg); } try { Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(applicationFQN); application = (Application)cl.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } else if (scan) { application = new Application() { @Override public Set<Class<?>> getClasses() { return new LinkedHashSet<>(ComponentFinder.findComponents()); } }; } return application; } EverrestServletContextInitializer(ServletContext servletContext); Application getApplication(); EverrestConfiguration createConfiguration(); RequestHandler createRequestHandler(); RequestDispatcher createRequestDispatcher(); ResourceBinder createResourceBinder(); DependencySupplier getDependencySupplier(); ProviderBinder createProviderBinder(); EverrestProcessor createEverrestProcessor(); static final String EVERREST_SCAN_COMPONENTS; static final String EVERREST_SCAN_SKIP_PACKAGES; static final String JAXRS_APPLICATION; }