1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.webapp;
20
21 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
22 import org.apache.myfaces.config.FacesConfigValidator;
23 import org.apache.myfaces.config.FacesConfigurator;
24 import org.apache.myfaces.config.ManagedBeanBuilder;
25 import org.apache.myfaces.config.RuntimeConfig;
26 import org.apache.myfaces.config.element.ManagedBean;
27 import org.apache.myfaces.context.ReleaseableExternalContext;
28 import org.apache.myfaces.context.servlet.StartupFacesContextImpl;
29 import org.apache.myfaces.context.servlet.StartupServletExternalContextImpl;
30 import org.apache.myfaces.ee.MyFacesContainerInitializer;
31 import org.apache.myfaces.shared.application.FacesServletMappingUtils;
32 import org.apache.myfaces.shared.context.ExceptionHandlerImpl;
33 import org.apache.myfaces.shared.util.StateUtils;
34 import org.apache.myfaces.shared.util.WebConfigParamUtils;
35 import org.apache.myfaces.cdi.util.BeanEntry;
36 import org.apache.myfaces.spi.InjectionProvider;
37 import org.apache.myfaces.spi.InjectionProviderException;
38 import org.apache.myfaces.spi.InjectionProviderFactory;
39 import org.apache.myfaces.spi.ViewScopeProvider;
40 import org.apache.myfaces.spi.ViewScopeProviderFactory;
41 import org.apache.myfaces.spi.WebConfigProvider;
42 import org.apache.myfaces.spi.WebConfigProviderFactory;
43 import org.apache.myfaces.util.ExternalSpecifications;
44 import org.apache.myfaces.view.facelets.tag.MetaRulesetImpl;
45
46 import javax.el.ExpressionFactory;
47 import javax.faces.application.Application;
48 import javax.faces.application.ProjectStage;
49 import javax.faces.component.UIViewRoot;
50 import javax.faces.context.ExceptionHandler;
51 import javax.faces.context.ExternalContext;
52 import javax.faces.context.FacesContext;
53 import javax.faces.event.PostConstructApplicationEvent;
54 import javax.faces.event.PreDestroyApplicationEvent;
55 import javax.faces.event.SystemEvent;
56 import javax.servlet.ServletContext;
57 import java.lang.reflect.InvocationTargetException;
58 import java.lang.reflect.Method;
59 import java.util.ArrayList;
60 import java.util.List;
61 import java.util.Locale;
62 import java.util.Map;
63 import java.util.logging.Level;
64 import java.util.logging.Logger;
65 import javax.faces.application.ViewVisitOption;
66 import javax.faces.push.PushContext;
67 import javax.servlet.ServletRegistration;
68 import javax.websocket.DeploymentException;
69 import javax.websocket.server.ServerContainer;
70 import javax.websocket.server.ServerEndpointConfig;
71 import org.apache.myfaces.push.EndpointImpl;
72 import org.apache.myfaces.push.WebsocketConfigurator;
73 import org.apache.myfaces.push.WebsocketFacesInit;
74 import org.apache.myfaces.shared.util.ClassUtils;
75 import org.apache.myfaces.spi.ServiceProviderFinder;
76 import org.apache.myfaces.spi.ServiceProviderFinderFactory;
77 import org.apache.myfaces.view.facelets.ViewPoolProcessor;
78
79
80
81
82 public abstract class AbstractFacesInitializer implements FacesInitializer
83 {
84 private static final Logger log = Logger.getLogger(AbstractFacesInitializer.class.getName());
85
86
87
88
89 @JSFWebConfigParam(since="1.2.7", group="EL")
90 protected static final String EXPRESSION_FACTORY = "org.apache.myfaces.EXPRESSION_FACTORY";
91
92
93
94
95 @JSFWebConfigParam(since="2.0.3", defaultValue="false")
96 protected static final String INITIALIZE_ALWAYS_STANDALONE = "org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE";
97
98
99
100
101
102
103
104 @JSFWebConfigParam(expectedValues="true, auto, false", defaultValue="auto")
105 public static final String INIT_PARAM_LOG_WEB_CONTEXT_PARAMS = "org.apache.myfaces.LOG_WEB_CONTEXT_PARAMS";
106 public static final String INIT_PARAM_LOG_WEB_CONTEXT_PARAMS_DEFAULT ="auto";
107
108
109
110
111 @JSFWebConfigParam(since="2.3", expectedValues = "true, false", defaultValue = "false")
112 public static final String INIT_PARAM_AUTOMATIC_EXTENSIONLESS_MAPPING =
113 "org.apache.myfaces.AUTOMATIC_EXTENSIONLESS_MAPPING";
114 public static final boolean INIT_PARAM_AUTOMATIC_EXTENSIONLESS_MAPPING_DEFAULT = false;
115
116 public static final String CDI_BEAN_MANAGER_INSTANCE = "oam.cdi.BEAN_MANAGER_INSTANCE";
117
118 private static final String CDI_SERVLET_CONTEXT_BEAN_MANAGER_ATTRIBUTE =
119 "javax.enterprise.inject.spi.BeanManager";
120
121 private static final String INJECTED_BEAN_STORAGE_KEY = "org.apache.myfaces.spi.BEAN_ENTRY_STORAGE";
122
123
124
125
126
127 @Override
128 public void initFaces(ServletContext servletContext)
129 {
130 try
131 {
132 if (log.isLoggable(Level.FINEST))
133 {
134 log.finest("Initializing MyFaces");
135 }
136
137
138
139
140
141
142
143 FacesContext facesContext = FacesContext.getCurrentInstance();
144 ExternalContext externalContext = facesContext.getExternalContext();
145
146
147 ServiceProviderFinder spf = ServiceProviderFinderFactory.getServiceProviderFinder(
148 externalContext);
149 Map<String, List<String>> spfConfig = spf.calculateKnownServiceProviderMapInfo(
150 externalContext, ServiceProviderFinder.KNOWN_SERVICES);
151 if (spfConfig != null)
152 {
153 spf.initKnownServiceProviderMapInfo(externalContext, spfConfig);
154 }
155
156
157
158 if (!WebConfigParamUtils.getBooleanInitParameter(externalContext, INITIALIZE_ALWAYS_STANDALONE, false))
159 {
160 WebConfigProvider webConfigProvider = WebConfigProviderFactory.getWebConfigProviderFactory(
161 facesContext.getExternalContext()).getWebConfigProvider(facesContext.getExternalContext());
162
163 if (webConfigProvider.getFacesServletMappings(facesContext.getExternalContext()).isEmpty())
164 {
165
166 Boolean mappingAdded = (Boolean) servletContext.getAttribute(
167 MyFacesContainerInitializer.FACES_SERVLET_FOUND);
168
169 if (mappingAdded == null || !mappingAdded)
170 {
171
172
173 mappingAdded = (Boolean) servletContext.getAttribute(
174 MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
175
176 if (mappingAdded == null || !mappingAdded)
177 {
178 if (log.isLoggable(Level.WARNING))
179 {
180 log.warning("No mappings of FacesServlet found. Abort initializing MyFaces.");
181 }
182 return;
183 }
184 }
185 }
186 }
187
188 initCDIIntegration(servletContext, externalContext);
189
190 initContainerIntegration(servletContext, externalContext);
191
192 ViewScopeProviderFactory factory = ViewScopeProviderFactory.getViewScopeHandlerFactory(
193 externalContext);
194
195 ViewScopeProvider viewScopeHandler = factory.getViewScopeHandler(
196 externalContext);
197
198 ManagedBeanDestroyerListener listener = (ManagedBeanDestroyerListener)
199 externalContext.getApplicationMap().get(
200 ManagedBeanDestroyerListener.APPLICATION_MAP_KEY);
201 if (listener != null)
202 {
203 listener.setViewScopeHandler(viewScopeHandler);
204 }
205
206 String useEncryption = servletContext.getInitParameter(StateUtils.USE_ENCRYPTION);
207 if ("false".equals(useEncryption))
208 {
209 log.warning(StateUtils.USE_ENCRYPTION + " is set to false. "
210 + "This is unsecure and should only be used for local or intranet applications!");
211 }
212 else
213 {
214 StateUtils.initSecret(servletContext);
215 }
216
217
218 _createEagerBeans(facesContext);
219
220 _dispatchApplicationEvent(servletContext, PostConstructApplicationEvent.class);
221
222 initWebsocketIntegration(servletContext, externalContext);
223
224 if ( (facesContext.isProjectStage(ProjectStage.Development) ||
225 facesContext.isProjectStage(ProjectStage.Production)) &&
226 log.isLoggable(Level.INFO))
227 {
228 log.info("ServletContext initialized.");
229 }
230
231 WebConfigParamsLogger.logWebContextParams(facesContext);
232
233 checkForDeprecatedContextParams(facesContext);
234
235
236 ExternalSpecifications.isBeanValidationAvailable();
237
238
239 ViewPoolProcessor.initialize(facesContext);
240
241 Boolean automaticExtensionlessMapping = WebConfigParamUtils.getBooleanInitParameter(
242 externalContext, INIT_PARAM_AUTOMATIC_EXTENSIONLESS_MAPPING,
243 INIT_PARAM_AUTOMATIC_EXTENSIONLESS_MAPPING_DEFAULT);
244 if (Boolean.TRUE.equals(automaticExtensionlessMapping))
245 {
246 initAutomaticExtensionlessMapping(facesContext, servletContext);
247 }
248
249
250 if (!facesContext.isProjectStage(ProjectStage.Production) &&
251 !facesContext.isProjectStage(ProjectStage.UnitTest))
252 {
253 ProjectStage projectStage = facesContext.getApplication().getProjectStage();
254 StringBuilder message = new StringBuilder("\n\n");
255 message.append("*******************************************************************\n");
256 message.append("*** WARNING: Apache MyFaces-2 is running in ");
257 message.append(projectStage.name().toUpperCase());
258 message.append(" mode.");
259 int length = projectStage.name().length();
260 for (int i = 0; i < 11 - length; i++)
261 {
262 message.append(" ");
263 }
264 message.append(" ***\n");
265 message.append("*** ");
266 for (int i = 0; i < length; i++)
267 {
268 message.append("^");
269 }
270 for (int i = 0; i < 20 - length; i++)
271 {
272 message.append(" ");
273 }
274 message.append("***\n");
275 message.append("*** Do NOT deploy to your live server(s) without changing this. ***\n");
276 message.append("*** See Application#getProjectStage() for more information. ***\n");
277 message.append("*******************************************************************\n");
278 log.log(Level.WARNING, message.toString());
279 }
280
281 }
282 catch (Exception ex)
283 {
284 log.log(Level.SEVERE, "An error occured while initializing MyFaces: "
285 + ex.getMessage(), ex);
286 }
287 }
288
289
290
291
292
293
294 private void _createEagerBeans(FacesContext facesContext)
295 {
296 ExternalContext externalContext = facesContext.getExternalContext();
297 RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
298 List<ManagedBean> eagerBeans = new ArrayList<ManagedBean>();
299
300
301 for (ManagedBean bean : runtimeConfig.getManagedBeans().values())
302 {
303 String eager = bean.getEager();
304 if (eager != null && "true".equals(eager))
305 {
306
307 if (ManagedBeanBuilder.APPLICATION.equals(bean.getManagedBeanScope()))
308 {
309
310 eagerBeans.add(bean);
311 }
312 else
313 {
314
315 log.log(Level.WARNING, "The managed-bean with name "
316 + bean.getManagedBeanName()
317 + " must be application scoped to support eager=true.");
318 }
319 }
320 }
321
322
323 if (!eagerBeans.isEmpty())
324 {
325 ManagedBeanBuilder managedBeanBuilder = new ManagedBeanBuilder();
326 Map<String, Object> applicationMap = externalContext.getApplicationMap();
327
328 for (ManagedBean bean : eagerBeans)
329 {
330
331 if (applicationMap.containsKey(bean.getManagedBeanName()))
332 {
333
334
335 continue;
336 }
337
338
339 Object beanInstance = managedBeanBuilder.buildManagedBean(facesContext, bean);
340
341
342 applicationMap.put(bean.getManagedBeanName(), beanInstance);
343 }
344 }
345 }
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362 private void _dispatchApplicationEvent(ServletContext servletContext, Class<? extends SystemEvent> eventClass)
363 {
364 FacesContext facesContext = FacesContext.getCurrentInstance();
365 Application application = facesContext.getApplication();
366 application.publishEvent(facesContext, eventClass, Application.class, application);
367 }
368
369
370
371
372 @Override
373 public void destroyFaces(ServletContext servletContext)
374 {
375
376 FacesContext facesContext = FacesContext.getCurrentInstance();
377
378 if (!WebConfigParamUtils.getBooleanInitParameter(facesContext.getExternalContext(),
379 INITIALIZE_ALWAYS_STANDALONE, false))
380 {
381
382 WebConfigProvider webConfigProvider = WebConfigProviderFactory.getWebConfigProviderFactory(
383 facesContext.getExternalContext()).getWebConfigProvider(facesContext.getExternalContext());
384
385 if (webConfigProvider.getFacesServletMappings(facesContext.getExternalContext()).isEmpty())
386 {
387
388 Boolean mappingAdded = (Boolean) servletContext.getAttribute(
389 MyFacesContainerInitializer.FACES_SERVLET_FOUND);
390
391 if (mappingAdded == null || !mappingAdded)
392 {
393
394
395 mappingAdded = (Boolean) servletContext.getAttribute(
396 MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
397
398 if (mappingAdded == null || !mappingAdded)
399 {
400 if (log.isLoggable(Level.WARNING))
401 {
402 log.warning("No mappings of FacesServlet found. Abort destroy MyFaces.");
403 }
404 return;
405 }
406 }
407 }
408 }
409
410 _dispatchApplicationEvent(servletContext, PreDestroyApplicationEvent.class);
411
412 _callPreDestroyOnInjectedJSFArtifacts(facesContext);
413
414
415 MetaRulesetImpl.clearMetadataTargetCache();
416
417 if (facesContext.getExternalContext().getApplicationMap().containsKey("org.apache.myfaces.push"))
418 {
419 WebsocketFacesInit.clearWebsocketSessionLRUCache(facesContext.getExternalContext());
420 }
421
422
423 try
424 {
425 Class<?> c = Class.forName("javax.faces.component.UIViewParameter");
426 Method m = c.getDeclaredMethod("releaseRenderer");
427 m.setAccessible(true);
428 m.invoke(null);
429 }
430 catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e)
431 {
432 log.log(Level.SEVERE, e.getMessage(), e);
433 }
434
435
436
437 }
438
439
440
441
442
443
444
445
446
447
448
449 protected RuntimeConfig buildConfiguration(ServletContext servletContext,
450 ExternalContext externalContext, ExpressionFactory expressionFactory)
451 {
452 RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
453 runtimeConfig.setExpressionFactory(expressionFactory);
454
455
456 new FacesConfigurator(externalContext).configure();
457
458 validateFacesConfig(servletContext, externalContext);
459
460 return runtimeConfig;
461 }
462
463 protected void validateFacesConfig(ServletContext servletContext, ExternalContext externalContext)
464 {
465 String validate = servletContext.getInitParameter(FacesConfigValidator.VALIDATE_CONTEXT_PARAM);
466 if ("true".equals(validate) && log.isLoggable(Level.WARNING))
467 {
468 List<String> warnings = FacesConfigValidator.validate(
469 externalContext);
470
471 for (String warning : warnings)
472 {
473 log.warning(warning);
474 }
475 }
476 }
477
478
479
480
481
482
483
484
485
486 protected static ExpressionFactory getUserDefinedExpressionFactory(ExternalContext externalContext)
487 {
488 String expressionFactoryClassName
489 = WebConfigParamUtils.getStringInitParameter(externalContext, EXPRESSION_FACTORY);
490 if (expressionFactoryClassName != null
491 && expressionFactoryClassName.trim().length() > 0)
492 {
493 if (log.isLoggable(Level.FINE))
494 {
495 log.fine("Attempting to load the ExpressionFactory implementation "
496 + "you've specified: '" + expressionFactoryClassName + "'.");
497 }
498
499 return loadExpressionFactory(expressionFactoryClassName);
500 }
501
502 return null;
503 }
504
505
506
507
508
509
510
511
512 protected static ExpressionFactory loadExpressionFactory(String expressionFactoryClassName)
513 {
514 return loadExpressionFactory(expressionFactoryClassName, true);
515 }
516
517 protected static ExpressionFactory loadExpressionFactory(String expressionFactoryClassName, boolean logMissing)
518 {
519 try
520 {
521 ClassLoader cl = ClassUtils.getContextClassLoader();
522 if (cl == null)
523 {
524 cl = AbstractFacesInitializer.class.getClassLoader();
525 }
526
527 Class<?> expressionFactoryClass = cl.loadClass(expressionFactoryClassName);
528 return (ExpressionFactory) expressionFactoryClass.newInstance();
529 }
530 catch (Exception ex)
531 {
532 if (log.isLoggable(Level.FINE))
533 {
534 log.log(Level.FINE, "An error occured while instantiating a new ExpressionFactory. "
535 + "Attempted to load class '" + expressionFactoryClassName + "'.", ex);
536 }
537 }
538
539 return null;
540 }
541
542 @Override
543 public FacesContext initStartupFacesContext(ServletContext servletContext)
544 {
545
546
547 return _createFacesContext(servletContext, true);
548 }
549
550 @Override
551 public void destroyStartupFacesContext(FacesContext facesContext)
552 {
553 _releaseFacesContext(facesContext);
554 }
555
556 @Override
557 public FacesContext initShutdownFacesContext(ServletContext servletContext)
558 {
559 return _createFacesContext(servletContext, false);
560 }
561
562 @Override
563 public void destroyShutdownFacesContext(FacesContext facesContext)
564 {
565 _releaseFacesContext(facesContext);
566 }
567
568 private FacesContext _createFacesContext(ServletContext servletContext, boolean startup)
569 {
570 ExternalContext externalContext = new StartupServletExternalContextImpl(servletContext, startup);
571 ExceptionHandler exceptionHandler = new ExceptionHandlerImpl();
572 FacesContext facesContext = new StartupFacesContextImpl(externalContext,
573 (ReleaseableExternalContext) externalContext, exceptionHandler, startup);
574
575
576
577 UIViewRoot startupViewRoot = new UIViewRoot();
578 startupViewRoot.setLocale(Locale.getDefault());
579 facesContext.setViewRoot(startupViewRoot);
580
581 return facesContext;
582 }
583
584 private void _releaseFacesContext(FacesContext facesContext)
585 {
586
587
588 if (facesContext != null)
589 {
590 facesContext.release();
591 }
592 }
593
594
595
596
597
598
599
600 protected abstract void initContainerIntegration(
601 ServletContext servletContext, ExternalContext externalContext);
602
603
604
605
606
607
608
609
610
611
612
613 protected void initCDIIntegration(
614 ServletContext servletContext, ExternalContext externalContext)
615 {
616
617
618
619
620
621 Object beanManager = servletContext.getAttribute(
622 CDI_SERVLET_CONTEXT_BEAN_MANAGER_ATTRIBUTE);
623 if (beanManager == null)
624 {
625 beanManager = lookupBeanManagerFromCDI();
626 }
627 if (beanManager == null)
628 {
629 beanManager = lookupBeanManagerFromJndi();
630 }
631 if (beanManager != null)
632 {
633 externalContext.getApplicationMap().put(CDI_BEAN_MANAGER_INSTANCE,
634 beanManager);
635 }
636 }
637
638
639
640
641
642
643
644 private Object lookupBeanManagerFromCDI()
645 {
646 try
647 {
648 Class cdiClass = null;
649 Method cdiCurrentMethod = null;
650 Method cdiGetBeanManagerMethod = null;
651 cdiClass = simpleClassForNameNoException("javax.enterprise.inject.spi.CDI");
652 if (cdiClass != null)
653 {
654 cdiCurrentMethod = cdiClass.getMethod("current");
655
656 Object cdiInstance = cdiCurrentMethod.invoke(null);
657
658 cdiGetBeanManagerMethod = cdiClass.getMethod("getBeanManager");
659 return cdiGetBeanManagerMethod.invoke(cdiInstance);
660 }
661 }
662 catch (Exception e)
663 {
664
665 }
666 return null;
667 }
668
669 private static Class simpleClassForNameNoException(String type)
670 {
671 try
672 {
673 return ClassUtils.classForName(type);
674 }
675 catch (ClassNotFoundException e)
676 {
677
678
679 return null;
680 }
681 }
682
683
684
685
686
687 private Object lookupBeanManagerFromJndi()
688 {
689 Object beanManager = null;
690
691 Class icclazz = null;
692 Method lookupMethod = null;
693 try
694 {
695 icclazz = ClassUtils.simpleClassForName("javax.naming.InitialContext");
696 if (icclazz != null)
697 {
698 lookupMethod = icclazz.getMethod("doLookup", String.class);
699 }
700 }
701 catch (Throwable t)
702 {
703
704 }
705 if (lookupMethod != null)
706 {
707
708 try
709 {
710
711
712 beanManager = lookupMethod.invoke(icclazz, "java:comp/BeanManager");
713 }
714 catch (Exception e)
715 {
716
717 }
718 catch (NoClassDefFoundError e)
719 {
720
721
722
723 }
724
725 if (beanManager == null)
726 {
727 try
728 {
729
730
731 beanManager = lookupMethod.invoke(icclazz, "java:comp/env/BeanManager");
732 }
733 catch (Exception e)
734 {
735
736 }
737 catch (NoClassDefFoundError e)
738 {
739
740
741
742 }
743 }
744 }
745
746 return beanManager;
747 }
748
749 public void _callPreDestroyOnInjectedJSFArtifacts(FacesContext facesContext)
750 {
751 InjectionProvider injectionProvider = InjectionProviderFactory.getInjectionProviderFactory(
752 facesContext.getExternalContext()).getInjectionProvider(facesContext.getExternalContext());
753 List<BeanEntry> injectedBeanStorage =
754 (List<BeanEntry>)facesContext.getExternalContext().getApplicationMap().get(INJECTED_BEAN_STORAGE_KEY);
755
756 if (injectedBeanStorage != null)
757 {
758 for (BeanEntry entry : injectedBeanStorage)
759 {
760 try
761 {
762 injectionProvider.preDestroy(entry.getInstance(), entry.getCreationMetaData());
763 }
764 catch (InjectionProviderException ex)
765 {
766 log.log(Level.INFO, "Exception on PreDestroy", ex);
767 }
768 }
769 injectedBeanStorage.clear();
770 }
771 }
772
773 protected void initWebsocketIntegration(
774 ServletContext servletContext, ExternalContext externalContext)
775 {
776 Boolean b = WebConfigParamUtils.getBooleanInitParameter(externalContext,
777 PushContext.ENABLE_WEBSOCKET_ENDPOINT_PARAM_NAME);
778
779 if (Boolean.TRUE.equals(b))
780 {
781
782
783 final ServerContainer serverContainer = (ServerContainer)
784 servletContext.getAttribute("javax.websocket.server.ServerContainer");
785
786 if (serverContainer != null)
787 {
788 try
789 {
790 serverContainer.addEndpoint(ServerEndpointConfig.Builder
791 .create(EndpointImpl.class, EndpointImpl.JAVAX_FACES_PUSH_PATH)
792 .configurator(new WebsocketConfigurator(externalContext)).build());
793
794
795 WebsocketFacesInit.initWebsocketSessionLRUCache(externalContext);
796
797 externalContext.getApplicationMap().put("org.apache.myfaces.push", "true");
798 }
799 catch (DeploymentException e)
800 {
801 log.log(Level.INFO, "Exception on Initialize Websocket Endpoint: ", e);
802 }
803 }
804 else
805 {
806 log.log(Level.INFO, "f:websocket support enabled but cannot found websocket ServerContainer instance "+
807 "on current context. If websocket library is available, please include a FakeEndpoint instance "
808 + "into your code to force enable it (Tyrus users).");
809 }
810 }
811 }
812
813
814
815
816
817
818 protected void initAutomaticExtensionlessMapping(FacesContext facesContext, ServletContext servletContext)
819 {
820 final ServletRegistration facesServletRegistration = getFacesServletRegistration(facesContext, servletContext);
821 if (facesServletRegistration != null)
822 {
823 facesContext.getApplication().getViewHandler().getViews(facesContext, "/",
824 ViewVisitOption.RETURN_AS_MINIMAL_IMPLICIT_OUTCOME).forEach(s -> {
825 facesServletRegistration.addMapping(s);
826 });
827 }
828 }
829
830 private ServletRegistration getFacesServletRegistration(FacesContext facesContext,
831 ServletContext servletContext)
832 {
833 ServletRegistration facesServletRegistration = null;
834 Map<String, ? extends ServletRegistration> map = servletContext.getServletRegistrations();
835 if (map != null)
836 {
837 for (Map.Entry<String, ? extends ServletRegistration> entry : map.entrySet())
838 {
839 if (FacesServletMappingUtils.isFacesServlet(facesContext, entry.getValue().getClassName()))
840 {
841 facesServletRegistration = entry.getValue();
842 break;
843 }
844 }
845 }
846 return facesServletRegistration;
847 }
848
849 protected void checkForDeprecatedContextParams(FacesContext facesContext)
850 {
851 ExternalContext externalContext = facesContext.getExternalContext();
852
853 String value;
854
855 value = externalContext.getInitParameter("org.apache.myfaces.CDI_MANAGED_CONVERTERS_ENABLED");
856 if (value != null && !value.isEmpty())
857 {
858 log.severe("'org.apache.myfaces.CDI_MANAGED_CONVERTERS_ENABLED' is not supported anymore since 2.3. "
859 + "Please use @FacesConverter with managed=true.");
860 }
861
862 value = externalContext.getInitParameter("org.apache.myfaces.CDI_MANAGED_VALIDATORS_ENABLED");
863 if (value != null && !value.isEmpty())
864 {
865 log.severe("'org.apache.myfaces.CDI_MANAGED_VALIDATORS_ENABLED' is not supported anymore since 2.3. "
866 + "Please use @FacesValidator with managed=true.");
867 }
868
869 value = externalContext.getInitParameter("org.apache.myfaces.SAVE_STATE_WITH_VISIT_TREE_ON_PSS");
870 if (value != null && !value.isEmpty())
871 {
872 log.severe("'org.apache.myfaces.SAVE_STATE_WITH_VISIT_TREE_ON_PSS' is not supported anymore since 2.3.");
873 }
874
875 value = externalContext.getInitParameter("org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE");
876 if (value != null && !value.isEmpty())
877 {
878 log.severe("'org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE' is not supported anymore since 2.3.");
879 }
880
881 value = externalContext.getInitParameter("org.apache.myfaces.HANDLE_STATE_CACHING_MECHANICS");
882 if (value != null && !value.isEmpty())
883 {
884 log.severe("'org.apache.myfaces.HANDLE_STATE_CACHING_MECHANICS' is not supported anymore since 2.3.");
885 }
886
887 value = externalContext.getInitParameter("org.apache.myfaces.ERROR_HANDLER");
888 if (value != null && !value.isEmpty())
889 {
890 log.severe("'org.apache.myfaces.ERROR_HANDLER' is not supported anymore since 2.3.");
891 }
892
893 value = externalContext.getInitParameter("org.apache.myfaces.STRICT_JSF_2_REFRESH_TARGET_AJAX");
894 if (value != null && !value.isEmpty())
895 {
896 log.severe("'org.apache.myfaces.STRICT_JSF_2_REFRESH_TARGET_AJAX' is not supported anymore since 2.3.");
897 }
898
899 value = externalContext.getInitParameter("org.apache.myfaces.ALLOW_JAVASCRIPT");
900 if (value != null && !value.isEmpty())
901 {
902 log.severe("'org.apache.myfaces.ALLOW_JAVASCRIPT' is not supported anymore.");
903 }
904
905 value = externalContext.getInitParameter("org.apache.myfaces.VIEWSTATE_JAVASCRIPT");
906 if (value != null && !value.isEmpty())
907 {
908 log.severe("'org.apache.myfaces.VIEWSTATE_JAVASCRIPT' is not supported anymore.");
909 }
910
911 value = externalContext.getInitParameter("org.apache.myfaces.PRETTY_HTML");
912 if (value != null && !value.isEmpty())
913 {
914 log.severe("'org.apache.myfaces.PRETTY_HTML' is not supported anymore.");
915 }
916
917 value = externalContext.getInitParameter("org.apache.myfaces.RENDER_FORM_SUBMIT_SCRIPT_INLINE");
918 if (value != null && !value.isEmpty())
919 {
920 log.severe("'org.apache.myfaces.RENDER_FORM_SUBMIT_SCRIPT_INLINE' is not supported anymore.");
921 }
922 }
923 }