Search in sources :

Example 96 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 97 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 98 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)

Example 99 with BasicHeader

use of org.apache.http.message.BasicHeader in project undertow by undertow-io.

the class AbstractModClusterTestBase method get.

static HttpGet get(final String context, final String host) {
    final HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + context);
    get.addHeader(new BasicHeader("Host", host));
    return get;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader)

Example 100 with BasicHeader

use of org.apache.http.message.BasicHeader in project android_frameworks_base by AOSPA.

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)

Aggregations

BasicHeader (org.apache.http.message.BasicHeader)123 Header (org.apache.http.Header)63 Test (org.junit.Test)29 List (java.util.List)21 HashMap (java.util.HashMap)19 HttpGet (org.apache.http.client.methods.HttpGet)17 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)14 Response (org.elasticsearch.client.Response)10 TestHttpResponse (org.robolectric.shadows.httpclient.TestHttpResponse)9 ArrayList (java.util.ArrayList)8 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7