Search in sources :

Example 1 with FacesServlet

use of jakarta.faces.webapp.FacesServlet in project org.openntf.xsp.jakartaee by OpenNTF.

the class NSFJsfServlet method doInit.

public void doInit(HttpServletRequest req, ServletConfig config) throws ServletException {
    try {
        CDI<Object> cdi = ContainerUtil.getContainer(NotesContext.getCurrent().getNotesDatabase());
        ServletContext context = config.getServletContext();
        // $NON-NLS-1$
        context.setAttribute("jakarta.enterprise.inject.spi.BeanManager", ContainerUtil.getBeanManager(cdi));
        // TODO investigate why partial state saving doesn't work with a basic form
        // $NON-NLS-1$ //$NON-NLS-2$
        context.setInitParameter("jakarta.faces.PARTIAL_STATE_SAVING", "false");
        Properties props = LibraryUtil.getXspProperties(module);
        // $NON-NLS-1$
        String projectStage = props.getProperty(ProjectStage.PROJECT_STAGE_PARAM_NAME, "");
        context.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, projectStage);
        Bundle b = FrameworkUtil.getBundle(FacesServlet.class);
        {
            ServletContainerInitializer initializer = new MyFacesContainerInitializer();
            Set<Class<?>> classes = null;
            HandlesTypes types = initializer.getClass().getAnnotation(HandlesTypes.class);
            if (types != null) {
                classes = buildMatchingClasses(types, b);
            }
            initializer.onStartup(classes, getServletContext());
        }
        {
            // Re-wrap the ServletContext to provide the context path
            javax.servlet.ServletContext oldCtx = ServletUtil.newToOld(getServletContext());
            ServletContext ctx = ServletUtil.oldToNew(req.getContextPath(), oldCtx, 5, 0);
            ctx.addListener(StartupServletContextListener.class);
            ServletUtil.getListeners(ctx, ServletContextListener.class).forEach(l -> l.contextInitialized(new ServletContextEvent(ctx)));
        }
        this.delegate = new FacesServlet();
        delegate.init(config);
    } catch (NotesAPIException e) {
        throw new ServletException(e);
    }
}
Also used : StartupServletContextListener(org.apache.myfaces.webapp.StartupServletContextListener) ProjectStage(jakarta.faces.application.ProjectStage) ComponentModule(com.ibm.designer.runtime.domino.adapter.ComponentModule) CDI(jakarta.enterprise.inject.spi.CDI) XSPErrorPage(com.ibm.designer.runtime.domino.adapter.util.XSPErrorPage) ServletConfig(jakarta.servlet.ServletConfig) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) URL(java.net.URL) FacesServlet(jakarta.faces.webapp.FacesServlet) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) FacesContext(jakarta.faces.context.FacesContext) ServletException(jakarta.servlet.ServletException) ServletContainerInitializer(jakarta.servlet.ServletContainerInitializer) HttpSessionListener(jakarta.servlet.http.HttpSessionListener) HashSet(java.util.HashSet) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) HttpSession(jakarta.servlet.http.HttpSession) MyFacesContainerInitializer(org.apache.myfaces.webapp.MyFacesContainerInitializer) ServletUtil(org.openntf.xsp.jakartaee.servlet.ServletUtil) ModuleUtil(org.openntf.xsp.jakartaee.util.ModuleUtil) ServletRequestListener(jakarta.servlet.ServletRequestListener) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) LibraryUtil(org.openntf.xsp.jakartaee.util.LibraryUtil) HandlesTypes(jakarta.servlet.annotation.HandlesTypes) PrintWriter(java.io.PrintWriter) Properties(java.util.Properties) AbstractProxyingContext(org.openntf.xsp.cdi.context.AbstractProxyingContext) Set(java.util.Set) IOException(java.io.IOException) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) HttpServlet(jakarta.servlet.http.HttpServlet) List(java.util.List) HttpSessionEvent(jakarta.servlet.http.HttpSessionEvent) StringUtil(com.ibm.commons.util.StringUtil) ServletContextEvent(jakarta.servlet.ServletContextEvent) Annotation(java.lang.annotation.Annotation) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) DiscoveryUtil(org.openntf.xsp.cdi.util.DiscoveryUtil) ServletContext(jakarta.servlet.ServletContext) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) AccessController(java.security.AccessController) ServletRequestEvent(jakarta.servlet.ServletRequestEvent) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) ContainerUtil(org.openntf.xsp.cdi.util.ContainerUtil) ServletContextListener(jakarta.servlet.ServletContextListener) HashSet(java.util.HashSet) Set(java.util.Set) Bundle(org.osgi.framework.Bundle) FacesServlet(jakarta.faces.webapp.FacesServlet) Properties(java.util.Properties) MyFacesContainerInitializer(org.apache.myfaces.webapp.MyFacesContainerInitializer) ServletContainerInitializer(jakarta.servlet.ServletContainerInitializer) ServletException(jakarta.servlet.ServletException) ServletContext(jakarta.servlet.ServletContext) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) HandlesTypes(jakarta.servlet.annotation.HandlesTypes) ServletContextEvent(jakarta.servlet.ServletContextEvent) StartupServletContextListener(org.apache.myfaces.webapp.StartupServletContextListener)

