Search in sources :

Example 36 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project ignite by apache.

the class IgniteSpringHelperImpl method initContext.

/**
 * @param stream Input stream containing Spring XML configuration.
 * @return Context.
 * @throws IgniteCheckedException In case of error.
 */
private ApplicationContext initContext(InputStream stream) throws IgniteCheckedException {
    GenericApplicationContext springCtx;
    try {
        springCtx = new GenericApplicationContext();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(springCtx);
        reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
        reader.loadBeanDefinitions(new InputStreamResource(stream));
        springCtx.refresh();
    } catch (BeansException e) {
        if (X.hasCause(e, ClassNotFoundException.class))
            throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) ", e);
        else
            throw new IgniteCheckedException("Failed to instantiate Spring XML application context" + ", err=" + e.getMessage() + ']', e);
    }
    return springCtx;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) InputStreamResource(org.springframework.core.io.InputStreamResource) BeansException(org.springframework.beans.BeansException)

Example 37 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project ignite by apache.

the class IgniteSpringHelperImpl method applicationContext.

/**
 * Creates Spring application context. Optionally excluded properties can be specified,
 * it means that if such a property is found in {@link org.apache.ignite.configuration.IgniteConfiguration}
 * then it is removed before the bean is instantiated.
 * For example, {@code streamerConfiguration} can be excluded from the configs that Visor uses.
 *
 * @param cfgStream Stream where config file is located.
 * @param excludedProps Properties to be excluded.
 * @return Spring application context.
 * @throws IgniteCheckedException If configuration could not be read.
 */
public static ApplicationContext applicationContext(InputStream cfgStream, final String... excludedProps) throws IgniteCheckedException {
    try {
        GenericApplicationContext springCtx = prepareSpringContext(excludedProps);
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(springCtx);
        reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
        reader.loadBeanDefinitions(new InputStreamResource(cfgStream));
        springCtx.refresh();
        return springCtx;
    } catch (BeansException e) {
        if (X.hasCause(e, ClassNotFoundException.class))
            throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) ", e);
        else
            throw new IgniteCheckedException("Failed to instantiate Spring XML application context [err=" + e.getMessage() + ']', e);
    }
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) InputStreamResource(org.springframework.core.io.InputStreamResource) BeansException(org.springframework.beans.BeansException)

Example 38 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project CzechIdMng by bcvsolutions.

the class WorkflowDefinitionController method getDiagram.

/**
 * Generate process definition diagram image
 *
 * @param definitionKey
 * @return
 */
@RequestMapping(value = "/{backendId}/diagram", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.WORKFLOW_DEFINITION_READ + "')")
@ApiOperation(value = "Workflow definition diagram", nickname = "getWorkflowDefinitionDiagram", tags = { WorkflowDefinitionController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.WORKFLOW_DEFINITION_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.WORKFLOW_DEFINITION_READ, description = "") }) }, notes = "Returns input stream to definition's diagram.")
public ResponseEntity<InputStreamResource> getDiagram(@ApiParam(value = "Workflow definition key.", required = true) @PathVariable String backendId) {
    // check rights
    WorkflowProcessDefinitionDto result = definitionService.getByName(backendId);
    if (result == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    InputStream is = definitionService.getDiagramByKey(backendId);
    try {
        return ResponseEntity.ok().contentLength(is.available()).contentType(MediaType.IMAGE_PNG).body(new InputStreamResource(is));
    } catch (IOException e) {
        throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 39 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project CzechIdMng by bcvsolutions.

the class WorkflowHistoricProcessInstanceController method getDiagram.

/**
 * Generate process instance diagram image
 *
 * @param historicProcessInstanceId
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/diagram", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
@ApiOperation(value = "Historic process instance diagram", nickname = "getHistoricProcessInstanceDiagram", response = WorkflowHistoricProcessInstanceDto.class, tags = { WorkflowHistoricProcessInstanceController.TAG })
public ResponseEntity<InputStreamResource> getDiagram(@ApiParam(value = "Historic process instance id.", required = true) @PathVariable @NotNull String backendId) {
    // check rights
    WorkflowHistoricProcessInstanceDto result = workflowHistoricProcessInstanceService.get(backendId);
    if (result == null) {
        throw new ResultCodeException(CoreResultCode.FORBIDDEN);
    }
    InputStream is = workflowHistoricProcessInstanceService.getDiagram(backendId);
    try {
        return ResponseEntity.ok().contentLength(is.available()).contentType(MediaType.IMAGE_PNG).body(new InputStreamResource(is));
    } catch (IOException e) {
        throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project zhcet-web by zhcet-amu.

the class AttendanceDownloadController method downloadAttendance.

private ResponseEntity<InputStreamResource> downloadAttendance(String context, String suffix, List<CourseRegistration> courseRegistrations) {
    try {
        InputStream stream = attendanceDownloadService.getAttendanceStream(suffix, context, courseRegistrations);
        String lastModified = getLastModifiedDate(courseRegistrations).map(localDateTime -> "_" + localDateTime.format(DateTimeFormatter.ISO_DATE_TIME)).orElse("");
        return ResponseEntity.ok().contentType(MediaType.parseMediaType("text/csv")).header("Content-disposition", "attachment;filename=attendance_" + suffix + lastModified + ".csv").body(new InputStreamResource(stream));
    } catch (IOException e) {
        log.error("Attendance Download Error", e);
        return ResponseEntity.notFound().build();
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) CourseRegistration(amu.zhcet.data.course.registration.CourseRegistration) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ErrorUtils(amu.zhcet.core.error.ErrorUtils) InputStreamResource(org.springframework.core.io.InputStreamResource) FloatedCourseNotFoundException(amu.zhcet.data.course.floated.FloatedCourseNotFoundException) GetMapping(org.springframework.web.bind.annotation.GetMapping) CourseInChargeNotFoundException(amu.zhcet.data.course.incharge.CourseInChargeNotFoundException) Attendance(amu.zhcet.data.attendance.Attendance) CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) StringUtils(amu.zhcet.common.utils.StringUtils) Department(amu.zhcet.data.department.Department) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CourseInChargeService(amu.zhcet.data.course.incharge.CourseInChargeService) Course(amu.zhcet.data.course.Course) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) FloatedCourse(amu.zhcet.data.course.floated.FloatedCourse) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) Comparator(java.util.Comparator) FloatedCourseService(amu.zhcet.data.course.floated.FloatedCourseService) InputStream(java.io.InputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) InputStreamResource(org.springframework.core.io.InputStreamResource)

Aggregations

InputStreamResource (org.springframework.core.io.InputStreamResource)40 InputStream (java.io.InputStream)18 Test (org.junit.Test)12 Resource (org.springframework.core.io.Resource)10 FileSystemResource (org.springframework.core.io.FileSystemResource)8 File (java.io.File)6 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)6 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)6 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 X509Certificate (java.security.cert.X509Certificate)3 ArrayList (java.util.ArrayList)3 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ApiOperation (io.swagger.annotations.ApiOperation)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2