Пример #1
0
 @Override
 public void setResources(final WebResourceRoot resources) {
   this.resources = resources;
   if (StandardRoot.class.isInstance(resources)) {
     final List<WebResourceSet> jars =
         (List<WebResourceSet>) Reflections.get(resources, "jarResources");
     if (jars != null && !jars.isEmpty()) {
       final Iterator<WebResourceSet> jarIt = jars.iterator();
       while (jarIt.hasNext()) {
         final WebResourceSet set = jarIt.next();
         if (set.getBaseUrl() == null) {
           continue;
         }
         final File file = URLs.toFile(set.getBaseUrl());
         try {
           if (file.exists()
               && (!TomEEClassLoaderEnricher.validateJarFile(file) || !jarIsAccepted(file))) {
             // need to remove this resource
             LOGGER.warning("Removing " + file.getAbsolutePath() + " since it is offending");
             jarIt.remove();
           }
         } catch (final IOException e) {
           // ignore
         }
       }
     }
   }
 }
Пример #2
0
 private void cleanUpClassLoader() {
   final LogManager lm = LogManager.getLogManager();
   if (ClassLoaderLogManager.class.isInstance(
       lm)) { // weak ref but ensure it is really removed otherwise in some cases we leak
     Map.class.cast(Reflections.get(lm, "classLoaderLoggers")).remove(this);
   }
 }
 @Test
 public void checkOnlyConfiguredExtensionsArePresent() {
   final Map<?, ?> extensions =
       Map.class.cast(
           Reflections.get(WebBeansContext.currentInstance().getExtensionLoader(), "extensions"));
   assertEquals(1, extensions.size());
   assertEquals(
       ThisTestExtensionWithoutSPIFiles.class, extensions.values().iterator().next().getClass());
 }
Пример #4
0
  @Test
  public void tomcatClassLoaderParentShouldntBeNulAfterAStopStartOtherwiseReloadIsBroken()
      throws Exception {
    final CxfRSService server = new CxfRSService();
    try {
      server.init(new Properties());
      server.start();

      server.afterApplicationCreated(
          new AssemblerAfterApplicationCreated(
              info, context, Collections.<BeanContext>emptyList()));

      {
        final ClassLoader beforeLoader =
            SystemInstance.get()
                .getComponent(ContainerSystem.class)
                .getWebContext("test")
                .getClassLoader();
        assertSame(loader, beforeLoader);
        assertNotNull(beforeLoader);
        assertNotNull(Reflections.get(beforeLoader, "parent"));
      }

      loader.internalStop();

      server.undeploy(new AssemblerBeforeApplicationDestroyed(info, context));

      {
        final URLClassLoader afterLoader =
            URLClassLoader.class.cast(
                SystemInstance.get()
                    .getComponent(ContainerSystem.class)
                    .getWebContext("test")
                    .getClassLoader());
        assertSame(loader, afterLoader);
        assertNotNull(afterLoader);
        assertEquals(0, afterLoader.getURLs().length);
        assertEquals(LifecycleState.STOPPED, loader.getState());
      }

      final StandardRoot resources = new StandardRoot();
      loader.setResources(resources);
      resources.setContext(
          new StandardContext() {
            @Override
            public String getDocBase() {
              final File file = new File("target/foo");
              file.mkdirs();
              return file.getAbsolutePath();
            }

            @Override
            public String getMBeanKeyProperties() {
              return "foo";
            }

            {
            }
          });
      resources.start();
      loader.start();
      // TomcatWebAppBuilder ill catch start event from StandardContext and force a classloader
      Reflections.set(loader, "parent", ParentClassLoaderFinder.Helper.get());

      server.afterApplicationCreated(
          new AssemblerAfterApplicationCreated(
              info, context, Collections.<BeanContext>emptyList()));

      {
        final ClassLoader afterLoader =
            SystemInstance.get()
                .getComponent(ContainerSystem.class)
                .getWebContext("test")
                .getClassLoader();
        assertSame(loader, afterLoader);
        assertNotNull(afterLoader);
        assertNotNull(Reflections.get(afterLoader, "parent"));
      }

      server.undeploy(new AssemblerBeforeApplicationDestroyed(info, context));
    } finally {
      server.stop();
    }
  }