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 ed...@apache.org on 2008/07/26 00:11:43 UTC
svn commit: r679906 - in /portals/pluto/branches/pluto-1.1.x:
pluto-container/src/main/java/org/apache/pluto/core/
pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/
pluto-portal-driver/src/test/java/org/apache/pluto/driver/serv...
Author: edalquist
Date: Fri Jul 25 15:11:42 2008
New Revision: 679906
URL: http://svn.apache.org/viewvc?rev=679906&view=rev
Log:
PLUTO-490 Add special handling for the root context in ServletContext lookup
Add extra logic to handle root context determination under Serlet 2.4 & Tomcat
Modified:
portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/DefaultApplicationIdResolver.java
portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java
portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PortletWindowConfig.java
portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/portal/PortletWindowConfigTest.java
Modified: portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/DefaultApplicationIdResolver.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/DefaultApplicationIdResolver.java?rev=679906&r1=679905&r2=679906&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/DefaultApplicationIdResolver.java (original)
+++ portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/DefaultApplicationIdResolver.java Fri Jul 25 15:11:42 2008
@@ -29,13 +29,24 @@
private static final Log LOG = LogFactory.getLog(DefaultApplicationIdResolver.class);
private static final String WEB_XML = "/WEB-INF/web.xml";
+ private static final String JNDI_PREFIX = "jndi:/";
public String resolveApplicationId(ServletContext context) {
try {
URL webXmlUrl = context.getResource(WEB_XML);
String path = webXmlUrl.toExternalForm();
path = path.substring(0, path.indexOf(WEB_XML));
- path = path.substring(path.lastIndexOf("/"));
+
+ int slash = path.lastIndexOf('/');
+ if ((slash < JNDI_PREFIX.length()) && path.startsWith(JNDI_PREFIX)) {
+ // Tomcat resources look like "jndi:/hostname/contextPath/WEB-INF/web.xml"
+ // where "/contextPath" is "" for the ROOT context.
+ // So if the last slash is the one in "jndi:/", the correct
+ // result is "" and not "/hostname"
+ path = "";
+ } else {
+ path = path.substring(slash);
+ }
int id = path.indexOf(".war");
if(id > 0) {
@@ -43,7 +54,7 @@
}
return path;
} catch (MalformedURLException e) {
- LOG.warn("Erorr retrieving web.xml from ServletContext. Unable to derive contextPath.");
+ LOG.warn("Error retrieving web.xml from ServletContext. Unable to derive contextPath.");
return null;
}
}
Modified: portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java?rev=679906&r1=679905&r2=679906&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java (original)
+++ portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java Fri Jul 25 15:11:42 2008
@@ -276,6 +276,12 @@
return portalContext;
}
}
+
+ //Hack to deal with inconsistence in root context handling between
+ //ServletContext.getContextPath and ServletContext.getContext
+ if ("".equals(portletContextPath)) {
+ portletContextPath = "/";
+ }
return portalContext.getContext(portletContextPath);
}
Modified: portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PortletWindowConfig.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PortletWindowConfig.java?rev=679906&r1=679905&r2=679906&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PortletWindowConfig.java (original)
+++ portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PortletWindowConfig.java Fri Jul 25 15:11:42 2008
@@ -150,13 +150,12 @@
/**
* Parses the portlet ID and returns the separator (".") index. The portlet
- * ID passed in should be a valid ID: not null, not starts with ".",
- * not ends with ".", and contains ".". The portlet ID can have more than
- * one dot, but the last one is taken to be the separator.
+ * ID passed in should be a valid ID: not null and contains ".". The portlet
+ * ID can have more than one dot, but the last one is taken to be the separator.
*
* @param portletId the portlet ID to parse.
* @return the separator index.
- * @throws IllegalArgumentException if portlet ID does not contain a dot or the dot is the first or last character.
+ * @throws IllegalArgumentException if portlet ID does not contain a dot.
* @throws NullPointerException if the portlet ID is null
*/
private static int getSeparatorIndex(String portletId)
@@ -166,9 +165,9 @@
}
int index = portletId.lastIndexOf(".");
- if (index <= 0 || index == portletId.length() - 1) {
- throw new IllegalArgumentException("Portlet ID '" + portletId + "' does not contain a dot or the dot is the first or last character");
- }
+ if (index < 0 || index == (portletId.length() - 1)) {
+ throw new IllegalArgumentException("Portlet ID '" + portletId + "' does not contain a dot");
+ }
return index;
}
Modified: portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/portal/PortletWindowConfigTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/portal/PortletWindowConfigTest.java?rev=679906&r1=679905&r2=679906&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/portal/PortletWindowConfigTest.java (original)
+++ portals/pluto/branches/pluto-1.1.x/pluto-portal-driver/src/test/java/org/apache/pluto/driver/services/portal/PortletWindowConfigTest.java Fri Jul 25 15:11:42 2008
@@ -53,7 +53,6 @@
}
public void testParseInvalidId() {
- testParseInvalid(".NoContext");
testParseInvalid("Use/Slash");
testParseInvalid("NoPortlet.");
}