Java Code Examples for org.springframework.http.HttpMethod#HEAD

The following examples show how to use org.springframework.http.HttpMethod#HEAD . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void handleRequest(HttpServerExchange exchange) {
	UndertowServerHttpRequest request = null;
	try {
		request = new UndertowServerHttpRequest(exchange, getDataBufferFactory());
	}
	catch (URISyntaxException ex) {
		if (logger.isWarnEnabled()) {
			logger.debug("Failed to get request URI: " + ex.getMessage());
		}
		exchange.setStatusCode(400);
		return;
	}
	ServerHttpResponse response = new UndertowServerHttpResponse(exchange, getDataBufferFactory(), request);

	if (request.getMethod() == HttpMethod.HEAD) {
		response = new HttpHeadResponseDecorator(response);
	}

	HandlerResultSubscriber resultSubscriber = new HandlerResultSubscriber(exchange, request);
	this.httpHandler.handle(request, response).subscribe(resultSubscriber);
}
 
Example 2
@Override
public void handleRequest(HttpServerExchange exchange) {
	UndertowServerHttpRequest request = null;
	try {
		request = new UndertowServerHttpRequest(exchange, getDataBufferFactory());
	}
	catch (URISyntaxException ex) {
		if (logger.isWarnEnabled()) {
			logger.debug("Failed to get request URI: " + ex.getMessage());
		}
		exchange.setStatusCode(400);
		return;
	}
	ServerHttpResponse response = new UndertowServerHttpResponse(exchange, getDataBufferFactory(), request);

	if (request.getMethod() == HttpMethod.HEAD) {
		response = new HttpHeadResponseDecorator(response);
	}

	HandlerResultSubscriber resultSubscriber = new HandlerResultSubscriber(exchange, request);
	this.httpHandler.handle(request, response).subscribe(resultSubscriber);
}
 
Example 3
Source Project: gemfirexd-oss   File: ClientHttpRequest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the HTTP method indicating the operation to perform on the resource identified in the client's HTTP request.
 * This method converts GemFire's HttpMethod enumerated value from the Link into a corresponding Spring HttpMethod
 * enumerated value.
 * <p/>
 * @return a Spring HttpMethod enumerated value indicating the operation to perform on the resource identified in the
 * client's HTTP request.
 * @see com.gemstone.gemfire.management.internal.web.http.HttpMethod
 * @see com.gemstone.gemfire.management.internal.web.domain.Link#getMethod()
 * @see org.springframework.http.HttpMethod
 * @see org.springframework.http.HttpRequest#getMethod()
 */
@Override
public HttpMethod getMethod() {
  switch (getLink().getMethod()) {
    case DELETE:
      return HttpMethod.DELETE;
    case HEAD:
      return HttpMethod.HEAD;
    case OPTIONS:
      return HttpMethod.OPTIONS;
    case POST:
      return HttpMethod.POST;
    case PUT:
      return HttpMethod.PUT;
    case TRACE:
      return HttpMethod.TRACE;
    case GET:
    default:
      return HttpMethod.GET;
  }
}
 
Example 4
Source Project: gemfirexd-oss   File: ClientHttpRequest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the HTTP method indicating the operation to perform on the resource identified in the client's HTTP request.
 * This method converts GemFire's HttpMethod enumerated value from the Link into a corresponding Spring HttpMethod
 * enumerated value.
 * <p/>
 * @return a Spring HttpMethod enumerated value indicating the operation to perform on the resource identified in the
 * client's HTTP request.
 * @see com.gemstone.gemfire.management.internal.web.http.HttpMethod
 * @see com.gemstone.gemfire.management.internal.web.domain.Link#getMethod()
 * @see org.springframework.http.HttpMethod
 * @see org.springframework.http.HttpRequest#getMethod()
 */
@Override
public HttpMethod getMethod() {
  switch (getLink().getMethod()) {
    case DELETE:
      return HttpMethod.DELETE;
    case HEAD:
      return HttpMethod.HEAD;
    case OPTIONS:
      return HttpMethod.OPTIONS;
    case POST:
      return HttpMethod.POST;
    case PUT:
      return HttpMethod.PUT;
    case TRACE:
      return HttpMethod.TRACE;
    case GET:
    default:
      return HttpMethod.GET;
  }
}
 
Example 5
@Nullable
private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) {
	HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue);
	if (httpMethod != null) {
		for (RequestMethod method : getMethods()) {
			if (httpMethod.matches(method.name())) {
				return requestMethodConditionCache.get(method.name());
			}
		}
		if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
			return requestMethodConditionCache.get(HttpMethod.GET.name());
		}
	}
	return null;
}
 
Example 6
private boolean isResourceNotModified(ServletServerHttpRequest request, ServletServerHttpResponse response) {
	ServletWebRequest servletWebRequest =
			new ServletWebRequest(request.getServletRequest(), response.getServletResponse());
	HttpHeaders responseHeaders = response.getHeaders();
	String etag = responseHeaders.getETag();
	long lastModifiedTimestamp = responseHeaders.getLastModified();
	if (request.getMethod() == HttpMethod.GET || request.getMethod() == HttpMethod.HEAD) {
		responseHeaders.remove(HttpHeaders.ETAG);
		responseHeaders.remove(HttpHeaders.LAST_MODIFIED);
	}

	return servletWebRequest.checkNotModified(etag, lastModifiedTimestamp);
}
 
