@Test public void getMatchingConditionWithEmptyConditions() { RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition(); for (RequestMethod method : RequestMethod.values()) { if (method != OPTIONS) { HttpServletRequest request = new MockHttpServletRequest(method.name(), ""); assertNotNull(condition.getMatchingCondition(request)); } } testNoMatch(condition, OPTIONS); }
@Test public void getMatchingConditionWithEmptyConditions() throws Exception { RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition(); for (RequestMethod method : RequestMethod.values()) { if (method != OPTIONS) { ServerWebExchange exchange = getExchange(method.name()); assertNotNull(condition.getMatchingCondition(exchange)); } } testNoMatch(condition, OPTIONS); }
@Override public void apply(OperationContext context) { Optional<ApiOperation> apiOperationAnnotation = context.findAnnotation(ApiOperation.class); if (apiOperationAnnotation.isPresent() && StringUtils.hasText(apiOperationAnnotation.get().httpMethod())) { String apiMethod = apiOperationAnnotation.get().httpMethod(); try { RequestMethod.valueOf(apiMethod); context.operationBuilder().method(HttpMethod.valueOf(apiMethod)); } catch (IllegalArgumentException e) { log.error("Invalid http method: " + apiMethod + "Valid ones are [" + RequestMethod.values() + "]", e); } } }
private void apiHandle ( PermissionResourceForm form , PermissionResource resource ) { if ( Objects.equals( resource.getResourceType().getValue() , ResourceType.API.getValue() ) ) { final Set< String > methods = Stream.of( RequestMethod.values() ) .map( RequestMethod::name ) .collect( Collectors.toSet() ); for ( String method : form.getResourceApiUriMethods() ) { AssertUtils.isTrue( ! methods.contains( method ) , "操作失败,resourceApiUriMethods格式不正确" ); } resource.setResourceApiUriMethods( form.getResourceApiUriMethods() .parallelStream() .collect( Collectors.joining( "," ) ) ); // 接口类型处理 // + 接口类型权限资源, 这两个字段不能为空 -> resourceApiUri resourceApiUriMethods AssertUtils.isTrue( StringUtils.isBlank( resource.getResourceApiUri() ) , "api类型权限资源,resourceApiUri字段不能为空" ); AssertUtils.isTrue( StringUtils.isBlank( resource.getResourceApiUriMethods() ) , "api类型权限资源,resourceApiUriMethods字段不能为空" ); } }
for (RequestMethod m : RequestMethod.values()) { rawPathsAndMethods.add(Maps.immutableEntry( PathUtils.joinPaths(prefixPath, suffixPath), m));
@Override public void apply(OperationContext context) { HandlerMethod handlerMethod = context.getHandlerMethod(); ApiOperation apiOperationAnnotation = handlerMethod.getMethodAnnotation(ApiOperation.class); if (apiOperationAnnotation != null && StringUtils.hasText(apiOperationAnnotation.httpMethod())) { String apiMethod = apiOperationAnnotation.httpMethod(); try { RequestMethod.valueOf(apiMethod); context.operationBuilder().method(apiMethod); } catch (IllegalArgumentException e) { log.error("Invalid http method: " + apiMethod + "Valid ones are [" + RequestMethod.values() + "]", e); } } }
@Override public void execute(RequestMappingContext context) { RequestMethod currentHttpMethod = (RequestMethod) context.get("currentHttpMethod"); HandlerMethod handlerMethod = context.getHandlerMethod(); String requestMethod = currentHttpMethod.toString(); ApiOperation apiOperationAnnotation = handlerMethod.getMethodAnnotation(ApiOperation.class); if (apiOperationAnnotation != null && StringUtils.hasText(apiOperationAnnotation.httpMethod())) { String apiMethod = apiOperationAnnotation.httpMethod(); try { RequestMethod.valueOf(apiMethod); requestMethod = apiMethod; } catch (IllegalArgumentException e) { log.error("Invalid http method: " + apiMethod + "Valid ones are [" + RequestMethod.values() + "]", e); } } context.put("httpRequestMethod", requestMethod); } }