Example usage for org.apache.http.client.methods HttpGetHC4 HttpGetHC4

List of usage examples for org.apache.http.client.methods HttpGetHC4 HttpGetHC4

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpGetHC4 HttpGetHC4.

Prototype

public HttpGetHC4(final String uri) 

Source Link

Usage

From source file:at.bitfire.davdroid.webdav.DavHttpClientTest.java

public void testCookies() throws IOException {
    CloseableHttpResponse response = null;

    HttpGetHC4 get = new HttpGetHC4(testCookieURI);
    get.setHeader("Accept", "text/xml");

    // at first, DavHttpClient doesn't send a cookie
    try {/*from   w ww. j  av  a 2 s. co  m*/
        response = httpClient.execute(get);
        assertEquals(412, response.getStatusLine().getStatusCode());
    } finally {
        if (response != null)
            response.close();
    }

    // POST sets a cookie to DavHttpClient
    try {
        response = httpClient.execute(new HttpPostHC4(testCookieURI));
        assertEquals(200, response.getStatusLine().getStatusCode());
    } finally {
        if (response != null)
            response.close();
    }

    // and now DavHttpClient sends a cookie for GET, too
    try {
        response = httpClient.execute(get);
        assertEquals(200, response.getStatusLine().getStatusCode());
    } finally {
        if (response != null)
            response.close();
    }
}

From source file:org.thoughtcrime.securesms.mms.IncomingMmsConnection.java

@Override
protected HttpUriRequest constructRequest(boolean useProxy) throws IOException {
    HttpGetHC4 request = new HttpGetHC4(apn.getMmsc());
    request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
    if (useProxy) {
        HttpHost proxy = new HttpHost(apn.getProxy(), apn.getPort());
        request.setConfig(RequestConfig.custom().setProxy(proxy).build());
    }/*from w w  w  . java2 s.c om*/
    return request;
}

From source file:com.microsoft.office365.meetingmgr.HttpHelperBase.java

public <TResult> TResult getItem(String uri, Class<TResult> clazz) {
    return doHttp(new HttpGetHC4(buildUri(uri)), null, clazz);
}

From source file:com.tingtingapps.securesms.mms.IncomingLegacyMmsConnection.java

private HttpUriRequest constructRequest(Apn contentApn, boolean useProxy) throws IOException {
    HttpGetHC4 request = new HttpGetHC4(contentApn.getMmsc());
    for (Header header : getBaseHeaders()) {
        request.addHeader(header);/*from   w  w w  .  j a  v a 2  s.  co m*/
    }
    if (useProxy) {
        HttpHost proxy = new HttpHost(contentApn.getProxy(), contentApn.getPort());
        request.setConfig(RequestConfig.custom().setProxy(proxy).build());
    }
    return request;
}

From source file:de.vanita5.twittnuker.util.net.TwidereHttpClientImpl.java

