Example usage for org.apache.hadoop.yarn.webapp ForbiddenException ForbiddenException

List of usage examples for org.apache.hadoop.yarn.webapp ForbiddenException ForbiddenException

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.webapp ForbiddenException ForbiddenException.

Prototype

public ForbiddenException(String msg) 

Source Link

Usage

From source file:org.apache.slider.core.restclient.UrlConnectionOperations.java

License:Apache License

/**
 * Uprate error codes 400 and up into faults; 
 * 404 is converted to a {@link NotFoundException},
 * 401 to {@link ForbiddenException}//  w w w .jav a2  s  .  c  o  m
 *
 * @param verb HTTP Verb used
 * @param url URL as string
 * @param resultCode response from the request
 * @param bodyAsString
 *@param body optional body of the request  @throws IOException if the result was considered a failure
 */
public static void uprateFaults(HttpVerb verb, String url, int resultCode, String bodyAsString, byte[] body)
        throws IOException {

    if (resultCode < 400) {
        //success
        return;
    }
    String msg = verb.toString() + " " + url;
    if (resultCode == 404) {
        throw new NotFoundException(msg);
    }
    if (resultCode == 401) {
        throw new ForbiddenException(msg);
    }
    // all other error codes

    // get a string respnse
    if (bodyAsString == null) {
        if (body != null && body.length > 0) {
            bodyAsString = new String(body);
        } else {
            bodyAsString = "";
        }
    }
    String message = msg + " failed with exit code " + resultCode + ", body length " + bodyAsString.length()
            + ":\n" + bodyAsString;
    log.error(message);
    throw new IOException(message);
}

From source file:org.apache.slider.server.appmaster.web.rest.AbstractSliderResource.java

License:Apache License

/**
 * Convert any exception caught into a web application
 * exception for rethrowing/*from  www  . j  a va  2  s  .com*/
 * @param path path of request
 * @param ex exception
 * @return an exception to throw
 */
public WebApplicationException buildException(String path, Exception ex) {
    try {
        throw ex;
    } catch (WebApplicationException e) {
        // rethrow direct
        throw e;
    } catch (FileNotFoundException e) {
        return new NotFoundException("Not found: " + path);
    } catch (PathNotFoundException e) {
        return new NotFoundException("Not found: " + path);
    } catch (AuthenticationFailedException e) {
        return new ForbiddenException(path);
    } catch (NoPathPermissionsException e) {
        return new ForbiddenException(path);
    } catch (Exception e) {
        log.error("Error during generation of response: {}", e, e);
        return new WebApplicationException(e);
    }
}

From source file:org.apache.slider.server.appmaster.web.rest.registry.RegistryResource.java

License:Apache License

/**
 * Do the actual processing of requests to responses; can be directly
 * invoked for testing./*from w w  w. j  a  v a  2  s.c  om*/
 * @param path path to query
 * @return the entry
 * @throws WebApplicationException on any failure.
 */
public PathEntryResource resolvePath(String path) throws WebApplicationException {
    try {
        PathEntryResource pathEntry = fromRegistry(path);
        if (log.isDebugEnabled()) {
            log.debug("Resolved:\n{}", pathEntry);
        }
        return pathEntry;
    } catch (WebApplicationException e) {
        // rethrow direct
        throw e;
    } catch (PathNotFoundException e) {
        throw new NotFoundException("Not found: " + path);
    } catch (AuthenticationFailedException e) {
        throw new ForbiddenException(path);
    } catch (NoPathPermissionsException e) {
        throw new ForbiddenException(path);
    } catch (Exception e) {
        log.error("Error during generation of response: {}", e, e);
        throw new WebApplicationException(e);
    }
}