Search in sources :

Example 51 with URL

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);
        }
    }
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) Test(org.junit.Test)

Example 52 with URL

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);
        }
    }
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) Test(org.junit.Test)

Example 53 with URL

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BufferedReader(java.io.BufferedReader) JCacheHelper(org.apache.camel.component.jcache.JCacheHelper) IOException(java.io.IOException) URL(java.net.URL) BundleContext(org.osgi.framework.BundleContext)

Example 54 with URL

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);
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 55 with URL

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");
}
Also used : URISyntaxException(java.net.URISyntaxException) URL(java.net.URL)

Aggregations

URL (java.net.URL)8112 IOException (java.io.IOException)2006 Test (org.junit.Test)1653 File (java.io.File)1638 MalformedURLException (java.net.MalformedURLException)1165 HttpURLConnection (java.net.HttpURLConnection)1030 InputStream (java.io.InputStream)1028 ArrayList (java.util.ArrayList)633 URLConnection (java.net.URLConnection)515 InputStreamReader (java.io.InputStreamReader)473 URLClassLoader (java.net.URLClassLoader)451 BufferedReader (java.io.BufferedReader)390 HashMap (java.util.HashMap)361 URISyntaxException (java.net.URISyntaxException)286 URI (java.net.URI)269 Map (java.util.Map)259 FileInputStream (java.io.FileInputStream)227 List (java.util.List)205 FileOutputStream (java.io.FileOutputStream)194 OutputStream (java.io.OutputStream)194