{
String location = multipart.getString("location", false, true);
String maxFile = multipart.getString("max-file-size", false, true);
String maxRequest = multipart.getString("max-request-size", false, true);
String threshold = multipart.getString("file-size-threshold",false,true);
MultipartConfigElement element = new MultipartConfigElement(location,
(maxFile==null||"".equals(maxFile)?-1L:Long.parseLong(maxFile)),
(maxRequest==null||"".equals(maxRequest)?-1L:Long.parseLong(maxRequest)),
(threshold==null||"".equals(threshold)?0:Integer.parseInt(threshold)));
switch (context.getMetaData().getOrigin(name+".servlet.multipart-config"))
{
case NotSet:
{
//hasn't been set, so set it
holder.getRegistration().setMultipartConfig(element);
context.getMetaData().setOrigin(name+".servlet.multipart-config", descriptor);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//was set in a web xml, only allow changes if we're parsing another web xml (web.xml/web-default.xml/web-override.xml)
if (!(descriptor instanceof FragmentDescriptor))
{
holder.getRegistration().setMultipartConfig(element);
context.getMetaData().setOrigin(name+".servlet.multipart-config", descriptor);
}
break;
}
case WebFragment:
{
//another fragment set the value, this fragment's values must match exactly or it is an error
MultipartConfigElement cfg = ((ServletHolder.Registration)holder.getRegistration()).getMultipartConfig();
if (cfg.getMaxFileSize() != element.getMaxFileSize())
throw new IllegalStateException("Conflicting multipart-config max-file-size for servlet "+name+" in "+descriptor.getResource());
if (cfg.getMaxRequestSize() != element.getMaxRequestSize())
throw new IllegalStateException("Conflicting multipart-config max-request-size for servlet "+name+" in "+descriptor.getResource());
if (cfg.getFileSizeThreshold() != element.getFileSizeThreshold())
throw new IllegalStateException("Conflicting multipart-config file-size-threshold for servlet "+name+" in "+descriptor.getResource());
if ((cfg.getLocation() != null && (element.getLocation() == null || element.getLocation().length()==0))
|| (cfg.getLocation() == null && (element.getLocation()!=null || element.getLocation().length() > 0)))
throw new IllegalStateException("Conflicting multipart-config location for servlet "+name+" in "+descriptor.getResource());
break;
}
default:
LOG.warn(new Throwable()); // TODO throw ISE?