org.springframework.http.HttpMethod#DELETE源码实例Demo

下面列出了org.springframework.http.HttpMethod#DELETE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
	addHeaders(this.connection, headers);
	// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
	if (getMethod() == HttpMethod.DELETE && bufferedOutput.length == 0) {
		this.connection.setDoOutput(false);
	}
	if (this.connection.getDoOutput() && this.outputStreaming) {
		this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
	}
	this.connection.connect();
	if (this.connection.getDoOutput()) {
		FileCopyUtils.copy(bufferedOutput, this.connection.getOutputStream());
	}
	else {
		// Immediately trigger the request in a no-output scenario as well
		this.connection.getResponseCode();
	}
	return new SimpleClientHttpResponse(this.connection);
}
 
@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());
		}
	}
}
 
@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
	addHeaders(this.connection, headers);
	// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
	if (getMethod() == HttpMethod.DELETE && bufferedOutput.length == 0) {
		this.connection.setDoOutput(false);
	}
	if (this.connection.getDoOutput() && this.outputStreaming) {
		this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
	}
	this.connection.connect();
	if (this.connection.getDoOutput()) {
		FileCopyUtils.copy(bufferedOutput, this.connection.getOutputStream());
	}
	else {
		// Immediately trigger the request in a no-output scenario as well
		this.connection.getResponseCode();
	}
	return new SimpleClientHttpResponse(this.connection);
}
 
@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());
		}
	}
}
 
源代码5 项目: lams   文件: SimpleBufferingClientHttpRequest.java
@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
	addHeaders(this.connection, headers);
	// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
	if (HttpMethod.DELETE == getMethod() && bufferedOutput.length == 0) {
		this.connection.setDoOutput(false);
	}
	if (this.connection.getDoOutput() && this.outputStreaming) {
		this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
	}
	this.connection.connect();
	if (this.connection.getDoOutput()) {
		FileCopyUtils.copy(bufferedOutput, this.connection.getOutputStream());
	}
	else {
		// Immediately trigger the request in a no-output scenario as well
		this.connection.getResponseCode();
	}
	return new SimpleClientHttpResponse(this.connection);
}
 
@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
	addHeaders(this.connection, headers);

	// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
	if (HttpMethod.DELETE == getMethod() && bufferedOutput.length == 0) {
		this.connection.setDoOutput(false);
	}

	if (this.connection.getDoOutput() && this.outputStreaming) {
		this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
	}
	this.connection.connect();
	if (this.connection.getDoOutput()) {
		FileCopyUtils.copy(bufferedOutput, this.connection.getOutputStream());
	}

	return new SimpleClientHttpResponse(this.connection);
}
 
源代码7 项目: gemfirexd-oss   文件: ClientHttpRequest.java
/**
 * 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;
  }
}
 
源代码8 项目: gemfirexd-oss   文件: ClientHttpRequest.java
/**
 * 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;
  }
}
 
源代码9 项目: zstack   文件: RestServer.java
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()));
    }
}
 
源代码10 项目: microcks   文件: HttpTestRunner.java
/**
 * 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;
}
 
源代码11 项目: cloudbreak   文件: DynamicRouteStack.java
public Route delete(String url, Route responseHandler) {
    RouteKey key = new RouteKey(HttpMethod.DELETE, url);
    boolean hasSparkRoute = mockResponders.containsKey(key);
    Route route = overrideResponseByUrlWithSimple(key, responseHandler);
    addDeleteIfNotPresent(url, hasSparkRoute, route);
    return route;
}
 
源代码12 项目: cloudbreak   文件: DynamicRouteStack.java
public void clearDelete(String url) {
    RouteKey key = new RouteKey(HttpMethod.DELETE, url);
    clearRouteIfPresent(key);
}
 
/**
 * Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param uriVars zero or more URI variables
 */
public static MockHttpServletRequestBuilder delete(String urlTemplate, Object... uriVars) {
	return new MockHttpServletRequestBuilder(HttpMethod.DELETE, urlTemplate, uriVars);
}
 
/**
 * Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
 * @param uri the URL
 * @since 4.0.3
 */
public static MockHttpServletRequestBuilder delete(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.DELETE, uri);
}
 
/**
 * Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param uriVars zero or more URI variables
 */
public static MockHttpServletRequestBuilder delete(String urlTemplate, Object... uriVars) {
	return new MockHttpServletRequestBuilder(HttpMethod.DELETE, urlTemplate, uriVars);
}
 
/**
 * Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
 * @param uri the URL
 * @since 4.0.3
 */
public static MockHttpServletRequestBuilder delete(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.DELETE, uri);
}
 
/**
 * Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 */
public static MockHttpServletRequestBuilder delete(String urlTemplate, Object... urlVariables) {
	return new MockHttpServletRequestBuilder(HttpMethod.DELETE, urlTemplate, urlVariables);
}
 
/**
 * Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
 * @param uri the URL
 * @since 4.0.3
 */
public static MockHttpServletRequestBuilder delete(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.DELETE, uri);
}