Browse Source

UrlResource eagerly closes HTTP connections in case of "getInputStream()" failure (SPR-5338)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@632 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 17 years ago
parent
commit
319fbf783b
  1. 14
      org.springframework.core/src/main/java/org/springframework/core/io/UrlResource.java

14
org.springframework.core/src/main/java/org/springframework/core/io/UrlResource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -19,6 +19,7 @@ package org.springframework.core.io; @@ -19,6 +19,7 @@ package org.springframework.core.io;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@ -120,7 +121,16 @@ public class UrlResource extends AbstractResource { @@ -120,7 +121,16 @@ public class UrlResource extends AbstractResource {
public InputStream getInputStream() throws IOException {
URLConnection con = this.url.openConnection();
con.setUseCaches(false);
return con.getInputStream();
try {
return con.getInputStream();
}
catch (IOException ex) {
// Close the HTTP connection (if applicable).
if (con instanceof HttpURLConnection) {
((HttpURLConnection) con).disconnect();
}
throw ex;
}
}
/**

Loading…
Cancel
Save