Java Code Examples for org.apache.openejb.loader.SystemInstance#isInitialized()

The following examples show how to use org.apache.openejb.loader.SystemInstance#isInitialized() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Resolver.java    From tomee with Apache License 2.0 6 votes vote down vote up
public InputStream resolve(final String rawLocation) {
       final boolean initialized = SystemInstance.isInitialized();
final String MVN_JNDI_PREFIX = "mvn:";

       if (!initialized) {
           SystemInstance.get().setComponent(ProvisioningResolver.class, new ProvisioningResolver());
       }

       try {
           if (rawLocation.startsWith(MVN_JNDI_PREFIX) && rawLocation.length() > MVN_JNDI_PREFIX.length()) {
               try {
                   return new FileInputStream(ShrinkwrapBridge.resolve(rawLocation));
               } catch (final Throwable th) {
                   // try aether if not in a mvn build
                   th.printStackTrace();
               }
           }
           return super.resolve(rawLocation);
       } finally {
           if (!initialized) {
               SystemInstance.reset();
           }
       }
   }
 
Example 2
Source File: Setup.java    From tomee with Apache License 2.0 6 votes vote down vote up
public static File downloadFile(final String artifactName, final String altUrl, final String defaultTempDir) {
    final String cache = SystemInstance.isInitialized() ?
        SystemInstance.get().getOptions().get(ProvisioningResolver.OPENEJB_DEPLOYER_CACHE_FOLDER, (String) null) :
        System.getProperty(ProvisioningResolver.OPENEJB_DEPLOYER_CACHE_FOLDER);
    if (cache == null && defaultTempDir != null) { // let the user override it
        System.setProperty(ProvisioningResolver.OPENEJB_DEPLOYER_CACHE_FOLDER, defaultTempDir);
    }

    try {
        final File artifact = MavenCache.getArtifact(artifactName, altUrl);
        if (artifact == null) {
            throw new NullPointerException(String.format("No such artifact: %s", artifactName));
        }
        return artifact.getAbsoluteFile();
    } finally {
        if (cache == null) {
            System.clearProperty(ProvisioningResolver.OPENEJB_DEPLOYER_CACHE_FOLDER);
        }
    }
}
 
Example 3
Source File: TestObserver.java    From tomee with Apache License 2.0 6 votes vote down vote up
public void release(@Observes final EventContext<BeforeUnDeploy> event) {
    if (!SystemInstance.isInitialized()) {
        event.proceed();
        return;
    }

    try {
        event.proceed();
    } finally {
        final BeanContext bc = beanContext();
        if (bc != null) { // can be null if deployment exception
            final CreationalContext<?> cc = bc.get(CreationalContext.class);
            if (cc != null) {
                cc.release();
            }
        }
    }
}
 
Example 4
Source File: EEFilter.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
    final SystemInstance si = SystemInstance.isInitialized() ? SystemInstance.get() : null;
    final Properties config = si != null ? si.getProperties() : System.getProperties();
    securityService = si != null ? si.getComponent(SecurityService.class) : null;
    active = Boolean.parseBoolean(config.getProperty("tomee.http.request.wrap", "true"));
}
 
Example 5
Source File: TomEEInjectionEnricher.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void enrich(final Object o) {
    if (!SystemInstance.isInitialized()) {
        return;
    }
    final Class<?> oClass = o.getClass();
    if (oClass.getName().startsWith("org.junit.rules.")) { // no need of enrichments
        return;
    }
    OpenEJBEnricher.enrich(o, getAppContext(oClass));
}
 
Example 6
Source File: TestObserver.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void switchLoader(final EventContext<?> event) {
    if (!SystemInstance.isInitialized()) {
        event.proceed();
        return;
    }
    final BeanContext context = beanContext();
    ThreadContext oldCtx = null;
    ClassLoader oldCl = null;
    if (context != null) {
        oldCtx = ThreadContext.enter(new ThreadContext(context, null));
    } else {
        oldCl = Thread.currentThread().getContextClassLoader();
        final ClassLoaders classLoaders = classLoader.get();
        if (classLoaders != null) {
            final ClassLoader loader = classLoaders.classloaders.size() == 1 /*assume it is the one we want*/ ?
                    classLoaders.classloaders.values().iterator().next() : oldCl /* we don't know the deployment so just passthrough */;
            setTCCL(loader);
        }
    }
    try {
        event.proceed();
    } finally {
        if (context != null) {
            ThreadContext.exit(oldCtx);
        } else {
            setTCCL(oldCl);
        }
    }
}
 
