Java 类org.apache.http.client.methods.HttpHead 实例源码
项目:datarouter
文件:DatarouterHttpRequest.java
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);
}
}
项目:aws-sdk-java-v2
文件:ApacheHttpRequestFactory.java
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());
}
}
项目:elasticsearch_my
文件:RestClient.java
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);
}
}
项目:elasticsearch_my
文件:RequestLoggerTests.java
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();
}
}
项目:elasticsearch_my
文件:ClientYamlTestResponse.java
/**
* 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);
}
项目:Open-DM
文件:Hcap2Adapter.java
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;
}
项目:lams
文件:HttpComponentsClientHttpRequestFactory.java
/**
* 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);
}
}
项目:lams
文件:DefaultRedirectHandler.java
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
}
项目:ibm-cos-sdk-java
文件:MockedClientTests.java
/**
* 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());
}
项目:apps-for-android
文件:DownloaderActivity.java
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;
}
项目:spring4-understanding
文件:HttpComponentsClientHttpRequestFactory.java
/**
* 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);
}
}
项目:AuxiliumLib
文件:MattpRequestEnvoy.java
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();
}
项目:AuxiliumLib
文件:HttpFetch.java
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();
}
项目:StashThisBot
文件:WaybackMachineServiceImpl.java
@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;
}
项目:vespa
文件:JDiscHttpServletTest.java
@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));
}
项目:fahrschein
文件:HttpComponentsRequestFactory.java
/**
* Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
* @param method the HTTP method
* @param uri the URI
* @return the Commons HttpMethodBase object
*/
private static HttpUriRequest createHttpUriRequest(String method, URI uri) {
switch (method) {
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: " + method);
}
}
项目:downloadclient
文件:WMSMapSwing.java
/**
* Checks status code of a getMap request, using a head request.
* Workaround to get geotools getMap request status codes.
* @param requestURL getMap URL
* @return Status string containing status code, reason phrase and method
*/
private String checkGetMap(String requestURL) {
try (
CloseableHttpClient client =
HTTP.getClient(new URL(requestURL), null, null);
) {
HttpHead head = new HttpHead(requestURL);
CloseableHttpResponse resp = client.execute(head);
return resp.getStatusLine().getStatusCode() + " "
+ resp.getStatusLine().getReasonPhrase() + " "
+ "GET";
} catch (IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
return "";
}
项目:Camel
文件:CMProducer.java
@Override
protected void doStart() throws Exception {
// log at debug level for singletons, for prototype scoped log at trace
// level to not spam logs
log.debug("Starting CMProducer");
final CMConfiguration configuration = getConfiguration();
if (configuration.isTestConnectionOnStartup()) {
try {
log.debug("Checking connection - {}", getEndpoint().getCMUrl());
HttpClientBuilder.create().build().execute(new HttpHead(getEndpoint().getCMUrl()));
log.debug("Connection to {}: OK", getEndpoint().getCMUrl());
} catch (final Exception e) {
throw new HostUnavailableException(String.format("Connection to %s: NOT AVAILABLE", getEndpoint().getCMUrl()), e);
}
}
// keep starting
super.doStart();
log.debug("CMProducer started");
}
项目:purecloud-iot
文件:TestResponseProtocolCompliance.java
@Test
public void consumesBodyIfOriginSendsOneInResponseToHEAD() throws Exception {
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpHead("http://foo.example.com/"));
final int nbytes = 128;
final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
setMinimalResponseHeaders(resp);
resp.setHeader("Content-Length","" + nbytes);
final Flag closed = new Flag();
final ByteArrayInputStream bais = makeTrackableBody(nbytes, closed);
resp.setEntity(new InputStreamEntity(bais, -1));
impl.ensureProtocolCompliance(wrapper, resp);
assertNull(resp.getEntity());
assertTrue(closed.set || bais.read() == -1);
}
项目:purecloud-iot
文件:DefaultRedirectHandler.java
@Override
public boolean isRedirectRequested(
final HttpResponse response,
final HttpContext context) {
Args.notNull(response, "HTTP response");
final int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_TEMPORARY_REDIRECT:
final HttpRequest request = (HttpRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);
final 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
}
项目:purecloud-iot
文件:DefaultRedirectStrategy.java
@Override
public HttpUriRequest getRedirect(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
final URI uri = getLocationURI(request, response, context);
final String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
return new HttpHead(uri);
} else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
return new HttpGet(uri);
} else {
final int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
return RequestBuilder.copy(request).setUri(uri).build();
} else {
return new HttpGet(uri);
}
}
}
项目:purecloud-iot
文件:TestDefaultRedirectStrategy.java
@Test
public void testGetRedirectRequest() throws Exception {
final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
HttpStatus.SC_SEE_OTHER, "Redirect");
response.addHeader("Location", "http://localhost/stuff");
final HttpContext context1 = new BasicHttpContext();
final HttpUriRequest redirect1 = redirectStrategy.getRedirect(
new HttpGet("http://localhost/"), response, context1);
Assert.assertEquals("GET", redirect1.getMethod());
final HttpContext context2 = new BasicHttpContext();
final HttpUriRequest redirect2 = redirectStrategy.getRedirect(
new HttpPost("http://localhost/"), response, context2);
Assert.assertEquals("GET", redirect2.getMethod());
final HttpContext context3 = new BasicHttpContext();
final HttpUriRequest redirect3 = redirectStrategy.getRedirect(
new HttpHead("http://localhost/"), response, context3);
Assert.assertEquals("HEAD", redirect3.getMethod());
}
项目:here-aaa-java-sdk
文件:ApacheHttpClientProviderTest.java
@Test
public void test_methods() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException {
verifyApacheType("GET", HttpGet.class);
verifyApacheType("POST", HttpPost.class);
verifyApacheType("PUT", HttpPut.class);
verifyApacheType("DELETE", HttpDelete.class);
verifyApacheType("HEAD", HttpHead.class);
verifyApacheType("OPTIONS", HttpOptions.class);
verifyApacheType("TRACE", HttpTrace.class);
verifyApacheType("PATCH", HttpPatch.class);
try {
verifyApacheType("BROKENMETHOD", null);
fail("BROKENMETHOD should have thrown IllegalArgumentException, but didn't");
} catch (IllegalArgumentException e) {
// expected
String message = e.getMessage();
String expectedContains = "no support for request method=BROKENMETHOD";
assertTrue("expected contains "+expectedContains+", actual "+message, message.contains(expectedContains));
}
}
项目:backblaze-b2-java-api
文件:BaseB2Request.java
/**
* Execute an HTTP HEAD request and return the response for further parsing
*
* @return the response object
*
* @throws B2ApiException if something went wrong with the call
* @throws IOException if there was an error communicating with the API service
*/
protected CloseableHttpResponse executeHead() throws B2ApiException, IOException {
URI uri = this.buildUri();
LOGGER.debug("HEAD request to URL '{}'", uri.toString());
HttpHead httpHead = new HttpHead(uri);
CloseableHttpResponse httpResponse = this.execute(httpHead);
switch(httpResponse.getStatusLine().getStatusCode()) {
case HttpStatus.SC_OK:
return httpResponse;
}
final B2ApiException failure = new B2ApiException(EntityUtils.toString(httpResponse.getEntity()), new HttpResponseException(
httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()));
if(httpResponse.containsHeader(HttpHeaders.RETRY_AFTER)) {
throw failure.withRetry(Integer.valueOf(httpResponse.getFirstHeader(HttpHeaders.RETRY_AFTER).getValue()));
}
throw failure;
}
项目:triplea
文件:PropertiesDiceRoller.java
@Override
public HttpUriRequest getRedirect(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
final URI uri = getLocationURI(request, response, context);
final String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
return new HttpHead(uri);
} else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
return new HttpGet(uri);
} else {
final int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_TEMPORARY_REDIRECT || status == HttpStatus.SC_MOVED_PERMANENTLY
|| status == HttpStatus.SC_MOVED_TEMPORARILY) {
return RequestBuilder.copy(request).setUri(uri).build();
}
return new HttpGet(uri);
}
}
项目:oreva
文件:ODataCxfClient.java
private HttpUriRequest getRequestByMethod(String method, URI uri) {
switch (ODataHttpMethod.fromString(method)) {
case GET:
return new HttpGet(uri);
case PUT:
return new HttpPut(uri);
case POST:
return new HttpPost(uri);
case DELETE:
return new HttpDelete(uri);
case OPTIONS:
return new HttpOptions(uri);
case HEAD:
return new HttpHead(uri);
default:
throw new RuntimeException("Method unknown: " + method);
}
}
项目:zeppelin
文件:HttpProxyClient.java
private HttpAsyncClientBuilder setRedirects(HttpAsyncClientBuilder clientBuilder) {
clientBuilder.setRedirectStrategy(new DefaultRedirectStrategy() {
/** Redirectable methods. */
private String[] REDIRECT_METHODS = new String[] {
HttpGet.METHOD_NAME, HttpPost.METHOD_NAME,
HttpPut.METHOD_NAME, HttpDelete.METHOD_NAME, HttpHead.METHOD_NAME
};
@Override
protected boolean isRedirectable(String method) {
for (String m : REDIRECT_METHODS) {
if (m.equalsIgnoreCase(method)) {
return true;
}
}
return false;
}
});
return clientBuilder;
}
项目:ShoppingMall
文件:HttpComponentsClientHttpRequestFactory.java
/**
* Create a HttpComponents HttpUriRequest object for the given HTTP method and URI specification.
*
* @param httpMethod the HTTP method
* @param uri the URI
* @return the HttpComponents HttpUriRequest object
*/
protected HttpUriRequest createHttpRequest(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);
default:
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
}
}
项目:ShoppingMall
文件:HttpComponentsClientHttpRequestFactory.java
/**
* Create a HttpComponents HttpUriRequest object for the given HTTP method and URI specification.
*
* @param httpMethod
* the HTTP method
* @param uri
* the URI
* @return the HttpComponents HttpUriRequest object
*/
protected HttpUriRequest createHttpRequest(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);
default:
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
}
}
项目:missing-http
文件:MatlabShim.java
/**
* HEAD request
* @param url URL to make request to
* @param headers Extra headers to add. Even-numbered elements will be treated as header names, and odd-numbered elements will be treated as header values.
* @return Response status code.
* @throws java.io.IOException
* @throws java.security.GeneralSecurityException
*/
public static String head(String url, String... headers) throws IOException, GeneralSecurityException {
try (CloseableHttpClient client = getClient()) {
HttpHead request = new HttpHead(url);
// Set request headers
if(headers != null) {
for(int i = 0; i < headers.length; i+=2) {
request.setHeader(headers[i], headers[i+1]);
}
}
// Execute the request
try (CloseableHttpResponse response = client.execute(request)) {
// Parse the response
int statusCode = response.getStatusLine().getStatusCode();
// Package it up for MATLAB.
String returnVal = Integer.toString(statusCode);
return returnVal;
}
}
}
项目:openimaj
文件:HttpUtils.java
@Override
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context)
throws ProtocolException
{
final URL metarefresh = (URL) context.getAttribute(METAREFRESH_LOCATION);
if (metarefresh == null) {
return super.getRedirect(request, response, context);
}
final String method = request.getRequestLine().getMethod();
try {
if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
return new HttpHead(metarefresh.toURI());
} else {
return new HttpGet(metarefresh.toURI());
}
} catch (final URISyntaxException e) {
return super.getRedirect(request, response, context);
}
}
项目:aliyunoss
文件:HeadObjectTask.java
/**
* 构造HttpHead
*/
protected HttpUriRequest generateHttpRequest() {
String resource = httpTool.generateCanonicalizedResource("/"
+ bucketName + "/" + objectKey);
String requestUri = OSS_END_POINT + resource;
HttpHead httpHead = new HttpHead(requestUri);
String dateStr = Helper.getGMTDate();
String authorization = OSSHttpTool
.generateAuthorization(accessId, accessKey,
httpMethod.toString(), "", "", dateStr, "", resource);
httpHead.setHeader(AUTHORIZATION, authorization);
httpHead.setHeader(DATE, dateStr);
httpHead.setHeader(HOST, OSS_HOST);
OSSHttpTool.addHttpRequestHeader(httpHead, IF_MODIFIED_SINCE,
Helper.getGMTDate(modifiedSince));
OSSHttpTool.addHttpRequestHeader(httpHead, IF_UNMODIFIED_SINCE,
Helper.getGMTDate(unModifiedSince));
OSSHttpTool.addHttpRequestHeader(httpHead, IF_MATCH, expectedETag);
OSSHttpTool.addHttpRequestHeader(httpHead, IF_NONE_MATCH,
unexpectedETag);
return httpHead;
}
项目:openbd-core
文件:cfHttpConnection.java
private HttpUriRequest resolveMethod( String _method, boolean _multipart ) throws cfmRunTimeException {
String method = _method.toUpperCase();
if ( method.equals( "GET" ) ) {
return new HttpGet();
} else if ( method.equals( "POST" ) ) {
return new HttpPost();
} else if ( method.equals( "HEAD" ) ) {
return new HttpHead();
} else if ( method.equals( "TRACE" ) ) {
return new HttpTrace();
} else if ( method.equals( "DELETE" ) ) {
return new HttpDelete();
} else if ( method.equals( "OPTIONS" ) ) {
return new HttpOptions();
} else if ( method.equals( "PUT" ) ) {
return new HttpPut();
}
throw newRunTimeException( "Unsupported METHOD value [" + method + "]. Valid METHOD values are GET, POST, HEAD, TRACE, DELETE, OPTIONS and PUT." );
}
项目:glvideoplayer-android
文件:HttpClient.java
public boolean head(String url) throws WebApiException {
content = null;
try {
HttpHead request = new HttpHead(url);
HttpResponse response;
response = client.execute(request);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
throw new WebApiException(WebApiException.BAD_REQUEST, "param error");
}
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
throw new WebApiException(WebApiException.SERVICE_UNAVAILABLE);
}
} catch (Exception e) {
throw new WebApiException(WebApiException.NETWORK_ERROR, "Network error");
}
return true;
}
项目:rdap-conformance
文件:Utils.java
private static HttpRequestBase httpRequest(
final Context context,
final String path,
final boolean followRedirects,
final String method) {
HttpRequestBase request =
(method.equals("get"))
? new HttpGet(path)
: new HttpHead(path);
request.setHeader("Accept", context.getContentType());
RequestConfig config =
RequestConfig.custom()
.setConnectionRequestTimeout(TIMEOUT_MS)
.setConnectTimeout(TIMEOUT_MS)
.setSocketTimeout(TIMEOUT_MS)
.setRedirectsEnabled(followRedirects)
.build();
request.setConfig(config);
return request;
}
项目:ant-ivy
文件:HttpClientHandler.java
private boolean checkStatusCode(final String httpMethod, final URL sourceURL, final HttpResponse response) {
final int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK) {
return true;
}
// IVY-1328: some servers return a 204 on a HEAD request
if (HttpHead.METHOD_NAME.equals(httpMethod) && (status == 204)) {
return true;
}
Message.debug("HTTP response status: " + status + " url=" + sourceURL);
if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
Message.warn("Your proxy requires authentication.");
} else if (String.valueOf(status).startsWith("4")) {
Message.verbose("CLIENT ERROR: " + response.getStatusLine().getReasonPhrase() + " url=" + sourceURL);
} else if (String.valueOf(status).startsWith("5")) {
Message.error("SERVER ERROR: " + response.getStatusLine().getReasonPhrase() + " url=" + sourceURL);
}
return false;
}
项目:detective
文件:HttpClientTask.java
/**
* 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 HttpDeleteWithBody(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);
}
}
项目:class-guard
文件:HttpComponentsClientHttpRequestFactory.java
/**
* 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);
}
}
项目:cJUnit-mc626
文件:DefaultRedirectHandler.java
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
}
项目:MLDS
文件:HttpAuthAdaptor.java
public String getCsrfToken() throws IOException {
HttpHead request = new HttpHead(queryUrl);
HttpResponse response = httpClient.execute(request);
try {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
Header[] headers = response.getHeaders(SET_COOKIE);
//CSRF-TOKEN
for (Header header : headers) {
if (header.getValue().startsWith(CSRF_COOKIE)) {
String csrfToken = getCookieValue(header);
return csrfToken;
}
}
throw new IOException("Authentication service returned ok, but did not offer a CrossScripting token");
} else {
throw new IOException("Authentication service returned unexpected status while requesting CrossScripting Token value: " + statusCode);
}
} finally {
request.releaseConnection();
}
}