List of usage examples for org.apache.http.client.methods HttpHead METHOD_NAME
String METHOD_NAME
To view the source code for org.apache.http.client.methods HttpHead METHOD_NAME.
Click Source Link
From source file:org.elasticsearch.client.RequestConverters.java
static Request indicesExist(GetIndexRequest getIndexRequest) { // this can be called with no indices as argument by transport client, not via REST though if (getIndexRequest.indices() == null || getIndexRequest.indices().length == 0) { throw new IllegalArgumentException("indices are mandatory"); }//from ww w .ja v a 2 s.co m String endpoint = endpoint(getIndexRequest.indices(), ""); Request request = new Request(HttpHead.METHOD_NAME, endpoint); Params params = new Params(request); params.withLocal(getIndexRequest.local()); params.withHuman(getIndexRequest.humanReadable()); params.withIndicesOptions(getIndexRequest.indicesOptions()); params.withIncludeDefaults(getIndexRequest.includeDefaults()); return request; }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testExistsAlias() { GetAliasesRequest getAliasesRequest = new GetAliasesRequest(); String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5); getAliasesRequest.indices(indices);/*from w ww. java 2 s . c om*/ // the HEAD endpoint requires at least an alias or an index boolean hasIndices = indices != null && indices.length > 0; String[] aliases; if (hasIndices) { aliases = randomBoolean() ? null : randomIndicesNames(0, 5); } else { aliases = randomIndicesNames(1, 5); } getAliasesRequest.aliases(aliases); Map<String, String> expectedParams = new HashMap<>(); setRandomLocal(getAliasesRequest, expectedParams); setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions, expectedParams); Request request = RequestConverters.existsAlias(getAliasesRequest); StringJoiner expectedEndpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { expectedEndpoint.add(String.join(",", indices)); } expectedEndpoint.add("_alias"); if (aliases != null && aliases.length > 0) { expectedEndpoint.add(String.join(",", aliases)); } assertEquals(HttpHead.METHOD_NAME, request.getMethod()); assertEquals(expectedEndpoint.toString(), request.getEndpoint()); assertEquals(expectedParams, request.getParameters()); assertNull(request.getEntity()); }
From source file:org.apache.http.impl.client.DefaultRedirectHandler.java
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:/*from www. j a va 2 s . co m*/ return false; } //end of switch }
From source file:org.apache.http.impl.client.DefaultRedirectStrategy.java
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 {//w ww .j a v a 2 s . c o m final int status = response.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_TEMPORARY_REDIRECT) { return RequestBuilder.copy(request).setUri(uri).build(); } else { return new HttpGet(uri); } } }
From source file:org.apache.nutch.protocol.httpclient.HttpClientRedirectStrategy.java
public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException { URI uri = getLocationURI(request, response, context); 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 {/* w w w. j a v a 2 s. c om*/ int status = response.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_TEMPORARY_REDIRECT) { if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) { return copyEntity(new HttpPost(uri), request); } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) { return copyEntity(new HttpPut(uri), request); } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) { return new HttpDelete(uri); } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) { return new HttpTrace(uri); } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) { return new HttpOptions(uri); } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) { return copyEntity(new HttpPatch(uri), request); } } return new HttpGet(uri); } }
From source file:org.fcrepo.integration.http.api.FedoraLdpIT.java
License:asdf
private static void assertNonRdfResourceDescriptionOptionsHeaders(final HttpResponse httpResponse) { final List<String> methods = headerValues(httpResponse, "Allow"); assertTrue("Should allow PATCH", methods.contains(HttpPatch.METHOD_NAME)); assertTrue("Should allow HEAD", methods.contains(HttpHead.METHOD_NAME)); final List<String> patchTypes = headerValues(httpResponse, "Accept-Patch"); assertTrue("PATCH should support application/sparql-update", patchTypes.contains(contentTypeSPARQLUpdate)); assertResourceOptionsHeaders(httpResponse); }
From source file:org.fcrepo.integration.http.api.FedoraVersioningIT.java
private static void assertMementoOptionsHeaders(final HttpResponse httpResponse) { final List<String> methods = headerValues(httpResponse, "Allow"); assertTrue("Should allow GET", methods.contains(HttpGet.METHOD_NAME)); assertTrue("Should allow HEAD", methods.contains(HttpHead.METHOD_NAME)); assertTrue("Should allow OPTIONS", methods.contains(HttpOptions.METHOD_NAME)); assertTrue("Should allow DELETE", methods.contains(HttpDelete.METHOD_NAME)); }