From e2f0dd40f6dbb24dc1cbc7da6ed6daa556cf798a Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 9 Feb 2018 12:30:37 -0500 Subject: [PATCH] Remove MyFacesFlowResponseStateManager After #3a165ea MyFacesFlowResponseStateManager no longer serves any purpose and it seems to works without it. Issue: SWF-1712 --- .../support/ResponseStateManagerWrapper.java | 67 ----------------- .../faces/webflow/FlowApplication.java | 4 +- .../faces/webflow/FlowRenderKit.java | 33 ++------- .../webflow/FlowResponseStateManager.java | 17 ++++- .../MyFacesFlowResponseStateManager.java | 73 ------------------- 5 files changed, 22 insertions(+), 172 deletions(-) delete mode 100644 spring-faces/src/main/java/org/springframework/faces/support/ResponseStateManagerWrapper.java delete mode 100644 spring-faces/src/main/java/org/springframework/faces/webflow/MyFacesFlowResponseStateManager.java diff --git a/spring-faces/src/main/java/org/springframework/faces/support/ResponseStateManagerWrapper.java b/spring-faces/src/main/java/org/springframework/faces/support/ResponseStateManagerWrapper.java deleted file mode 100644 index 6b8f360e..00000000 --- a/spring-faces/src/main/java/org/springframework/faces/support/ResponseStateManagerWrapper.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.faces.support; - -import java.io.IOException; - -import javax.faces.FacesWrapper; -import javax.faces.context.FacesContext; -import javax.faces.render.ResponseStateManager; - -/** - * Provides a simple implementation of {@link ResponseStateManager} that can be subclassed by developers wishing to - * provide specialized behavior to an existing {@link ResponseStateManager instance} . The default implementation of all - * methods is to call through to the wrapped {@link ResponseStateManager}. - * - * @author Phillip Webb - * - * @since 2.4 - */ -public abstract class ResponseStateManagerWrapper extends ResponseStateManager implements - FacesWrapper { - - public abstract ResponseStateManager getWrapped(); - - @Override - public void writeState(FacesContext context, Object state) throws IOException { - getWrapped().writeState(context, state); - } - - @Override - public Object getState(FacesContext context, String viewId) { - return getWrapped().getState(context, viewId); - } - - @Override - public boolean isStateless(FacesContext context, String viewId) { - return getWrapped().isStateless(context, viewId); - } - - @Override - public boolean isPostback(FacesContext context) { - return getWrapped().isPostback(context); - } - - @Override - public String getViewState(FacesContext context, Object state) { - return getWrapped().getViewState(context, state); - } - - @Override - public String getCryptographicallyStrongTokenFromSession(FacesContext context) { - return getWrapped().getCryptographicallyStrongTokenFromSession(context); - } -} diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowApplication.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowApplication.java index b2d768d6..1f2b0383 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowApplication.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowApplication.java @@ -94,12 +94,10 @@ public class FlowApplication extends ApplicationWrapper { return (delegateViewHandler != null) && (!(delegateViewHandler instanceof FlowViewHandler)); } - private boolean wrapAndSetViewHandler(ViewHandler target) { + private void wrapAndSetViewHandler(ViewHandler target) { if ((target != null) && (!(target instanceof FlowViewHandler))) { ViewHandler handler = new FlowViewHandler(target); super.setViewHandler(handler); - return true; } - return false; } } diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java index 2bafa153..0f72e0b3 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java @@ -15,6 +15,10 @@ */ package org.springframework.faces.webflow; +import javax.faces.render.RenderKit; +import javax.faces.render.RenderKitWrapper; +import javax.faces.render.ResponseStateManager; + /** * A render kit implementation that ensures use of Web Flow's FlowViewResponseStateManager, which takes over reading and * writing JSF state and manages that in Web Flow's view scope. @@ -23,15 +27,6 @@ package org.springframework.faces.webflow; * @author Phillip Webb * @since 2.2.0 */ -import java.lang.reflect.Constructor; - -import javax.faces.render.RenderKit; -import javax.faces.render.RenderKitWrapper; -import javax.faces.render.ResponseStateManager; - -import org.springframework.beans.BeanUtils; -import org.springframework.util.ClassUtils; - public class FlowRenderKit extends RenderKitWrapper { private final RenderKit wrapped; @@ -40,24 +35,7 @@ public class FlowRenderKit extends RenderKitWrapper { public FlowRenderKit(RenderKit wrapped) { this.wrapped = wrapped; - this.flowViewResponseStateManager = initResponseStateManager(wrapped.getResponseStateManager()); - } - - private ResponseStateManager initResponseStateManager(ResponseStateManager wrapped) { - if (JsfRuntimeInformation.isMojarraPresent() && !JsfRuntimeInformation.isMyFacesInUse()) { - return new FlowResponseStateManager(wrapped); - } - Constructor constructor; - try { - String className = "org.springframework.faces.webflow.MyFacesFlowResponseStateManager"; - Class clazz = ClassUtils.forName(className, FlowRenderKit.class.getClassLoader()); - constructor = ClassUtils.getConstructorIfAvailable(clazz, FlowResponseStateManager.class); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Could not initialize MyFacesFlowResponseStateManager", e); - } catch (LinkageError e) { - throw new IllegalStateException("Could not initialize MyFacesFlowResponseStateManager", e); - } - return (ResponseStateManager) BeanUtils.instantiateClass(constructor, new FlowResponseStateManager(wrapped)); + this.flowViewResponseStateManager = new FlowResponseStateManager(wrapped.getResponseStateManager()); } public RenderKit getWrapped() { @@ -74,4 +52,5 @@ public class FlowRenderKit extends RenderKitWrapper { } return this.wrapped.getResponseStateManager(); } + } diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowResponseStateManager.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowResponseStateManager.java index 7b9b54ee..e08526a7 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowResponseStateManager.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowResponseStateManager.java @@ -18,6 +18,7 @@ package org.springframework.faces.webflow; import java.io.IOException; import java.io.Writer; +import javax.faces.FacesWrapper; import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.render.RenderKitFactory; @@ -25,7 +26,7 @@ import javax.faces.render.ResponseStateManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.faces.support.ResponseStateManagerWrapper; + import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.execution.RequestContextHolder; @@ -38,7 +39,8 @@ import org.springframework.webflow.execution.RequestContextHolder; * * @since 2.2.0 */ -public class FlowResponseStateManager extends ResponseStateManagerWrapper { +public class FlowResponseStateManager extends ResponseStateManager + implements FacesWrapper { private static final Log logger = LogFactory.getLog(FlowResponseStateManager.class); @@ -147,4 +149,15 @@ public class FlowResponseStateManager extends ResponseStateManagerWrapper { writer.endElement("input"); } } + + @Override + public boolean isPostback(FacesContext context) { + return getWrapped().isPostback(context); + } + + @Override + public String getCryptographicallyStrongTokenFromSession(FacesContext context) { + return getWrapped().getCryptographicallyStrongTokenFromSession(context); + } + } diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/MyFacesFlowResponseStateManager.java b/spring-faces/src/main/java/org/springframework/faces/webflow/MyFacesFlowResponseStateManager.java deleted file mode 100644 index 20e529cd..00000000 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/MyFacesFlowResponseStateManager.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2004-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.faces.webflow; - -import javax.faces.FacesWrapper; -import javax.faces.context.FacesContext; -import javax.faces.render.ResponseStateManager; - -import org.springframework.faces.support.ResponseStateManagerWrapper; -import org.springframework.webflow.execution.RequestContext; -import org.springframework.webflow.execution.RequestContextHolder; - -/** - * A wrapper for {@link FlowResponseStateManager} used to support MyFaces partial - * state saving. MyFaces supports an extension to the {@link ResponseStateManager} - * that reduces the amount of buffering required when writing a response. Empty - * state is provided at the time that the {@link #writeState(FacesContext, Object) - * writeState} method is invoked with an additional - * {@link #saveState(FacesContext, Object) saveState} method called later - * containing the real state to save. - * - *

