From: markt Date: Tue, 17 Nov 2009 20:53:32 +0000 (+0000) Subject: Add support for multipart config in web.xml (partially complete) X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1c521c29b281aede38c194aa462d1968a2cb69a8;p=tomcat7.0 Add support for multipart config in web.xml (partially complete) Review and fix issues in WebXml merge code git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@881503 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/deploy/MultipartDef.java b/java/org/apache/catalina/deploy/MultipartDef.java new file mode 100644 index 000000000..47930aaca --- /dev/null +++ b/java/org/apache/catalina/deploy/MultipartDef.java @@ -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; + } + +} diff --git a/java/org/apache/catalina/deploy/ServletDef.java b/java/org/apache/catalina/deploy/ServletDef.java index cad08bba0..6fec5922a 100644 --- a/java/org/apache/catalina/deploy/ServletDef.java +++ b/java/org/apache/catalina/deploy/ServletDef.java @@ -207,4 +207,17 @@ public class ServletDef implements Serializable { 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; + } } diff --git a/java/org/apache/catalina/startup/WebRuleSet.java b/java/org/apache/catalina/startup/WebRuleSet.java index 46e1d251b..05f4aa406 100644 --- a/java/org/apache/catalina/startup/WebRuleSet.java +++ b/java/org/apache/catalina/startup/WebRuleSet.java @@ -368,6 +368,19 @@ public class WebRuleSet extends RuleSetBase { "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)); diff --git a/java/org/apache/catalina/startup/WebXml.java b/java/org/apache/catalina/startup/WebXml.java index f67c91755..41c159125 100644 --- a/java/org/apache/catalina/startup/WebXml.java +++ b/java/org/apache/catalina/startup/WebXml.java @@ -43,6 +43,7 @@ import org.apache.catalina.deploy.JspPropertyGroup; 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 @@ public class WebXml { roleRef.getName(), roleRef.getLink()); } wrapper.setServletClass(servlet.getServletClass()); + // TODO SERVLET3 - Multipart config context.addChild(wrapper); } for (String pattern : servletMappings.keySet()) { @@ -699,6 +701,7 @@ public class WebXml { } } } + filters.putAll(temp.getFilters()); for (WebXml fragment : fragments) { for (JspPropertyGroup jspPropertyGroup : fragment.getJspPropertyGroups()) { @@ -721,7 +724,7 @@ public class WebXml { return false; } } - errorPages.putAll(temp.getErrorPages()); + localeEncodingMappings.putAll(temp.getLocalEncodingMappings()); if (getLoginConfig() == null) { LoginConfig tempLoginConfig = null; @@ -766,6 +769,7 @@ public class WebXml { return false; } } + mimeMappings.putAll(temp.getMimeMappings()); for (WebXml fragment : fragments) { if (!mergeResourceMap(fragment.getResourceEnvRefs(), resourceEnvRefs, @@ -836,7 +840,7 @@ public class WebXml { } } } - + servlets.putAll(temp.getServlets()); if (sessionTimeout == null) { for (WebXml fragment : fragments) { @@ -919,7 +923,7 @@ public class WebXml { 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 @@ public class WebXml { 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