Example usage for org.apache.hadoop.security.authentication.client AuthenticatedURL openConnection

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

Introduction

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

Prototype

public HttpURLConnection openConnection(URL url, Token token) throws IOException, AuthenticationException 

Source Link

Document

Returns an authenticated HttpURLConnection .

Usage

From source file:com.trendmicro.hdfs.webdav.tool.Get.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Process command line 

    Options options = new Options();
    options.addOption("d", "debug", false, "Enable debug logging");

    CommandLine cmd = null;/*from  w ww.  ja v  a2  s.  c om*/
    try {
        cmd = new PosixParser().parse(options, args);
    } catch (ParseException e) {
        printUsageAndExit(options, -1);
    }
    boolean debug = cmd.hasOption('d');
    args = cmd.getArgs();
    if (args.length < 1) {
        printUsageAndExit(options, -1);
    }

    // Do the fetch

    AuthenticatedURL.Token token = new AuthenticatedURL.Token();
    AuthenticatedURL url = new AuthenticatedURL();
    HttpURLConnection conn = url.openConnection(new URL(args[0]), token);
    if (debug) {
        System.out.println("Token value: " + token);
        System.out.println("Status code: " + conn.getResponseCode() + " " + conn.getResponseMessage());
    }
    if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        reader.close();
    }
    System.out.println();
}