Author: markt Date: Tue Nov 17 20:53:32 2009 New Revision: 881503 URL: http://svn.apache.org/viewvc?rev=881503&view=rev Log: Add support for multipart config in web.xml (partially complete) Review and fix issues in WebXml merge code
Added: tomcat/trunk/java/org/apache/catalina/deploy/MultipartDef.java (with props) Modified: tomcat/trunk/java/org/apache/catalina/deploy/ServletDef.java tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java tomcat/trunk/java/org/apache/catalina/startup/WebXml.java Added: tomcat/trunk/java/org/apache/catalina/deploy/MultipartDef.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/MultipartDef.java?rev=881503&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/catalina/deploy/MultipartDef.java (added) +++ tomcat/trunk/java/org/apache/catalina/deploy/MultipartDef.java Tue Nov 17 20:53:32 2009 @@ -0,0 +1,134 @@ +/* + * 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.catalina.deploy; + + +/** + * Representation of a the multipart configuration for a servlet. + */ +public class MultipartDef { + + // ------------------------------------------------------------- Properties + private String location; + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + + private Long maxFileSize; + + public Long getMaxFileSize() { + return maxFileSize; + } + + public void setMaxFileSize(Long maxFileSize) { + this.maxFileSize = maxFileSize; + } + + + private Long maxRequestSize; + + public Long getMaxRequestSize() { + return maxRequestSize; + } + + public void setMaxRequestSize(Long maxRequestSize) { + this.maxRequestSize = maxRequestSize; + } + + + private Integer fileSizeThreshold; + + public Integer getFileSizeThreshold() { + return fileSizeThreshold; + } + + public void setFileSizeThreshold(Integer fileSizeThreshold) { + this.fileSizeThreshold = fileSizeThreshold; + } + + + // ---------------------------------------------------------- Object methods + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime + * result + + ((fileSizeThreshold == null) ? 0 : fileSizeThreshold + .hashCode()); + result = prime * result + + ((location == null) ? 0 : location.hashCode()); + result = prime * result + + ((maxFileSize == null) ? 0 : maxFileSize.hashCode()); + result = prime * result + + ((maxRequestSize == null) ? 0 : maxRequestSize.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof MultipartDef)) { + return false; + } + MultipartDef other = (MultipartDef) obj; + if (fileSizeThreshold == null) { + if (other.fileSizeThreshold != null) { + return false; + } + } else if (!fileSizeThreshold.equals(other.fileSizeThreshold)) { + return false; + } + if (location == null) { + if (other.location != null) { + return false; + } + } else if (!location.equals(other.location)) { + return false; + } + if (maxFileSize == null) { + if (other.maxFileSize != null) { + return false; + } + } else if (!maxFileSize.equals(other.maxFileSize)) { + return false; + } + if (maxRequestSize == null) { + if (other.maxRequestSize != null) { + return false; + } + } else if (!maxRequestSize.equals(other.maxRequestSize)) { + return false; + } + return true; + } + +} Propchange: tomcat/trunk/java/org/apache/catalina/deploy/MultipartDef.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/java/org/apache/catalina/deploy/ServletDef.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/ServletDef.java?rev=881503&r1=881502&r2=881503&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/deploy/ServletDef.java (original) +++ tomcat/trunk/java/org/apache/catalina/deploy/ServletDef.java Tue Nov 17 20:53:32 2009 @@ -207,4 +207,17 @@ securityRoleRefs.add(securityRoleRef); } + + /** + * The multipart configuration, if any, for this servlet + */ + private MultipartDef multipartDef = new MultipartDef(); + + public MultipartDef getMultipartDef() { + return this.multipartDef; + } + + public void setMultipartDef(MultipartDef multipartDef) { + this.multipartDef = multipartDef; + } } Modified: tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java?rev=881503&r1=881502&r2=881503&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java Tue Nov 17 20:53:32 2009 @@ -368,6 +368,19 @@ "setServletClass", 0); digester.addCallMethod(fullPrefix + "/servlet/servlet-name", "setServletName", 0); + + digester.addObjectCreate(fullPrefix + "/servlet/multipart-config", + "org.apache.catalina.deploy.MultipartDef"); + digester.addSetNext(fullPrefix + "/servlet/multipart-config", + "setMultipartConfig"); + digester.addCallMethod(fullPrefix + "/servlet/multipart-config/location", + "setLocation", 0); + digester.addCallMethod(fullPrefix + "/servlet/multipart-config/max-file-size", + "setMaxFileSize", 0); + digester.addCallMethod(fullPrefix + "/servlet/multipart-config/max-request-size", + "setMaxRequestSize", 0); + digester.addCallMethod(fullPrefix + "/servlet/multipart-config/file-size-threshold", + "setFileSizeThreshold", 0); digester.addRule(fullPrefix + "/servlet-mapping", new CallMethodMultiRule("addServletMapping", 2, 0)); Modified: tomcat/trunk/java/org/apache/catalina/startup/WebXml.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebXml.java?rev=881503&r1=881502&r2=881503&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/WebXml.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/WebXml.java Tue Nov 17 20:53:32 2009 @@ -43,6 +43,7 @@ import org.apache.catalina.deploy.LoginConfig; import org.apache.catalina.deploy.MessageDestination; import org.apache.catalina.deploy.MessageDestinationRef; +import org.apache.catalina.deploy.MultipartDef; import org.apache.catalina.deploy.ResourceBase; import org.apache.catalina.deploy.SecurityConstraint; import org.apache.catalina.deploy.SecurityRoleRef; @@ -561,6 +562,7 @@ roleRef.getName(), roleRef.getLink()); } wrapper.setServletClass(servlet.getServletClass()); + // TODO SERVLET3 - Multipart config context.addChild(wrapper); } for (String pattern : servletMappings.keySet()) { @@ -699,6 +701,7 @@ } } } + filters.putAll(temp.getFilters()); for (WebXml fragment : fragments) { for (JspPropertyGroup jspPropertyGroup : fragment.getJspPropertyGroups()) { @@ -721,7 +724,7 @@ return false; } } - errorPages.putAll(temp.getErrorPages()); + localeEncodingMappings.putAll(temp.getLocalEncodingMappings()); if (getLoginConfig() == null) { LoginConfig tempLoginConfig = null; @@ -766,6 +769,7 @@ return false; } } + mimeMappings.putAll(temp.getMimeMappings()); for (WebXml fragment : fragments) { if (!mergeResourceMap(fragment.getResourceEnvRefs(), resourceEnvRefs, @@ -836,7 +840,7 @@ } } } - + servlets.putAll(temp.getServlets()); if (sessionTimeout == null) { for (WebXml fragment : fragments) { @@ -919,7 +923,7 @@ for (String key : fragmentMap.keySet()) { if (!mainMap.containsKey(key)) { // Not defined in main web.xml - T value =fragmentMap.get(key); + T value = fragmentMap.get(key); if (tempMap.containsKey(key)) { if (value != null && !value.equals( tempMap.get(key))) { @@ -1019,10 +1023,62 @@ dest.addInitParameter(srcEntry.getKey(), srcEntry.getValue()); } } + + if (dest.getMultipartDef() == null) { + dest.setMultipartDef(src.getMultipartDef()); + } else if (src.getMultipartDef() != null) { + return mergeMultipartDef(src.getMultipartDef(), + dest.getMultipartDef(), failOnConflict); + } + return true; } + private boolean mergeMultipartDef(MultipartDef src, MultipartDef dest, + boolean failOnConflict) { + + if (dest.getLocation() == null) { + dest.setLocation(src.getLocation()); + } else if (src.getLocation() != null) { + if (failOnConflict && + !src.getLocation().equals(dest.getLocation())) { + return false; + } + } + + if (dest.getFileSizeThreshold() == null) { + dest.setFileSizeThreshold(src.getFileSizeThreshold()); + } else if (src.getFileSizeThreshold() != null) { + if (failOnConflict && + !src.getFileSizeThreshold().equals( + dest.getFileSizeThreshold())) { + return false; + } + } + if (dest.getMaxFileSize() == null) { + dest.setMaxFileSize(src.getMaxFileSize()); + } else if (src.getLocation() != null) { + if (failOnConflict && + !src.getMaxFileSize().equals(dest.getMaxFileSize())) { + return false; + } + } + + if (dest.getMaxRequestSize() == null) { + dest.setMaxRequestSize(src.getMaxRequestSize()); + } else if (src.getMaxRequestSize() != null) { + if (failOnConflict && + !src.getMaxRequestSize().equals( + dest.getMaxRequestSize())) { + return false; + } + } + + return true; + } + + /** * Generates the sub-set of the web-fragment.xml files to be processed in * the order that the fragments must be processed as per the rules in the --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org