List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource
public ClassPathResource(String path)
From source file:org.messic.server.facade.controllers.pages.LoginController.java
/** * Obtain a timestamp based on maven. This timestamp allow to the .css and .js files to force to be updated by the * navigator. If a new version of messic is released, this number will change and the navigator will update those * files./* w w w . jav a2 s .co m*/ * * @return {@link String} the timestamp */ private String getTimestamp() { ClassPathResource resource = new ClassPathResource( "/org/messic/server/facade/controllers/pages/timestamp.properties"); Properties p = new Properties(); InputStream inputStream = null; try { inputStream = resource.getInputStream(); p.load(inputStream); } catch (IOException e) { return "12345"; } finally { Closeables.closeQuietly(inputStream); } return p.getProperty("messic.timestamp"); }
From source file:net.thewaffleshop.nimbus.web.WebJarsController.java
@ResponseBody @RequestMapping("/webjarslocator/{webjar}/**") public ResponseEntity locateWebjarAsset(@PathVariable String webjar, HttpServletRequest request) { try {/*from ww w .j av a 2 s . co m*/ String mvcPrefix = "/webjarslocator/" + webjar + "/"; String mvcPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String fullPath = assetLocator.getFullPath(webjar, mvcPath.substring(mvcPrefix.length())); return new ResponseEntity(new ClassPathResource(fullPath), HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } }
From source file:nl.flotsam.calendar.core.memory.InMemoryComoundCalendarTest.java
@Test public void shouldParseNingCalendarCorrectly() throws IOException, ValidationException { Resource resource = new ClassPathResource("/ning.ical"); assertTrue(resource.exists());//from w w w . j av a 2 s. co m URI uri = resource.getURI(); InMemoryCompoundCalendarRepository repository = new InMemoryCompoundCalendarRepository(urlFetchService); Calendar calendar = repository.putCalendar("test", Arrays.asList(uri)); calendar = repository.getCalendar("test"); assertThat(calendar, is(not(nullValue()))); }
From source file:pl.softech.eav.example.DocumentManagementService.java
private String readConfiguration(String filename) throws Exception { ClassPathResource rs = new ClassPathResource(filename); StringBuffer buffer = new StringBuffer(); try (InputStreamReader in = new InputStreamReader(rs.getInputStream())) { try (BufferedReader bin = new BufferedReader(in)) { String line;/*from w ww.ja v a 2 s . co m*/ while ((line = bin.readLine()) != null) { buffer.append(line).append("\n"); } } } return buffer.toString(); }
From source file:au.id.hazelwood.xmltvguidebuilder.config.ConfigFactoryUnitTest.java
@Test(expected = InvalidConfigException.class) public void invalidConfigWithDupChannel() throws Exception { final ClassPathResource resource = new ClassPathResource( "/au/id/hazelwood/xmltvguidebuilder/config/invalid-config-dup-channel.xml"); configFactory.create(resource.getFile()); }
From source file:com.consol.citrus.demo.devoxx.ReportOrderMailIT.java
@CitrusTest public void shouldSendMail() { echo("Add 1000+ order and receive mail"); variable("orderType", "chocolate"); http().client(reportingClient).put("/reporting").queryParam("id", "citrus:randomNumber(10)") .queryParam("name", "${orderType}").queryParam("amount", "1001"); http().client(reportingClient).response(HttpStatus.OK); echo("Receive report mail for 1000+ order"); receive(mailServer).payload(new ClassPathResource("templates/mail.xml")) .header(CitrusMailMessageHeaders.MAIL_SUBJECT, "Congratulations!") .header(CitrusMailMessageHeaders.MAIL_FROM, "cookie-report@example.com") .header(CitrusMailMessageHeaders.MAIL_TO, "stakeholders@example.com"); echo("Receive report with 1000+ order"); http().client(reportingClient).get("/reporting/json"); http().client(reportingClient).response(HttpStatus.OK).messageType(MessageType.JSON).payload( "{\"caramel\": \"@ignore@\",\"blueberry\": \"@ignore@\",\"chocolate\": \"@greaterThan(1000)@\"}"); }
From source file:org.intalio.deploy.deployment.impl.ClusteredDeployServiceDeployTest.java
public void setUp() throws Exception { PropertyConfigurator.configure(new File(TestUtils.getTestBase(), "log4j.properties").getAbsolutePath()); Utils.deleteRecursively(_deployDir); XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("clustered-test.xml")); cluster = (ClusterProxy) factory.getBean("cluster"); cluster.startUpProcesses();/* ww w . j av a 2 s .c o m*/ Thread.sleep(6000); cluster.setNodes((List<ClusteredNode>) factory.getBean("nodes")); // setup database DataSource ds = cluster.getDataSource(); ClassPathResource script = new ClassPathResource("deploy.derby.sql"); if (script == null) throw new IOException("Unable to find file: deploy.derby.sql"); SQLScript sql = new SQLScript(script.getInputStream(), ds); sql.setIgnoreErrors(true); sql.setInteractive(false); sql.executeScript(); Connection c = ds.getConnection(); EasyStatement.execute(c, "DELETE FROM DEPLOY_RESOURCES"); EasyStatement.execute(c, "DELETE FROM DEPLOY_COMPONENTS"); EasyStatement.execute(c, "DELETE FROM DEPLOY_ASSEMBLIES"); c.close(); }
From source file:org.springframework.cloud.config.monitor.GithubPropertyPathNotificationExtractorTests.java
@Test public void notAPushNotDetected() throws Exception { Map<String, Object> value = new ObjectMapper().readValue( new ClassPathResource("github.json").getInputStream(), new TypeReference<Map<String, Object>>() { });//from w ww. j av a2s .co m this.headers.set("X-Github-Event", "issues"); PropertyPathNotification extracted = this.extractor.extract(this.headers, value); assertNull(extracted); }
From source file:org.ow2.proactive.scheduling.api.graphql.service.AuthenticationServiceTestConfig.java
@Bean public PropertyPlaceholderConfigurer properties() throws Exception { PropertyPlaceholderConfigurer placeholderConfigurer = new PropertyPlaceholderConfigurer(); placeholderConfigurer.setLocation(new ClassPathResource("application-test.properties")); return placeholderConfigurer; }
From source file:org.zalando.stups.spring.boot.actuator.ExtInfoEndpointConfiguration.java
@Bean public InfoEndpoint infoEndpoint() throws Exception { LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>(); for (String filename : getAllPropertiesFiles()) { Resource resource = new ClassPathResource("/" + filename); Properties properties = new Properties(); if (resource.exists()) { properties = PropertiesLoaderUtils.loadProperties(resource); String name = resource.getFilename(); info.put(name.replace(PROPERTIES_SUFFIX, PROPERTIES_SUFFIX_REPLACEMENT), Maps.fromProperties(properties)); } else {// w w w . j a va 2 s . co m if (failWhenResourceNotExists()) { throw new RuntimeException("Resource : " + filename + " does not exist"); } else { log.info("Resource {} does not exist", filename); } } } return new InfoEndpoint(info); }