Author: woonsan Date: Thu Dec 10 13:16:15 2009 New Revision: 889253 URL: http://svn.apache.org/viewvc?rev=889253&view=rev Log: JS2-1087: Allowing portal url valve to read custom portal path info from query parameter or http header. With additional properties configuration, this can be enabled. Currently, rest api pipeline uses these options because there are two separate url spaces in rest url invocations: (1) rest resource request url, (2) portal page context url. >From the ajax developer's view, the request url needs to be just rest resource >request url; the portal page path in the context can be passed by query >parameter or http header in ajax codes.
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/url/PortalURL.java portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java?rev=889253&r1=889252&r2=889253&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java (original) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java Thu Dec 10 13:16:15 2009 @@ -17,12 +17,16 @@ package org.apache.jetspeed.container.url.impl; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; + import org.apache.jetspeed.container.state.NavigationalStateComponent; +import org.apache.jetspeed.container.url.PortalURL; +import org.apache.jetspeed.desktop.JetspeedDesktop; import org.apache.jetspeed.pipeline.PipelineException; import org.apache.jetspeed.pipeline.valve.AbstractValve; import org.apache.jetspeed.pipeline.valve.ValveContext; import org.apache.jetspeed.request.RequestContext; -import org.apache.jetspeed.desktop.JetspeedDesktop; /** * Creates the PortalURL for the current Request @@ -33,39 +37,89 @@ public class PortalURLValveImpl extends AbstractValve { private NavigationalStateComponent navComponent; - + private boolean pathInfoParamAllowed; + private String defaultPathInfoParam; + public PortalURLValveImpl(NavigationalStateComponent navComponent) { this.navComponent = navComponent; } + public void setPathInfoParamAllowed(boolean pathInfoParamAllowed) + { + this.pathInfoParamAllowed = pathInfoParamAllowed; + } + + public void setDefaultPathInfoParam(String defaultPathInfoParam) + { + this.defaultPathInfoParam = defaultPathInfoParam; + } + public void invoke(RequestContext request, ValveContext context) throws PipelineException { try - { - if ( request.getPortalURL() == null ) + { + if (request.getPortalURL() == null) { + HttpServletRequest servletRequest = getHttpServletRequest(request); String encoding = request.getRequestParameter(JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER); - if (encoding != null && encoding.equals(JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER_VALUE)) + + if (JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER_VALUE.equals(encoding)) { - request.setPortalURL(navComponent.createDesktopURL(request.getRequest(), request.getCharacterEncoding())); + request.setPortalURL(navComponent.createDesktopURL(servletRequest, request.getCharacterEncoding())); request.setAttribute( JetspeedDesktop.DESKTOP_ENABLED_REQUEST_ATTRIBUTE, Boolean.TRUE ); } else { - request.setPortalURL(navComponent.createURL(request.getRequest(), request.getCharacterEncoding())); + request.setPortalURL(navComponent.createURL(servletRequest, request.getCharacterEncoding())); } - } } catch (Exception e) { throw new PipelineException(e); } + // Pass control to the next Valve in the Pipeline context.invokeNext( request ); } + + private HttpServletRequest getHttpServletRequest(RequestContext request) + { + HttpServletRequest servletRequest = request.getRequest(); + + if (pathInfoParamAllowed) + { + String param = servletRequest.getParameter(PortalURL.PATH_INFO_QUERY); + + if (param == null) + { + param = servletRequest.getHeader(PortalURL.PATH_INFO_HEADER); + + if (param == null) + { + param = defaultPathInfoParam; + } + } + + if (param != null) + { + final String pathInfoParam = param; + + servletRequest = new HttpServletRequestWrapper(servletRequest) + { + @Override + public String getPathInfo() + { + return pathInfoParam; + } + }; + } + } + + return servletRequest; + } public String toString() { Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/url/PortalURL.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/url/PortalURL.java?rev=889253&r1=889252&r2=889253&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/url/PortalURL.java (original) +++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/container/url/PortalURL.java Thu Dec 10 13:16:15 2009 @@ -64,6 +64,12 @@ /** HTTPS protocol. */ public static final String HTTPS = "https"; + /** Portal Path Info Query parameter. */ + public static final String PATH_INFO_QUERY = "_portalpath"; + + /** Portal Path Info HTTP Header name. */ + public static final String PATH_INFO_HEADER = "X-Portal-Path"; + /** * @return true if only relative urls should be generated (without scheme, servername, port) */ Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml?rev=889253&r1=889252&r2=889253&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml (original) +++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml Thu Dec 10 13:16:15 2009 @@ -66,7 +66,17 @@ <ref bean="NavigationalStateComponent" /> </constructor-arg> </bean> - + + <bean id="pathInfoParamEnabledPortalURLValve" class="org.apache.jetspeed.container.url.impl.PortalURLValveImpl" + init-method="initialize"> + <meta key="j2:cat" value="default" /> + <constructor-arg> + <ref bean="NavigationalStateComponent" /> + </constructor-arg> + <property name="pathInfoParamAllowed" value="true" /> + <property name="defaultPathInfoParam" value="/" /> + </bean> + <bean id="securityValve" class="org.apache.jetspeed.security.impl.SecurityValveImpl" init-method="initialize"> <meta key="j2:cat" value="default" /> <constructor-arg index='0'> @@ -731,7 +741,7 @@ <constructor-arg> <list> <ref bean="capabilityValve" /> - <ref bean="portalURLValve" /> + <ref bean="pathInfoParamEnabledPortalURLValve" /> <ref bean="securityValve" /> <ref bean="localizationValve" /> <ref bean="profilerValve" /> --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscr...@portals.apache.org For additional commands, e-mail: jetspeed-dev-h...@portals.apache.org