Browse Source

Servlet/PortletContextResource's getFile prefers "file:" URL resolution over calling getRealPath (SPR-8461)

pull/7/head
Juergen Hoeller 13 years ago
parent
commit
b55040cf02
  1. 20
      org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/context/PortletContextResource.java
  2. 20
      org.springframework.web/src/main/java/org/springframework/web/context/support/ServletContextResource.java

20
org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/context/PortletContextResource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ import org.springframework.core.io.AbstractFileResolvingResource; @@ -28,6 +28,7 @@ import org.springframework.core.io.AbstractFileResolvingResource;
import org.springframework.core.io.ContextResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.portlet.util.PortletUtils;
@ -135,14 +136,23 @@ public class PortletContextResource extends AbstractFileResolvingResource implem @@ -135,14 +136,23 @@ public class PortletContextResource extends AbstractFileResolvingResource implem
}
/**
* This implementation delegates to <code>PortletContext.getRealPath</code>,
* but throws a FileNotFoundException if not found or not resolvable.
* This implementation resolves "file:" URLs or alternatively delegates to
* <code>PortletContext.getRealPath</code>, throwing a FileNotFoundException
* if not found or not resolvable.
* @see javax.portlet.PortletContext#getResource(String)
* @see javax.portlet.PortletContext#getRealPath(String)
*/
@Override
public File getFile() throws IOException {
String realPath = PortletUtils.getRealPath(this.portletContext, this.path);
return new File(realPath);
URL url = getURL();
if (ResourceUtils.isFileURL(url)) {
// Proceed with file system resolution...
return super.getFile();
}
else {
String realPath = PortletUtils.getRealPath(this.portletContext, this.path);
return new File(realPath);
}
}
@Override

20
org.springframework.web/src/main/java/org/springframework/web/context/support/ServletContextResource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ import org.springframework.core.io.AbstractFileResolvingResource; @@ -28,6 +28,7 @@ import org.springframework.core.io.AbstractFileResolvingResource;
import org.springframework.core.io.ContextResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.util.WebUtils;
@ -135,14 +136,23 @@ public class ServletContextResource extends AbstractFileResolvingResource implem @@ -135,14 +136,23 @@ public class ServletContextResource extends AbstractFileResolvingResource implem
}
/**
* This implementation delegates to <code>ServletContext.getRealPath</code>,
* but throws a FileNotFoundException if not found or not resolvable.
* This implementation resolves "file:" URLs or alternatively delegates to
* <code>ServletContext.getRealPath</code>, throwing a FileNotFoundException
* if not found or not resolvable.
* @see javax.servlet.ServletContext#getResource(String)
* @see javax.servlet.ServletContext#getRealPath(String)
*/
@Override
public File getFile() throws IOException {
String realPath = WebUtils.getRealPath(this.servletContext, this.path);
return new File(realPath);
URL url = getURL();
if (ResourceUtils.isFileURL(url)) {
// Proceed with file system resolution...
return super.getFile();
}
else {
String realPath = WebUtils.getRealPath(this.servletContext, this.path);
return new File(realPath);
}
}
/**

Loading…
Cancel
Save