use of org.apache.http.client.methods.HttpHead in project openolat by klemens.
the class UserMgmtTest method testPortrait_HEAD_sizes.
/**
* Check the 3 sizes
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void testPortrait_HEAD_sizes() throws IOException, URISyntaxException {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("portrait-3");
URL portraitUrl = UserMgmtTest.class.getResource("portrait.jpg");
Assert.assertNotNull(portraitUrl);
File portrait = new File(portraitUrl.toURI());
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(id.getName(), "A6B7C8"));
// upload portrait
URI request = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("portrait").build();
HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
conn.addMultipart(method, "portrait.jpg", portrait);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// check 200
URI headMasterRequest = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("portrait").path("master").build();
HttpHead headMasterMethod = conn.createHead(headMasterRequest, MediaType.APPLICATION_OCTET_STREAM, true);
HttpResponse headMasterResponse = conn.execute(headMasterMethod);
assertEquals(200, headMasterResponse.getStatusLine().getStatusCode());
EntityUtils.consume(headMasterResponse.getEntity());
// check 200
URI headBigRequest = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("portrait").path("big").build();
HttpHead headBigMethod = conn.createHead(headBigRequest, MediaType.APPLICATION_OCTET_STREAM, true);
HttpResponse headBigResponse = conn.execute(headBigMethod);
assertEquals(200, headBigResponse.getStatusLine().getStatusCode());
EntityUtils.consume(headBigResponse.getEntity());
// check 200
URI headSmallRequest = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("portrait").path("small").build();
HttpHead headSmallMethod = conn.createHead(headSmallRequest, MediaType.APPLICATION_OCTET_STREAM, true);
HttpResponse headSmallResponse = conn.execute(headSmallMethod);
assertEquals(200, headSmallResponse.getStatusLine().getStatusCode());
EntityUtils.consume(headSmallResponse.getEntity());
}
use of org.apache.http.client.methods.HttpHead in project openolat by klemens.
the class RestConnection method createHead.
public HttpHead createHead(URI uri, String accept, boolean cookie) {
HttpHead head = new HttpHead(uri);
decorateHttpMessage(head, accept, "en", cookie);
return head;
}
use of org.apache.http.client.methods.HttpHead in project ant-ivy by apache.
the class HttpClientHandler method doHead.
private CloseableHttpResponse doHead(final URL url, final int connectionTimeout, final int readTimeout) throws IOException {
final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(readTimeout).setConnectTimeout(connectionTimeout).setAuthenticationEnabled(hasCredentialsConfigured(url)).setTargetPreferredAuthSchemes(getAuthSchemePreferredOrder()).setProxyPreferredAuthSchemes(getAuthSchemePreferredOrder()).build();
final HttpHead httpHead = new HttpHead(normalizeToString(url));
httpHead.setConfig(requestConfig);
return this.httpClient.execute(httpHead);
}
use of org.apache.http.client.methods.HttpHead in project structr by structr.
the class HttpHelper method head.
public static Map<String, String> head(final String address, final String username, final String password, final String proxyUrl, final String proxyUsername, final String proxyPassword, final String cookie, final Map<String, String> headers) {
final Map<String, String> responseHeaders = new HashMap<>();
try {
final URI url = URI.create(address);
final HttpHead req = new HttpHead(url);
configure(req, username, password, proxyUrl, proxyUsername, proxyPassword, cookie, headers, false);
final CloseableHttpResponse response = client.execute(req);
responseHeaders.put("status", Integer.toString(response.getStatusLine().getStatusCode()));
for (final Header header : response.getAllHeaders()) {
responseHeaders.put(header.getName(), header.getValue());
}
} catch (final Throwable t) {
logger.error("Unable to get headers from address {}, {}", new Object[] { address, t.getMessage() });
}
return responseHeaders;
}
use of org.apache.http.client.methods.HttpHead in project collect by openforis.
the class SaikuService method testUrl.
private boolean testUrl(String url) {
try {
HttpClientBuilder cb = HttpClientBuilder.create();
CloseableHttpClient httpClient = cb.build();
HttpHead req = new HttpHead(url);
CloseableHttpResponse resp = httpClient.execute(req);
int statusCode = resp.getStatusLine().getStatusCode();
return statusCode == 200;
} catch (Exception e) {
return false;
}
}
Aggregations