Example usage for org.eclipse.jgit.util HttpSupport proxyFor

List of usage examples for org.eclipse.jgit.util HttpSupport proxyFor

Introduction

In this page you can find the example usage for org.eclipse.jgit.util HttpSupport proxyFor.

Prototype

public static Proxy proxyFor(ProxySelector proxySelector, URL u) throws ConnectException 

Source Link

Document

Determine the proxy server (if any) needed to obtain a URL.

Usage

From source file:com.google.gerrit.pgm.init.LibraryDownloader.java

License:Apache License

private static InputStream openHttpStream(String urlStr) throws IOException {
    ProxySelector proxySelector = ProxySelector.getDefault();
    URL url = new URL(urlStr);
    Proxy proxy = HttpSupport.proxyFor(proxySelector, url);
    HttpURLConnection c = (HttpURLConnection) url.openConnection(proxy);

    switch (HttpSupport.response(c)) {
    case HttpURLConnection.HTTP_OK:
        return c.getInputStream();

    case HttpURLConnection.HTTP_NOT_FOUND:
        throw new FileNotFoundException(url.toString());

    default:/*from ww w .  ja v  a  2  s  .co  m*/
        throw new IOException(url.toString() + ": " + HttpSupport.response(c) + " " + c.getResponseMessage());
    }
}

From source file:com.googlesource.gerrit.plugins.its.jira.restapi.JiraURL.java

License:Apache License

public HttpURLConnection openConnection(ProxySelector proxySelector) throws IOException {
    Proxy proxy = HttpSupport.proxyFor(proxySelector, url);
    return (HttpURLConnection) url.openConnection(proxy);
}

From source file:it.com.atlassian.labs.speakeasy.util.jgit.FixedTransportHttp.java

License:Eclipse Distribution License

final HttpURLConnection httpOpen(String method, URL u) throws IOException {
    final Proxy proxy = HttpSupport.proxyFor(proxySelector, u);
    HttpURLConnection conn = (HttpURLConnection) u.openConnection(proxy);

    if (!http.sslVerify && "https".equals(u.getProtocol())) {
        disableSslVerify(conn);/*from   w  w w .  j  a va  2 s.  co  m*/
    }

    conn.setRequestMethod(method);
    conn.setUseCaches(false);
    conn.setRequestProperty(HDR_ACCEPT_ENCODING, ENCODING_GZIP);
    conn.setRequestProperty(HDR_PRAGMA, "no-cache"); //$NON-NLS-1$
    conn.setRequestProperty(HDR_USER_AGENT, userAgent);
    conn.setConnectTimeout(getTimeout() * 1000);
    conn.setReadTimeout(getTimeout() * 1000);
    authMethod.configureRequest(conn);
    return conn;
}