Example 7
Source File: ProvisioningResolver.java    From tomee with Apache License 2.0 5 votes vote down vote up
public ProvisioningResolver() {
    resolvers.put("mvn", new MavenResolver());
    resolvers.put("http", new HttpResolver());
    resolvers.put("https", new HttpResolver());

    if (SystemInstance.isInitialized()) {
        final String userOnes = SystemInstance.get().getProperty("openejb.provisinig.archive-resolvers");
        if (userOnes != null) {
            for (final String u : userOnes.split(" *, *")) {
                final String c = u.trim();
                if (!c.isEmpty()) {
                    continue;
                }
                try {
                    final ArchiveResolver instance = ArchiveResolver.class.cast(ProvisioningResolver.class.getClassLoader().loadClass(c));
                    addResolver(instance);
                } catch (final ClassNotFoundException e) {
                    throw new IllegalArgumentException(e);
                }
            }
        }

        SystemInstance.get().fireEvent(new ProvisiningResolverCreated(this));
    }
    for (final ArchiveResolver ar : resolvers.values()) {
        if (ProvisioningResolverAware.class.isInstance(ar)) {
            ProvisioningResolverAware.class.cast(ar).setResolver(this);
        }
    }
}
 
Example 8
Source File: PersistenceBootstrap.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static String getAltDD() {
    final String property = "openejb.altdd.prefix";
    if (SystemInstance.isInitialized()) {
        return SystemInstance.get().getOptions().get(property, (String) null);
    }
    return JavaSecurityManagers.getSystemProperty(property);
}
 
Example 9
Source File: JuliLogStreamFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public String getProperty(final String name) {
    final String parentValue = super.getProperty(name);

    if (SystemInstance.isInitialized()) {
        if (SystemInstance.get().getProperties().containsKey(name)) {
            return SystemInstance.get().getProperty(name);
        }

        final String propertyKeyValue = "logging" + reverseProperty(name);
        if (SystemInstance.get().getProperties().containsKey(propertyKeyValue)) {
            return SystemInstance.get().getProperty(propertyKeyValue);
        }
    }

    // if it is one of ours loggers and no value is defined let set our nice logging style
    if (OpenEJBLogManager.class.getName().equals(JavaSecurityManagers.getSystemProperty("java.util.logging.manager")) // custom logging
        && isOverridableLogger(name) // managed loggers
        && parentValue == null) { // not already defined
        if (name.endsWith(".handlers")) {
            return consoleHandlerClazz;
        } else if (name.endsWith(".useParentHandlers")) {
            return "false";
        }
    }
    return parentValue;
}
 
Example 10
Source File: ParentClassLoaderFinder.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static ClassLoader get() {
    final ParentClassLoaderFinder parentFinder = SystemInstance.isInitialized() ?
        SystemInstance.get().getComponent(ParentClassLoaderFinder.class) : null;
    if (parentFinder != null) {
        return parentFinder.getParentClassLoader(FALLBACK);
    }
    return FALLBACK;
}
 
Example 11
Source File: OpenEJBHttpRegistry.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void onMessage(HttpRequest request, HttpResponse response) throws Exception {
    final Thread thread = Thread.currentThread();
    final ClassLoader oldCl = thread.getContextClassLoader();

    WebBeansContext wbc = null;
    try {
        if (request instanceof HttpRequestImpl) {
            final HttpRequestImpl httpRequest = HttpRequestImpl.class.cast(request);
            final WebContext web = findWebContext(request.getURI() == null ? request.getContextPath() : request.getURI().getPath());
            if (web != null) {
                httpRequest.setApplication(web);

                if (web.getClassLoader() != null) {
                    thread.setContextClassLoader(web.getClassLoader());
                } else if (web.getAppContext().getClassLoader() != null) {
                    thread.setContextClassLoader(web.getAppContext().getClassLoader());
                }

                final String ctx = (web.getContextRoot().startsWith("/") ? "" : "/") + web.getContextRoot();
                httpRequest.initPathFromContext(ctx);
                wbc = web.getWebbeansContext() != null ? web.getWebbeansContext() : web.getAppContext().getWebBeansContext();
            } else {
                thread.setContextClassLoader(classLoader);

                if (SystemInstance.isInitialized()) { // avoid to rely on default if we didnt init it and then create lazily a context
                    try { // surely an issue or something just tolerated for fake webapps
                        wbc = WebBeansContext.currentInstance();
                    } catch (final IllegalStateException ise) {
                        // no-op
                    }
                }
            }
            if (wbc != null) {
                httpRequest.setAttribute("openejb_owb_context", wbc);
                initCdi(wbc, httpRequest).init();
            }
        }

        delegate.onMessage(request, response);
    } finally {
        if (wbc != null) {
            HttpRequestImpl.class.cast(request).destroy();
        }

        thread.setContextClassLoader(oldCl);
    }
}
 
Example 12
Source File: AbstractSecurityService.java    From tomee with Apache License 2.0 4 votes vote down vote up
protected static String autoJaccProvider() {
    return SystemInstance.isInitialized() ?
            SystemInstance.get().getProperty(JaccProvider.class.getName(), BasicJaccProvider.class.getName()) :
            BasicJaccProvider.class.getName();
}