Search in sources :

Example 26 with CrossOrigin

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();
}
Also used : CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 27 with CrossOrigin

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);
    }
}
Also used : GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) IOException(java.io.IOException) ModelId(org.eclipse.vorto.model.ModelId) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 Task (com.viadee.sonarQuest.entities.Task)8 SpecialTask (com.viadee.sonarQuest.entities.SpecialTask)7 Quest (com.viadee.sonarQuest.entities.Quest)6 ApiOperation (io.swagger.annotations.ApiOperation)5 IOException (java.io.IOException)5 NotFoundException (org.c4sg.exception.NotFoundException)4 UserOrganizationException (org.c4sg.exception.UserOrganizationException)4 SpecialTaskDto (com.viadee.sonarQuest.dtos.SpecialTaskDto)3 TaskDto (com.viadee.sonarQuest.dtos.TaskDto)3 TaskDto.toTaskDto (com.viadee.sonarQuest.dtos.TaskDto.toTaskDto)3 World (com.viadee.sonarQuest.entities.World)3 WikiParsing (infoeval.main.WikiData.WikiParsing)3 ApiResponses (io.swagger.annotations.ApiResponses)3 ArrayList (java.util.ArrayList)3 CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)3 OrganizationDTO (org.c4sg.dto.OrganizationDTO)3 BadRequestException (org.c4sg.exception.BadRequestException)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3