Example usage for org.apache.hadoop.security.authentication.client AuthenticationException AuthenticationException

List of usage examples for org.apache.hadoop.security.authentication.client AuthenticationException AuthenticationException

Introduction

In this page you can find the example usage for org.apache.hadoop.security.authentication.client AuthenticationException AuthenticationException.

Prototype

public AuthenticationException(String msg, Throwable cause) 

Source Link

Document

Creates an AuthenticationException .

Usage

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

License:Apache License

public HttpOperationResponse execHttpOperation(HttpVerb verb, URL url, byte[] payload, String contentType)
        throws IOException, AuthenticationException {
    HttpURLConnection conn = null;
    HttpOperationResponse outcome = new HttpOperationResponse();
    int resultCode;
    byte[] body = null;
    log.debug("{} {} spnego={}", verb, url, useSpnego);

    boolean doOutput = verb.hasUploadBody();
    if (doOutput) {
        Preconditions.checkArgument(payload != null, "Null payload on a verb which expects one");
    }//from   w w w.java 2s  . c o  m
    try {
        conn = openConnection(url);
        conn.setRequestMethod(verb.getVerb());
        conn.setDoOutput(doOutput);
        if (doOutput) {
            conn.setRequestProperty("Content-Type", contentType);
        }

        // now do the connection
        conn.connect();

        if (doOutput) {
            OutputStream output = conn.getOutputStream();
            IOUtils.write(payload, output);
            output.close();
        }

        resultCode = conn.getResponseCode();
        outcome.lastModified = conn.getLastModified();
        outcome.contentType = conn.getContentType();
        outcome.headers = conn.getHeaderFields();
        InputStream stream = conn.getErrorStream();
        if (stream == null) {
            stream = conn.getInputStream();
        }
        if (stream != null) {
            // read into a buffer.
            body = IOUtils.toByteArray(stream);
        } else {
            // no body: 
            log.debug("No body in response");

        }
    } catch (SSLException e) {
        throw e;
    } catch (IOException e) {
        throw NetUtils.wrapException(url.toString(), url.getPort(), "localhost", 0, e);

    } catch (AuthenticationException e) {
        throw new AuthenticationException("From " + url + ": " + e, e);

    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }
    uprateFaults(HttpVerb.GET, url.toString(), resultCode, "", body);
    outcome.responseCode = resultCode;
    outcome.data = body;
    return outcome;
}