Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/main/java/io/minio/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ private Client(URL url) {
* @throws MalformedURLException malformed url
* @see #getClient(String)
*/
public static Client getClient(URL url) throws MalformedURLException {
public static Client getClient(URL url) throws MalformedURLException, ClientException {
// URL should not be null
if (url == null) {
throw new NullPointerException();
throw new InvalidArgumentException();
}

// check if url is http or https
Expand Down Expand Up @@ -155,9 +155,9 @@ public static Client getClient(URL url) throws MalformedURLException {
* @throws MalformedURLException malformed url
* @see #getClient(URL url)
*/
public static Client getClient(String url) throws MalformedURLException {
public static Client getClient(String url) throws MalformedURLException, ClientException {
if (url == null) {
throw new NullPointerException();
throw new InvalidArgumentException();
}
return getClient(new URL(url));
}
Expand Down Expand Up @@ -220,7 +220,7 @@ private void parseError(HttpResponse response) throws IOException, ClientExcepti
int statusCode = response.getStatusCode();

if (statusCode == 307 || statusCode == 301) {
throw new RedirectionException();
throw new HTTPRedirectException();
}

if (statusCode == 404 || statusCode == 403 || statusCode == 501 || statusCode == 405) {
Expand Down Expand Up @@ -286,11 +286,11 @@ private void parseError(HttpResponse response) throws IOException, ClientExcepti
else if ("InvalidObjectName".equals(code)) e = new InvalidKeyNameException();
else if ("AccessDenied".equals(code)) e = new AccessDeniedException();
else if ("BucketAlreadyExists".equals(code)) e = new BucketExistsException();
else if ("ObjectAlreadyExists".equals(code)) e = new ObjectExistsException();
else if ("InternalError".equals(code)) e = new InternalServerException();
else if ("KeyTooLong".equals(code)) e = new InvalidKeyNameException();
else if ("TooManyBuckets".equals(code)) e = new MaxBucketsReachedException();
else if ("PermanentRedirect".equals(code)) e = new RedirectionException();
else if ("PermanentRedirect".equals(code)) e = new HTTPRedirectException();
else if ("TemporaryRedirect".equals(code)) e = new HTTPRedirectException();
else if ("MethodNotAllowed".equals(code)) e = new ObjectExistsException();
else if ("BucketAlreadyOwnedByYou".equals(code)) e = new BucketExistsException();
else e = new InternalClientException(errorResponse.toString());
Expand Down Expand Up @@ -690,7 +690,7 @@ public Iterator<Bucket> listBuckets() throws IOException, ClientException {
}
try {
parseError(response);
} catch (RedirectionException ex) {
} catch (HTTPRedirectException ex) {
AccessDeniedException fe = new AccessDeniedException();
fe.initCause(ex);
throw fe;
Expand Down Expand Up @@ -839,7 +839,7 @@ public void removeBucket(String bucket) throws IOException, ClientException {
public Acl getBucketACL(String bucket) throws IOException, ClientException {
AccessControlPolicy policy = this.getAccessPolicy(bucket);
if (policy == null) {
throw new NullPointerException();
throw new InvalidArgumentException();
}
Acl acl = Acl.PRIVATE;
List<Grant> accessControlList = policy.getAccessControlList();
Expand Down Expand Up @@ -991,7 +991,7 @@ public void putObject(String bucket, String key, String contentType, long size,
if (!isMultipart) {
Data data = readData((int) size, body);
if (data.getData().length != size || destructiveHasMore(body)) {
throw new DataSizeMismatchException();
throw new InputSizeMismatchException();
}
try {
putObject(bucket, key, contentType, data.getData(), data.getMD5());
Expand All @@ -1011,7 +1011,7 @@ public void putObject(String bucket, String key, String contentType, long size,
Data data = readData(partSize, body);
totalSeen += data.getData().length;
if (totalSeen > size) {
throw new DataSizeMismatchException();
throw new InputSizeMismatchException();
}
if (existingParts.hasNext()) {
Part existingPart = existingParts.next();
Expand All @@ -1035,7 +1035,7 @@ public void putObject(String bucket, String key, String contentType, long size,
throw new IOException("Data size mismatched");
}
if (totalSeen != size) {
throw new DataSizeMismatchException();
throw new InputSizeMismatchException();
}
try {
completeMultipart(bucket, key, uploadID, parts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

package io.minio.client.errors;

public class RedirectionException extends ClientException {
public class HTTPRedirectException extends ClientException {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Minimal Object Storage Library, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.minio.client.errors;

public class InputSizeMismatchException extends ClientException {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

package io.minio.client.errors;

public class DataSizeMismatchException extends ClientException {
public class InvalidArgumentException extends ClientException {
}
22 changes: 11 additions & 11 deletions src/test/java/io/minio/client/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
@SuppressWarnings("unused")
public class ClientTest {
@Test()
public void instantiateNewClient() throws MalformedURLException {
public void instantiateNewClient() throws MalformedURLException, ClientException {
String expectedHost = "example.com";
Client client = Client.getClient("http://" + expectedHost);

Expand All @@ -58,7 +58,7 @@ public void instantiateNewClient() throws MalformedURLException {
}

@Test()
public void instantiateNewClientWithTrailingSlash() throws MalformedURLException {
public void instantiateNewClientWithTrailingSlash() throws MalformedURLException, ClientException {
String expectedHost = "example.com";
Client client = Client.getClient("http://" + expectedHost + "/");

Expand All @@ -70,34 +70,34 @@ public void instantiateNewClientWithTrailingSlash() throws MalformedURLException
}

@Test()
public void setUserAgentOnceSet() throws IOException {
public void setUserAgentOnceSet() throws IOException, ClientException {
String expectedHost = "example.com";
Client client = Client.getClient("http://" + expectedHost + "/");
client.setUserAgent("testApp", "1.0.0", "");
}

@Test(expected = IOException.class)
public void setUserAgentTwiceSet() throws IOException {
public void setUserAgentTwiceSet() throws IOException, ClientException {
String expectedHost = "example.com";
Client client = Client.getClient("http://" + expectedHost + "/");
client.setUserAgent("testApp", "1.0.0", "");
client.setUserAgent("testApp", "1.0.0", "");
}

@Test(expected = MalformedURLException.class)
public void newClientWithPathFails() throws MalformedURLException {
public void newClientWithPathFails() throws MalformedURLException, ClientException {
Client.getClient("http://example.com/path");
throw new RuntimeException("Expected exception did not fire");
}

@Test(expected = NullPointerException.class)
public void newClientWithNullURLFails() throws MalformedURLException {
@Test(expected = InvalidArgumentException.class)
public void newClientWithNullURLFails() throws MalformedURLException, ClientException {
Client.getClient((URL) null);
throw new RuntimeException("Expected exception did not fire");
}

@Test(expected = NullPointerException.class)
public void newClientWithNullURLStringFails() throws MalformedURLException {
@Test(expected = InvalidArgumentException.class)
public void newClientWithNullURLStringFails() throws MalformedURLException, ClientException {
Client.getClient((String) null);
throw new RuntimeException("Expected exception did not fire");
}
Expand Down Expand Up @@ -737,7 +737,7 @@ public LowLevelHttpResponse execute() throws IOException {

// this case only occurs for minio object storage
// @Test(expected = ObjectExistsException.class)
@Test(expected = DataSizeMismatchException.class)
@Test(expected = InputSizeMismatchException.class)
public void testPutIncompleteSmallPut() throws IOException, NoSuchAlgorithmException, XmlPullParserException, ClientException {
final ErrorResponse errResponse = new ErrorResponse();
errResponse.setCode("MethodNotAllowed");
Expand Down Expand Up @@ -770,7 +770,7 @@ public LowLevelHttpResponse execute() throws IOException {
throw new RuntimeException("Expected exception did not fire");
}

@Test(expected = DataSizeMismatchException.class)
@Test(expected = InputSizeMismatchException.class)
public void testPutOversizedSmallPut() throws IOException, NoSuchAlgorithmException, XmlPullParserException, ClientException {
final ErrorResponse errResponse = new ErrorResponse();
errResponse.setCode("MethodNotAllowed");
Expand Down