use of com.ibm.domino.xsp.module.nsf.NotesContext in project org.openntf.xsp.jakartaee by OpenNTF.
the class AbstractProxyingContext method getHttpServletRequest.
protected Optional<HttpServletRequest> getHttpServletRequest() {
if (THREAD_REQUESTS.get() != null) {
return Optional.of(THREAD_REQUESTS.get());
}
// Check the active session
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
javax.servlet.ServletContext context = (javax.servlet.ServletContext) facesContext.getExternalContext().getContext();
javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest) facesContext.getExternalContext().getRequest();
return Optional.ofNullable(ServletUtil.oldToNew(context, request));
}
// If we're not in a Faces context, check the OSGi servlet context
NotesContext notesContext = NotesContext.getCurrentUnchecked();
if (notesContext != null) {
Optional<HttpServletRequest> request = getHttpServletRequest(notesContext);
if (request.isPresent()) {
return request;
}
}
if (osgiNotesContextRequestField != null) {
com.ibm.domino.xsp.adapter.osgi.NotesContext osgiContext = com.ibm.domino.xsp.adapter.osgi.NotesContext.getCurrentUnchecked();
if (osgiContext != null) {
Optional<HttpServletRequest> request = getHttpServletRequest(osgiContext);
if (request.isPresent()) {
return request;
}
}
}
return Optional.empty();
}
use of com.ibm.domino.xsp.module.nsf.NotesContext 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.NotesContext in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFCdiInjectorFactory method lookupBeanManager.
@Override
@SuppressWarnings("nls")
protected BeanManager lookupBeanManager() {
ApplicationEx application = ApplicationEx.getInstance();
if (application != null) {
return ContainerUtil.getBeanManager(application);
}
NotesContext ctx = NotesContext.getCurrentUnchecked();
if (ctx != null) {
try {
NotesDatabase database = ctx.getNotesDatabase();
if (database != null) {
return ContainerUtil.getBeanManager(database);
}
} catch (NotesAPIException e) {
throw new RuntimeException(e);
}
}
throw new IllegalStateException("Unable to locate active application!");
}
use of com.ibm.domino.xsp.module.nsf.NotesContext in project org.openntf.xsp.jakartaee by OpenNTF.
the class AbstractOpenAPIResource method buildOpenAPI.
protected OpenAPI buildOpenAPI() throws IOException, NotesException {
Set<Class<?>> classes = new HashSet<>();
classes.addAll(application.getClasses());
classes.add(application.getClass());
Index index = Index.of(classes);
Config mpConfig = CDI.current().select(Config.class).get();
OpenApiConfig config = OpenApiConfigImpl.fromConfig(mpConfig);
ClassLoader cl = new DelegatingClassLoader(OpenApiProcessor.class.getClassLoader(), Thread.currentThread().getContextClassLoader());
OpenAPI openapi;
synchronized (OpenApiProcessor.class) {
// OpenApiProcessor appears to be not thread-safe
openapi = OpenApiProcessor.bootstrap(config, index, cl);
}
NotesContext notesContext = NotesContext.getCurrent();
Database database = notesContext.getCurrentDatabase();
Info info = openapi.getInfo();
String existingTitle = config.getInfoTitle();
if (existingTitle == null || existingTitle.isEmpty()) {
info.setTitle(database.getTitle());
} else {
info.setTitle(existingTitle);
}
String existingVersion = config.getInfoVersion();
if (existingVersion == null || existingVersion.isEmpty()) {
String templateBuild = getVersionNumber(database);
if (templateBuild != null && !templateBuild.isEmpty()) {
info.setVersion(templateBuild);
} else {
info.setVersion(existingVersion);
}
} else {
info.setVersion(existingVersion);
}
// Build a URI to the base of JAX-RS
Set<String> servers = config.servers();
if (servers == null || servers.isEmpty()) {
Server server = new ServerImpl();
URI uri = URI.create(req.getRequestURL().toString());
String jaxrsRoot = JAXRSServletFactory.getServletPath(notesContext.getModule());
uri = uri.resolve(PathUtil.concat(req.getContextPath(), jaxrsRoot, '/'));
String uriString = uri.toString();
if (uriString.endsWith("/")) {
// $NON-NLS-1$
uriString = uriString.substring(0, uriString.length() - 1);
}
server.setUrl(uriString);
openapi.addServer(server);
}
return openapi;
}
use of com.ibm.domino.xsp.module.nsf.NotesContext 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();
}
}
Aggregations