Example usage for org.springframework.core.io Resource getInputStream

List of usage examples for org.springframework.core.io Resource getInputStream

Introduction

In this page you can find the example usage for org.springframework.core.io Resource getInputStream.

Prototype

InputStream getInputStream() throws IOException;

Source Link

Document

Return an InputStream for the content of an underlying resource.

Usage

From source file:com.fns.grivet.api.GrivetApiClientIT.java

@Test
public void testLinkAndUnlinkJsonSchemaHappyPath() {
    registerTestType();//w w  w  . jav  a 2  s  . c  o  m
    Resource r = resolver.getResource("classpath:TestTypeSchema.json");
    try {
        String schema = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        given().contentType("application/json").request().body(schema).then().expect().statusCode(equalTo(200))
                .when().post("/api/v1/schema");
        given().contentType("application/json").request().then().expect().statusCode(equalTo(200)).when()
                .delete("/api/v1/schema/TestType");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    deregisterType();
}

From source file:com.fns.grivet.api.GrivetApiClientIT.java

@Test
public void testAllRegisteredNamedQueriesHappyPath() {
    Resource r = resolver.getResource("classpath:TestSelectQuery.json");
    try {/*ww  w  .  j a  v  a2s .  com*/
        String select = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        given().contentType("application/json").request().body(select).then().expect().statusCode(equalTo(204))
                .when().post("/api/v1/query");
        Response response = given().contentType("application/json").request().then().expect()
                .statusCode(equalTo(200)).when().get("/api/v1/queries");
        JSONArray result = new JSONArray(response.body().asString());
        Assertions.assertEquals(1, result.length());
        given().contentType("application/json").request().then().expect().statusCode(equalTo(204)).when()
                .delete("/api/v1/query/getAttributesCreatedBefore");
    } catch (IOException e) {
        fail(e.getMessage());
    }
}

From source file:com.fns.grivet.api.GrivetApiClientIT.java

@Test
public void testRegisterAndStoreMultipleCoursesAccepted() {
    registerMultipleTypes();/*  www.  j  a va  2 s. co  m*/
    Resource r = resolver.getResource("classpath:BadCourseData.json");
    try {
        String courses = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());

        // link Course schema
        r = resolver.getResource("classpath:CourseSchema.json");
        String schema = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        given().contentType("application/json").request().body(schema).then().expect().statusCode(equalTo(200))
                .when().post("/api/v1/schema");

        given().contentType("application/json").request().header("Type", "Course").body(courses).then().expect()
                .statusCode(equalTo(202)).when().post("/api/v1/types");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    deregisterTypes();
}

From source file:org.mifos.tools.service.PPIUploaderService.java

private void uploadLookupTable(final Properties properties, final MifosRestResource restResource,
        final String countryCode, final Long surveyId) {
    final Resource lookupTableResource = this.resourceLoader
            .getResource("classpath:template/" + countryCode.toUpperCase() + "/lookuptable.json");

    if (lookupTableResource.exists()) {
        try {//from  ww w  .  ja  va  2  s  .  c  o m
            final JsonReader reader = new JsonReader(
                    new InputStreamReader(lookupTableResource.getInputStream()));
            final List<LookupTable> lookupTables = this.gson.fromJson(reader,
                    new TypeToken<List<LookupTable>>() {
                    }.getType());
            if (lookupTables != null && !lookupTables.isEmpty()) {
                for (final LookupTable lookupTable : lookupTables) {
                    restResource.createLookupTable(this.authToken(properties), properties.getProperty("tenant"),
                            PPIUploaderConstant.CONTENT_TYPE, surveyId, lookupTable);
                }
            }
        } catch (Throwable th) {
            this.logger.error("Error while uploading survey!", th);
            System.out.println("Could not upload survey! See logfile for more information.");
        }
    } else {
        System.out.println("Unknown country code " + countryCode + "!");
    }
}

From source file:com.fns.grivet.api.GrivetApiClientIT.java

@Test
public void testNamedQueryRegistrationAndRetrievalSelectHappyPath() {
    registerTestType();//from  ww  w.j a  va2 s.  c o m
    Resource r = resolver.getResource("classpath:TestSelectQuery3.json");
    try {
        String select = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        given().contentType("application/json").request().body(select).then().expect().statusCode(equalTo(201))
                .when().post("/api/v1/query");
        Response response = given().contentType("application/json").request().then().expect()
                .statusCode(equalTo(200)).when().get("/api/v1/query/getClassesCreatedToday");
        JSONArray result = new JSONArray(response.body().asString());
        Assertions.assertEquals(1, result.length());
        given().contentType("application/json").request().then().expect().statusCode(equalTo(204)).when()
                .delete("/api/v1/query/getClassesCreatedToday");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    deregisterType();
}

From source file:com.fns.grivet.api.GrivetApiClientIT.java

@Test
@Disabled("Cannot test w/ H2")
public void testNamedQueryRegistrationAndRetrievalSprocHappyPath() {
    registerTestType();//  w w w.  jav  a 2  s .  c o  m
    Resource r = resolver.getResource("classpath:TestSprocQuery.json");
    try {
        String sproc = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        given().contentType("application/json").request().body(sproc).then().expect().statusCode(equalTo(204))
                .when().post("/api/v1/query");
        LocalDateTime now = LocalDateTime.now();
        Response response = given().contentType("application/json").request().then().expect()
                .statusCode(equalTo(200)).when()
                .get("/api/v1/query/sproc.getAttributesCreatedBefore?createdTime=" + now.toString());
        JSONArray result = new JSONArray(response.body().asString());
        Assertions.assertEquals(7, result.length());
        given().contentType("application/json").request().then().expect().statusCode(equalTo(204)).when()
                .delete("/api/v1/query/sproc.getAttributesCreatedBefore");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    deregisterType();
}

From source file:com.enonic.cms.core.structure.SitePropertiesServiceImpl.java

public void start() {
    if (started) {
        return;/* w  w  w . j  a  v a  2 s.  c om*/
    }

    Resource resource = resourceLoader
            .getResource("classpath:com/enonic/cms/business/render/site-default.properties");
    try {
        defaultProperties = new Properties();
        defaultProperties.load(resource.getInputStream());
    } catch (IOException e) {
        throw new RuntimeException("Failed to load site-default.properties", e);
    }

    // Load properties for all sites
    final List<SiteEntity> allSites = siteDao.findAll();
    for (final SiteEntity currSite : allSites) {
        loadSiteProperties(currSite.getKey());
    }

    // Broadcast properties loaded for all sites
    for (final SiteEntity currSite : allSites) {
        final SiteProperties siteProperties = sitePropertiesMap.get(currSite.getKey());
        for (SitePropertiesListener listener : sitePropertiesListeners) {
            listener.sitePropertiesLoaded(siteProperties);
        }
    }

    started = true;
}

From source file:com.haulmont.restapi.config.RestJsonTransformations.java

protected void init() {
    String configName = AppContext.getProperty(CUBA_REST_JSON_TRANSFORMATION_CONFIG_PROP_NAME);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                loadConfig(Dom4j.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }//from ww  w  . j a va2 s .  co  m
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }
}

From source file:org.jasig.schedassist.impl.caldav.xml.ReportResponseHandlerImplTest.java

@Test
public void testExtractCalendarScheduleStatus() throws IOException {
    Resource scheduleStatusExample = new ClassPathResource(
            "vevent-examples/example-individual-appointment-schedule-status.ics");
    ReportResponseHandlerImpl handler = new ReportResponseHandlerImpl();
    Calendar cal = handler.extractCalendar(IOUtils.toString(scheduleStatusExample.getInputStream()));
    Assert.assertNotNull(cal);//from  w w w  . j  a  v  a  2  s . c o  m
    Assert.assertEquals(1, cal.getComponents(VEvent.VEVENT).size());
}

From source file:com.fns.grivet.api.GrivetApiClientIT.java

@Test
public void testRegisterAndStoreMultipleContactsHappyPath() {
    registerMultipleTypes();//from  w w  w  .j  a  v a2 s  .co  m
    Resource r = resolver.getResource("classpath:TestMultipleContactsData.json");
    try {
        String contacts = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        given().contentType("application/json").request().header("Type", "Contact").body(contacts).then()
                .expect().statusCode(equalTo(201)).when().post("/api/v1/types");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    deregisterTypes();
}