use of java.net.URL in project camel by apache.
the class HdfsProducerTest method testWriteTextWithDynamicFilenameExpression.
@Test
public void testWriteTextWithDynamicFilenameExpression() throws Exception {
if (!canTest()) {
return;
}
for (int i = 0; i < 5; i++) {
template.sendBodyAndHeader("direct:write_dynamic_filename", "CIAO" + i, Exchange.FILE_NAME, simple("file-${body}"));
}
for (int i = 0; i < 5; i++) {
InputStream in = null;
try {
in = new URL("file:///" + TEMP_DIR.toUri() + "/test-camel-dynamic/file-CIAO" + i).openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copyBytes(in, bos, 4096, false);
assertEquals("CIAO" + i, new String(bos.toByteArray()));
} finally {
IOHelper.close(in);
}
}
}
use of java.net.URL in project camel by apache.
the class HdfsProducerTest method testWriteTextWithDynamicFilenameExpression.
@Test
public void testWriteTextWithDynamicFilenameExpression() throws Exception {
if (!canTest()) {
return;
}
for (int i = 0; i < 5; i++) {
template.sendBodyAndHeader("direct:write_dynamic_filename", "CIAO" + i, Exchange.FILE_NAME, simple("file-${body}"));
}
for (int i = 0; i < 5; i++) {
InputStream in = null;
try {
in = new URL("file:///" + TEMP_DIR.toUri() + "/test-camel-dynamic/file-CIAO" + i).openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copyBytes(in, bos, 4096, false);
assertEquals("CIAO" + i, new String(bos.toByteArray()));
} finally {
IOHelper.close(in);
}
}
}
use of java.net.URL in project camel by apache.
the class OSGiCacheManager method getClassLoader.
private ClassLoader getClassLoader(String providerName) throws Exception {
if (providerName == null || !getConfiguration().isLookupProviders()) {
return null;
}
final BundleContext bc = FrameworkUtil.getBundle(JCacheHelper.class).getBundleContext();
final ClassLoader bcl = bc.getBundle().adapt(BundleWiring.class).getClassLoader();
final ClassLoader acl = getConfiguration().getApplicationContextClassLoader();
for (final Bundle bundle : bc.getBundles()) {
URL spi = bundle.getResource("META-INF/services/javax.cache.spi.CachingProvider");
if (spi != null) {
try (BufferedReader in = new BufferedReader(new InputStreamReader(spi.openStream()))) {
if (ObjectHelper.equal(providerName, in.readLine())) {
return new ClassLoader(bcl) {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
try {
return acl.loadClass(name);
} catch (ClassNotFoundException e) {
return bundle.loadClass(name);
}
}
@Override
protected URL findResource(String name) {
URL resource = acl.getResource(name);
if (resource == null) {
resource = bundle.getResource(name);
}
return resource;
}
@Override
protected Enumeration findResources(String name) throws IOException {
try {
return acl.getResources(name);
} catch (IOException e) {
return bundle.getResources(name);
}
}
};
}
}
}
}
return null;
}
use of java.net.URL in project camel by apache.
the class HttpsAsyncRouteTest method testHelloEndpoint.
@Test
public void testHelloEndpoint() throws Exception {
// these tests does not run well on Windows
if (isPlatform("windows")) {
return;
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
InputStream is = new URL("https://localhost:" + port1 + "/hello").openStream();
int c;
while ((c = is.read()) >= 0) {
os.write(c);
}
String data = new String(os.toByteArray());
assertEquals("<b>Hello World</b>", data);
}
use of java.net.URL in project camel by apache.
the class HttpsAsyncRouteTest method configureSslContextFactory.
protected void configureSslContextFactory(SslContextFactory sslContextFactory) {
sslContextFactory.setKeyManagerPassword(pwd);
sslContextFactory.setKeyStorePassword(pwd);
URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
try {
sslContextFactory.setKeyStorePath(keyStoreUrl.toURI().getPath());
} catch (URISyntaxException e) {
throw new RuntimeException(e.getMessage(), e);
}
sslContextFactory.setTrustStoreType("JKS");
}
Aggregations