Commit 009ccefd authored by Matija Obreza's avatar Matija Obreza
Browse files

S3#exists() must not throw exception on 4XX error

parent 53365934
......@@ -44,6 +44,7 @@ import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
// TODO: Auto-generated Javadoc
......@@ -336,8 +337,13 @@ public class S3StorageServiceImpl implements BytesStorageService {
});
}
return true;
} catch (final HttpClientErrorException e4XX) {
if (LOG.isDebugEnabled()) {
LOG.debug("4XX error returned: {}", e4XX.getMessage());
}
return false;
} catch (final Throwable e) {
LOG.warn("Catch this thing!");
LOG.warn("Catch this thing!", e);
throw e;
}
}
......
......@@ -301,4 +301,32 @@ public class S3StorageServiceTest {
public void invalidRemoveNullFilename() throws IOException, InvalidKeyException, NoSuchAlgorithmException {
bytesStorageService.remove("/test/", null);
}
/**
* Ensure 404 exception is not thrown for non-existent file.
*/
@Test
public void testExistsWithoutExceptions() {
assertThat("File should not exist", bytesStorageService.exists(PATH, "file-should-not-exist"), is(false));
}
/**
* Ensure 404 exception is not thrown for non-existent file.
*
* @throws IOException
*/
@Test
public void testExistsNoYesNo() throws IOException {
assertThat("File should not exist", bytesStorageService.exists(PATH, FILENAME), is(false));
bytesStorageService.upsert(PATH, FILENAME, SOME_BYTES);
final byte[] response = bytesStorageService.get(PATH, FILENAME);
assertThat("File bytes length is different", response.length, is(SOME_BYTES.length));
assertArrayEquals("File bytes don't match", SOME_BYTES, response);
assertThat("File must exist", bytesStorageService.exists(PATH, FILENAME), is(true));
bytesStorageService.remove(PATH, FILENAME);
assertThat("File must not exist", bytesStorageService.exists(PATH, FILENAME), is(false));
}
}
Supports Markdown
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