Example 2 with FacesServlet

use of jakarta.faces.webapp.FacesServlet in project myfaces by apache.

the class MyFacesProcessor method buildServlet.

@BuildStep
void buildServlet(WebMetadataBuildItem webMetaDataBuildItem, BuildProducer<FeatureBuildItem> feature, BuildProducer<ServletBuildItem> servlet, BuildProducer<ListenerBuildItem> listener) throws IOException {
    WebMetaData webMetaData = webMetaDataBuildItem.getWebMetaData();
    ServletMetaData facesServlet = null;
    if (webMetaData.getServlets() != null) {
        facesServlet = webMetaData.getServlets().stream().filter(servletMeta -> FacesServlet.class.getName().equals(servletMeta.getServletClass())).findFirst().orElse(null);
    }
    if (facesServlet == null) {
        // Only define here if not explictly defined in web.xml
        servlet.produce(ServletBuildItem.builder("Faces Servlet", FacesServlet.class.getName()).setMultipartConfig(new MultipartConfigElement("")).addMapping("*.xhtml").build());
    }
    // sometimes Quarkus doesn't scan web-fragments?! lets add it manually
    listener.produce(new ListenerBuildItem(StartupServletContextListener.class.getName()));
}
Also used : MyFacesRecorder(org.apache.myfaces.core.extensions.quarkus.runtime.MyFacesRecorder) Arrays(java.util.Arrays) Produces(javax.enterprise.inject.Produces) FacesValidator(jakarta.faces.validator.FacesValidator) FieldInfo(org.jboss.jandex.FieldInfo) WebMetaData(org.jboss.metadata.web.spec.WebMetaData) FlowBuilderFactoryBean(org.apache.myfaces.flow.cdi.FlowBuilderFactoryBean) WebsocketChannelTokenBuilderBean(org.apache.myfaces.push.cdi.WebsocketChannelTokenBuilderBean) ServletBuildItem(io.quarkus.undertow.deployment.ServletBuildItem) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) StateManager(jakarta.faces.application.StateManager) ClassUtils(org.apache.myfaces.util.lang.ClassUtils) FacesConverter(jakarta.faces.convert.FacesConverter) ConverterHandler(jakarta.faces.view.facelets.ConverterHandler) MyFacesContainerInitializer(org.apache.myfaces.webapp.MyFacesContainerInitializer) QuarkusFacesScopeContext(org.apache.myfaces.core.extensions.quarkus.runtime.scopes.QuarkusFacesScopeContext) ErrorPageWriter(org.apache.myfaces.renderkit.ErrorPageWriter) BeanEntry(org.apache.myfaces.cdi.util.BeanEntry) AnnotationValue(org.jboss.jandex.AnnotationValue) NativeImageResourceBundleBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem) SystemEvent(jakarta.faces.event.SystemEvent) DefaultELResolverBuilder(org.apache.myfaces.el.DefaultELResolverBuilder) WebsocketApplicationBean(org.apache.myfaces.push.cdi.WebsocketApplicationBean) ExpressionFactoryImpl(org.apache.el.ExpressionFactoryImpl) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ComponentSupport(org.apache.myfaces.view.facelets.tag.faces.ComponentSupport) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) FacesDataModel(jakarta.faces.model.FacesDataModel) Converter(jakarta.faces.convert.Converter) JsfArtifactProducer(org.apache.myfaces.cdi.JsfArtifactProducer) StartupServletContextListener(org.apache.myfaces.webapp.StartupServletContextListener) SAXCompiler(org.apache.myfaces.view.facelets.compiler.SAXCompiler) Record(io.quarkus.deployment.annotations.Record) ServletMetaData(org.jboss.metadata.web.spec.ServletMetaData) QuarkusFacesInitilializer(org.apache.myfaces.core.extensions.quarkus.runtime.QuarkusFacesInitilializer) DotName(org.jboss.jandex.DotName) ValidatorHandler(jakarta.faces.view.facelets.ValidatorHandler) ServletInitParamBuildItem(io.quarkus.undertow.deployment.ServletInitParamBuildItem) FacesContext(jakarta.faces.context.FacesContext) ApplicationImplEventManager(org.apache.myfaces.application.ApplicationImplEventManager) MethodRule(org.apache.myfaces.view.facelets.tag.MethodRule) ArrayList(java.util.ArrayList) ExternalContextUtils(org.apache.myfaces.util.ExternalContextUtils) DefaultWebConfigProviderFactory(org.apache.myfaces.spi.impl.DefaultWebConfigProviderFactory) FlowDefinition(jakarta.faces.flow.builder.FlowDefinition) PropertyDescriptorUtils(org.apache.myfaces.core.api.shared.lang.PropertyDescriptorUtils) ViewScopeProxyMap(org.apache.myfaces.view.ViewScopeProxyMap) DefaultFacesInitilializer(org.apache.myfaces.webapp.DefaultFacesInitilializer) Named(javax.inject.Named) Validator(jakarta.faces.validator.Validator) FacesComponent(jakarta.faces.component.FacesComponent) ClientBehaviorRenderer(jakarta.faces.render.ClientBehaviorRenderer) ViewScopeBeanHolder(org.apache.myfaces.cdi.view.ViewScopeBeanHolder) IOException(java.io.IOException) FacesConfigBeanHolder(org.apache.myfaces.cdi.config.FacesConfigBeanHolder) QuarkusViewTransientScopeContext(org.apache.myfaces.core.extensions.quarkus.runtime.scopes.QuarkusViewTransientScopeContext) ELResolver(javax.el.ELResolver) ViewHandler(jakarta.faces.application.ViewHandler) QuarkusExceptionHandlerFactory(org.apache.myfaces.core.extensions.quarkus.runtime.exception.QuarkusExceptionHandlerFactory) AbstractFacesInitializer(org.apache.myfaces.webapp.AbstractFacesInitializer) WebsocketViewBean(org.apache.myfaces.push.cdi.WebsocketViewBean) ComponentHandler(jakarta.faces.view.facelets.ComponentHandler) BeanDefiningAnnotationBuildItem(io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem) ContextRegistrarBuildItem(io.quarkus.arc.deployment.ContextRegistrarBuildItem) NamedEvent(org.apache.myfaces.config.element.NamedEvent) FacesRenderer(jakarta.faces.render.FacesRenderer) FaceletsResourceResolver(jakarta.faces.view.facelets.FaceletsResourceResolver) FacesBehaviorRenderer(jakarta.faces.render.FacesBehaviorRenderer) ListenerBuildItem(io.quarkus.undertow.deployment.ListenerBuildItem) ClassInfo(org.jboss.jandex.ClassInfo) QuarkusInjectionProvider(org.apache.myfaces.core.extensions.quarkus.runtime.spi.QuarkusInjectionProvider) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) MethodInfo(org.jboss.jandex.MethodInfo) CdiAnnotationProviderExtension(org.apache.myfaces.config.annotation.CdiAnnotationProviderExtension) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) ExceptionQueuedEventContext(jakarta.faces.event.ExceptionQueuedEventContext) AnnotationTarget(org.jboss.jandex.AnnotationTarget) BeanRegistrationPhaseBuildItem(io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem) MetaRuleset(jakarta.faces.view.facelets.MetaRuleset) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) FacesBehavior(jakarta.faces.component.behavior.FacesBehavior) Config(org.eclipse.microprofile.config.Config) MultipartConfigElement(javax.servlet.MultipartConfigElement) Collectors(java.util.stream.Collectors) FacesConfigurator(org.apache.myfaces.config.FacesConfigurator) FlowScoped(jakarta.faces.flow.FlowScoped) StateUtils(org.apache.myfaces.application.viewstate.StateUtils) Behavior(jakarta.faces.component.behavior.Behavior) List(java.util.List) FactoryFinder(jakarta.faces.FactoryFinder) LambdaBeanELResolver(org.apache.myfaces.el.resolver.LambdaBeanELResolver) BeanRegistrarBuildItem(io.quarkus.arc.deployment.BeanRegistrarBuildItem) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) LambdaMetadataTargetImpl(org.apache.myfaces.view.facelets.tag.LambdaMetadataTargetImpl) TagHandler(jakarta.faces.view.facelets.TagHandler) QuarkusFactoryFinderProvider(org.apache.myfaces.core.extensions.quarkus.runtime.spi.QuarkusFactoryFinderProvider) ProjectStage(jakarta.faces.application.ProjectStage) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) Renderer(jakarta.faces.render.Renderer) FacesServlet(jakarta.faces.webapp.FacesServlet) ViewScoped(jakarta.faces.view.ViewScoped) Type(org.jboss.jandex.Type) LaunchMode(io.quarkus.runtime.LaunchMode) JsfApplicationArtifactHolder(org.apache.myfaces.cdi.JsfApplicationArtifactHolder) WebMetadataBuildItem(io.quarkus.undertow.deployment.WebMetadataBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) FactoryFinderProviderFactory(org.apache.myfaces.spi.FactoryFinderProviderFactory) FacesDataModelManager(org.apache.myfaces.cdi.model.FacesDataModelManager) ViewTransientScoped(org.apache.myfaces.cdi.view.ViewTransientScoped) AdditionalApplicationArchiveMarkerBuildItem(io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem) Application(jakarta.faces.application.Application) WebsocketSessionBean(org.apache.myfaces.push.cdi.WebsocketSessionBean) RuntimeInitializedClassBuildItem(io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem) FlowScopeBeanHolder(org.apache.myfaces.flow.cdi.FlowScopeBeanHolder) MyfacesConfig(org.apache.myfaces.config.MyfacesConfig) QuarkusFlowScopedContext(org.apache.myfaces.core.extensions.quarkus.runtime.scopes.QuarkusFlowScopedContext) UIComponent(jakarta.faces.component.UIComponent) PushContextFactoryBean(org.apache.myfaces.push.cdi.PushContextFactoryBean) ProfileManager(io.quarkus.runtime.configuration.ProfileManager) QuarkusViewScopeContext(org.apache.myfaces.core.extensions.quarkus.runtime.scopes.QuarkusViewScopeContext) FacesScoped(org.apache.myfaces.cdi.FacesScoped) TagLibraryConfig(org.apache.myfaces.view.facelets.compiler.TagLibraryConfig) MultipartConfigElement(javax.servlet.MultipartConfigElement) FacesServlet(jakarta.faces.webapp.FacesServlet) ServletMetaData(org.jboss.metadata.web.spec.ServletMetaData) WebMetaData(org.jboss.metadata.web.spec.WebMetaData) ListenerBuildItem(io.quarkus.undertow.deployment.ListenerBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with FacesServlet

use of jakarta.faces.webapp.FacesServlet in project mojarra by eclipse-ee4j.

the class FacesServletTestCase method testPositiveInitWithNoContextParams.

public void testPositiveInitWithNoContextParams() throws Exception {
    FacesServlet me = new FacesServlet();
    me.init(config);
    this.sendRequest(me, "OPTIONS");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "GET");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "HEAD");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "POST");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "PUT");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "DELETE");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "TRACE");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "CONNECT");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
}
Also used : FacesServlet(jakarta.faces.webapp.FacesServlet)

