Search in sources :

Example 1 with ServletBuildItem

use of io.quarkus.undertow.deployment.ServletBuildItem in project quarkus by vaadin.

the class VaadinQuarkusProcessor method registerUserServlets.

private void registerUserServlets(BuildProducer<ServletBuildItem> servletProducer, Collection<ClassInfo> vaadinServlets) {
    // TODO: check that we don't register 2 of the same mapping
    for (ClassInfo info : vaadinServlets) {
        final AnnotationInstance webServletInstance = info.classAnnotation(DotName.createSimple(WebServlet.class.getName()));
        String servletName = Optional.ofNullable(webServletInstance.value("name")).map(AnnotationValue::asString).orElse(info.name().toString());
        final ServletBuildItem.Builder servletBuildItem = ServletBuildItem.builder(servletName, info.name().toString());
        Stream.of(webServletInstance.value("value"), webServletInstance.value("urlPatterns")).filter(Objects::nonNull).flatMap(value -> Stream.of(value.asStringArray())).forEach(servletBuildItem::addMapping);
        addWebInitParameters(webServletInstance, servletBuildItem);
        setAsyncSupportedIfDefined(webServletInstance, servletBuildItem);
        servletProducer.produce(servletBuildItem.build());
    }
}
Also used : RouteContextWrapper(com.vaadin.quarkus.context.RouteContextWrapper) UIContextWrapper(com.vaadin.quarkus.context.UIContextWrapper) DotName(org.jboss.jandex.DotName) RouteScoped(com.vaadin.quarkus.annotation.RouteScoped) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) VaadinServiceScoped(com.vaadin.quarkus.annotation.VaadinServiceScoped) VaadinSessionScopedContext(com.vaadin.quarkus.context.VaadinSessionScopedContext) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) Route(com.vaadin.flow.router.Route) ServletBuildItem(io.quarkus.undertow.deployment.ServletBuildItem) NormalUIScoped(com.vaadin.quarkus.annotation.NormalUIScoped) BuildStep(io.quarkus.deployment.annotations.BuildStep) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) HasErrorParameter(com.vaadin.flow.router.HasErrorParameter) BeanArchiveIndexBuildItem(io.quarkus.arc.deployment.BeanArchiveIndexBuildItem) UIScoped(com.vaadin.quarkus.annotation.UIScoped) IndexView(org.jboss.jandex.IndexView) AnnotationValue(org.jboss.jandex.AnnotationValue) VaadinServiceScopedContext(com.vaadin.quarkus.context.VaadinServiceScopedContext) ContextRegistrationPhaseBuildItem(io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem) UIScopedContext(com.vaadin.quarkus.context.UIScopedContext) Collection(java.util.Collection) ContextConfiguratorBuildItem(io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem.ContextConfiguratorBuildItem) VaadinServlet(com.vaadin.flow.server.VaadinServlet) CustomScopeBuildItem(io.quarkus.arc.deployment.CustomScopeBuildItem) RouteScopedContext(com.vaadin.quarkus.context.RouteScopedContext) Collectors(java.util.stream.Collectors) WebServlet(javax.servlet.annotation.WebServlet) Objects(java.util.Objects) Stream(java.util.stream.Stream) AnnotationInstance(org.jboss.jandex.AnnotationInstance) BeanDefiningAnnotationBuildItem(io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem) NormalRouteScoped(com.vaadin.quarkus.annotation.NormalRouteScoped) Optional(java.util.Optional) VaadinSessionScoped(com.vaadin.quarkus.annotation.VaadinSessionScoped) QuarkusVaadinServlet(com.vaadin.quarkus.QuarkusVaadinServlet) ServletBuildItem(io.quarkus.undertow.deployment.ServletBuildItem) Objects(java.util.Objects) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with ServletBuildItem

use of io.quarkus.undertow.deployment.ServletBuildItem 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 ServletBuildItem

use of io.quarkus.undertow.deployment.ServletBuildItem in project quarkus by vaadin.

the class VaadinQuarkusProcessor method mapVaadinServletPaths.

