Search in sources :

Example 46 with URL

use of java.net.URL in project camel by apache.

the class SplitterTest method testSplitterWithStreamingAndFileBody.

public void testSplitterWithStreamingAndFileBody() throws Exception {
    URL url = this.getClass().getResource("/org/apache/camel/processor/simple.txt");
    assertNotNull("We should find this simple file here.", url);
    File file = new File(url.getFile());
    sendToSplitterWithStreaming(file);
}
Also used : File(java.io.File) URL(java.net.URL)

Example 47 with URL

use of java.net.URL in project camel by apache.

the class KeyStoreParametersTest method testValidParameters.

public void testValidParameters() throws GeneralSecurityException, IOException, URISyntaxException {
    KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
    KeyStore ks = ksp.createKeyStore();
    assertNotNull(ks.getCertificate("server"));
    URL resourceUrl = this.getClass().getResource("/org/apache/camel/util/jsse/localhost.ks");
    ksp.setResource(resourceUrl.toExternalForm());
    ks = ksp.createKeyStore();
    assertNotNull(ks.getCertificate("server"));
    resourceUrl = this.getClass().getResource("/org/apache/camel/util/jsse/localhost.ks");
    File file = new File(resourceUrl.toURI());
    ksp.setResource(file.getAbsolutePath());
    ks = ksp.createKeyStore();
    assertNotNull(ks.getCertificate("server"));
}
Also used : KeyStore(java.security.KeyStore) File(java.io.File) URL(java.net.URL)

Example 48 with URL

use of java.net.URL in project camel by apache.

the class ResourceHelperTest method testLoadClasspathAsUrl.

public void testLoadClasspathAsUrl() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.start();
    URL url = ResourceHelper.resolveMandatoryResourceAsUrl(context.getClassResolver(), "classpath:log4j2.properties");
    assertNotNull(url);
    String text = context.getTypeConverter().convertTo(String.class, url);
    assertNotNull(text);
    assertTrue(text.contains("rootLogger"));
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) URL(java.net.URL)

Example 49 with URL

use of java.net.URL in project camel by apache.

the class EHCacheUtilTest method testCreateCacheManagers.

@Test
public void testCreateCacheManagers() throws Exception {
    // no arg
    assertNotNull("create with no arg", EHCacheUtil.createCacheManager());
    URL configURL = EHCacheUtil.class.getResource("/test-ehcache.xml");
    assertNotNull(configURL);
    // string
    assertNotNull("create with string", EHCacheUtil.createCacheManager(configURL.getPath()));
    // url
    assertNotNull("create with url", EHCacheUtil.createCacheManager(configURL));
    // inputstream
    assertNotNull("create with inputstream", EHCacheUtil.createCacheManager(configURL.openStream()));
    // config
    Configuration conf = ConfigurationFactory.parseConfiguration(configURL);
    assertNotNull(conf);
    assertNotNull("create with configuration", EHCacheUtil.createCacheManager(conf));
}
Also used : Configuration(net.sf.ehcache.config.Configuration) URL(java.net.URL) Test(org.junit.Test)

Example 50 with URL

use of java.net.URL in project camel by apache.

the class GeoCoderProducer method processCurrentLocation.

protected void processCurrentLocation(Exchange exchange) throws Exception {
    LOG.debug("Geocode for current address");
    String json = exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, new URL("http://freegeoip.net/json/"));
    if (isEmpty(json)) {
        throw new IllegalStateException("Got the unexpected value '" + json + "' for the geolocation");
    }
    LOG.debug("Geocode response {}", json);
    exchange.getIn().setHeader(GeoCoderConstants.STATUS, GeocoderStatus.OK);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readValue(json, JsonNode.class);
    JsonNode latitudeNode = notNull(node.get("latitude"), "latitude");
    JsonNode longitudeNode = notNull(node.get("longitude"), "longitude");
    String resLatlng = latitudeNode.asText() + "," + longitudeNode.asText();
    exchange.getIn().setHeader(GeoCoderConstants.LATLNG, resLatlng);
    JsonNode countryCode = node.get("country_code");
    JsonNode countryName = node.get("country_name");
    if (countryCode != null) {
        exchange.getIn().setHeader(GeoCoderConstants.COUNTRY_SHORT, countryCode.asText());
    }
    if (countryName != null) {
        exchange.getIn().setHeader(GeoCoderConstants.COUNTRY_LONG, countryName.asText());
    }
    JsonNode regionCode = node.get("region_code");
    JsonNode regionName = node.get("region_name");
    if (regionCode != null) {
        exchange.getIn().setHeader(GeoCoderConstants.REGION_CODE, regionCode.asText());
    }
    if (regionName != null) {
        exchange.getIn().setHeader(GeoCoderConstants.REGION_NAME, regionName.asText());
    }
    JsonNode city = node.get("city");
    if (city != null) {
        exchange.getIn().setHeader(GeoCoderConstants.CITY, city.asText());
    }
    // should we include body
    if (!endpoint.isHeadersOnly()) {
        exchange.getIn().setBody(json);
    }
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) URL(java.net.URL) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

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