use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFBeanArchiveHandler method handle.
@Override
public BeanArchiveBuilder handle(String beanArchiveReference) {
NotesContext context = NotesContext.getCurrentUnchecked();
if (context != null) {
NSFComponentModule module = context.getModule();
try {
if (LibraryUtil.usesLibrary(CDILibrary.LIBRARY_ID, module)) {
// If it uses a CDI bundle ref, skip processing
String bundleId = ContainerUtil.getApplicationCDIBundle(context.getNotesDatabase());
if (StringUtil.isNotEmpty(bundleId)) {
return null;
}
// Slightly customize the builder to keep some extra metadata
BeanArchiveBuilder builder = new BeanArchiveBuilder() {
{
super.setBeansXml(BeansXml.EMPTY_BEANS_XML);
super.setId(module.getDatabasePath());
}
@Override
public BeanArchiveBuilder setBeansXml(BeansXml beansXml) {
return this;
}
};
ModuleUtil.getClassNames(module).filter(className -> !ModuleUtil.GENERATED_CLASSNAMES.matcher(className).matches()).forEach(builder::addClass);
return builder;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFJAXRSApplication method getProperties.
@Override
public Map<String, Object> getProperties() {
Map<String, Object> result = new LinkedHashMap<>();
// Read in xsp.properties
NSFComponentModule module = NotesContext.getCurrent().getModule();
Properties xspProperties = new Properties();
try (InputStream is = module.getResourceAsStream("/WEB-INF/xsp.properties")) {
// $NON-NLS-1$
xspProperties.load(is);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
xspProperties.forEach((key, value) -> result.put(key.toString(), value));
return result;
}
use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.domino by OpenNTF.
the class XotsWrappedTask method invokeTasklet.
/**
* Invokes the tasklet
*
* @param codeModule
* @param bubbleException
* @param sessionFactory
* @param wrappedTask
* @return
* @throws Exception
*/
@SuppressWarnings({ "restriction" })
protected Object invokeTasklet(final NotesContext ctx, final NSFComponentModule module) throws Exception {
ClassLoader mcl = null;
ThreadLock readLock = null;
NSFComponentModule codeModule = null;
if (module == null) {
mcl = getWrappedTask().getClass().getClassLoader();
} else {
// RPr: In my opinion, This is the proper way how to run runnables in a different thread
codeModule = module.getTemplateModule();
if (codeModule == null)
codeModule = module;
mcl = codeModule.getModuleClassLoader();
if (ODAPlatform.isAppFlagSet("LOCKXOTS", codeModule.getNotesApplication())) {
// $NON-NLS-1$
readLock = XotsDominoExecutor.getLockManager(codeModule).getReadLock();
}
}
if (sessionFactory != null) {
Factory.setSessionFactory(sessionFactory, SessionType.CURRENT);
@SuppressWarnings("unused") org.openntf.domino.Session current = Factory.getSession(SessionType.CURRENT);
}
try {
if (readLock != null)
// we want to read data from the module, so lock it!
readLock.acquire();
// set up the classloader
ClassLoader oldCl = switchClassLoader(mcl);
try {
Object wrappedTask = getWrappedTask();
XotsDominoExecutor.initModule(ctx, mcl, wrappedTask);
XotsConfiguration config = null;
if (mcl instanceof org.eclipse.osgi.internal.loader.ModuleClassLoader) {
// Determine the bundle of mcl
String bundle = ((org.eclipse.osgi.internal.loader.ModuleClassLoader) mcl).getBundle().getSymbolicName();
config = Configuration.getXotsBundleConfiguration(bundle, wrappedTask.getClass().getName());
} else {
config = Configuration.getXotsNSFConfiguration(module.getDatabasePath(), wrappedTask.getClass().getName());
}
try {
config.logStart();
Object ret = invokeObject(wrappedTask);
config.logSuccess();
return ret;
} catch (Exception e) {
config.logError(e);
throw e;
}
} finally {
switchClassLoader(oldCl);
}
} finally {
if (readLock != null)
readLock.release();
}
}
use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.domino by OpenNTF.
the class XotsWrappedTask method callOrRun.
/**
* Common code for the wrappers
*
* @param module
* @param bubbleException
* @param sessionFactory
* @param callable
* @param runnable
* @return
*/
protected Object callOrRun(final NSFComponentModule module) throws Exception {
NSFComponentModule codeModule = null;
if (module != null) {
codeModule = module.getTemplateModule() == null ? module : module.getTemplateModule();
if (module.isDestroyed() || codeModule.isDestroyed()) {
// $NON-NLS-1$
throw new IllegalArgumentException("Module was destroyed in the meantime. Cannot run");
}
module.updateLastModuleAccess();
codeModule.updateLastModuleAccess();
}
final NotesContext ctx = new NotesContext(module);
NotesContext.initThread(ctx);
try {
// checkme: What should we use here?
// Factory.initThread(ODAPlatform.getAppThreadConfig(module.getNotesApplication()));
Factory.initThread(sourceThreadConfig);
try {
return invokeTasklet(ctx, codeModule);
} catch (Exception e) {
DominoUtils.handleException(e);
return null;
} finally {
Factory.termThread();
}
} finally {
NotesContext.termThread();
}
}
use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.domino by OpenNTF.
the class XotsDominoExecutor method wrap.
@Override
protected <V> IWrappedCallable<V> wrap(final Callable<V> inner) {
if (inner instanceof IWrappedCallable)
return (IWrappedCallable<V>) inner;
NSFComponentModule module = getCurrentModule();
Tasklet annot = inner.getClass().getAnnotation(Tasklet.class);
if (annot == null || annot.context() == Context.DEFAULT) {
if (module == null) {
return super.wrap(inner);
} else {
if (inner instanceof AbstractXotsCallable) {
XotsContext ctx = new XotsContext();
ctx.setOpenLogApiPath(ODAPlatform.getXspPropertyAsString("xsp.openlog.filepath"));
ctx.setContextApiPath(module.getDatabasePath());
ctx.setTaskletClass(inner.getClass().getName());
((AbstractXotsCallable) inner).setContext(ctx);
}
return new XotsWrappedCallable<V>(module, inner);
}
} else if (annot.context() == Context.PLUGIN) {
return super.wrap(inner);
} else if (annot.context() == Context.XSPSCOPED || annot.context() == Context.XSPBARE) {
if (inner instanceof AbstractXotsXspCallable) {
XotsXspContext ctx = new XotsXspContext();
if (annot.context() == Context.XSPSCOPED) {
ctx.initialiseXspContext(true);
} else {
ctx.initialiseXspContext(false);
}
if (module != null) {
ctx.setOpenLogApiPath(ODAPlatform.getXspPropertyAsString("xsp.openlog.filepath"));
ctx.setContextApiPath(module.getDatabasePath());
ctx.setTaskletClass(inner.getClass().getName());
}
((AbstractXotsXspCallable) inner).setContext(ctx);
}
if (module == null) {
return super.wrap(inner);
} else {
return new XotsWrappedCallable<V>(module, inner);
}
} else {
if (module == null) {
throw new NullPointerException("No module is running");
}
return new XotsWrappedCallable<V>(module, inner);
}
}
Aggregations