Commit c14f5fb6 authored by Andy Wilkinson's avatar Andy Wilkinson

Polish "Fix handling of spaces in container's document root"

Closes gh-10706
parent 8031a1bd
...@@ -19,7 +19,6 @@ package org.springframework.boot.context.embedded; ...@@ -19,7 +19,6 @@ package org.springframework.boot.context.embedded;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.JarURLConnection; import java.net.JarURLConnection;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.net.URLConnection; import java.net.URLConnection;
...@@ -88,7 +87,7 @@ public abstract class AbstractEmbeddedServletContainerFactory ...@@ -88,7 +87,7 @@ public abstract class AbstractEmbeddedServletContainerFactory
} }
private File getExplodedWarFileDocumentRoot() { private File getExplodedWarFileDocumentRoot() {
return getExplodedWarFileDocumentRoot(getCodeSourceArchive(getCodeSource())); return getExplodedWarFileDocumentRoot(getCodeSourceArchive());
} }
protected List<URL> getUrlsOfJarsWithMetaInfResources() { protected List<URL> getUrlsOfJarsWithMetaInfResources() {
...@@ -173,7 +172,7 @@ public abstract class AbstractEmbeddedServletContainerFactory ...@@ -173,7 +172,7 @@ public abstract class AbstractEmbeddedServletContainerFactory
} }
private File getArchiveFileDocumentRoot(String extension) { private File getArchiveFileDocumentRoot(String extension) {
File file = getCodeSourceArchive(getCodeSource()); File file = getCodeSourceArchive();
if (this.logger.isDebugEnabled()) { if (this.logger.isDebugEnabled()) {
this.logger.debug("Code archive: " + file); this.logger.debug("Code archive: " + file);
} }
...@@ -194,6 +193,10 @@ public abstract class AbstractEmbeddedServletContainerFactory ...@@ -194,6 +193,10 @@ public abstract class AbstractEmbeddedServletContainerFactory
return null; return null;
} }
private File getCodeSourceArchive() {
return getCodeSourceArchive(getClass().getProtectionDomain().getCodeSource());
}
File getCodeSourceArchive(CodeSource codeSource) { File getCodeSourceArchive(CodeSource codeSource) {
try { try {
URL location = (codeSource == null ? null : codeSource.getLocation()); URL location = (codeSource == null ? null : codeSource.getLocation());
...@@ -213,16 +216,9 @@ public abstract class AbstractEmbeddedServletContainerFactory ...@@ -213,16 +216,9 @@ public abstract class AbstractEmbeddedServletContainerFactory
} }
return new File(path); return new File(path);
} }
catch (IOException ex) { catch (Exception ex) {
return null; return null;
} }
catch (URISyntaxException e) {
return null;
}
}
private CodeSource getCodeSource() {
return getClass().getProtectionDomain().getCodeSource();
} }
protected final File getValidSessionStoreDir() { protected final File getValidSessionStoreDir() {
......
...@@ -678,16 +678,18 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -678,16 +678,18 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void codeSourceArchivePath() throws Exception { public void codeSourceArchivePath() throws Exception {
AbstractEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
final CodeSource codeSource = new CodeSource(new URL("file", "", "/some/test/path/"), (Certificate[]) null); CodeSource codeSource = new CodeSource(new URL("file", "", "/some/test/path/"),
final File codeSourceArchive = factory.getCodeSourceArchive(codeSource); (Certificate[]) null);
File codeSourceArchive = factory.getCodeSourceArchive(codeSource);
assertThat(codeSourceArchive).isEqualTo(new File("/some/test/path/")); assertThat(codeSourceArchive).isEqualTo(new File("/some/test/path/"));
} }
@Test @Test
public void codeSourceArchivePathContainingSpaces() throws Exception { public void codeSourceArchivePathContainingSpaces() throws Exception {
AbstractEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
final CodeSource codeSource = new CodeSource(new URL("file", "", "/test/path/with%20space/"), (Certificate[]) null); CodeSource codeSource = new CodeSource(
final File codeSourceArchive = factory.getCodeSourceArchive(codeSource); new URL("file", "", "/test/path/with%20space/"), (Certificate[]) null);
File codeSourceArchive = factory.getCodeSourceArchive(codeSource);
assertThat(codeSourceArchive).isEqualTo(new File("/test/path/with space/")); assertThat(codeSourceArchive).isEqualTo(new File("/test/path/with space/"));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment