public RequestMethod[] getRequestMethods() { RequestMethod[] requestMethods = new RequestMethod[this.methods.length]; for (int i = 0; i < this.methods.length; i++) { requestMethods[i] = RequestMethod.valueOf(this.methods[i].name()); } return requestMethods; }
@Override public RequestMethod getMethod() { return RequestMethod.valueOf(request.getMethod()); }
private RequestMappingInfo createRequestMappingInfo(WebOperation operation) { WebOperationRequestPredicate predicate = operation.getRequestPredicate(); PatternsRequestCondition patterns = patternsRequestConditionForPattern( predicate.getPath()); RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( RequestMethod.valueOf(predicate.getHttpMethod().name())); ConsumesRequestCondition consumes = new ConsumesRequestCondition( StringUtils.toStringArray(predicate.getConsumes())); ProducesRequestCondition produces = new ProducesRequestCondition( StringUtils.toStringArray(predicate.getProduces())); return new RequestMappingInfo(null, patterns, methods, null, null, consumes, produces, null); }
private RequestMappingInfo createRequestMappingInfo(WebOperation operation) { WebOperationRequestPredicate predicate = operation.getRequestPredicate(); PatternsRequestCondition patterns = new PatternsRequestCondition(pathPatternParser .parse(this.endpointMapping.createSubPath(predicate.getPath()))); RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( RequestMethod.valueOf(predicate.getHttpMethod().name())); ConsumesRequestCondition consumes = new ConsumesRequestCondition( StringUtils.toStringArray(predicate.getConsumes())); ProducesRequestCondition produces = new ProducesRequestCondition( StringUtils.toStringArray(predicate.getProduces())); return new RequestMappingInfo(null, patterns, methods, null, null, consumes, produces, null); }
public List<ResponseMessage> getGlobalResponseMessages(String forHttpMethod) { if (documentationContext.getGlobalResponseMessages().containsKey(RequestMethod.valueOf(forHttpMethod))) { return documentationContext.getGlobalResponseMessages().get(RequestMethod.valueOf(forHttpMethod)); } return newArrayList(); }
public RequestMethod[] getRequestMethods() { RequestMethod[] requestMethods = new RequestMethod[this.methods.length]; for (int i = 0; i < this.methods.length; i++) { requestMethods[i] = RequestMethod.valueOf(this.methods[i].name()); } return requestMethods; }
private List<ResourceInfo> buildResourcesFromProperties(Properties properties, Properties defaults) { Set<ResourceInfo> resources = new TreeSet<ResourceInfo>(); if (properties == null) { if (defaults == null) { return new ArrayList<ResourceInfo>(); } properties = defaults; } for (Enumeration<?> iterator = properties.propertyNames(); iterator.hasMoreElements();) { String key = (String) iterator.nextElement(); String method = key.substring(0, key.indexOf("/")); String url = key.substring(key.indexOf("/")); String description = properties.getProperty(key, defaults.getProperty(key)); resources.add(new ResourceInfo(url, RequestMethod.valueOf(method), description)); } return new ArrayList<ResourceInfo>(resources); }
private List<ResourceInfo> buildResourcesFromProperties(Properties properties, Properties defaults) { Set<ResourceInfo> resources = new TreeSet<ResourceInfo>(); if (properties == null) { if (defaults == null) { return new ArrayList<ResourceInfo>(); } properties = defaults; } for (Enumeration<?> iterator = properties.propertyNames(); iterator.hasMoreElements();) { String key = (String) iterator.nextElement(); String method = key.substring(0, key.indexOf("/")); String url = key.substring(key.indexOf("/")); String description = properties.getProperty(key, defaults.getProperty(key)); resources.add(new ResourceInfo(url, RequestMethod.valueOf(method), description)); } return new ArrayList<ResourceInfo>(resources); }
@Override protected void doFilterInternal( // final HttpServletRequest request, // final HttpServletResponse response, // final FilterChain filterChain // ) throws ServletException, IOException { final RequestMethod requestMethod = RequestMethod.valueOf(request.getMethod()); final String contentType = request.getContentType(); final Boolean interested = requestMethod != GET && requestMethod != OPTIONS && // contentType != null && (contentType.contains("xml") || contentType.contains("json")); if (interested) { final ContentCachingRequestWrapper found = findWrapper(request, ContentCachingRequestWrapper.class); if (found == null) { filterChain.doFilter(new ContentCachingRequestWrapper(request), response); } else { filterChain.doFilter(request, response); } } else { filterChain.doFilter(request, response); } } }
@Override protected void doFilterInternal( // final HttpServletRequest request, // final HttpServletResponse response, // final FilterChain filterChain // ) throws ServletException, IOException { final RequestMethod requestMethod = RequestMethod.valueOf(request.getMethod()); final String contentType = request.getContentType(); final Boolean interested = requestMethod != GET && requestMethod != OPTIONS && // contentType != null && (contentType.contains("xml") || contentType.contains("json")); if (interested) { final ContentCachingRequestWrapper found = findWrapper(request, ContentCachingRequestWrapper.class); if (found == null) { filterChain.doFilter(new ContentCachingRequestWrapper(request), response); } else { filterChain.doFilter(request, response); } } else { filterChain.doFilter(request, response); } } }
@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); } } }
public Group validateJsonGroup(HttpServletRequest request) throws IOException { String jsonInput = getRequestBody(request); Validator validator = validators.get(RequestMethod.valueOf(request.getMethod())); Group group; try { group = validator.validateGroup(jsonInput); } catch (JsonParseException ex) { throw new IllegalArgumentException("The JSON structure is invalid", ex); } if (group.getSchemas() == null || group.getSchemas().isEmpty() || !group.getSchemas().contains(Constants.GROUP_CORE_SCHEMA)) { throw new SchemaUnknownException(); } return group; }
private static String getModelProperty(String href, ActionDescriptor actionDescriptor) { RequestMethod httpMethod = RequestMethod.valueOf(actionDescriptor.getHttpMethod()); StringBuffer model = new StringBuffer(); switch (httpMethod) { case POST: case PUT: case PATCH: { List<UberField> uberFields = new ArrayList<UberField>(); recurseBeanCreationParams(uberFields, actionDescriptor.getRequestBody() .getParameterType(), actionDescriptor, actionDescriptor.getRequestBody(), actionDescriptor .getRequestBody() .getValue(), "", Collections.<String>emptySet()); for (UberField uberField : uberFields) { if (model.length() > 0) { model.append("&"); } model.append(String.format(MODEL_FORMAT, uberField.getName(), uberField.getName())); } break; } default: } return model.length() == 0 ? null : model.toString(); }
private static String getModelProperty(String href, ActionDescriptor actionDescriptor) { RequestMethod httpMethod = RequestMethod.valueOf(actionDescriptor.getHttpMethod()); StringBuffer model = new StringBuffer(); switch (httpMethod) { case POST: case PUT: case PATCH: { List<UberField> uberFields = new ArrayList<UberField>(); recurseBeanCreationParams(uberFields, actionDescriptor.getRequestBody() .getParameterType(), actionDescriptor, actionDescriptor.getRequestBody(), actionDescriptor .getRequestBody() .getValue(), "", Collections.<String>emptySet()); for (UberField uberField : uberFields) { if (model.length() > 0) { model.append("&"); } model.append(String.format(MODEL_FORMAT, uberField.getName(), uberField.getName())); } break; } default: } return model.length() == 0 ? null : model.toString(); }
public User validateJsonUser(HttpServletRequest request) throws IOException { String jsonInput = getRequestBody(request); Validator validator = validators.get(RequestMethod.valueOf(request.getMethod())); User user; try { user = validator.validateJsonUser(jsonInput); } catch (JsonParseException ex) { throw new IllegalArgumentException("The JSON structure is invalid", ex); } if (user.getSchemas() == null || user.getSchemas().isEmpty() || !user.getSchemas().contains(Constants.USER_CORE_SCHEMA)) { throw new SchemaUnknownException(); } if (user.getId() != null && !user.getId().isEmpty()) { user = new User.Builder(user).setId(null).build(); } return user; }
@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); } }
/** * {@inheritDoc} */ @Override protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception { String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); MethodAwareKey key = new MethodAwareKey(RequestMethod.valueOf(request.getMethod()), getUniformUrl(lookupPath)); //We should clear map in case if plugin version was changed pluginHandlerMethods.clear(); //We should update Web plugins before resolving handler pluginLoader.reloadPlugins(new TypeFilter(WebControllerPlugin.class)); HandlerMethod handlerMethod = findHandlerMethod(key); if (handlerMethod != null) { RequestMappingInfo mappingInfo = getMappingForMethod(handlerMethod.getMethod(), handlerMethod.getBeanType()); //IMPORTANT: Should be called to set request attributes which allows resolve path variables handleMatch(mappingInfo, lookupPath, request); return handlerMethod; } else { return super.getHandlerInternal(request); } }
/** * Converts single link to uber node. * * @param href * to use * @param actionDescriptor * to use for action and model, never null * @param rels * of the link * @return uber link */ public static UberNode toUberLink(String href, ActionDescriptor actionDescriptor, List<String> rels) { Assert.notNull(actionDescriptor, "actionDescriptor must not be null"); UberNode uberLink = new UberNode(); uberLink.setRel(rels); PartialUriTemplateComponents partialUriTemplateComponents = new PartialUriTemplate(href).expand(Collections .<String, Object>emptyMap()); uberLink.setUrl(partialUriTemplateComponents.toString()); uberLink.setTemplated(partialUriTemplateComponents.hasVariables() ? Boolean.TRUE : null); uberLink.setModel(getModelProperty(href, actionDescriptor)); if (actionDescriptor != null) { RequestMethod requestMethod = RequestMethod.valueOf(actionDescriptor.getHttpMethod()); uberLink.setAction(UberAction.forRequestMethod(requestMethod)); } return uberLink; }
/** * Converts single link to uber node. * * @param href * to use * @param actionDescriptor * to use for action and model, never null * @param rels * of the link * @return uber link */ public static UberNode toUberLink(String href, ActionDescriptor actionDescriptor, List<String> rels) { Assert.notNull(actionDescriptor, "actionDescriptor must not be null"); UberNode uberLink = new UberNode(); uberLink.setRel(rels); PartialUriTemplateComponents partialUriTemplateComponents = new PartialUriTemplate(href).expand(Collections .<String, Object>emptyMap()); uberLink.setUrl(partialUriTemplateComponents.toString()); uberLink.setTemplated(partialUriTemplateComponents.hasVariables() ? Boolean.TRUE : null); uberLink.setModel(getModelProperty(href, actionDescriptor)); if (actionDescriptor != null) { RequestMethod requestMethod = RequestMethod.valueOf(actionDescriptor.getHttpMethod()); uberLink.setAction(UberAction.forRequestMethod(requestMethod)); } return uberLink; }