类org.apache.hadoop.fs.swift.exceptions.SwiftBadRequestException源码实例Demo

下面列出了怎么用org.apache.hadoop.fs.swift.exceptions.SwiftBadRequestException的API类实例代码及写法,或者点击链接到github查看源代码。


@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);
  }
}
 

@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);
  }
}
 

@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);
  }
}
 
源代码4 项目: hadoop   文件: SwiftRestClient.java

/**
 * Create a container -if it already exists, do nothing
 *
 * @param containerName the container name
 * @throws IOException IO problems
 * @throws SwiftBadRequestException invalid container name
 * @throws SwiftInvalidResponseException error from the server
 */
public void createContainer(String containerName) throws IOException {
  SwiftObjectPath objectPath = new SwiftObjectPath(containerName, "");
  try {
    //see if the data is there
    headRequest("createContainer", objectPath, NEWEST);
  } catch (FileNotFoundException ex) {
    int status = 0;
    try {
      status = putRequest(objectPath);
    } catch (FileNotFoundException e) {
      //triggered by a very bad container name.
      //re-insert the 404 result into the status
      status = SC_NOT_FOUND;
    }
    if (status == SC_BAD_REQUEST) {
      throw new SwiftBadRequestException(
        "Bad request -authentication failure or bad container name?",
        status,
        "PUT",
        null);
    }
    if (!isStatusCodeExpected(status,
            SC_OK,
            SC_CREATED,
            SC_ACCEPTED,
            SC_NO_CONTENT)) {
      throw new SwiftInvalidResponseException("Couldn't create container "
              + containerName +
              " for storing data in Swift." +
              " Try to create container " +
              containerName + " manually ",
              status,
              "PUT",
              null);
    } else {
      throw ex;
    }
  }
}
 
源代码5 项目: big-c   文件: SwiftRestClient.java

/**
 * Create a container -if it already exists, do nothing
 *
 * @param containerName the container name
 * @throws IOException IO problems
 * @throws SwiftBadRequestException invalid container name
 * @throws SwiftInvalidResponseException error from the server
 */
public void createContainer(String containerName) throws IOException {
  SwiftObjectPath objectPath = new SwiftObjectPath(containerName, "");
  try {
    //see if the data is there
    headRequest("createContainer", objectPath, NEWEST);
  } catch (FileNotFoundException ex) {
    int status = 0;
    try {
      status = putRequest(objectPath);
    } catch (FileNotFoundException e) {
      //triggered by a very bad container name.
      //re-insert the 404 result into the status
      status = SC_NOT_FOUND;
    }
    if (status == SC_BAD_REQUEST) {
      throw new SwiftBadRequestException(
        "Bad request -authentication failure or bad container name?",
        status,
        "PUT",
        null);
    }
    if (!isStatusCodeExpected(status,
            SC_OK,
            SC_CREATED,
            SC_ACCEPTED,
            SC_NO_CONTENT)) {
      throw new SwiftInvalidResponseException("Couldn't create container "
              + containerName +
              " for storing data in Swift." +
              " Try to create container " +
              containerName + " manually ",
              status,
              "PUT",
              null);
    } else {
      throw ex;
    }
  }
}
 
源代码6 项目: sahara-extra   文件: SwiftRestClient.java

/**
 * Create a container -if it already exists, do nothing
 *
 * @param containerName the container name
 * @throws IOException IO problems
 * @throws SwiftBadRequestException invalid container name
 * @throws SwiftInvalidResponseException error from the server
 */
public void createContainer(String containerName) throws IOException {
  SwiftObjectPath objectPath = new SwiftObjectPath(containerName, "");
  try {
    //see if the data is there
    headRequest("createContainer", objectPath, NEWEST);
  } catch (FileNotFoundException ex) {
    int status = 0;
    try {
      status = putRequest(objectPath);
    } catch (FileNotFoundException e) {
      //triggered by a very bad container name.
      //re-insert the 404 result into the status
      status = SC_NOT_FOUND;
    }
    if (status == SC_BAD_REQUEST) {
      throw new SwiftBadRequestException(
        "Bad request -authentication failure or bad container name?",
        status,
        "PUT",
        null);
    }
    if (!isStatusCodeExpected(status,
            SC_OK,
            SC_CREATED,
            SC_ACCEPTED,
            SC_NO_CONTENT)) {
      throw new SwiftInvalidResponseException("Couldn't create container "
              + containerName +
              " for storing data in Swift." +
              " Try to create container " +
              containerName + " manually ",
              status,
              "PUT",
              null);
    } else {
      throw ex;
    }
  }
}
 
源代码7 项目: hadoop   文件: SwiftRestClient.java

/**
 * Performs the HTTP request, validates the response code and returns
 * the received data. HTTP Status codes are converted into exceptions.
 *
 * @param uri URI to source
 * @param processor HttpMethodProcessor
 * @param <M> method
 * @param <R> result type
 * @return result of HTTP request
 * @throws IOException IO problems
 * @throws SwiftBadRequestException the status code indicated "Bad request"
 * @throws SwiftInvalidResponseException the status code is out of range
 * for the action (excluding 404 responses)
 * @throws SwiftInternalStateException the internal state of this client
 * is invalid
 * @throws FileNotFoundException a 404 response was returned
 */
private <M extends HttpMethod, R> R perform(URI uri,
                    HttpMethodProcessor<M, R> processor)
  throws IOException,
         SwiftBadRequestException,
         SwiftInternalStateException,
         SwiftInvalidResponseException,
         FileNotFoundException {
  return perform("",uri, processor);
}
 
源代码8 项目: big-c   文件: SwiftRestClient.java

/**
 * Performs the HTTP request, validates the response code and returns
 * the received data. HTTP Status codes are converted into exceptions.
 *
 * @param uri URI to source
 * @param processor HttpMethodProcessor
 * @param <M> method
 * @param <R> result type
 * @return result of HTTP request
 * @throws IOException IO problems
 * @throws SwiftBadRequestException the status code indicated "Bad request"
 * @throws SwiftInvalidResponseException the status code is out of range
 * for the action (excluding 404 responses)
 * @throws SwiftInternalStateException the internal state of this client
 * is invalid
 * @throws FileNotFoundException a 404 response was returned
 */
private <M extends HttpMethod, R> R perform(URI uri,
                    HttpMethodProcessor<M, R> processor)
  throws IOException,
         SwiftBadRequestException,
         SwiftInternalStateException,
         SwiftInvalidResponseException,
         FileNotFoundException {
  return perform("",uri, processor);
}
 
源代码9 项目: sahara-extra   文件: SwiftRestClient.java

/**
 * Performs the HTTP request, validates the response code and returns
 * the received data. HTTP Status codes are converted into exceptions.
 *
 * @param uri URI to source
 * @param processor HttpMethodProcessor
 * @param <M> method
 * @param <R> result type
 * @return result of HTTP request
 * @throws IOException IO problems
 * @throws SwiftBadRequestException the status code indicated "Bad request"
 * @throws SwiftInvalidResponseException the status code is out of range
 * for the action (excluding 404 responses)
 * @throws SwiftInternalStateException the internal state of this client
 * is invalid
 * @throws FileNotFoundException a 404 response was returned
 */
private <M extends HttpMethod, R> R perform(URI uri,
                    HttpMethodProcessor<M, R> processor)
  throws IOException,
         SwiftBadRequestException,
         SwiftInternalStateException,
         SwiftInvalidResponseException,
         FileNotFoundException {
  return perform("",uri, processor);
}
 
 类所在包
 同包方法