private String[] parseLocations(String[] locations) { String[] answer = new String[locations.length]; for (int i = 0; i < locations.length; i++) { String location = locations[i]; LOG.trace("Parsing location: {} ", location); Matcher matcher = ENV_PATTERN.matcher(location); while (matcher.find()) { String key = matcher.group(1); String value = System.getenv(key); if (ObjectHelper.isEmpty(value)) { throw new IllegalArgumentException("Cannot find system environment with key: " + key); } // must quote the replacement to have it work as literal replacement value = Matcher.quoteReplacement(value); location = matcher.replaceFirst(value); // must match again as location is changed matcher = ENV_PATTERN.matcher(location); } matcher = SYS_PATTERN.matcher(location); while (matcher.find()) { String key = matcher.group(1); String value = System.getProperty(key); if (ObjectHelper.isEmpty(value)) { throw new IllegalArgumentException("Cannot find JVM system property with key: " + key); } // must quote the replacement to have it work as literal replacement value = Matcher.quoteReplacement(value); location = matcher.replaceFirst(value); // must match again as location is changed matcher = SYS_PATTERN.matcher(location); } LOG.debug("Parsed location: {} ", location); answer[i] = location; } return answer; }
/** * Finds matching classes within a jar files that contains a folder structure matching the package * structure. If the File is not a JarFile or does not exist a warning will be logged, but no * error will be raised. * * @param test a Test used to filter the classes that are discovered * @param parent the parent package under which classes must be in order to be considered * @param stream the inputstream of the jar file to be examined for classes * @param urlPath the url of the jar file to be examined for classes * @param classes to add found and matching classes * @param jarCache cache for JARs to speedup loading */ private void loadImplementationsInJar( PackageScanFilter test, String parent, InputStream stream, String urlPath, Set<Class<?>> classes, Map<String, List<String>> jarCache) { ObjectHelper.notNull(classes, "classes"); ObjectHelper.notNull(jarCache, "jarCache"); List<String> entries = jarCache != null ? jarCache.get(urlPath) : null; if (entries == null) { entries = doLoadJarClassEntries(stream, urlPath); if (jarCache != null) { jarCache.put(urlPath, entries); log.trace("Cached {} JAR with {} entries", urlPath, entries.size()); } } else { log.trace("Using cached {} JAR with {} entries", urlPath, entries.size()); } doLoadImplementationsInJar(test, parent, entries, classes); }
@Override protected DataFormat createDataFormat(FlowContext flowContext) { if (unmarshallClass == null && unmarshallTypeName != null) { try { unmarshallClass = flowContext .getVramelContext() .getClassResolver() .resolveMandatoryClass(unmarshallTypeName); } catch (ClassNotFoundException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } } return super.createDataFormat(flowContext); }
/** * Returns with the exception that is caught by this processor. * * <p>This method traverses exception causes, so sometimes the exception returned from this method * might be one of causes of the parameter passed. * * @param exchange the current exchange * @param exception the thrown exception * @return Throwable that this processor catches. <tt>null</tt> if nothing matches. */ public Throwable catches(Exchange exchange, Throwable exception) { // use the exception iterator to walk the caused by hierarchy Iterator<Throwable> it = ObjectHelper.createExceptionIterator(exception); while (it.hasNext()) { Throwable e = it.next(); // see if we catch this type for (Class<?> type : exceptions) { if (type.isInstance(e) && matchesWhen(exchange)) { return e; } } } // not found return null; }