Search in sources :

Example 16 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.

the class AccessPointMonitorConfigDaoJaxbTest method testAfterPropertiesSetWithGoodConfigFile.

public void testAfterPropertiesSetWithGoodConfigFile() throws Exception {
    AccessPointMonitorConfigDaoJaxb dao = new AccessPointMonitorConfigDaoJaxb();
    InputStream in = ConfigurationTestUtils.getInputStreamForConfigFile("access-point-monitor-configuration.xml");
    dao.setConfigResource(new InputStreamResource(in));
    dao.afterPropertiesSet();
    assertNotNull("access point monitor config should not be null", dao.getConfig());
}
Also used : InputStream(java.io.InputStream) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 17 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project Activiti by Activiti.

the class ProcessEngineMvcEndpoint method processDefinitionDiagram.

/**
     * Look up the process definition by key. For example,
     * this is <A href="http://localhost:8080/activiti/processes/fulfillmentProcess">process-diagram for</A>
     * a process definition named {@code fulfillmentProcess}.
     */
@RequestMapping(value = "/processes/{processDefinitionKey:.*}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public ResponseEntity processDefinitionDiagram(@PathVariable String processDefinitionKey) {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processDefinitionKey).latestVersion().singleResult();
    if (processDefinition == null) {
        return ResponseEntity.status(NOT_FOUND).body(null);
    }
    ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
    if (bpmnModel.getLocationMap().size() == 0) {
        BpmnAutoLayout autoLayout = new BpmnAutoLayout(bpmnModel);
        autoLayout.execute();
    }
    InputStream is = processDiagramGenerator.generateJpgDiagram(bpmnModel);
    return ResponseEntity.ok(new InputStreamResource(is));
}
Also used : DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) BpmnModel(org.activiti.bpmn.model.BpmnModel) InputStreamResource(org.springframework.core.io.InputStreamResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with InputStreamResource

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

the class ExportLogController method getErrorResponse.

private ResponseEntity<InputStreamResource> getErrorResponse(String result) {
    HttpHeaders respHeaders = new HttpHeaders();
    // if the command is successful, the output is the filepath,
    InputStreamResource isr;
    // into a Result object
    try {
        isr = new InputStreamResource(IOUtils.toInputStream(result, "UTF-8"));
        respHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
        return new ResponseEntity<InputStreamResource>(isr, respHeaders, HttpStatus.OK);
    } catch (Exception e) {
        throw new RuntimeException("IO Error writing file to output stream", e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 19 with InputStreamResource

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

the class ExportLogController method getOKResponse.

private ResponseEntity<InputStreamResource> getOKResponse(Result commandResult) {
    HttpHeaders respHeaders = new HttpHeaders();
    // if the command is successful, the output is the filepath,
    InputStreamResource isr;
    String filePath = commandResult.nextLine().trim();
    File zipFile = new File(filePath);
    try {
        isr = new InputStreamResource(new FileInputStream(zipFile));
        respHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
        return new ResponseEntity<InputStreamResource>(isr, respHeaders, HttpStatus.OK);
    } catch (Exception e) {
        throw new RuntimeException("IO Error writing file to output stream", e);
    } finally {
        FileUtils.deleteQuietly(zipFile);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) File(java.io.File) FileInputStream(java.io.FileInputStream) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 20 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project dhis2-core by dhis2.

the class DefaultDhisConfigurationProvider method loadDhisConf.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private Properties loadDhisConf() throws IllegalStateException {
    try (InputStream in = locationManager.getInputStream(CONF_FILENAME)) {
        Properties conf = PropertiesLoaderUtils.loadProperties(new InputStreamResource(in));
        substituteEnvironmentVariables(conf);
        return conf;
    } catch (LocationManagerException | IOException | SecurityException ex) {
        log.debug(String.format("Could not load %s", CONF_FILENAME), ex);
        throw new IllegalStateException("Properties could not be loaded", ex);
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) LocationManagerException(org.hisp.dhis.external.location.LocationManagerException) InputStreamResource(org.springframework.core.io.InputStreamResource)

Aggregations

InputStreamResource (org.springframework.core.io.InputStreamResource)32 Test (org.junit.Test)12 InputStream (java.io.InputStream)11 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 FileInputStream (java.io.FileInputStream)4 ClassPathResource (org.springframework.core.io.ClassPathResource)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 X509Certificate (java.security.cert.X509Certificate)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)2 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)2 DefaultStatisticsDaemonConfigDao (org.opennms.netmgt.dao.jaxb.DefaultStatisticsDaemonConfigDao)2 BeansException (org.springframework.beans.BeansException)2 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)2 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)2