本文整理匯總了Java中org.apache.http.client.methods.HttpHead類的典型用法代碼示例。如果您正苦於以下問題:Java HttpHead類的具體用法?Java HttpHead怎麽用?Java HttpHead使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpHead類屬於org.apache.http.client.methods包,在下文中一共展示了HttpHead類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRequest
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
private HttpRequestBase getRequest(String url){
switch(method){
case DELETE:
return new HttpDelete(url);
case GET:
return new HttpGet(url);
case HEAD:
return new HttpHead(url);
case PATCH:
return new HttpPatch(url);
case POST:
return new HttpPost(url);
case PUT:
return new HttpPut(url);
default:
throw new IllegalArgumentException("Invalid or null HttpMethod: " + method);
}
}
示例2: createApacheRequest
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
private HttpRequestBase createApacheRequest(SdkHttpFullRequest request, String uri) {
switch (request.method()) {
case HEAD:
return new HttpHead(uri);
case GET:
return new HttpGet(uri);
case DELETE:
return new HttpDelete(uri);
case OPTIONS:
return new HttpOptions(uri);
case PATCH:
return wrapEntity(request, new HttpPatch(uri));
case POST:
return wrapEntity(request, new HttpPost(uri));
case PUT:
return wrapEntity(request, new HttpPut(uri));
default:
throw new RuntimeException("Unknown HTTP method name: " + request.method());
}
}
示例3: createHttpRequest
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
private static HttpRequestBase createHttpRequest(String method, URI uri, HttpEntity entity) {
switch(method.toUpperCase(Locale.ROOT)) {
case HttpDeleteWithEntity.METHOD_NAME:
return addRequestBody(new HttpDeleteWithEntity(uri), entity);
case HttpGetWithEntity.METHOD_NAME:
return addRequestBody(new HttpGetWithEntity(uri), entity);
case HttpHead.METHOD_NAME:
return addRequestBody(new HttpHead(uri), entity);
case HttpOptions.METHOD_NAME:
return addRequestBody(new HttpOptions(uri), entity);
case HttpPatch.METHOD_NAME:
return addRequestBody(new HttpPatch(uri), entity);
case HttpPost.METHOD_NAME:
HttpPost httpPost = new HttpPost(uri);
addRequestBody(httpPost, entity);
return httpPost;
case HttpPut.METHOD_NAME:
return addRequestBody(new HttpPut(uri), entity);
case HttpTrace.METHOD_NAME:
return addRequestBody(new HttpTrace(uri), entity);
default:
throw new UnsupportedOperationException("http method not supported: " + method);
}
}
示例4: randomHttpRequest
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
private static HttpUriRequest randomHttpRequest(URI uri) {
int requestType = randomIntBetween(0, 7);
switch(requestType) {
case 0:
return new HttpGetWithEntity(uri);
case 1:
return new HttpPost(uri);
case 2:
return new HttpPut(uri);
case 3:
return new HttpDeleteWithEntity(uri);
case 4:
return new HttpHead(uri);
case 5:
return new HttpTrace(uri);
case 6:
return new HttpOptions(uri);
case 7:
return new HttpPatch(uri);
default:
throw new UnsupportedOperationException();
}
}
示例5: evaluate
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
/**
* Parses the response body and extracts a specific value from it (identified by the provided path)
*/
public Object evaluate(String path, Stash stash) throws IOException {
if (response == null) {
return null;
}
if (parsedResponse == null) {
//special case: api that don't support body (e.g. exists) return true if 200, false if 404, even if no body
//is_true: '' means the response had no body but the client returned true (caused by 200)
//is_false: '' means the response had no body but the client returned false (caused by 404)
if ("".equals(path) && HttpHead.METHOD_NAME.equals(response.getRequestLine().getMethod())) {
return isError() == false;
}
return null;
}
return parsedResponse.evaluate(path, stash);
}
示例6: getSSLCerts
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
public SSLCertChain getSSLCerts() throws IOException, StorageAdapterException {
HttpHost httpHost = new HttpHost(getHost(), profile.getPort(), "getcerts");
HttpUriRequest request = new HttpHead("/");
// Eventually we will just return this cookie which will be passed back to the caller.
HcapAdapterCookie cookie = new HcapAdapterCookie(request, httpHost);
synchronized (savingCookieLock) {
if (savedCookie != null) {
throw new RuntimeException(
"This adapter already has a current connection to host -- cannot create two at once.");
}
savedCookie = cookie;
}
try {
executeMethod(cookie);
} catch (SSLException e) {
LOG.log(Level.WARNING, "Exception getting certs. sslCerts = " + sslCerts, e);
throw new SSLCertException(e, sslCerts);
} finally {
close();
}
LOG.finer("Returning sslCerts = " + sslCerts);
return sslCerts;
}
示例7: createHttpUriRequest
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
/**
* Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
* @param httpMethod the HTTP method
* @param uri the URI
* @return the Commons HttpMethodBase object
*/
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
switch (httpMethod) {
case GET:
return new HttpGet(uri);
case DELETE:
return new HttpDelete(uri);
case HEAD:
return new HttpHead(uri);
case OPTIONS:
return new HttpOptions(uri);
case POST:
return new HttpPost(uri);
case PUT:
return new HttpPut(uri);
case TRACE:
return new HttpTrace(uri);
case PATCH:
return new HttpPatch(uri);
default:
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
}
}
示例8: isRedirectRequested
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
public boolean isRedirectRequested(
final HttpResponse response,
final HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_TEMPORARY_REDIRECT:
HttpRequest request = (HttpRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);
String method = request.getRequestLine().getMethod();
return method.equalsIgnoreCase(HttpGet.METHOD_NAME)
|| method.equalsIgnoreCase(HttpHead.METHOD_NAME);
case HttpStatus.SC_SEE_OTHER:
return true;
default:
return false;
} //end of switch
}
示例9: requestTimeoutEnabled_HeadRequestCompletesWithinTimeout_EntityNotBuffered
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
/**
* Response to HEAD requests don't have an entity so we shouldn't try to wrap the response in a
* {@link BufferedHttpEntity}.
*/
@Test
public void requestTimeoutEnabled_HeadRequestCompletesWithinTimeout_EntityNotBuffered() throws Exception {
ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000).withMaxErrorRetry(0);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpHeadResponseProxy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpHead.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
execute(httpClient, createMockHeadRequest());
fail("Exception expected");
} catch (AmazonClientException e) {
NullResponseHandler.assertIsUnmarshallingException(e);
}
assertNull(responseProxy.getEntity());
}
示例10: getSize
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
private long getSize(String url) throws ClientProtocolException,
IOException {
url = normalizeUrl(url);
Log.i(LOG_TAG, "Head " + url);
HttpHead httpGet = new HttpHead(url);
HttpResponse response = mHttpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new IOException("Unexpected Http status code "
+ response.getStatusLine().getStatusCode());
}
Header[] clHeaders = response.getHeaders("Content-Length");
if (clHeaders.length > 0) {
Header header = clHeaders[0];
return Long.parseLong(header.getValue());
}
return -1;
}
示例11: createHttpUriRequest
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
/**
* Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
* @param httpMethod the HTTP method
* @param uri the URI
* @return the Commons HttpMethodBase object
*/
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
switch (httpMethod) {
case GET:
return new HttpGet(uri);
case HEAD:
return new HttpHead(uri);
case POST:
return new HttpPost(uri);
case PUT:
return new HttpPut(uri);
case PATCH:
return new HttpPatch(uri);
case DELETE:
return new HttpDelete(uri);
case OPTIONS:
return new HttpOptions(uri);
case TRACE:
return new HttpTrace(uri);
default:
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
}
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:29,代碼來源:HttpComponentsClientHttpRequestFactory.java
示例12: getRawMethodRequest
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
private HttpUriRequest getRawMethodRequest()
{
AbstractURL url = request.getUrl();
switch(request.getMattpMethod())
{
case GET:
return new HttpGet(url.toString());
case HEAD:
return new HttpHead(url.toString());
case POST:
return new HttpPost(url.toString());
case PUT:
return new HttpPut(url.toString());
case DELETE:
return new HttpDelete(url.toString());
case TRACE:
return new HttpTrace(url.toString());
case OPTIONS:
return new HttpOptions(url.toString());
case PATCH:
return new HttpPatch(url.toString());
}
throw new ShouldNeverHappenError();
}
示例13: getRequest
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
private HttpUriRequest getRequest(AbstractURL url)
{
switch(this)
{
case GET:
return new HttpGet(url.toString());
case HEAD:
return new HttpHead(url.toString());
case POST:
return new HttpPost(url.toString());
case PUT:
return new HttpPut(url.toString());
case DELETE:
return new HttpDelete(url.toString());
case TRACE:
return new HttpTrace(url.toString());
case OPTIONS:
return new HttpOptions(url.toString());
case PATCH:
return new HttpPatch(url.toString());
}
throw new ShouldNeverHappenError();
}
示例14: isHealthy
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
@Override
public boolean isHealthy() {
CloseableHttpClient client = HttpClientBuilder.create().build();
HttpHead headMethod = new HttpHead(WAYBACK_ROOT_URL);
CloseableHttpResponse response = null;
try {
response = client.execute(headMethod);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
LOG.info("Health check failed, got response code: %d: ", statusCode);
}
} catch (Throwable t) {
LOG.info("Health check failed, caught exception: " + t.getMessage());
return false;
} finally {
closeHttpObjects(response, client);
}
return true;
}
示例15: requireThatServerRespondsToAllMethods
import org.apache.http.client.methods.HttpHead; //導入依賴的package包/類
@Test
public void requireThatServerRespondsToAllMethods() throws Exception {
final TestDriver driver = TestDrivers.newInstance(newEchoHandler());
final URI uri = driver.client().newUri("/status.html");
driver.client().execute(new HttpGet(uri))
.expectStatusCode(is(OK));
driver.client().execute(new HttpPost(uri))
.expectStatusCode(is(OK));
driver.client().execute(new HttpHead(uri))
.expectStatusCode(is(OK));
driver.client().execute(new HttpPut(uri))
.expectStatusCode(is(OK));
driver.client().execute(new HttpDelete(uri))
.expectStatusCode(is(OK));
driver.client().execute(new HttpOptions(uri))
.expectStatusCode(is(OK));
driver.client().execute(new HttpTrace(uri))
.expectStatusCode(is(OK));
driver.client().execute(new HttpPatch(uri))
.expectStatusCode(is(OK));
assertThat(driver.close(), is(true));
}