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

The following examples show how to use org.springframework.http.HttpMethod#HEAD . 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
Source File: UndertowHttpHandlerAdapter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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
Source File: ClientHttpRequest.java    From gemfirexd-oss with 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 3
Source File: ClientHttpRequest.java    From gemfirexd-oss with 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 File: UndertowHttpHandlerAdapter.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 5
Source File: HttpEntityMethodProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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 6
Source File: RestTemplateBasicLiveTest.java    From tutorials with 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 7
Source File: HttpEntityMethodProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: RequestMethodsRequestCondition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 9
Source File: HttpEntityMethodProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
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
Source File: RestTemplateBasicLiveTest.java    From tutorials with 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 11
Source File: RequestMethodsRequestCondition.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 12
Source File: RequestMethodsRequestCondition.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 13
Source File: HttpHandlerConnector.java    From java-technology-stack with MIT License 4 votes vote down vote up
private ServerHttpResponse prepareResponse(ServerHttpResponse response, ServerHttpRequest request) {
	return (request.getMethod() == HttpMethod.HEAD ? new HttpHeadResponseDecorator(response) : response);
}
 
Example 14
Source File: HttpHandlerConnector.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private ServerHttpResponse prepareResponse(ServerHttpResponse response, ServerHttpRequest request) {
	return (request.getMethod() == HttpMethod.HEAD ? new HttpHeadResponseDecorator(response) : response);
}
 
Example 15
Source File: MockMvcRequestBuilders.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * 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
Source File: MockMvcRequestBuilders.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * 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
Source File: MockMvcRequestBuilders.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * 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 18
Source File: MockMvcRequestBuilders.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * 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
Source File: MockMvcRequestBuilders.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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 20
Source File: MockMvcRequestBuilders.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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);
}