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;
}
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"));
}
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();
}
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);
}
}
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);
}
}
}
}
Aggregations