Author: ate Date: Thu Apr 13 06:52:14 2006 New Revision: 393806 URL: http://svn.apache.org/viewcvs?rev=393806&view=rev Log: Finally fixing Critical issue JS2-464. Now the checksum of portlet.xml, jetspeed-portlet.xml *and* web.xml will be calculated and checked when a portlet application is (re)started to see if a full (re)registration might be needed. Note: this change will lead to re-registering of *all* deployed portlet applications as the current stored checksum (only taking portlet.xml into account) won't be valid anymore!
See: http://issues.apache.org/jira/browse/JS2-464 Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/MultiFileChecksumHelper.java Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/MultiFileChecksumHelper.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/MultiFileChecksumHelper.java?rev=393806&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/MultiFileChecksumHelper.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/MultiFileChecksumHelper.java Thu Apr 13 06:52:14 2006 @@ -0,0 +1,77 @@ +/* + * Copyright 2000-2001,2004 The Apache Software Foundation. + * + * 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.apache.jetspeed.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.zip.Adler32; +import java.util.zip.CheckedInputStream; +import java.util.zip.Checksum; + +/** + * Perform a single checksum calculation for multiple files + * + * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma</a> + * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a> + * @version $Id$ + */ +public class MultiFileChecksumHelper +{ + public static long getChecksum(File[] files) + { + CheckedInputStream cis = null; + FileInputStream is = null; + Checksum checksum = new Adler32(); + byte[] tempBuf = new byte[128]; + + for ( int i = 0; i < files.length && files[i] != null && files[i].exists() && files[i].isFile(); i++ ) + { + try + { + is = new FileInputStream(files[i]); + cis = new CheckedInputStream(is, checksum); + while (cis.read(tempBuf) >= 0) {} + } + catch (Exception e) + { + throw new RuntimeException(e); + } + finally + { + if (cis != null) + { + try + { + cis.close(); + } + catch (IOException ioe) {} + cis = null; + } + if (is != null) + { + try + { + is.close(); + } + catch (IOException ioe) {} + is = null; + } + } + } + return checksum.getValue(); + } +} Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java?rev=393806&r1=393805&r2=393806&view=diff ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java (original) +++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java Thu Apr 13 06:52:14 2006 @@ -47,6 +47,7 @@ import org.apache.jetspeed.tools.pamanager.PortletApplicationException; import org.apache.jetspeed.util.DirectoryHelper; import org.apache.jetspeed.util.FileSystemHelper; +import org.apache.jetspeed.util.MultiFileChecksumHelper; import org.apache.pluto.om.common.SecurityRoleRef; import org.apache.pluto.om.common.SecurityRoleRefSet; import org.apache.pluto.om.common.SecurityRoleSet; @@ -129,10 +130,13 @@ this.webAppContextRoot = webAppContextRoot; this.openedResources = new ArrayList(); this.warStruct = warStruct; - this.paChecksum = warStruct.getChecksum(PORTLET_XML_PATH); + this.paChecksum = MultiFileChecksumHelper.getChecksum(new File[] { + new File(warStruct.getRootDirectory(), WEB_XML_PATH), + new File(warStruct.getRootDirectory(), PORTLET_XML_PATH), + new File(warStruct.getRootDirectory(), EXTENDED_PORTLET_XML_PATH) }); if (paChecksum == 0) { - throw new IOException("Cannot find required "+PORTLET_XML_PATH+" for Portlet Application "+paName); + throw new IOException("Cannot find any deployment descriptor for Portlet Application "+paName); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
