Search in sources :

Example 6 with Logger

use of org.apache.openejb.util.Logger in project tomee by apache.

the class TomEERealm method logInTomEE.

private Principal logInTomEE(final Principal pcp) {
    if (pcp == null) {
        return null;
    }
    if (securityService == null) {
        // tomee-embedded get it later than startInternals so we need it this way
        securityService = (TomcatSecurityService) SystemInstance.get().getComponent(SecurityService.class);
    }
    // normally we don't care about oldstate because the listener already contains one
    // which is the previous one
    // so no need to clean twice here
    final Request request = OpenEJBSecurityListener.requests.get();
    if (request != null) {
        final Object securityContext = securityService.enterWebApp(this, pcp, OpenEJBSecurityListener.requests.get().getWrapper().getRunAs());
        request.setNote(SECURITY_NOTE, securityContext);
    } else {
        final CUTask.Context context = CUTask.Context.CURRENT.get();
        if (context != null) {
            final Object state = securityService.enterWebApp(this, pcp, null);
            context.pushExitTask(new Runnable() {

                @Override
                public void run() {
                    securityService.exitWebApp(state);
                }
            });
        } else {
            final Logger instance = Logger.getInstance(LogCategory.OPENEJB_SECURITY, TomEERealm.class);
            if (instance.isDebugEnabled()) {
                instance.debug("No request or concurrency-utilities context so skipping login context propagation, " + "thread=" + Thread.currentThread().getName());
            }
        }
    }
    return pcp;
}
Also used : Request(org.apache.catalina.connector.Request) Logger(org.apache.openejb.util.Logger) CUTask(org.apache.openejb.threads.task.CUTask)

Example 7 with Logger

use of org.apache.openejb.util.Logger in project tomee by apache.

the class LoggingSqlTest method checkOutput.

@Test
public void checkOutput() throws Exception {
    final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SQL, LoggingPreparedSqlStatement.class);
    final JuliLogStream stream = JuliLogStream.class.cast(Reflections.get(logger, "logStream"));
    final LoggerCreator julCreator = LoggerCreator.class.cast(Reflections.get(stream, "logger"));
    final java.util.logging.Logger actualLogger = julCreator.call();
    final Collection<String> msgs = new LinkedList<>();
    final Handler handler = new Handler() {

        @Override
        public void publish(final LogRecord record) {
            msgs.add(record.getMessage());
        }

        @Override
        public void flush() {
        // no-op
        }

        @Override
        public void close() throws SecurityException {
        // no-op
        }
    };
    actualLogger.addHandler(handler);
    final Connection c = ds.getConnection();
    final PreparedStatement preparedStatement = c.prepareStatement("select 1 from INFORMATION_SCHEMA.SYSTEM_USERS");
    preparedStatement.execute();
    preparedStatement.close();
    c.close();
    actualLogger.removeHandler(handler);
    assertEquals(1, msgs.size());
    final String msg = msgs.iterator().next();
    assertTrue(msg.contains("select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"));
    assertTrue(msg.contains("stack: -> org.apache.openejb.resource.jdbc.logging.LoggingSqlTest.checkOutput:83"));
}
Also used : JuliLogStream(org.apache.openejb.util.JuliLogStream) Connection(java.sql.Connection) Handler(java.util.logging.Handler) PreparedStatement(java.sql.PreparedStatement) Logger(org.apache.openejb.util.Logger) LinkedList(java.util.LinkedList) LoggerCreator(org.apache.openejb.log.LoggerCreator) LogRecord(java.util.logging.LogRecord) Test(org.junit.Test)

Example 8 with Logger

use of org.apache.openejb.util.Logger in project tomee by apache.

the class LoggingJAXRSCommons method getLooger.

protected java.util.logging.Logger getLooger() throws Exception {
    final Logger logger = Logger.getInstance(LogCategory.OPENEJB_RS, RESTService.class);
    final LogStreamAsync stream = LogStreamAsync.class.cast(Reflections.get(logger, "logStream"));
    final JuliLogStream ls = JuliLogStream.class.cast(Reflections.get(stream, "ls"));
    final LoggerCreator julCreator = LoggerCreator.class.cast(Reflections.get(ls, "logger"));
    return julCreator.call();
}
Also used : LoggerCreator(org.apache.openejb.log.LoggerCreator) JuliLogStream(org.apache.openejb.util.JuliLogStream) Logger(org.apache.openejb.util.Logger) LogStreamAsync(org.apache.openejb.util.LogStreamAsync)

Example 9 with Logger

use of org.apache.openejb.util.Logger in project tomee by apache.

the class MethodTransactionBuilder method applyTransactionAttributes.

public static void applyTransactionAttributes(final BeanContext beanContext, List<MethodTransactionInfo> methodTransactionInfos) throws OpenEJBException {
    if (beanContext.isBeanManagedTransaction()) {
        return;
    }
    methodTransactionInfos = normalize(methodTransactionInfos);
    final Map<MethodInfoUtil.ViewMethod, MethodAttributeInfo> attributes = resolveViewAttributes(methodTransactionInfos, beanContext);
    final Logger log = Logger.getInstance(LogCategory.OPENEJB_STARTUP.createChild("attributes"), MethodTransactionBuilder.class);
    final boolean debug = log.isDebugEnabled();
    for (final Map.Entry<MethodInfoUtil.ViewMethod, MethodAttributeInfo> entry : attributes.entrySet()) {
        final MethodInfoUtil.ViewMethod viewMethod = entry.getKey();
        final Method method = viewMethod.getMethod();
        final String view = viewMethod.getView();
        final MethodTransactionInfo transactionInfo = (MethodTransactionInfo) entry.getValue();
        if (debug) {
            log.debug("Transaction Attribute: " + method + " -- " + MethodInfoUtil.toString(transactionInfo));
        }
        beanContext.setMethodTransactionAttribute(method, TransactionType.get(transactionInfo.transAttribute), view);
    }
}
Also used : Method(java.lang.reflect.Method) Logger(org.apache.openejb.util.Logger) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with Logger

