use of org.springframework.web.bind.annotation.CrossOrigin in project spring-framework by spring-projects.
the class RequestMappingHandlerMapping method initCorsConfiguration.
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
HandlerMethod handlerMethod = createHandlerMethod(handler, method);
Class<?> beanType = handlerMethod.getBeanType();
CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);
if (typeAnnotation == null && methodAnnotation == null) {
return null;
}
CorsConfiguration config = new CorsConfiguration();
updateCorsConfig(config, typeAnnotation);
updateCorsConfig(config, methodAnnotation);
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
return config.applyPermitDefaultValues();
}
use of org.springframework.web.bind.annotation.CrossOrigin in project vorto by eclipse.
the class GenericGeneratorController method generateAndExtract.
@RequestMapping(value = "/{serviceKey}/models/{modelId:.+}/!/**", method = RequestMethod.GET)
@CrossOrigin(origins = "https://www.eclipse.org")
public void generateAndExtract(@ApiParam(value = "The iD of vorto model, e.g. com.mycompany:Car:1.0.0", required = true) @PathVariable final String modelId, @ApiParam(value = "Service key for a specified platform, e.g. lwm2m", required = true) @PathVariable String serviceKey, final HttpServletRequest request, final HttpServletResponse response) {
try {
ModelId modelIdToGen = ModelId.fromPrettyFormat(modelId);
GeneratedOutput generatedOutput = generatorService.generate(getUserContext(modelIdToGen), modelIdToGen, URLDecoder.decode(serviceKey, "utf-8"), getRequestParams(request));
String extractPath = getExtractPath(request);
if (extractPath == null || extractPath.trim().isEmpty()) {
writeToResponse(response, generatedOutput);
return;
}
if (generatedOutput.getFileName().endsWith(ZIPFILE_EXTENSION)) {
Optional<GeneratedOutput> extractionResult = extractFromZip(generatedOutput.getContent(), extractPath);
if (extractionResult.isPresent()) {
writeToResponse(response, extractionResult.get());
return;
}
}
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (IOException e) {
throw new RuntimeException("Error copying file.", e);
}
}
Aggregations