Example 7
@Nullable
private RequestMethodsRequestCondition matchRequestMethod(@Nullable HttpMethod httpMethod) {
	if (httpMethod != null) {
		for (RequestMethod method : getMethods()) {
			if (httpMethod.matches(method.name())) {
				return new RequestMethodsRequestCondition(method);
			}
		}
		if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
			return GET_CONDITION;
		}
	}
	return null;
}
 
Example 8
Source Project: tutorials   File: RestTemplateBasicLiveTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenFooService_whenCallOptionsForAllow_thenReceiveValueOfAllowHeader() {
    final Set<HttpMethod> optionsForAllow = restTemplate.optionsForAllow(fooResourceUrl);
    final HttpMethod[] supportedMethods = { HttpMethod.GET, HttpMethod.POST, HttpMethod.HEAD };

    assertTrue(optionsForAllow.containsAll(Arrays.asList(supportedMethods)));
}
 
Example 9
private boolean isResourceNotModified(ServletServerHttpRequest request, ServletServerHttpResponse response) {
	ServletWebRequest servletWebRequest =
			new ServletWebRequest(request.getServletRequest(), response.getServletResponse());
	HttpHeaders responseHeaders = response.getHeaders();
	String etag = responseHeaders.getETag();
	long lastModifiedTimestamp = responseHeaders.getLastModified();
	if (request.getMethod() == HttpMethod.GET || request.getMethod() == HttpMethod.HEAD) {
		responseHeaders.remove(HttpHeaders.ETAG);
		responseHeaders.remove(HttpHeaders.LAST_MODIFIED);
	}

	return servletWebRequest.checkNotModified(etag, lastModifiedTimestamp);
}
 
Example 10
private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) {
	HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue);
	if (httpMethod != null) {
		for (RequestMethod method : getMethods()) {
			if (httpMethod.matches(method.name())) {
				return new RequestMethodsRequestCondition(method);
			}
		}
		if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
			return GET_CONDITION;
		}
	}
	return null;
}
 
Example 11
private boolean isResourceNotModified(ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage) {
	ServletWebRequest servletWebRequest =
			new ServletWebRequest(inputMessage.getServletRequest(), outputMessage.getServletResponse());
	HttpHeaders responseHeaders = outputMessage.getHeaders();
	String etag = responseHeaders.getETag();
	long lastModifiedTimestamp = responseHeaders.getLastModified();
	if (inputMessage.getMethod() == HttpMethod.GET || inputMessage.getMethod() == HttpMethod.HEAD) {
		responseHeaders.remove(HttpHeaders.ETAG);
		responseHeaders.remove(HttpHeaders.LAST_MODIFIED);
	}

	return servletWebRequest.checkNotModified(etag, lastModifiedTimestamp);
}
 
Example 12
Source Project: tutorials   File: RestTemplateBasicLiveTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenFooService_whenCallOptionsForAllow_thenReceiveValueOfAllowHeader() {
    final Set<HttpMethod> optionsForAllow = restTemplate.optionsForAllow(fooResourceUrl);
    final HttpMethod[] supportedMethods = { HttpMethod.GET, HttpMethod.POST, HttpMethod.HEAD };

    assertTrue(optionsForAllow.containsAll(Arrays.asList(supportedMethods)));
}
 
Example 13
private ServerHttpResponse prepareResponse(ServerHttpResponse response, ServerHttpRequest request) {
	return (request.getMethod() == HttpMethod.HEAD ? new HttpHeadResponseDecorator(response) : response);
}
 
Example 14
private ServerHttpResponse prepareResponse(ServerHttpResponse response, ServerHttpRequest request) {
	return (request.getMethod() == HttpMethod.HEAD ? new HttpHeadResponseDecorator(response) : response);
}
 
Example 15
/**
 * Create a {@link MockHttpServletRequestBuilder} for a HEAD request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param uriVars zero or more URI variables
 * @since 4.1
 */
public static MockHttpServletRequestBuilder head(String urlTemplate, Object... uriVars) {
	return new MockHttpServletRequestBuilder(HttpMethod.HEAD, urlTemplate, uriVars);
}
 
Example 16
/**
 * Create a {@link MockHttpServletRequestBuilder} for a HEAD request.
 * @param uri the URL
 * @since 4.1
 */
public static MockHttpServletRequestBuilder head(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.HEAD, uri);
}
 
Example 17
/**
 * Create a {@link MockHttpServletRequestBuilder} for a HEAD request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param uriVars zero or more URI variables
 * @since 4.1
 */
public static MockHttpServletRequestBuilder head(String urlTemplate, Object... uriVars) {
	return new MockHttpServletRequestBuilder(HttpMethod.HEAD, urlTemplate, uriVars);
}
 
Example 18
/**
 * Create a {@link MockHttpServletRequestBuilder} for a HEAD request.
 * @param uri the URL
 * @since 4.1
 */
public static MockHttpServletRequestBuilder head(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.HEAD, uri);
}
 
Example 19
/**
 * Create a {@link MockHttpServletRequestBuilder} for a HEAD request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 * @since 4.1
 */
public static MockHttpServletRequestBuilder head(String urlTemplate, Object... urlVariables) {
	return new MockHttpServletRequestBuilder(HttpMethod.HEAD, urlTemplate, urlVariables);
}
 
Example 20
/**
 * Create a {@link MockHttpServletRequestBuilder} for a HEAD request.
 * @param uri the URL
 * @since 4.1
 */
public static MockHttpServletRequestBuilder head(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.HEAD, uri);
}