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;
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
Aggregations