use of org.apache.openejb.util.Logger in project tomee by apache.

the class CdiScanner method init.

@Override
public void init(final Object object) {
    if (!StartupObject.class.isInstance(object)) {
        return;
    }
    containerLoader = ParentClassLoaderFinder.Helper.get();
    final StartupObject startupObject = StartupObject.class.cast(object);
    final AppInfo appInfo = startupObject.getAppInfo();
    final ClassLoader classLoader = startupObject.getClassLoader();
    final ClassLoaderComparator comparator;
    if (classLoader instanceof ClassLoaderComparator) {
        comparator = (ClassLoaderComparator) classLoader;
    } else {
        comparator = new DefaultClassLoaderComparator(classLoader);
    }
    final WebBeansContext webBeansContext = startupObject.getWebBeansContext();
    final InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();
    // app beans
    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
        final BeansInfo beans = ejbJar.beans;
        if (beans == null || "false".equalsIgnoreCase(ejbJar.properties.getProperty("openejb.cdi.activated"))) {
            continue;
        }
        if (startupObject.isFromWebApp()) {
            // deploy only the related ejbmodule
            if (!ejbJar.moduleId.equals(startupObject.getWebContext().getId())) {
                continue;
            }
        } else if (ejbJar.webapp && !appInfo.webAppAlone) {
            continue;
        }
        if (appInfo.webAppAlone || !ejbJar.webapp) {
            // "manual" extension to avoid to add it through SPI mecanism
            classes.addAll(asList(TRANSACTIONAL_INTERCEPTORS));
            for (final Class<?> interceptor : TRANSACTIONAL_INTERCEPTORS) {
                interceptorsManager.addEnabledInterceptorClass(interceptor);
            }
        }
        // here for ears we need to skip classes in the parent classloader
        final ClassLoader scl = ClassLoader.getSystemClassLoader();
        final boolean filterByClassLoader = "true".equals(ejbJar.properties.getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, SystemInstance.get().getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, "true")));
        final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
        final boolean openejb = OpenEJBBeanInfoService.class.isInstance(beanArchiveService);
        final Map<BeansInfo.BDAInfo, BeanArchiveService.BeanArchiveInformation> infoByBda = new HashMap<>();
        for (final BeansInfo.BDAInfo bda : beans.bdas) {
            if (bda.uri != null) {
                try {
                    beansXml.add(bda.uri.toURL());
                } catch (final MalformedURLException e) {
                // no-op
                }
            }
            infoByBda.put(bda, handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda));
        }
        for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
            // infoByBda.put() not needed since we know it means annotated
            handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda);
        }
        if (startupObject.getBeanContexts() != null) {
            for (final BeanContext bc : startupObject.getBeanContexts()) {
                final String name = bc.getBeanClass().getName();
                if (BeanContext.Comp.class.getName().equals(name)) {
                    continue;
                }
                boolean cdi = false;
                for (final BeansInfo.BDAInfo bda : beans.bdas) {
                    final BeanArchiveService.BeanArchiveInformation info = infoByBda.get(bda);
                    if (info.getBeanDiscoveryMode() == BeanArchiveService.BeanDiscoveryMode.NONE) {
                        continue;
                    }
                    if (bda.managedClasses.contains(name)) {
                        classes.add(load(name, classLoader));
                        cdi = true;
                        break;
                    }
                }
                if (!cdi) {
                    for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
                        if (bda.managedClasses.contains(name)) {
                            classes.add(load(name, classLoader));
                            break;
                        }
                    }
                }
            }
        }
        if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.cdi.debug", "false"))) {
            final Logger logger = Logger.getInstance(LogCategory.OPENEJB, CdiScanner.class.getName());
            logger.info("CDI beans for " + startupObject.getAppInfo().appId + (startupObject.getWebContext() != null ? " webcontext = " + startupObject.getWebContext().getContextRoot() : ""));
            final List<String> names = new ArrayList<>(classes.size());
            for (final Class<?> c : classes) {
                names.add(c.getName());
            }
            Collections.sort(names);
            for (final String c : names) {
                logger.info("    " + c);
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ClassLoaderComparator(org.apache.openejb.util.classloader.ClassLoaderComparator) DefaultClassLoaderComparator(org.apache.openejb.util.classloader.DefaultClassLoaderComparator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Logger(org.apache.openejb.util.Logger) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeansInfo(org.apache.openejb.assembler.classic.BeansInfo) DefaultClassLoaderComparator(org.apache.openejb.util.classloader.DefaultClassLoaderComparator) BeanArchiveService(org.apache.webbeans.spi.BeanArchiveService) AppInfo(org.apache.openejb.assembler.classic.AppInfo) BeanContext(org.apache.openejb.BeanContext) InterceptorsManager(org.apache.webbeans.intercept.InterceptorsManager) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Aggregations

Logger (org.apache.openejb.util.Logger)10 HashMap (java.util.HashMap)4 Map (java.util.Map)3 Method (java.lang.reflect.Method)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 LoggerCreator (org.apache.openejb.log.LoggerCreator)2 JuliLogStream (org.apache.openejb.util.JuliLogStream)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 Handler (java.util.logging.Handler)1 LogRecord (java.util.logging.LogRecord)1 XAConnection (javax.sql.XAConnection)1 RollbackException (javax.transaction.RollbackException)1