Search in sources :

Example 1 with ComponentModule

use of com.ibm.designer.runtime.domino.adapter.ComponentModule in project org.openntf.xsp.jakartaee by OpenNTF.

the class JAXRSServletFactory method getServletPath.

/**
 * Determines the effective base servlet path for the provided module.
 *
 * @param module the {@link ComponentModule} housing the servlet.
 * @return the base servlet path for JAX-RS, e.g. {@code "/xsp/.jaxrs/"}
 */
public static String getServletPath(ComponentModule module) {
    Map<String, Object> attrs = module.getAttributes();
    // Module attributes aren't reset on app refresh, so check here
    Object refresh = attrs.get(ATTR_REFRESH);
    if (refresh == null || (Long) refresh < module.getLastRefresh()) {
        attrs.remove(ATTR_PATH);
    }
    attrs.put(ATTR_REFRESH, module.getLastRefresh());
    String path = (String) attrs.computeIfAbsent(JAXRSServletFactory.class.getName() + "_path", key -> {
        // $NON-NLS-1$
        Properties props = new Properties();
        try (InputStream is = module.getResourceAsStream("/WEB-INF/xsp.properties")) {
            // $NON-NLS-1$
            if (is != null) {
                props.load(is);
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        return props.getProperty(PROP_SERVLET_PATH);
    });
    if (StringUtil.isEmpty(path)) {
        path = SERVLET_PATH_DEFAULT;
    }
    // $NON-NLS-1$
    path = PathUtil.concat("/xsp", path, '/');
    if (!path.endsWith("/")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        path += "/";
    }
    return path;
}
Also used : PathUtil(com.ibm.commons.util.PathUtil) ComponentModule(com.ibm.designer.runtime.domino.adapter.ComponentModule) Properties(java.util.Properties) ServletMatch(com.ibm.designer.runtime.domino.adapter.ServletMatch) ServletException(javax.servlet.ServletException) Servlet(javax.servlet.Servlet) FacesJAXRSServletContainer(org.openntf.xsp.jaxrs.impl.FacesJAXRSServletContainer) IOException(java.io.IOException) HashMap(java.util.HashMap) IServletFactory(com.ibm.designer.runtime.domino.adapter.IServletFactory) UncheckedIOException(java.io.UncheckedIOException) ResteasyContextParameters(org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters) StringUtil(com.ibm.commons.util.StringUtil) Map(java.util.Map) ServletUtil(org.openntf.xsp.jakartaee.servlet.ServletUtil) NSFJAXRSApplication(org.openntf.xsp.jaxrs.impl.NSFJAXRSApplication) InputStream(java.io.InputStream) InputStream(java.io.InputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Properties(java.util.Properties)

Example 2 with ComponentModule

use of com.ibm.designer.runtime.domino.adapter.ComponentModule in project openliberty-domino by OpenNTF.

the class ReverseProxyHttpService method notifyMessage.

@Override
public void notifyMessage(EventObject event) {
    if (event instanceof ReverseProxyConfigChangedEvent) {
        this.targets.values().forEach(ComponentModule::destroyModule);
        ReverseProxyConfig config = ((ReverseProxyConfigChangedEvent) event).getSource();
        this.enabled = config.isEnabled(this);
        this.targets = buildModules(config.getTargets());
    }
}
Also used : ReverseProxyConfig(org.openntf.openliberty.domino.reverseproxy.ReverseProxyConfig) ComponentModule(com.ibm.designer.runtime.domino.adapter.ComponentModule) ReverseProxyConfigChangedEvent(org.openntf.openliberty.domino.reverseproxy.event.ReverseProxyConfigChangedEvent)

Example 3 with ComponentModule

use of com.ibm.designer.runtime.domino.adapter.ComponentModule in project org.openntf.xsp.jakartaee by OpenNTF.

the class OldServletContextWrapper method getRequestDispatcher.

@Override
public RequestDispatcher getRequestDispatcher(String path) {
    // Unsupported on Domino, so try to replicate the behavior from the ComponentModule
    ServletMatch match = getServletFactories().stream().map(f -> {
        try {
            return f.getServletMatch(getContextPath(), path);
        } catch (javax.servlet.ServletException e) {
            throw new RuntimeException(e);
        }
    }).filter(Objects::nonNull).findFirst().orElse(null);
    if (match != null) {
        // TODO figure out if this behavior should change
        return new RequestDispatcher() {

            @Override
            public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
                Servlet servlet = ServletUtil.oldToNew(match.getServlet());
                servlet.service(request, response);
            }

            @Override
            public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException {
                Servlet servlet = ServletUtil.oldToNew(match.getServlet());
                servlet.service(request, response);
            }
        };
    }
    return null;
}
Also used : ComponentModule(com.ibm.designer.runtime.domino.adapter.ComponentModule) RequestDispatcher(jakarta.servlet.RequestDispatcher) ServletRegistration(jakarta.servlet.ServletRegistration) SessionCookieConfig(jakarta.servlet.SessionCookieConfig) Enumeration(java.util.Enumeration) URL(java.net.URL) Dynamic(jakarta.servlet.FilterRegistration.Dynamic) HashMap(java.util.HashMap) ServletContextAttributeListener(jakarta.servlet.ServletContextAttributeListener) IServletFactory(com.ibm.designer.runtime.domino.adapter.IServletFactory) ServletException(jakarta.servlet.ServletException) ArrayList(java.util.ArrayList) MappingBasedServletFactory(org.openntf.xsp.jakartaee.MappingBasedServletFactory) Filter(jakarta.servlet.Filter) JspPropertyGroupDescriptor(jakarta.servlet.descriptor.JspPropertyGroupDescriptor) Map(java.util.Map) ServletContextAttributeEvent(jakarta.servlet.ServletContextAttributeEvent) EnumSet(java.util.EnumSet) PrivilegedActionException(java.security.PrivilegedActionException) ServletMatch(com.ibm.designer.runtime.domino.adapter.ServletMatch) ServletRequest(jakarta.servlet.ServletRequest) MalformedURLException(java.net.MalformedURLException) Collection(java.util.Collection) Set(java.util.Set) SessionTrackingMode(jakarta.servlet.SessionTrackingMode) TaglibDescriptor(jakarta.servlet.descriptor.TaglibDescriptor) IOException(java.io.IOException) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) Field(java.lang.reflect.Field) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) EventListener(java.util.EventListener) List(java.util.List) Stream(java.util.stream.Stream) JspConfigDescriptor(jakarta.servlet.descriptor.JspConfigDescriptor) FilterRegistration(jakarta.servlet.FilterRegistration) ServletResponse(jakarta.servlet.ServletResponse) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) Servlet(jakarta.servlet.Servlet) ServletContext(jakarta.servlet.ServletContext) AccessController(java.security.AccessController) Collections(java.util.Collections) InputStream(java.io.InputStream) ServletException(jakarta.servlet.ServletException) ServletRequest(jakarta.servlet.ServletRequest) ServletResponse(jakarta.servlet.ServletResponse) ServletMatch(com.ibm.designer.runtime.domino.adapter.ServletMatch) Objects(java.util.Objects) Servlet(jakarta.servlet.Servlet) RequestDispatcher(jakarta.servlet.RequestDispatcher)

Aggregations

ComponentModule (com.ibm.designer.runtime.domino.adapter.ComponentModule)3 IServletFactory (com.ibm.designer.runtime.domino.adapter.IServletFactory)2 ServletMatch (com.ibm.designer.runtime.domino.adapter.ServletMatch)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 PathUtil (com.ibm.commons.util.PathUtil)1 StringUtil (com.ibm.commons.util.StringUtil)1 NSFComponentModule (com.ibm.domino.xsp.module.nsf.NSFComponentModule)1 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)1 Filter (jakarta.servlet.Filter)1 FilterRegistration (jakarta.servlet.FilterRegistration)1 Dynamic (jakarta.servlet.FilterRegistration.Dynamic)1 RequestDispatcher (jakarta.servlet.RequestDispatcher)1 Servlet (jakarta.servlet.Servlet)1 ServletContext (jakarta.servlet.ServletContext)1 ServletContextAttributeEvent (jakarta.servlet.ServletContextAttributeEvent)1 ServletContextAttributeListener (jakarta.servlet.ServletContextAttributeListener)1 ServletException (jakarta.servlet.ServletException)1