@Override
public twitter4j.http.HttpResponse request(final twitter4j.http.HttpRequest req) throws TwitterException {
    final HostAddressResolver resolver = FactoryUtils.getHostAddressResolver(conf);
    final String urlString = req.getURL();
    final URI urlOrig = ParseUtils.parseURI(urlString);
    final String host = urlOrig.getHost(), authority = urlOrig.getAuthority();
    try {/* w  w  w  .  j a  v  a  2 s . c  o  m*/
        HttpRequestBaseHC4 commonsRequest;
        final String resolvedHost = resolver != null ? resolver.resolve(host) : null;
        final String resolvedUrl = !isEmpty(resolvedHost)
                ? urlString.replace("://" + host, "://" + resolvedHost)
                : urlString;
        final RequestMethod method = req.getMethod();
        if (method == RequestMethod.GET) {
            commonsRequest = new HttpGetHC4(resolvedUrl);
        } else if (method == RequestMethod.POST) {
            final HttpPostHC4 post = new HttpPostHC4(resolvedUrl);
            post.setEntity(getAsEntity(req.getParameters()));
            post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
            commonsRequest = post;
        } else if (method == RequestMethod.DELETE) {
            commonsRequest = new HttpDeleteHC4(resolvedUrl);
        } else if (method == RequestMethod.HEAD) {
            commonsRequest = new HttpHeadHC4(resolvedUrl);
        } else if (method == RequestMethod.PUT) {
            final HttpPutHC4 put = new HttpPutHC4(resolvedUrl);
            put.setEntity(getAsEntity(req.getParameters()));
            commonsRequest = put;
        } else
            throw new TwitterException("Unsupported request method " + method);
        final HttpParams httpParams = commonsRequest.getParams();
        HttpClientParams.setRedirecting(httpParams, false);
        final Map<String, String> headers = req.getRequestHeaders();
        for (final String headerName : headers.keySet()) {
            commonsRequest.addHeader(headerName, headers.get(headerName));
        }
        final Authorization authorization = req.getAuthorization();
        final String authorizationHeader = authorization != null ? authorization.getAuthorizationHeader(req)
                : null;
        if (authorizationHeader != null) {
            commonsRequest.addHeader(HttpHeaders.AUTHORIZATION, authorizationHeader);
        }
        if (resolvedHost != null && !resolvedHost.isEmpty() && !resolvedHost.equals(host)) {
            commonsRequest.addHeader(HttpHeaders.HOST, authority);
        }

        final ApacheHttpClientHttpResponseImpl res;
        try {
            final HttpContext httpContext = new BasicHttpContextHC4();
            httpContext.setAttribute(HostResolvedSSLConnectionSocketFactory.HTTP_CONTEXT_KEY_ORIGINAL_HOST,
                    host);
            res = new ApacheHttpClientHttpResponseImpl(client.execute(commonsRequest, httpContext), conf);
        } catch (final IllegalStateException e) {
            throw new TwitterException("Please check your API settings.", e);
        } catch (final NullPointerException e) {
            // Bug http://code.google.com/p/android/issues/detail?id=5255
            throw new TwitterException("Please check your APN settings, make sure not to use WAP APNs.", e);
        } catch (final OutOfMemoryError e) {
            // I don't know why OOM thown, but it should be catched.
            System.gc();
            throw new TwitterException("Unknown error", e);
        }
        final int statusCode = res.getStatusCode();
        if (statusCode < OK || statusCode > ACCEPTED)
            throw new TwitterException(res.asString(), req, res);
        return res;
    } catch (final IOException e) {
        // TODO
        if (resolver instanceof TwidereHostAddressResolver) {
            final TwidereHostAddressResolver twidereResolver = (TwidereHostAddressResolver) resolver;
            twidereResolver.removeCachedHost(host);
        }
        throw new TwitterException(e);
    }
}

From source file:at.bitfire.davdroid.webdav.WebDavResource.java

public void get(String acceptedMimeTypes) throws URISyntaxException, IOException, HttpException, DavException {
    HttpGetHC4 get = new HttpGetHC4(location);
    get.addHeader("Accept", acceptedMimeTypes);

    @Cleanup//from  ww  w  .j a  v  a2 s .c o m
    CloseableHttpResponse response = httpClient.execute(get, context);
    checkResponse(response);

    HttpEntity entity = response.getEntity();
    if (entity == null)
        throw new DavNoContentException();

    properties.contentType = ContentType.get(entity);
    content = EntityUtilsHC4.toByteArray(entity);
}

From source file:com.granita.icloudcalsync.webdav.WebDavResource.java

public void get(String acceptedMimeTypes) throws URISyntaxException, IOException, HttpException, DavException {
    HttpGetHC4 get = new HttpGetHC4(location);
    get.addHeader("Accept", acceptedMimeTypes);

    @Cleanup/*  ww  w. j ava 2s . co  m*/
    CloseableHttpResponse response = httpClient.execute(get, context);
    checkResponse(response);

    HttpEntity entity = response.getEntity();
    if (entity == null)
        throw new DavNoContentException();

    content = EntityUtilsHC4.toByteArray(entity);
}