You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by es...@apache.org on 2008/01/06 09:15:39 UTC
svn commit: r609273 - in
/portals/pluto/branches/1.1-286-trunk-merge/pluto-container: ./
src/main/java/org/apache/pluto/internal/impl/
src/test/java/org/apache/pluto/internal/impl/
Author: esm
Date: Sun Jan 6 00:15:38 2008
New Revision: 609273
URL: http://svn.apache.org/viewvc?rev=609273&view=rev
Log:
[PLUTO-417]: Updating PortletResponseImpl to allow wsrp rewrite urls. Merged from the 1.1.x branch, revs 569865 and 569919. PortletResponseImplTest was updated to accommodate 286 cache control.
Added:
portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java
- copied, changed from r569865, portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java
portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java
- copied, changed from r569865, portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java
Modified:
portals/pluto/branches/1.1-286-trunk-merge/pluto-container/pom.xml
portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletResponseImpl.java
Modified: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/pom.xml
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/pom.xml?rev=609273&r1=609272&r2=609273&view=diff
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/pom.xml (original)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/pom.xml Sun Jan 6 00:15:38 2008
@@ -119,6 +119,24 @@
<version>${jmock.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>jmock</groupId>
+ <artifactId>jmock-cglib</artifactId>
+ <version>${jmock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-mock</artifactId>
+ <version>${springframework.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${springframework.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletResponseImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletResponseImpl.java?rev=609273&r1=609272&r2=609273&view=diff
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletResponseImpl.java (original)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletResponseImpl.java Sun Jan 6 00:15:38 2008
@@ -18,28 +18,21 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.Collection;
-import javax.portlet.PortletMode;
import javax.portlet.PortletResponse;
-import javax.portlet.PortletURL;
-import javax.portlet.ResourceURL;
import javax.servlet.ServletOutputStream;
-import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import org.apache.pluto.PortletContainer;
+import org.apache.pluto.RequiredContainerServices;
import org.apache.pluto.internal.InternalPortletResponse;
import org.apache.pluto.internal.InternalPortletWindow;
+import org.apache.pluto.spi.PortalCallbackService;
import org.apache.pluto.spi.ResourceURLProvider;
import org.apache.pluto.util.ArgumentUtility;
-import org.apache.pluto.util.NamespaceMapper;
import org.apache.pluto.util.PrintWriterServletOutputStream;
-import org.apache.pluto.util.impl.NamespaceMapperImpl;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Element;
/**
* Abstract <code>javax.portlet.PortletResponse</code> implementation.
@@ -48,33 +41,26 @@
*/
public abstract class PortletResponseImpl extends HttpServletResponseWrapper
implements PortletResponse, InternalPortletResponse {
-
+
// Private Member Variables ------------------------------------------------
-
+
/** The portlet container. */
- private PortletContainer container;
-
+ private final PortletContainer container;
+
/** The internal portlet window. */
- private InternalPortletWindow internalPortletWindow;
+ private final InternalPortletWindow internalPortletWindow;
/** The servlet request of the target/portlet's web module. */
- private HttpServletRequest httpServletRequest;
-
+ private final HttpServletRequest httpServletRequest;
+
private boolean usingWriter;
private boolean usingStream;
private ServletOutputStream wrappedWriter;
-
- private NamespaceMapper mapper = new NamespaceMapperImpl();
-
- /** True if we are in an include call. */
- private boolean included = false;
-
- /** True if we are in an forwarded call. */
- private boolean forwarded = false;
-
+
+
// Constructor -------------------------------------------------------------
-
+
public PortletResponseImpl(PortletContainer container,
InternalPortletWindow internalPortletWindow,
HttpServletRequest servletRequest,
@@ -84,10 +70,10 @@
this.httpServletRequest = servletRequest;
this.internalPortletWindow = internalPortletWindow;
}
-
-
+
+
// PortletResponse Impl ----------------------------------------------------
-
+
public void addProperty(String name, String value) {
ArgumentUtility.validateNotNull("propertyName", name);
container.getRequiredContainerServices()
@@ -97,28 +83,6 @@
internalPortletWindow,
name, value);
}
-
- public void addProperty(String name, String value, int scope) {
- // FIXME: What should this do? (scope seems to be new)
- ArgumentUtility.validateNotNull("propertyName", name);
- container.getRequiredContainerServices()
- .getPortalCallbackService()
- .addResponseProperty(
- getHttpServletRequest(),
- internalPortletWindow,
- name, value);
- }
-
- public void addProperty(String key, Element element) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("This method needs to be implemented.");
- }
-
-
- public void addProperty(Cookie cookie) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("This method needs to be implemented.");
- }
public void setProperty(String name, String value) {
ArgumentUtility.validateNotNull("propertyName", name);
@@ -129,48 +93,47 @@
internalPortletWindow,
name, value);
}
-
-// public void setProperty(String name, String value, int scope) {
-// // FIXME: What should this do? (scope seems to be new)
-// ArgumentUtility.validateNotNull("propertyName", name);
-// container.getRequiredContainerServices()
-// .getPortalCallbackService()
-// .setResponseProperty(
-// getHttpServletRequest(),
-// internalPortletWindow,
-// name, value);
-// }
public String encodeURL(String path) {
- if (path.indexOf("://") == -1 && !path.startsWith("/")) {
+
+ if ( path == null ) {
+ throw new IllegalArgumentException( "Argument to encodeURL must not be null." );
+ }
+
+ final String wsrpRewriteToken = "wsrp_rewrite?";
+
+ if ( (path.indexOf("://") == -1 && !path.startsWith("/")) &&
+ !path.startsWith( wsrpRewriteToken ) ) {
throw new IllegalArgumentException(
"only absolute URLs or full path URIs are allowed");
}
-
+
ResourceURLProvider provider = getContainer()
.getRequiredContainerServices()
.getPortalCallbackService()
.getResourceURLProvider(
httpServletRequest,
internalPortletWindow);
- if (path.indexOf("://") != -1) {
+
+ if (isAbsolute(path)) {
provider.setAbsoluteURL(path);
- } else {
+ } else {
provider.setFullPath(path);
}
+
return getHttpServletResponse().encodeURL(provider.toString());
}
-
-
+
+
// InternalPortletResponse impl --------------------------------------------
-
+
public InternalPortletWindow getInternalPortletWindow() {
return internalPortletWindow;
}
-
-
+
+
// Internal Methods --------------------------------------------------------
-
+
/**
* Returns the portlet container.
* @return the portlet container.
@@ -178,7 +141,7 @@
protected PortletContainer getContainer() {
return container;
}
-
+
/**
* Returns the nested HttpServletRequest instance.
* @return the nested HttpServletRequest instance.
@@ -188,20 +151,63 @@
}
/**
+ * Determines if the supplied path should be treated as an
+ * absolute URL. This default implementation considers the
+ * following conditions when evaluating the path:
+ * <ol>
+ * <li>If the path is null, return false</li>
+ * <li>If the path contains the string "://", then return true</li>
+ * <li>If the path starts with the string "wsrp-rewrite?" then
+ * return true</li>
+ * <li>If none of the previous conditions hold true, return false</li>
+ * </ol>
+ * <p/>
+ * If the path is considered absolute, then ResourceURL providers
+ * (e.g. ResourceURLProvider implementations) should perform little,
+ * if any, manipulation of the path.
+ * <p/>
+ * If the path is not considered absolute, then the ResourceURL provider
+ * may modify it to be absolute according to the
+ * <code>ResourceURLProvider.toString()</code> contract. For example,
+ * they may pre-pend a scheme and host to the supplied path.
+ *
+ * @param path a string representing a resource path
+ * @return true if the resource path should be considered absolute
+ */
+ protected boolean isAbsolute(String path) {
+ final String wsrpToken = "wsrp_rewrite?";
+ final String schemeToken = "://";
+
+ if ( path == null ) {
+ return false;
+ }
+
+ if ( path.indexOf( schemeToken ) != -1 ) {
+ return true;
+ }
+
+ if ( path.startsWith( wsrpToken ) ) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Returns the nested HttpServletResponse instance.
* @return the nested HttpServletResponse instance.
*/
public HttpServletResponse getHttpServletResponse() {
return (HttpServletResponse) super.getResponse();
}
-
-
+
+
// HttpServletResponse Methods ---------------------------------------------
-
+
public String encodeUrl(String url) {
return this.encodeURL(url);
}
-
+
/**
* TODO: javadoc about why we are using a wrapped writer here.
* @see org.apache.pluto.util.PrintWriterServletOutputStream
@@ -220,7 +226,7 @@
usingStream = true;
return wrappedWriter;
}
-
+
public PrintWriter getWriter()
throws IllegalStateException, IOException {
if (usingStream) {
@@ -232,142 +238,4 @@
return getHttpServletResponse().getWriter();
}
- public PortletURL createRenderURL() {
- return createURL(false,false);
- }
-
-
- public PortletURL createActionURL() {
- return createURL(true,false);
- }
-
- public ResourceURL createResourceURL(){
- return new ResourceURLImpl(getContainer(),
- getInternalPortletWindow(),
- getHttpServletRequest(),
- getHttpServletResponse());
- }
-
- public ResourceURL createResourceURL(boolean markupContainsPortletURLs){
- throw new UnsupportedOperationException("This method needs to be implemented.");
- }
-
- /**
- * Creates a portlet URL.
- * TODO: make dynamic? as service?
- * @param isAction true for an action URL, false for a render URL.
- * @return the created portlet (action/render) URL.
- */
- private PortletURL createURL(boolean isAction, boolean isResourceServing) {
- return new PortletURLImpl(getContainer(),
- getInternalPortletWindow(),
- getHttpServletRequest(),
- getHttpServletResponse(),
- isAction);
- }
-
-
- public String getNamespace() {
- String namespace = mapper.encode(getInternalPortletWindow().getId(), "");
- StringBuffer validNamespace = new StringBuffer();
- for (int i = 0; i < namespace.length(); i++) {
- char ch = namespace.charAt(i);
- if (Character.isJavaIdentifierPart(ch)) {
- validNamespace.append(ch);
- } else {
- validNamespace.append('_');
- }
- }
- return validNamespace.toString();
- }
-
- @Override
- public void addCookie(Cookie arg0) {
- if (isIncluded()){
- //no operation
- }
- else if (isForwarded()){
- addProperty(arg0);
- }
- else
- super.addCookie(arg0);
- }
-
- @Override
- public boolean containsHeader(String arg0) {
- if (isForwarded() || isIncluded()){
- return false;
- }
- else
- return super.containsHeader(arg0);
- }
-
- @Override
- public String encodeRedirectUrl(String arg0) {
- if (isForwarded() || isIncluded()){
- return null;
- }
- else
- return super.encodeRedirectUrl(arg0);
- }
-
- @Override
- public String encodeRedirectURL(String arg0) {
- if (isForwarded() || isIncluded()){
- return null;
- }
- else
- return super.encodeRedirectURL(arg0);
- }
-
- @Override
- public void sendError(int arg0) throws IOException {
- if (isForwarded() || isIncluded()){
- // no operation
- }
- else
- super.sendError(arg0);
- }
-
-
-
- @Override
- public void sendError(int arg0, String arg1) throws IOException {
- if (isForwarded() || isIncluded()){
- // no operation
- }
- else
- super.sendError(arg0, arg1);
- }
-
- public Element createElement(String tagName) throws DOMException {
- // TODO Auto-generated method stub
- return null;
- }
-// InternalRenderResponse Impl ---------------------------------------------
-
- public void setIncluded(boolean included) {
- this.included = included;
- }
-
- public boolean isIncluded() {
- return included;
- }
-
- public boolean isForwarded() {
- return forwarded;
- }
-
-
- public void setForwarded(boolean forwared) {
- this.forwarded = forwared;
-
- }
-
- public boolean isForwardedAllowed(){
- if (usingWriter || usingStream)
- return false;
- else
- return true;
- }
}
Copied: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java (from r569865, portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java)
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java?p2=portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java&p1=portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java&r1=569865&r2=609273&rev=609273&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java (original)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/MockResourceUrlProviderImpl.java Sun Jan 6 00:15:38 2008
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.pluto.internal.impl;
import org.apache.pluto.spi.ResourceURLProvider;
Copied: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java (from r569865, portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java)
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java?p2=portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java&p1=portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java&r1=569865&r2=609273&rev=609273&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java (original)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletResponseImplTest.java Sun Jan 6 00:15:38 2008
@@ -1,5 +1,18 @@
-/**
- *
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.pluto.internal.impl;
@@ -10,10 +23,13 @@
import org.apache.pluto.PortletContainer;
import org.apache.pluto.RequiredContainerServices;
import org.apache.pluto.core.PortletContainerImpl;
+import org.apache.pluto.descriptors.portlet.PortletDD;
import org.apache.pluto.internal.InternalPortletWindow;
+import org.apache.pluto.internal.PortletEntity;
import org.apache.pluto.spi.PortalCallbackService;
import org.jmock.Mock;
import org.jmock.cglib.MockObjectTestCase;
+import org.jmock.expectation.ReturnValue;
import org.springframework.mock.web.MockHttpServletResponse;
/**
@@ -57,7 +73,18 @@
mockContainer = mock( PortletContainerImpl.class,
new Class[] { String.class, RequiredContainerServices.class, OptionalContainerServices.class },
new Object[] { "Mock Pluto Container", (RequiredContainerServices) mockServices.proxy(), null } );
- InternalPortletWindow window = (InternalPortletWindow) mock( InternalPortletWindow.class ).proxy();
+
+ // MimeResponseImpl needs a ExpirationCacheDD to implement cache control.
+ Mock mockPortletDefinition = mock( PortletDD.class );
+ mockPortletDefinition.expects( once() ).method( "getExpirationCacheDD" ).will( returnValue( null ) );
+
+ Mock mockPortletEntity = mock( PortletEntity.class );
+ mockPortletEntity.expects( once() ).method( "getPortletDefinition" ).will( returnValue( mockPortletDefinition.proxy() ) );
+
+ Mock mockWindow = mock( InternalPortletWindow.class );
+ mockWindow.expects( once() ).method( "getPortletEntity" ).will( returnValue( mockPortletEntity.proxy() ) );
+
+ InternalPortletWindow window = (InternalPortletWindow) mockWindow.proxy();
HttpServletRequest req = (HttpServletRequest) mock( HttpServletRequest.class ).proxy();
// Create Spring mock objects (we need functional HttpServletResponse for encodeURL)