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);
}
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);
}
}
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);
}
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;
}
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);
}
Aggregations