Java Code Examples for org.springframework.web.bind.annotation.RequestMapping#produces()
The following examples show how to use
org.springframework.web.bind.annotation.RequestMapping#produces() .
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: CrossOriginTests.java From spring-analysis-note with MIT License | 7 votes |
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class); if (annotation != null) { return new RequestMappingInfo( new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true), new RequestMethodsRequestCondition(annotation.method()), new ParamsRequestCondition(annotation.params()), new HeadersRequestCondition(annotation.headers()), new ConsumesRequestCondition(annotation.consumes(), annotation.headers()), new ProducesRequestCondition(annotation.produces(), annotation.headers()), null); } else { return null; } }
Example 2
Source File: RequestMappingInfoHandlerMappingTests.java From spring-analysis-note with MIT License | 6 votes |
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMapping annot = AnnotationUtils.findAnnotation(method, RequestMapping.class); if (annot != null) { return new RequestMappingInfo( new PatternsRequestCondition(annot.value(), getUrlPathHelper(), getPathMatcher(), true, true), new RequestMethodsRequestCondition(annot.method()), new ParamsRequestCondition(annot.params()), new HeadersRequestCondition(annot.headers()), new ConsumesRequestCondition(annot.consumes(), annot.headers()), new ProducesRequestCondition(annot.produces(), annot.headers()), null); } else { return null; } }
Example 3
Source File: CrossOriginTests.java From java-technology-stack with MIT License | 6 votes |
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class); if (annotation != null) { return new RequestMappingInfo( new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true), new RequestMethodsRequestCondition(annotation.method()), new ParamsRequestCondition(annotation.params()), new HeadersRequestCondition(annotation.headers()), new ConsumesRequestCondition(annotation.consumes(), annotation.headers()), new ProducesRequestCondition(annotation.produces(), annotation.headers()), null); } else { return null; } }
Example 4
Source File: RequestMappingInfoHandlerMappingTests.java From java-technology-stack with MIT License | 6 votes |
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMapping annot = AnnotationUtils.findAnnotation(method, RequestMapping.class); if (annot != null) { return new RequestMappingInfo( new PatternsRequestCondition(annot.value(), getUrlPathHelper(), getPathMatcher(), true, true), new RequestMethodsRequestCondition(annot.method()), new ParamsRequestCondition(annot.params()), new HeadersRequestCondition(annot.headers()), new ConsumesRequestCondition(annot.consumes(), annot.headers()), new ProducesRequestCondition(annot.produces(), annot.headers()), null); } else { return null; } }
Example 5
Source File: RequestMappingMethodHandlerMapping.java From stategen with GNU Affero General Public License v3.0 | 6 votes |
protected RequestMappingInfo createRequestMappingInfoByApiMethodAnno(RequestMapping requestMapping, RequestCondition<?> customCondition, Method method) { String[] patterns = resolveEmbeddedValuesInPatterns(requestMapping.value()); if (!method.isAnnotationPresent(RequestMapping.class) || CollectionUtil.isEmpty(patterns)) { RequestMappingResolveResult methodParsered = RequestMappingResolver.resolveOwnPath(method); String path = methodParsered.getPath(); patterns = new String[] { path }; } return new RequestMappingInfo( new PatternsRequestCondition(patterns, getUrlPathHelper(), getPathMatcher(), this.useSuffixPatternMatch, this.useTrailingSlashMatch, this.fileExtensions), new RequestMethodsRequestCondition(requestMapping.method()), new ParamsRequestCondition(requestMapping.params()), new HeadersRequestCondition(requestMapping.headers()), new ConsumesRequestCondition(requestMapping.consumes(), requestMapping.headers()), new ProducesRequestCondition(requestMapping.produces(), requestMapping.headers(), this.contentNegotiationManager), customCondition); }
Example 6
Source File: CrossOriginTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class); if (annotation != null) { return new RequestMappingInfo( new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true), new RequestMethodsRequestCondition(annotation.method()), new ParamsRequestCondition(annotation.params()), new HeadersRequestCondition(annotation.headers()), new ConsumesRequestCondition(annotation.consumes(), annotation.headers()), new ProducesRequestCondition(annotation.produces(), annotation.headers()), null); } else { return null; } }
Example 7
Source File: RequestMappingInfoHandlerMappingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMapping annotation = AnnotationUtils.findAnnotation(method, RequestMapping.class); if (annotation != null) { return new RequestMappingInfo( new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true), new RequestMethodsRequestCondition(annotation.method()), new ParamsRequestCondition(annotation.params()), new HeadersRequestCondition(annotation.headers()), new ConsumesRequestCondition(annotation.consumes(), annotation.headers()), new ProducesRequestCondition(annotation.produces(), annotation.headers()), null); } else { return null; } }
Example 8
Source File: GenericResponseBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Build generic response. * * @param components the components * @param findControllerAdvice the find controller advice */ public void buildGenericResponse(Components components, Map<String, Object> findControllerAdvice) { // ControllerAdvice for (Map.Entry<String, Object> entry : findControllerAdvice.entrySet()) { List<Method> methods = new ArrayList<>(); Object controllerAdvice = entry.getValue(); // get all methods with annotation @ExceptionHandler Class<?> objClz = controllerAdvice.getClass(); if (org.springframework.aop.support.AopUtils.isAopProxy(controllerAdvice)) objClz = org.springframework.aop.support.AopUtils.getTargetClass(controllerAdvice); ControllerAdviceInfo controllerAdviceInfo = new ControllerAdviceInfo(controllerAdvice); Arrays.stream(objClz.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(ExceptionHandler.class)).forEach(methods::add); // for each one build ApiResponse and add it to existing responses for (Method method : methods) { if (!operationBuilder.isHidden(method)) { RequestMapping reqMappringMethod = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class); String[] methodProduces = { springDocConfigProperties.getDefaultProducesMediaType() }; if (reqMappringMethod != null) methodProduces = reqMappringMethod.produces(); Map<String, ApiResponse> controllerAdviceInfoApiResponseMap = controllerAdviceInfo.getApiResponseMap(); MethodParameter methodParameter = new MethodParameter(method, -1); ApiResponses apiResponsesOp = new ApiResponses(); MethodAttributes methodAttributes = new MethodAttributes(methodProduces, springDocConfigProperties.getDefaultConsumesMediaType(), springDocConfigProperties.getDefaultProducesMediaType(), controllerAdviceInfoApiResponseMap); Map<String, ApiResponse> apiResponses = computeResponseFromDoc(components, methodParameter, apiResponsesOp, methodAttributes); buildGenericApiResponses(components, methodParameter, apiResponsesOp, methodAttributes); apiResponses.forEach(controllerAdviceInfoApiResponseMap::put); } } controllerAdviceInfos.add(controllerAdviceInfo); } }
Example 9
Source File: OpenFeignSpringMvcContract.java From summerframework with Apache License 2.0 | 5 votes |
protected void parseProduces(MethodMetadata md, Method method, RequestMapping annotation) { String[] serverProduces = annotation.produces(); String clientAccepts = serverProduces.length == 0 ? null : emptyToNull(serverProduces[0]); if (clientAccepts != null) { md.template().header(ACCEPT, clientAccepts); } }
Example 10
Source File: SpringMvcContract.java From spring-cloud-openfeign with Apache License 2.0 | 5 votes |
private void parseProduces(MethodMetadata md, Method method, RequestMapping annotation) { String[] serverProduces = annotation.produces(); String clientAccepts = serverProduces.length == 0 ? null : emptyToNull(serverProduces[0]); if (clientAccepts != null) { md.template().header(ACCEPT, clientAccepts); } }
Example 11
Source File: SpringMvcContract.java From raptor with Apache License 2.0 | 5 votes |
private void parseProduces(MethodMetadata md, Method method, RequestMapping annotation) { String[] serverProduces = annotation.produces(); String clientAccepts = serverProduces.length == 0 ? null : emptyToNull(serverProduces[0]); if (clientAccepts != null) { md.template().header(ACCEPT, clientAccepts); } }
Example 12
Source File: VenusSpringMvcContract.java From venus-cloud-feign with Apache License 2.0 | 5 votes |
private void parseProduces(MethodMetadata md, Method method, RequestMapping annotation) { String[] serverProduces = annotation.produces(); String clientAccepts = serverProduces.length == 0 ? null : emptyToNull(serverProduces[0]); if (clientAccepts != null) { md.template().header(ACCEPT, clientAccepts); } }
Example 13
Source File: SpringMvcApiReader.java From swagger-maven-plugin with Apache License 2.0 | 4 votes |
public Swagger read(SpringResource resource) { if (swagger == null) { swagger = new Swagger(); } List<Method> methods = resource.getMethods(); Map<String, Tag> tags = new HashMap<String, Tag>(); List<SecurityRequirement> resourceSecurities = new ArrayList<SecurityRequirement>(); // Add the description from the controller api Class<?> controller = resource.getControllerClass(); RequestMapping controllerRM = findMergedAnnotation(controller, RequestMapping.class); String[] controllerProduces = new String[0]; String[] controllerConsumes = new String[0]; if (controllerRM != null) { controllerConsumes = controllerRM.consumes(); controllerProduces = controllerRM.produces(); } if (controller.isAnnotationPresent(Api.class)) { Api api = findMergedAnnotation(controller, Api.class); if (!canReadApi(false, api)) { return swagger; } tags = updateTagsForApi(null, api); resourceSecurities = getSecurityRequirements(api); } resourcePath = resource.getControllerMapping(); //collect api from method with @RequestMapping Map<String, List<Method>> apiMethodMap = collectApisByRequestMapping(methods); for (String path : apiMethodMap.keySet()) { for (Method method : apiMethodMap.get(path)) { RequestMapping requestMapping = findMergedAnnotation(method, RequestMapping.class); if (requestMapping == null) { continue; } ApiOperation apiOperation = findMergedAnnotation(method, ApiOperation.class); if (apiOperation != null && apiOperation.hidden()) { continue; } Map<String, String> regexMap = new HashMap<String, String>(); String operationPath = parseOperationPath(path, regexMap); //http method for (RequestMethod requestMethod : requestMapping.method()) { String httpMethod = requestMethod.toString().toLowerCase(); Operation operation = parseMethod(method, requestMethod); updateOperationParameters(new ArrayList<Parameter>(), regexMap, operation); updateOperationProtocols(apiOperation, operation); String[] apiProduces = requestMapping.produces(); String[] apiConsumes = requestMapping.consumes(); apiProduces = (apiProduces.length == 0) ? controllerProduces : apiProduces; apiConsumes = (apiConsumes.length == 0) ? controllerConsumes : apiConsumes; apiConsumes = updateOperationConsumes(new String[0], apiConsumes, operation); apiProduces = updateOperationProduces(new String[0], apiProduces, operation); updateTagsForOperation(operation, apiOperation); updateOperation(apiConsumes, apiProduces, tags, resourceSecurities, operation); updatePath(operationPath, httpMethod, operation); } } } return swagger; }