Search in sources :

Example 1 with TestStage

use of org.apache.deltaspike.core.api.projectstage.TestStage in project deltaspike by apache.

the class DeltaSpikeFacesContextWrapper method init.

private synchronized void init() {
    // switch into paranoia mode
    if (this.initialized == null) {
        this.beanManager = BeanManagerProvider.getInstance().getBeanManager();
        this.jsfModuleConfig = BeanProvider.getContextualReference(this.beanManager, JsfModuleConfig.class, false);
        if (ClassDeactivationUtils.isActivated(JsfRequestBroadcaster.class)) {
            this.jsfRequestBroadcaster = BeanProvider.getContextualReference(JsfRequestBroadcaster.class, true);
        }
        ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class);
        //deactivate it, if there is no default-error-view available
        this.defaultErrorViewExceptionHandlerActivated = viewConfigResolver.getDefaultErrorViewConfigDescriptor() != null && ClassDeactivationUtils.isActivated(DefaultErrorViewAwareExceptionHandlerWrapper.class);
        this.bridgeExceptionHandlerActivated = ClassDeactivationUtils.isActivated(BridgeExceptionHandlerWrapper.class);
        this.bridgeExceptionQualifier = AnnotationInstanceProvider.of(jsfModuleConfig.getExceptionQualifier());
        this.preDestroyViewMapEventFilterMode = ClassDeactivationUtils.isActivated(SecurityAwareViewHandler.class);
        this.isNavigationAwareApplicationWrapperActivated = ClassDeactivationUtils.isActivated(NavigationHandlerAwareApplication.class);
        org.apache.deltaspike.core.api.projectstage.ProjectStage dsProjectStage = ProjectStageProducer.getInstance().getProjectStage();
        for (ProjectStage ps : ProjectStage.values()) {
            if (ps.name().equals(dsProjectStage.getClass().getSimpleName())) {
                this.projectStage = ps;
                break;
            }
        }
        if (this.projectStage == null && dsProjectStage instanceof TestStage) {
            this.projectStage = ProjectStage.Development;
        }
        if (this.projectStage == ProjectStage.Production) {
            //reset it to force the delegation to the default handling
            this.projectStage = null;
        }
        this.initialized = true;
    }
}
Also used : NavigationHandlerAwareApplication(org.apache.deltaspike.jsf.impl.navigation.NavigationHandlerAwareApplication) JsfModuleConfig(org.apache.deltaspike.jsf.api.config.JsfModuleConfig) BridgeExceptionHandlerWrapper(org.apache.deltaspike.jsf.impl.exception.control.BridgeExceptionHandlerWrapper) ProjectStage(javax.faces.application.ProjectStage) SecurityAwareViewHandler(org.apache.deltaspike.jsf.impl.security.SecurityAwareViewHandler) TestStage(org.apache.deltaspike.core.api.projectstage.TestStage) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 2 with TestStage

use of org.apache.deltaspike.core.api.projectstage.TestStage in project deltaspike by apache.

the class DefaultErrorViewAwareExceptionHandlerWrapper method handle.

@Override
public void handle() throws FacesException {
    lazyInit();
    Iterator<ExceptionQueuedEvent> exceptionQueuedEventIterator = getUnhandledExceptionQueuedEvents().iterator();
    while (exceptionQueuedEventIterator.hasNext()) {
        ExceptionQueuedEventContext exceptionQueuedEventContext = (ExceptionQueuedEventContext) exceptionQueuedEventIterator.next().getSource();
        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" }) Throwable throwable = exceptionQueuedEventContext.getException();
        String viewId = null;
        if (!isExceptionToHandle(throwable)) {
            continue;
        }
        FacesContext facesContext = exceptionQueuedEventContext.getContext();
        Flash flash = facesContext.getExternalContext().getFlash();
        if (throwable instanceof ViewExpiredException) {
            viewId = ((ViewExpiredException) throwable).getViewId();
        } else if (throwable instanceof ContextNotActiveException) {
            //(it's recorded below - see flash.put(throwable.getClass().getName(), throwable);)
            if (flash.containsKey(ContextNotActiveException.class.getName())) {
                //TODO show it in case of project-stage development
                break;
            }
            if (facesContext.getViewRoot() != null) {
                viewId = facesContext.getViewRoot().getViewId();
            } else {
                viewId = BeanProvider.getContextualReference(ViewConfigResolver.class).getDefaultErrorViewConfigDescriptor().getViewId();
            }
        }
        if (viewId != null) {
            UIViewRoot uiViewRoot = facesContext.getApplication().getViewHandler().createView(facesContext, viewId);
            if (uiViewRoot == null) {
                continue;
            }
            if (facesContext.isProjectStage(javax.faces.application.ProjectStage.Development) || ProjectStageProducer.getInstance().getProjectStage() == ProjectStage.Development || ProjectStageProducer.getInstance().getProjectStage() instanceof TestStage) {
                throwable.printStackTrace();
            }
            facesContext.setViewRoot(uiViewRoot);
            exceptionQueuedEventIterator.remove();
            //record the current exception -> to check it at the next call or to use it on the error-page
            flash.put(throwable.getClass().getName(), throwable);
            flash.keep(throwable.getClass().getName());
            this.viewNavigationHandler.navigateTo(DefaultErrorView.class);
            break;
        }
    }
    this.wrapped.handle();
}
Also used : ExceptionQueuedEvent(javax.faces.event.ExceptionQueuedEvent) FacesContext(javax.faces.context.FacesContext) ViewExpiredException(javax.faces.application.ViewExpiredException) ExceptionQueuedEventContext(javax.faces.event.ExceptionQueuedEventContext) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) Flash(javax.faces.context.Flash) UIViewRoot(javax.faces.component.UIViewRoot) TestStage(org.apache.deltaspike.core.api.projectstage.TestStage)

Aggregations

TestStage (org.apache.deltaspike.core.api.projectstage.TestStage)2 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)1 ProjectStage (javax.faces.application.ProjectStage)1 ViewExpiredException (javax.faces.application.ViewExpiredException)1 UIViewRoot (javax.faces.component.UIViewRoot)1 FacesContext (javax.faces.context.FacesContext)1 Flash (javax.faces.context.Flash)1 ExceptionQueuedEvent (javax.faces.event.ExceptionQueuedEvent)1 ExceptionQueuedEventContext (javax.faces.event.ExceptionQueuedEventContext)1 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)1 JsfModuleConfig (org.apache.deltaspike.jsf.api.config.JsfModuleConfig)1 BridgeExceptionHandlerWrapper (org.apache.deltaspike.jsf.impl.exception.control.BridgeExceptionHandlerWrapper)1 NavigationHandlerAwareApplication (org.apache.deltaspike.jsf.impl.navigation.NavigationHandlerAwareApplication)1 SecurityAwareViewHandler (org.apache.deltaspike.jsf.impl.security.SecurityAwareViewHandler)1