Example usage for org.springframework.core.io ClassPathResource ClassPathResource

List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource

Introduction

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

Prototype

public ClassPathResource(String path) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:com.turbospaces.monitor.services.GroupDiscoveryService.java

public synchronized JChannel connect(final String group, final byte[] bytes) throws Exception {
    JChannel jChannel = channels.get(group);
    if (jChannel == null || bytes != null) {
        ClassPathResource resource = new ClassPathResource("udp-largecluster.xml");
        InputStream inputStream = resource.getInputStream();
        jChannel = new JChannel(inputStream);
        inputStream.close();//from w  ww.  j  a v a 2 s  .  c om
        if (bytes != null) {
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
            jChannel = new JChannel(byteArrayInputStream);
            byteArrayInputStream.close();
        }
        jChannel.setDiscardOwnMessages(true);
        ProtocolStack protocolStack = jChannel.getProtocolStack();
        protocolStack.getTransport().setValue("enable_diagnostics", false);
        logger.info("joining network group {}", group);
        jChannel.connect(group);
        channels.put(group, jChannel);
    }

    return jChannel;
}

From source file:org.cleverbus.admin.web.changes.ChangesController.java

@RequestMapping(value = CHANGES_URI, method = RequestMethod.GET)
@ResponseBody/*from  w  ww. j a va 2 s . co m*/
public String getChangesContent() throws IOException {
    ClassPathResource resource = new ClassPathResource("changes.txt");

    // add end of lines
    String resStr = "";
    List<String> lines = IOUtils.readLines(resource.getInputStream(), "utf-8");
    for (String line : lines) {
        resStr += line;
        resStr += "<br/>\n";
    }

    return resStr;
}

From source file:org.jdal.beans.IconPropertyEditor.java

/**
 * Load image from classpath /*from   w  w  w .j  av  a 2s.  c o  m*/
 * @param text the classpath of image resource
 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    Resource resource = new ClassPathResource(text);
    Icon icon = null;
    try {
        Image image = Toolkit.getDefaultToolkit().getImage(resource.getURL());
        icon = new ImageIcon(image);
    } catch (IOException e) {
        log.error(e);
    }
    setValue(icon);
}

From source file:biz.c24.io.spring.integration.config.FileSplitterTests.java

@Before
public void setUp() {
    feedChannel = new QueueChannel(100);
    transformer = new C24FileSplittingTransformer(feedChannel);
    resource = new ClassPathResource("datafixtures/10-lines.txt");
}

From source file:no.dusken.common.plugin.PluginPropertyPlaceholderConfigurer.java

public PluginPropertyPlaceholderConfigurer(DuskenPlugin plugin) {
    super();//from   ww w  . j a va2s .c o  m
    this.setLocation(new ClassPathResource(plugin.getPluginUid().concat(".conf")));
    this.plugin = plugin;
}

From source file:com.graphaware.module.timetree.module.TimeTreeModuleDeclarativeTest.java

@Override
protected String propertiesFile() {
    try {//from  w  w w. j  a va2  s  .c o m
        return new ClassPathResource("neo4j-timetree.properties").getFile().getAbsolutePath();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 * Returns a bad spring application that will cause crashes.
 *
 * @return the bad-spring-app WAR file/* w ww.ja  v  a2 s . c om*/
 * @throws IOException
 */
public static File badSpringApp() throws IOException {
    ClassPathResource cpr = new ClassPathResource("bad-spring-app.war");
    File file = cpr.getFile();
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:com.thinkbiganalytics.feedmgr.rest.model.FeedMetadataJsonTest.java

@Test
public void deserializationUnsortedTest() throws Exception {

    Resource r = new ClassPathResource("unsorted-feed.json");
    String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
    FeedMetadata feed = ObjectMapperSerializer.deserialize(json, FeedMetadata.class);
    assertNotNull(feed);/*ww  w  .  j  a  va 2s.com*/

}

From source file:com.consol.citrus.samples.todolist.config.SoapClientSslConfig.java

@Bean
public HttpClient httpClient() {
    try {//from w  w  w . j a va2s .c  o m
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(new ClassPathResource("keys/citrus.jks").getFile(), "secret".toCharArray(),
                        new TrustSelfSignedStrategy())
                .build();

        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext,
                NoopHostnameVerifier.INSTANCE);

        return HttpClients.custom().setSSLSocketFactory(sslSocketFactory)
                .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                .addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor()).build();
    } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException
            | KeyManagementException e) {
        throw new BeanCreationException("Failed to create http client for ssl connection", e);
    }
}

From source file:com.consol.citrus.samples.todolist.config.HttpClientSslConfig.java

@Bean
public HttpClient httpClient() {
    try {//from w  ww  . ja va  2  s.co m
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(new ClassPathResource("keys/citrus.jks").getFile(), "secret".toCharArray(),
                        new TrustSelfSignedStrategy())
                .build();

        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext,
                NoopHostnameVerifier.INSTANCE);

        return HttpClients.custom().setSSLSocketFactory(sslSocketFactory)
                .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
    } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException
            | KeyManagementException e) {
        throw new BeanCreationException("Failed to create http client for ssl connection", e);
    }
}