Search in sources :

Example 91 with BasicHeader

use of org.apache.http.message.BasicHeader in project platform_frameworks_base by android.

the class DefaultHttpClientTest method authenticateDigestAlgorithm.

private void authenticateDigestAlgorithm(String algorithm) throws Exception {
    String challenge = "Digest realm=\"protected area\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "algorithm=" + algorithm;
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
    HttpGet get = new HttpGet();
    digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 92 with BasicHeader

use of org.apache.http.message.BasicHeader in project spring-boot by spring-projects.

the class InitializrService method executeInitializrMetadataRetrieval.

/**
	 * Retrieves the meta-data of the service at the specified URL.
	 * @param url the URL
	 * @return the response
	 */
private CloseableHttpResponse executeInitializrMetadataRetrieval(String url) {
    HttpGet request = new HttpGet(url);
    request.setHeader(new BasicHeader(HttpHeaders.ACCEPT, ACCEPT_META_DATA));
    return execute(request, url, "retrieve metadata");
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader)

Example 93 with BasicHeader

use of org.apache.http.message.BasicHeader in project spring-boot by spring-projects.

the class AbstractHttpClientMockTests method mockHttpHeader.

protected void mockHttpHeader(CloseableHttpResponse response, String headerName, String value) {
    Header header = value != null ? new BasicHeader(headerName, value) : null;
    given(response.getFirstHeader(headerName)).willReturn(header);
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader)

Example 94 with BasicHeader

use of org.apache.http.message.BasicHeader in project spring-boot by spring-projects.

the class AbstractHttpClientMockTests method mockHttpEntity.

protected HttpEntity mockHttpEntity(CloseableHttpResponse response, byte[] content, String contentType) {
    try {
        HttpEntity entity = mock(HttpEntity.class);
        given(entity.getContent()).willReturn(new ByteArrayInputStream(content));
        Header contentTypeHeader = contentType != null ? new BasicHeader("Content-Type", contentType) : null;
        given(entity.getContentType()).willReturn(contentTypeHeader);
        given(response.getEntity()).willReturn(entity);
        return entity;
    } catch (IOException ex) {
        throw new IllegalStateException("Should not happen", ex);
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) BasicHeader(org.apache.http.message.BasicHeader)

Example 95 with BasicHeader

use of org.apache.http.message.BasicHeader in project spring-boot by spring-projects.

the class InitializrService method loadServiceCapabilities.

/**
	 * Loads the service capabilities of the service at the specified URL. If the service
	 * supports generating a textual representation of the capabilities, it is returned,
	 * otherwise {@link InitializrServiceMetadata} is returned.
	 * @param serviceUrl to url of the initializer service
	 * @return the service capabilities (as a String) or the
	 * {@link InitializrServiceMetadata} describing the service
	 * @throws IOException if the service capabilities cannot be loaded
	 */
public Object loadServiceCapabilities(String serviceUrl) throws IOException {
    HttpGet request = new HttpGet(serviceUrl);
    request.setHeader(new BasicHeader(HttpHeaders.ACCEPT, ACCEPT_SERVICE_CAPABILITIES));
    CloseableHttpResponse httpResponse = execute(request, serviceUrl, "retrieve help");
    validateResponse(httpResponse, serviceUrl);
    HttpEntity httpEntity = httpResponse.getEntity();
    ContentType contentType = ContentType.getOrDefault(httpEntity);
    if (contentType.getMimeType().equals("text/plain")) {
        return getContent(httpEntity);
    }
    return parseJsonMetadata(httpEntity);
}
Also used : HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BasicHeader(org.apache.http.message.BasicHeader)

Aggregations

BasicHeader (org.apache.http.message.BasicHeader)128 Header (org.apache.http.Header)67 Test (org.junit.Test)29 List (java.util.List)21 HashMap (java.util.HashMap)19 HttpGet (org.apache.http.client.methods.HttpGet)18 BasicStatusLine (org.apache.http.message.BasicStatusLine)17 ProtocolVersion (org.apache.http.ProtocolVersion)16 StatusLine (org.apache.http.StatusLine)16 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)16 IOException (java.io.IOException)15 HttpURLConnection (java.net.HttpURLConnection)15 URL (java.net.URL)15 HttpResponse (org.apache.http.HttpResponse)15 Response (org.elasticsearch.client.Response)10 ArrayList (java.util.ArrayList)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 TestHttpResponse (org.robolectric.shadows.httpclient.TestHttpResponse)9 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)8 StringEntity (org.apache.http.entity.StringEntity)8