From fa9a7b18c63dece2be07567b265c09cca43dcb87 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 28 Nov 2011 21:11:57 +0000 Subject: [PATCH] refined Resource "exists()" check for HTTP URLs to always return false for 404 status (SPR-7881) --- .../core/io/AbstractFileResolvingResource.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java b/org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java index a6456a8235..fd00f909f0 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java +++ b/org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java @@ -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. @@ -100,9 +100,13 @@ public abstract class AbstractFileResolvingResource extends AbstractResource { (con instanceof HttpURLConnection ? (HttpURLConnection) con : null); if (httpCon != null) { httpCon.setRequestMethod("HEAD"); - if (httpCon.getResponseCode() == HttpURLConnection.HTTP_OK) { + int code = httpCon.getResponseCode(); + if (code == HttpURLConnection.HTTP_OK) { return true; } + else if (code == HttpURLConnection.HTTP_NOT_FOUND) { + return false; + } } if (con.getContentLength() >= 0) { return true;