org.springframework.http.HttpMethod#equals ( )源码实例Demo

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

源代码1 项目: cucumber-rest-steps   文件: RestSteps.java
private void callWithFile(String httpMethodString, String path, String file, Resource resource) {
  HttpMethod httpMethod = HttpMethod.valueOf(httpMethodString.toUpperCase());

  if (httpMethod.equals(HttpMethod.GET)) {
    throw new IllegalArgumentException("You can't submit a file in a GET call");
  }

  MultipartBodyBuilder builder = new MultipartBodyBuilder();
  builder.part(file, resource);

  responseSpec = webClient.method(httpMethod)
      .uri(path)
      .syncBody(builder.build())
      .exchange();
  expectBody = null;
}
 
源代码2 项目: Poseidon   文件: APIApplication.java
@Override
public void handleRequest(PoseidonRequest request, PoseidonResponse response) throws ElementNotFoundException, BadRequestException, ProcessingException, InternalErrorException {
    HttpMethod method = request.getAttribute(RequestConstants.METHOD);
    boolean handled = false;
    if (method != null && method.equals(HttpMethod.OPTIONS)) {
        handled = handleOptionsRequest(request, response);
    }

    if (!handled) {
        // Ideally, we have to get the buildable for this request, get
        // API name from the buildable and use it to start a meter here.
        // As getting a buildable could be time consuming (say we use trie
        // instead of a map as in APIBuildable), we start a meter in
        // APILegoSet.getBuildable() and stop it here
        try {
            lego.buildResponse(request, response);
        } finally {
            Object timerContext = request.getAttribute(TIMER_CONTEXT);
            if (timerContext != null && timerContext instanceof Timer.Context) {
                ((Timer.Context) timerContext).stop();
            }
        }
    }
}
 
源代码3 项目: cucumber-rest-steps   文件: RestSteps.java
private void call(String httpMethodString, URI uri, Object requestObj) throws JSONException {
  HttpMethod httpMethod = HttpMethod.valueOf(httpMethodString.toUpperCase());

  if (httpMethod.equals(HttpMethod.GET) && requestObj != null) {
    throw new IllegalArgumentException("You can't pass data in a GET call");
  }

  final String path = uri.toString();
  if (path.contains("$.")) {
    initExpectBody();
    Pattern pattern = Pattern.compile("(((\\$.*)\\/.*)|(\\$.*))");
    Matcher matcher = pattern.matcher(path);
    assertTrue(matcher.find());
    final String jsonPath = matcher.group(0);
    final byte[] responseBody = expectBody.jsonPath(jsonPath).exists().returnResult().getResponseBody();
    final String value = ((JSONObject) JSONParser.parseJSON(new String(responseBody))).getString(jsonPath.replace("$.", ""));
    uri = URI.create(path.replace(jsonPath, value));
  }

  final RequestBodySpec requestBodySpec = webClient.method(httpMethod).uri(uri);
  if (requestObj != null) {
    requestBodySpec.syncBody(requestObj);
    requestBodySpec.contentType(MediaType.APPLICATION_JSON);
  }

  if (headers != null) {
    headers.forEach((key, value) -> requestBodySpec.header(key, value.toArray(new String[0])));
  }

  responseSpec = requestBodySpec.exchange();
  expectBody = null;
  headers = null;
}
 
@Override
public boolean match(HttpRequest request) {
	boolean matched = false;
	HttpMethod httpMethod = request.getMethod();
	if (httpMethod != null) {
		for (HttpMethod method : getMethods()) {
			if (httpMethod.equals(method)) {
				matched = true;
				break;
			}
		}
	}
	return matched;
}
 
源代码5 项目: alfresco-remote-api   文件: ResourceInspector.java
/**
 * Determines if the resources supports the resource action specified by resourceInterfaceWithOneMethod 
 * @param resourceInterfaceWithOneMethod The resource action
 * @param httpMethod http method the action supports.
 * @param helper Holder of simple meta data
 */
private static void findOperation(Class<? extends ResourceAction> resourceInterfaceWithOneMethod, HttpMethod httpMethod, MetaHelperCallback helper)
{
    if (resourceInterfaceWithOneMethod.isAssignableFrom(helper.resource))
    {
        Method aMethod = findMethod(resourceInterfaceWithOneMethod, helper.resource);
        ResourceOperation operation = inspectOperation(helper.resource, aMethod, httpMethod);

        if (isDeleted(aMethod))
        {
            helper.whenOperationDeleted(resourceInterfaceWithOneMethod, aMethod);    
        } 
        else 
        {
            helper.whenNewOperation(operation, aMethod);
        }

        if (isNoAuth(aMethod))
        {
            if (! (httpMethod.equals(HttpMethod.GET) || httpMethod.equals(HttpMethod.POST)))
            {
                throw new IllegalArgumentException("@WebApiNoAuth should only be on GET or POST methods: " + operation.getTitle());
            }
            helper.whenOperationNoAuth(resourceInterfaceWithOneMethod, aMethod);
        }
    }
}
 
@Test
public void wrapPutAndPatchOnly() throws Exception {
	request.setContent("".getBytes("ISO-8859-1"));
	for (HttpMethod method : HttpMethod.values()) {
		request.setMethod(method.name());
		filterChain = new MockFilterChain();
		filter.doFilter(request, response, filterChain);
		if (method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH)) {
			assertNotSame("Should wrap HTTP method " + method, request, filterChain.getRequest());
		}
		else {
			assertSame("Should not wrap for HTTP method " + method, request, filterChain.getRequest());
		}
	}
}
 
源代码7 项目: spring-cloud-function   文件: FunctionWebUtils.java
public static Object findFunction(HttpMethod method, FunctionCatalog functionCatalog,
										Map<String, Object> attributes, String path) {
	if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.POST)) {
		return doFindFunction(method, functionCatalog, attributes, path);
	}
	else {
		throw new IllegalStateException("HTTP method '" + method + "' is not supported;");
	}
}
 
源代码8 项目: spring-cloud-function   文件: FunctionWebUtils.java
private static Object doFindFunction(HttpMethod method, FunctionCatalog functionCatalog,
										Map<String, Object> attributes, String path) {
	path = path.startsWith("/") ? path.substring(1) : path;
	if (method.equals(HttpMethod.GET)) {
		Supplier<Publisher<?>> supplier = functionCatalog.lookup(Supplier.class, path);
		if (supplier != null) {
			attributes.put(WebRequestConstants.SUPPLIER, supplier);
			return supplier;
		}
	}

	StringBuilder builder = new StringBuilder();
	String name = path;
	String value = null;
	for (String element : path.split("/")) {
		if (builder.length() > 0) {
			builder.append("/");
		}
		builder.append(element);
		name = builder.toString();
		value = path.length() > name.length() ? path.substring(name.length() + 1)
				: null;
		Function<Object, Object> function = functionCatalog.lookup(Function.class,
				name);
		if (function != null) {
			attributes.put(WebRequestConstants.FUNCTION, function);
			if (value != null) {
				attributes.put(WebRequestConstants.ARGUMENT, value);
			}
			return function;
		}
	}
	return null;
}