Search in sources :

Example 1 with DelegatingClassLoader

use of org.openntf.xsp.jakartaee.DelegatingClassLoader in project org.openntf.xsp.jakartaee by OpenNTF.

the class NSFJsfServlet method buildJsfClassLoader.

// *******************************************************************************
// * Internal utility methods
// *******************************************************************************
private synchronized ClassLoader buildJsfClassLoader(ServletContext context, ClassLoader delegate) throws BundleException, IOException {
    if (context.getAttribute(PROP_CLASSLOADER) == null) {
        ClassLoader apiCl = FacesContext.class.getClassLoader();
        ClassLoader implCl = MyFacesContainerInitializer.class.getClassLoader();
        ClassLoader cl = new DelegatingClassLoader(apiCl, implCl, delegate) {

            @Override
            public Class<?> loadClass(String name) throws ClassNotFoundException {
                if (name != null && name.startsWith("com.sun.faces.")) {
                    // $NON-NLS-1$
                    throw new ClassNotFoundException();
                }
                return super.loadClass(name);
            }
        };
        context.setAttribute(PROP_CLASSLOADER, cl);
    }
    return (ClassLoader) context.getAttribute(PROP_CLASSLOADER);
}
Also used : DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader)

Example 2 with DelegatingClassLoader

use of org.openntf.xsp.jakartaee.DelegatingClassLoader 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)

Aggregations

DelegatingClassLoader (org.openntf.xsp.jakartaee.DelegatingClassLoader)2 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)1 OpenApiConfig (io.smallrye.openapi.api.OpenApiConfig)1 ServerImpl (io.smallrye.openapi.api.models.servers.ServerImpl)1 OpenApiProcessor (io.smallrye.openapi.runtime.OpenApiProcessor)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Database (lotus.domino.Database)1 Config (org.eclipse.microprofile.config.Config)1 OpenAPI (org.eclipse.microprofile.openapi.models.OpenAPI)1 Info (org.eclipse.microprofile.openapi.models.info.Info)1 Server (org.eclipse.microprofile.openapi.models.servers.Server)1 Index (org.jboss.jandex.Index)1