Search in sources :

Example 1 with ProxySetup

use of aQute.bnd.service.url.ProxyHandler.ProxySetup in project bnd by bndtools.

the class HttpClient method send0.

public TaggedData send0(final HttpRequest<?> request) throws Exception {
    final ProxySetup proxy = getProxySetup(request.url);
    final URLConnection con = getProxiedAndConfiguredConnection(request.url, proxy);
    final HttpURLConnection hcon = (HttpURLConnection) (con instanceof HttpURLConnection ? con : null);
    if (request.ifNoneMatch != null) {
        request.headers.put("If-None-Match", entitytag(request.ifNoneMatch));
    }
    if (request.ifMatch != null) {
        request.headers.put("If-Match", "\"" + entitytag(request.ifMatch));
    }
    if (request.ifModifiedSince > 0) {
        request.headers.put("If-Modified-Since", httpDateFormat().format(new Date(request.ifModifiedSince)));
    }
    if (request.ifUnmodifiedSince != 0) {
        request.headers.put("If-Unmodified-Since", httpDateFormat().format(new Date(request.ifUnmodifiedSince)));
    }
    setHeaders(request.headers, con);
    configureHttpConnection(request.verb, hcon);
    final ProgressPlugin.Task task = getTask(request);
    try {
        TaggedData td = connectWithProxy(proxy, new Callable<TaggedData>() {

            @Override
            public TaggedData call() throws Exception {
                return doConnect(request.upload, request.download, con, hcon, request, task);
            }
        });
        logger.debug("result {}", td);
        return td;
    } catch (Throwable t) {
        task.done("Failed " + t, t);
        throw t;
    }
}
Also used : Task(aQute.bnd.service.progress.ProgressPlugin.Task) HttpURLConnection(java.net.HttpURLConnection) ProgressPlugin(aQute.bnd.service.progress.ProgressPlugin) ProxySetup(aQute.bnd.service.url.ProxyHandler.ProxySetup) TaggedData(aQute.bnd.service.url.TaggedData) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SocketTimeoutException(java.net.SocketTimeoutException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ProtocolException(java.net.ProtocolException)

Aggregations

ProgressPlugin (aQute.bnd.service.progress.ProgressPlugin)1 Task (aQute.bnd.service.progress.ProgressPlugin.Task)1 ProxySetup (aQute.bnd.service.url.ProxyHandler.ProxySetup)1 TaggedData (aQute.bnd.service.url.TaggedData)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 ProtocolException (java.net.ProtocolException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URISyntaxException (java.net.URISyntaxException)1 URLConnection (java.net.URLConnection)1 Date (java.util.Date)1