From 59b0938e046ec58fb808e229f00a3158f055c5bd Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 29 May 2014 17:01:06 -0400 Subject: [PATCH] Fix NPE issue with JSF/Portlet support --- .../portlet/PortletExternalContextImpl.java | 29 ++++++++++--------- .../portlet/PortletFacesContextImpl.java | 5 ++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletExternalContextImpl.java b/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletExternalContextImpl.java index f68c497b..b1972207 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletExternalContextImpl.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletExternalContextImpl.java @@ -308,11 +308,18 @@ public class PortletExternalContextImpl extends ExternalContext { @Override public String getRequestCharacterEncoding() { - return getActionRequest().getCharacterEncoding(); + if (request instanceof ClientDataRequest) { + return ((ClientDataRequest) request).getCharacterEncoding(); + } + else { + Assert.state(response instanceof MimeResponse); + return ((MimeResponse) response).getCharacterEncoding(); + } } public void setRequestCharacterEncoding(String encoding) throws java.io.UnsupportedEncodingException { - getActionRequest().setCharacterEncoding(encoding); + Assert.isInstanceOf(ClientDataRequest.class, request); + ((ClientDataRequest) request).setCharacterEncoding(encoding); } @Override @@ -365,11 +372,6 @@ public class PortletExternalContextImpl extends ExternalContext { return requestParameterValuesMap; } - @Override - public String getRequestPathInfo() { - return null; - } - @Override public String getRequestServletPath() { // Return "" instead of null in order to prevent NullPointerException in Apache MyFaces 1.2 when it tries to @@ -379,7 +381,13 @@ public class PortletExternalContextImpl extends ExternalContext { // Alternatively this method could be implemented to provide an actual servlet path derived from the // viewId when that becomes available during rendering as the MyFaces Portlet Bridge does. // - return (JsfRuntimeInformation.isMyFacesPresent()) ? "" : null; +// return JsfRuntimeInformation.isMyFacesPresent() ? "" : null; + return ""; + } + + @Override + public String getRequestPathInfo() { + return ""; } public int getRequestContentLength() { @@ -387,11 +395,6 @@ public class PortletExternalContextImpl extends ExternalContext { return ((ClientDataRequest) request).getContentLength(); } - private ActionRequest getActionRequest() { - Assert.isInstanceOf(ActionRequest.class, request); - return (ActionRequest) request; - } - @Override public String getAuthType() { return request.getAuthType(); diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletFacesContextImpl.java b/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletFacesContextImpl.java index e779c337..7b539251 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletFacesContextImpl.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletFacesContextImpl.java @@ -61,7 +61,7 @@ import org.springframework.util.ObjectUtils; * implementation provides an alternative that accepts Portlet request and response structures and creates a * {@link PortletExternalContextImpl} in its constructor. The rest of the method implementations mimic the equivalent * methods in the default FacesContext implementation. - * + * * @author Rossen Stoyanchev * @author Phillip Webb * @since 2.2.0 @@ -119,8 +119,9 @@ public class PortletFacesContextImpl extends FacesContext { application = JsfUtils.findFactory(ApplicationFactory.class).getApplication(); renderKitFactory = JsfUtils.findFactory(RenderKitFactory.class); this.externalContext = new PortletExternalContextImpl(portletContext, portletRequest, portletResponse); - this.exceptionHandler = JsfUtils.findFactory(ExceptionHandlerFactory.class).getExceptionHandler(); FacesContext.setCurrentInstance(this); + // This depends on the current FacesContext instance + this.exceptionHandler = JsfUtils.findFactory(ExceptionHandlerFactory.class).getExceptionHandler(); } public void release() {