Example usage for org.apache.solr.common.util Base64 byteArrayToBase64

List of usage examples for org.apache.solr.common.util Base64 byteArrayToBase64

Introduction

In this page you can find the example usage for org.apache.solr.common.util Base64 byteArrayToBase64.

Prototype

public static String byteArrayToBase64(byte[] a) 

Source Link

Usage

From source file:com.ilscipio.scipio.solr.util.ScipioHttpSolrClient.java

License:Apache License

/**
 * Sets basic auth header to the given username and password.
 * <p>/*from w  ww .j a v  a2  s  .c o  m*/
 * DEV NOTE: Derived from {@link HttpSolrClient#setBasicAuthHeader}, which is private in superclass.
 */
protected void setBasicAuthHeader(HttpRequestBase method, String username, String password)
        throws UnsupportedEncodingException {
    String userPass = username + ":" + password;
    String encoded = Base64.byteArrayToBase64(userPass.getBytes(UTF_8));
    method.setHeader(new BasicHeader("Authorization", "Basic " + encoded));
}

From source file:uk.bl.wa.annotation.AnnotationsFromAct.java

License:Open Source License

/**
 * Performs login operation to ACT, setting Cookie and CSRF.
 * @throws IOException//from  w  ww .j  av a 2  s.c  om
 */
private void actLogin() throws IOException {
    Config loginConf = ConfigFactory.parseFile(new File("credentials.conf"));
    URL login = new URL(loginConf.getString("act.login"));
    LOG.info("Logging in at " + login);

    HttpURLConnection connection = (HttpURLConnection) login.openConnection();
    StringBuilder credentials = new StringBuilder();
    credentials.append(loginConf.getString("act.username"));
    credentials.append(":");
    credentials.append(loginConf.getString("act.password"));
    connection.setRequestProperty("Authorization",
            "Basic " + Base64.byteArrayToBase64(credentials.toString().getBytes()));
    connection.setRequestProperty("Content-Type", "text/plain");

    Scanner scanner;
    if (connection.getResponseCode() != 200) {
        scanner = new Scanner(connection.getErrorStream());
        scanner.useDelimiter("\\Z");
        throw new IOException(scanner.next());
    } else {
        scanner = new Scanner(connection.getInputStream());
    }
    scanner.useDelimiter("\\Z");
    this.csrf = scanner.next();
    this.cookie = connection.getHeaderField("set-cookie");
}