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);
}
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"));
}
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();
}
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));
}
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);
}
}
Aggregations