Since JSF 2.0, the strategy used by MyFaces to determine if a - * {@link org.apache.myfaces.renderkit.MyfacesResponseStateManager} is available - * will always succeed since it - * follows {@link FacesWrapper}s to find the root HtmlResponseStateManager - * implementation. Since state management for web flow requests is handled by the - * {@link FlowResponseStateManager} this* assumption causes problems and results - * in empty state data being saved. This wrapper provides the additional hook - * required to ensure that the {@link #saveState(FacesContext, Object) saveState} - * method also triggers web flow state management. - * - * @author Phillip Webb - * @since 2.4 - * @see FlowResponseStateManager - * @see FlowRenderKit - */ -public class MyFacesFlowResponseStateManager extends ResponseStateManagerWrapper - implements FacesWrapper { - - private final ResponseStateManager wrapped; - - public MyFacesFlowResponseStateManager(FlowResponseStateManager wrapped) { - this.wrapped = wrapped; - } - - public ResponseStateManager getWrapped() { - return this.wrapped; - } - - @Override - public boolean isStateless(FacesContext context, String viewId) { - return false; - } - - public void saveState(FacesContext facesContext, Object state) { - RequestContext requestContext = RequestContextHolder.getRequestContext(); - requestContext.getViewScope().put(FlowResponseStateManager.FACES_VIEW_STATE, state); - } - -}