@BuildStep
void mapVaadinServletPaths(final BeanArchiveIndexBuildItem beanArchiveIndex, final BuildProducer<ServletBuildItem> servletProducer) {
    final IndexView indexView = beanArchiveIndex.getIndex();
    // Collect all VaadinServlet instances and remove QuarkusVaadinServlet
    // and VaadinServlet from the list.
    final Collection<ClassInfo> vaadinServlets = indexView.getAllKnownSubclasses(DotName.createSimple(VaadinServlet.class.getName())).stream().filter(servlet -> !servlet.name().toString().equals(QuarkusVaadinServlet.class.getName()) && !servlet.name().toString().equals(VaadinServlet.class.getName())).collect(Collectors.toList());
    // If no VaadinServlet instances found register QuarkusVaadinServlet
    if (vaadinServlets.isEmpty()) {
        servletProducer.produce(ServletBuildItem.builder(QuarkusVaadinServlet.class.getName(), QuarkusVaadinServlet.class.getName()).addMapping("/*").setAsyncSupported(true).build());
    } else {
        registerUserServlets(servletProducer, vaadinServlets);
    }
}
Also used : RouteContextWrapper(com.vaadin.quarkus.context.RouteContextWrapper) UIContextWrapper(com.vaadin.quarkus.context.UIContextWrapper) DotName(org.jboss.jandex.DotName) RouteScoped(com.vaadin.quarkus.annotation.RouteScoped) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) VaadinServiceScoped(com.vaadin.quarkus.annotation.VaadinServiceScoped) VaadinSessionScopedContext(com.vaadin.quarkus.context.VaadinSessionScopedContext) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) Route(com.vaadin.flow.router.Route) ServletBuildItem(io.quarkus.undertow.deployment.ServletBuildItem) NormalUIScoped(com.vaadin.quarkus.annotation.NormalUIScoped) BuildStep(io.quarkus.deployment.annotations.BuildStep) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) HasErrorParameter(com.vaadin.flow.router.HasErrorParameter) BeanArchiveIndexBuildItem(io.quarkus.arc.deployment.BeanArchiveIndexBuildItem) UIScoped(com.vaadin.quarkus.annotation.UIScoped) IndexView(org.jboss.jandex.IndexView) AnnotationValue(org.jboss.jandex.AnnotationValue) VaadinServiceScopedContext(com.vaadin.quarkus.context.VaadinServiceScopedContext) ContextRegistrationPhaseBuildItem(io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem) UIScopedContext(com.vaadin.quarkus.context.UIScopedContext) Collection(java.util.Collection) ContextConfiguratorBuildItem(io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem.ContextConfiguratorBuildItem) VaadinServlet(com.vaadin.flow.server.VaadinServlet) CustomScopeBuildItem(io.quarkus.arc.deployment.CustomScopeBuildItem) RouteScopedContext(com.vaadin.quarkus.context.RouteScopedContext) Collectors(java.util.stream.Collectors) WebServlet(javax.servlet.annotation.WebServlet) Objects(java.util.Objects) Stream(java.util.stream.Stream) AnnotationInstance(org.jboss.jandex.AnnotationInstance) BeanDefiningAnnotationBuildItem(io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem) NormalRouteScoped(com.vaadin.quarkus.annotation.NormalRouteScoped) Optional(java.util.Optional) VaadinSessionScoped(com.vaadin.quarkus.annotation.VaadinSessionScoped) QuarkusVaadinServlet(com.vaadin.quarkus.QuarkusVaadinServlet) QuarkusVaadinServlet(com.vaadin.quarkus.QuarkusVaadinServlet) IndexView(org.jboss.jandex.IndexView) VaadinServlet(com.vaadin.flow.server.VaadinServlet) QuarkusVaadinServlet(com.vaadin.quarkus.QuarkusVaadinServlet) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)3 BeanDefiningAnnotationBuildItem (io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem)3 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)3 BuildStep (io.quarkus.deployment.annotations.BuildStep)3 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)3 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)3 ServletBuildItem (io.quarkus.undertow.deployment.ServletBuildItem)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 AnnotationInstance (org.jboss.jandex.AnnotationInstance)3 AnnotationValue (org.jboss.jandex.AnnotationValue)3 ClassInfo (org.jboss.jandex.ClassInfo)3 DotName (org.jboss.jandex.DotName)3 HasErrorParameter (com.vaadin.flow.router.HasErrorParameter)2 Route (com.vaadin.flow.router.Route)2 VaadinServlet (com.vaadin.flow.server.VaadinServlet)2 QuarkusVaadinServlet (com.vaadin.quarkus.QuarkusVaadinServlet)2 NormalRouteScoped (com.vaadin.quarkus.annotation.NormalRouteScoped)2 NormalUIScoped (com.vaadin.quarkus.annotation.NormalUIScoped)2 RouteScoped (com.vaadin.quarkus.annotation.RouteScoped)2