Search in sources :

Example 1 with NotesContext

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();
}
Also used : FacesContext(javax.faces.context.FacesContext) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) HttpServletRequest(jakarta.servlet.http.HttpServletRequest)

Example 2 with NotesContext

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;
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanArchiveBuilder(org.jboss.weld.environment.deployment.discovery.BeanArchiveBuilder) StringUtil(com.ibm.commons.util.StringUtil) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) ModuleUtil(org.openntf.xsp.jakartaee.util.ModuleUtil) BeanArchiveHandler(org.jboss.weld.environment.deployment.discovery.BeanArchiveHandler) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) Priority(jakarta.annotation.Priority) CDILibrary(org.openntf.xsp.cdi.CDILibrary) ContainerUtil(org.openntf.xsp.cdi.util.ContainerUtil) LibraryUtil(org.openntf.xsp.jakartaee.util.LibraryUtil) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) BeanArchiveBuilder(org.jboss.weld.environment.deployment.discovery.BeanArchiveBuilder)

Example 3 with NotesContext

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!");
}
Also used : NotesDatabase(com.ibm.designer.domino.napi.NotesDatabase) ApplicationEx(com.ibm.xsp.application.ApplicationEx) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException)

Example 4 with NotesContext

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;
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) Config(org.eclipse.microprofile.config.Config) OpenApiConfig(io.smallrye.openapi.api.OpenApiConfig) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) Index(org.jboss.jandex.Index) OpenApiProcessor(io.smallrye.openapi.runtime.OpenApiProcessor) Info(org.eclipse.microprofile.openapi.models.info.Info) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) URI(java.net.URI) ServerImpl(io.smallrye.openapi.api.models.servers.ServerImpl) OpenApiConfig(io.smallrye.openapi.api.OpenApiConfig) Database(lotus.domino.Database) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) HashSet(java.util.HashSet)

Example 5 with NotesContext

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();
    }
}
Also used : NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext)

Aggregations

NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)6 NSFComponentModule (com.ibm.domino.xsp.module.nsf.NSFComponentModule)2 StringUtil (com.ibm.commons.util.StringUtil)1 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 NotesDatabase (com.ibm.designer.domino.napi.NotesDatabase)1 RuntimeFileSystem (com.ibm.domino.xsp.module.nsf.RuntimeFileSystem)1 ApplicationEx (com.ibm.xsp.application.ApplicationEx)1 OpenApiConfig (io.smallrye.openapi.api.OpenApiConfig)1 ServerImpl (io.smallrye.openapi.api.models.servers.ServerImpl)1 OpenApiProcessor (io.smallrye.openapi.runtime.OpenApiProcessor)1 Priority (jakarta.annotation.Priority)1 ServletException (jakarta.servlet.ServletException)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 FacesContext (javax.faces.context.FacesContext)1