Example 4 with FacesServlet

use of jakarta.faces.webapp.FacesServlet in project mojarra by eclipse-ee4j.

the class FacesServletTestCase method testNegativeInitWithContextParamsOfKnownHttpMethods.

public void testNegativeInitWithContextParamsOfKnownHttpMethods() throws Exception {
    FacesServlet me = new FacesServlet();
    servletContext.addInitParameter(ALLOWED_HTTP_METHODS_ATTR_COPY, "GET   POST GET  POST");
    me.init(config);
    this.sendRequest(me, "OPTIONS");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "GET");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "HEAD");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "POST");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "PUT");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "DELETE");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "TRACE");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "CONNECT");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
}
Also used : FacesServlet(jakarta.faces.webapp.FacesServlet)

Example 5 with FacesServlet

use of jakarta.faces.webapp.FacesServlet in project mojarra by eclipse-ee4j.

the class FacesServletTestCase method testPositiveInitWithContextParamsOfUnknownAndKnownHttpMethods.

public void testPositiveInitWithContextParamsOfUnknownAndKnownHttpMethods() throws Exception {
    FacesServlet me = new FacesServlet();
    servletContext.addInitParameter(ALLOWED_HTTP_METHODS_ATTR_COPY, "GET\tPOST\tGETAAAAA");
    me.init(config);
    this.sendRequest(me, "OPTIONS");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "GET");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "HEAD");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "POST");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    this.sendRequest(me, "PUT");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "DELETE");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "TRACE");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "CONNECT");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "BOO_YA");
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
    this.sendRequest(me, "GETAAAAA");
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
}
Also used : FacesServlet(jakarta.faces.webapp.FacesServlet)

Aggregations

FacesServlet (jakarta.faces.webapp.FacesServlet)9 ProjectStage (jakarta.faces.application.ProjectStage)2 FacesContext (jakarta.faces.context.FacesContext)2 IOException (java.io.IOException)2 List (java.util.List)2 MyFacesContainerInitializer (org.apache.myfaces.webapp.MyFacesContainerInitializer)2 StartupServletContextListener (org.apache.myfaces.webapp.StartupServletContextListener)2 StringUtil (com.ibm.commons.util.StringUtil)1 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 ComponentModule (com.ibm.designer.runtime.domino.adapter.ComponentModule)1 XSPErrorPage (com.ibm.designer.runtime.domino.adapter.util.XSPErrorPage)1 NSFComponentModule (com.ibm.domino.xsp.module.nsf.NSFComponentModule)1 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)1 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)1 BeanDefiningAnnotationBuildItem (io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem)1 BeanRegistrarBuildItem (io.quarkus.arc.deployment.BeanRegistrarBuildItem)1 BeanRegistrationPhaseBuildItem (io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem)1 ContextRegistrarBuildItem (io.quarkus.arc.deployment.ContextRegistrarBuildItem)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1