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

The following examples show how to use org.springframework.http.HttpMethod#PUT . 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: AbstractAsyncHttpRequestFactoryTestCase.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
	ClientHttpResponse response = null;
	try {
		AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/methods/" + path), method);
		if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
			// requires a body
			request.getBody().write(32);
		}
		Future<ClientHttpResponse> futureResponse = request.executeAsync();
		response = futureResponse.get();
		assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
		assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
	}
	finally {
		if (response != null) {
			response.close();
		}
	}
}
 
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: AbstractHttpRequestFactoryTestCase.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
	ClientHttpResponse response = null;
	try {
		ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/methods/" + path), method);
		if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
			// requires a body
			try {
				request.getBody().write(32);
			}
			catch (UnsupportedOperationException ex) {
				// probably a streaming request - let's simply ignore it
			}
		}
		response = request.execute();
		assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
		assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
	}
	finally {
		if (response != null) {
			response.close();
		}
	}
}
 
Example 5
Source File: FormContentFilterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void wrapPutPatchAndDeleteOnly() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/");
		request.setContent("foo=bar".getBytes("ISO-8859-1"));
		request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
		this.filterChain = new MockFilterChain();
		this.filter.doFilter(request, this.response, this.filterChain);
		if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) {
			assertNotSame(request, this.filterChain.getRequest());
		}
		else {
			assertSame(request, this.filterChain.getRequest());
		}
	}
}
 
Example 6
Source File: FormContentFilterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void wrapPutPatchAndDeleteOnly() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/");
		request.setContent("foo=bar".getBytes("ISO-8859-1"));
		request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
		this.filterChain = new MockFilterChain();
		this.filter.doFilter(request, this.response, this.filterChain);
		if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) {
			assertNotSame(request, this.filterChain.getRequest());
		}
		else {
			assertSame(request, this.filterChain.getRequest());
		}
	}
}
 
Example 7
Source File: DynamicRouteStack.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public Route put(String url, Route responseHandler) {
    RouteKey key = new RouteKey(HttpMethod.PUT, url);
    boolean hasSparkRoute = mockResponders.containsKey(key);
    Route route = overrideResponseByUrlWithSimple(key, responseHandler);
    addPutIfNotPresent(url, hasSparkRoute, route);
    return route;
}
 
Example 8
Source File: RestServer.java    From zstack with Apache License 2.0 5 votes vote down vote up
private void collectRestRequestErrConfigApi(List<String> errorApiList, Class apiClass, RestRequest apiRestRequest){
    if (apiRestRequest.isAction() && !RESTConstant.DEFAULT_PARAMETER_NAME.equals(apiRestRequest.parameterName())) {
        errorApiList.add(String.format("[%s] RestRequest config error, Setting parameterName is not allowed when isAction set true", apiClass.getName()));
    } else if (apiRestRequest.isAction() && HttpMethod.PUT != apiRestRequest.method()) {
        errorApiList.add(String.format("[%s] RestRequest config error, method can only be set to HttpMethod.PUT when isAction set true", apiClass.getName()));
    }else if (!RESTConstant.DEFAULT_PARAMETER_NAME.equals(apiRestRequest.parameterName()) && (HttpMethod.PUT == apiRestRequest.method() || HttpMethod.DELETE == apiRestRequest.method())){
        errorApiList.add(String.format("[%s] RestRequest config error, method is not allowed to set to HttpMethod.PUT(HttpMethod.DELETE) when parameterName set a value", apiClass.getName()));
    }else if(HttpMethod.GET == apiRestRequest.method() && !RESTConstant.DEFAULT_PARAMETER_NAME.equals(apiRestRequest.parameterName())){
        errorApiList.add(String.format("[%s] RestRequest config error, Setting parameterName is not allowed when method set HttpMethod.GET", apiClass.getName()));
    }
}
 
Example 9
Source File: HttpTestRunner.java    From microcks with Apache License 2.0 5 votes vote down vote up
/**
 * Build the HttpMethod corresponding to string. Default to POST
 * if unknown or unrecognized.
 */
@Override
public HttpMethod buildMethod(String method){
   if (method != null){
      if ("GET".equals(method.toUpperCase().trim())){
         return HttpMethod.GET;
      } else if ("PUT".equals(method.toUpperCase().trim())){
         return HttpMethod.PUT;
      } else if ("DELETE".equals(method.toUpperCase().trim())){
         return HttpMethod.DELETE;
      }
   }
   return HttpMethod.POST;
}
 
Example 10
Source File: CartRepositoryImpl.java    From AppStash with Apache License 2.0 4 votes vote down vote up
@Override
public String create(CartItem cartItem) {
    RequestEntity<CartItem> requestEntity = new RequestEntity<>(cartItem, HttpMethod.PUT, CREATE_TEMPLATE.expand());
    ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
    return responseEntity.getBody();
}
 
Example 11
Source File: ApiProxyController.java    From demo-spring-webflux-api-gateway with Apache License 2.0 4 votes vote down vote up
private boolean requireHttpBody(HttpMethod method)
{
	    return HttpMethod.POST == method || HttpMethod.PUT == method || 
	    		   HttpMethod.PATCH == method || HttpMethod.TRACE == method ;
}
 
Example 12
Source File: DynamicRouteStack.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public void clearPut(String url) {
    RouteKey key = new RouteKey(HttpMethod.PUT, url);
    clearRouteIfPresent(key);
}
 
Example 13
Source File: CartRepositoryImpl.java    From the-app with Apache License 2.0 4 votes vote down vote up
@Override
public String create(CartItem cartItem) {
    RequestEntity<CartItem> requestEntity = new RequestEntity<>(cartItem, HttpMethod.PUT, CREATE_TEMPLATE.expand());
    ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
    return responseEntity.getBody();
}
 
Example 14
Source File: MockMvcRequestBuilders.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PUT request.
 * @param uri the URL
 * @since 4.0.3
 */
public static MockHttpServletRequestBuilder put(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.PUT, uri);
}
 
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 PUT request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param uriVars zero or more URI variables
 */
public static MockHttpServletRequestBuilder put(String urlTemplate, Object... uriVars) {
	return new MockHttpServletRequestBuilder(HttpMethod.PUT, urlTemplate, uriVars);
}
 
Example 16
Source File: DisableStaffServiceListener.java    From MicroCommunity with Apache License 2.0 2 votes vote down vote up
/**
 * 接口请求方法
 *
 * @return
 */
@Override
public HttpMethod getHttpMethod() {
    return HttpMethod.PUT;
}
 
Example 17
Source File: EnableStaffServiceListener.java    From MicroCommunity with Apache License 2.0 2 votes vote down vote up
/**
 * 接口请求方法
 *
 * @return
 */
@Override
public HttpMethod getHttpMethod() {
    return HttpMethod.PUT;
}
 
Example 18
Source File: MockMvcRequestBuilders.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PUT request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param uriVars zero or more URI variables
 */
public static MockHttpServletRequestBuilder put(String urlTemplate, Object... uriVars) {
	return new MockHttpServletRequestBuilder(HttpMethod.PUT, urlTemplate, uriVars);
}
 
Example 19
Source File: MockMvcRequestBuilders.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PUT request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 */
public static MockHttpServletRequestBuilder put(String urlTemplate, Object... urlVariables) {
	return new MockHttpServletRequestBuilder(HttpMethod.PUT, urlTemplate, urlVariables);
}
 
Example 20
Source File: MockMvcRequestBuilders.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PUT request.
 * @param uri the URL
 * @since 4.0.3
 */
public static MockHttpServletRequestBuilder put(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.PUT, uri);
}