use of org.apache.hadoop.fs.swift.exceptions.SwiftBadRequestException in project hadoop by apache.
the class SwiftRestClient method buildException.
/**
* Build an exception from a failed operation. This can include generating
* specific exceptions (e.g. FileNotFound), as well as the default
* {@link SwiftInvalidResponseException}.
*
* @param uri URI for operation
* @param method operation that failed
* @param statusCode status code
* @param <M> method type
* @return an exception to throw
*/
private <M extends HttpMethod> IOException buildException(URI uri, M method, int statusCode) {
IOException fault;
//log the failure @debug level
String errorMessage = String.format("Method %s on %s failed, status code: %d," + " status line: %s", method.getName(), uri, statusCode, method.getStatusLine());
if (LOG.isDebugEnabled()) {
LOG.debug(errorMessage);
}
//send the command
switch(statusCode) {
case SC_NOT_FOUND:
fault = new FileNotFoundException("Operation " + method.getName() + " on " + uri);
break;
case SC_BAD_REQUEST:
//bad HTTP request
fault = new SwiftBadRequestException("Bad request against " + uri, method.getName(), uri, method);
break;
case SC_REQUESTED_RANGE_NOT_SATISFIABLE:
//out of range
StringBuilder errorText = new StringBuilder(method.getStatusText());
//get the requested length
Header requestContentLen = method.getRequestHeader(HEADER_CONTENT_LENGTH);
if (requestContentLen != null) {
errorText.append(" requested ").append(requestContentLen.getValue());
}
//and the result
Header availableContentRange = method.getResponseHeader(HEADER_CONTENT_RANGE);
if (availableContentRange != null) {
errorText.append(" available ").append(availableContentRange.getValue());
}
fault = new EOFException(errorText.toString());
break;
case SC_UNAUTHORIZED:
//auth failure; should only happen on the second attempt
fault = new SwiftAuthenticationFailedException("Operation not authorized- current access token =" + getToken(), method.getName(), uri, method);
break;
case SwiftProtocolConstants.SC_TOO_MANY_REQUESTS_429:
case SwiftProtocolConstants.SC_THROTTLED_498:
//response code that may mean the client is being throttled
fault = new SwiftThrottledRequestException("Client is being throttled: too many requests", method.getName(), uri, method);
break;
default:
//return a generic invalid HTTP response
fault = new SwiftInvalidResponseException(errorMessage, method.getName(), uri, method);
}
return fault;
}
use of org.apache.hadoop.fs.swift.exceptions.SwiftBadRequestException in project hadoop by apache.
the class TestSwiftFileSystemBasicOps method testLongObjectNamesForbidden.
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testLongObjectNamesForbidden() throws Throwable {
StringBuilder buffer = new StringBuilder(1200);
buffer.append("/");
for (int i = 0; i < (1200 / 4); i++) {
buffer.append(String.format("%04x", i));
}
String pathString = buffer.toString();
Path path = new Path(pathString);
try {
writeTextFile(fs, path, pathString, true);
//if we get here, problems.
fs.delete(path, false);
fail("Managed to create an object with a name of length " + pathString.length());
} catch (SwiftBadRequestException e) {
//expected
//LOG.debug("Caught exception " + e, e);
}
}
Aggregations