@Override protected void doStart() throws Exception { ObjectHelper.notEmpty(cron, "cron", this); trigger = new CronTrigger(getCron(), getTimeZone()); if (taskScheduler == null) { taskScheduler = new CamelThreadPoolTaskScheduler(getCamelContext(), consumer, consumer.getEndpoint().getEndpointUri()); taskScheduler.afterPropertiesSet(); destroyTaskScheduler = true; } LOG.debug("Scheduling cron trigger {}", getCron()); future = taskScheduler.schedule(runnable, trigger); }
public void validate() throws IllegalArgumentException { ObjectHelper.notEmpty(userName, "userName"); if (ObjectHelper.isEmpty(userPassword) && secureStorage == null) { throw new IllegalArgumentException("Property userPassword or secureStorage is required"); } ObjectHelper.notEmpty(clientId, "clientId"); ObjectHelper.notEmpty(clientSecret, "clientSecret"); ObjectHelper.notEmpty(redirectUri, "redirectUri"); } }
public void validate() throws IllegalArgumentException { ObjectHelper.notEmpty(userName, "userName"); if (ObjectHelper.isEmpty(userPassword) && secureStorage == null) { throw new IllegalArgumentException("Property userPassword or secureStorage is required"); } ObjectHelper.notEmpty(clientId, "clientId"); ObjectHelper.notEmpty(clientSecret, "clientSecret"); ObjectHelper.notEmpty(redirectUri, "redirectUri"); } }
@Override public Consumer createConsumer(Processor processor) throws Exception { ObjectHelper.notEmpty(clientId, "clientId", this); ObjectHelper.notEmpty(username, "username", this); ObjectHelper.notEmpty(password, "password", this); Consumer consumer = new OpenShiftConsumer(this, processor); configureConsumer(consumer); return consumer; }
protected Class<?> doLoadClass(String name, Bundle loader) { ObjectHelper.notEmpty(name, "name"); Class<?> answer = null; // Try to use the camel context's bundle's classloader to load the class if (loader != null) { try { answer = loader.loadClass(name); } catch (ClassNotFoundException e) { if (LOG.isTraceEnabled()) { LOG.trace("Cannot load class: " + name + " using classloader: " + loader + ". This exception will be ignored.", e); } } } return answer; }
private OutputStream resolveStreamFromFile() throws IOException { String fileName = endpoint.getFileName(); ObjectHelper.notEmpty(fileName, "fileName"); LOG.debug("About to write to file: {}", fileName); File f = new File(fileName); // will create a new file if missing or append to existing f.getParentFile().mkdirs(); f.createNewFile(); return new FileOutputStream(f, true); }
public void register() throws Exception { ObjectHelper.notEmpty(alias, "alias", this); ObjectHelper.notEmpty(servletName, "servletName", this); HttpContext actualHttpContext = (httpContext == null) ? httpService.createDefaultHttpContext() : httpContext; final Dictionary<String, String> initParams = new Hashtable<>(); initParams.put("matchOnUriPrefix", matchOnUriPrefix ? "true" : "false"); initParams.put("servlet-name", servletName); httpService.registerServlet(alias, servlet, initParams, actualHttpContext); alreadyRegistered = true; }
/** * Transforms a Docker Component header value to its analogous URI * parameter * * @param name * @return */ public static String transformFromHeaderName(String name) { ObjectHelper.notEmpty(name, "name"); StringBuilder formattedName = new StringBuilder(); String nameSubstring = name.substring(DockerConstants.DOCKER_PREFIX.length()); if (nameSubstring.length() > 0) { formattedName.append(nameSubstring.substring(0, 1).toLowerCase()); formattedName.append(nameSubstring.substring(1)); } return formattedName.toString(); }
/** * Validates this endpoint if its configured properly. * * @throws Exception is thrown if endpoint is invalid configured for its mandatory options */ protected void afterPropertiesSet() throws Exception { RemoteFileConfiguration config = getConfiguration(); ObjectHelper.notEmpty(config.getHost(), "host"); ObjectHelper.notEmpty(config.getProtocol(), "protocol"); }
@Override public URL loadResourceAsURL(String uri) { ObjectHelper.notEmpty(uri, "uri"); String resolvedName = resolveUriPath(uri); URL answer = bundleContext.getBundle().getResource(resolvedName); // fallback to default as OSGi may have issues loading resources if (answer == null) { answer = super.loadResourceAsURL(uri); } return answer; }
@Override public Enumeration<URL> loadResourcesAsURL(String uri) { ObjectHelper.notEmpty(uri, "uri"); try { String resolvedName = resolveUriPath(uri); return bundleContext.getBundle().getResources(resolvedName); } catch (IOException e) { throw new RuntimeException("Cannot load resource: " + uri, e); } }
private InputStream resolveStreamFromFile() throws IOException { String fileName = endpoint.getFileName(); ObjectHelper.notEmpty(fileName, "fileName"); FileInputStream fileStream; file = new File(fileName); if (LOG.isDebugEnabled()) { LOG.debug("File to be scanned: {}, path: {}", file.getName(), file.getAbsolutePath()); } if (file.canRead()) { fileStream = new FileInputStream(file); } else if (endpoint.isScanStream()) { // if we scan the stream then it may not be available and we should return null fileStream = null; } else { throw new IllegalArgumentException(INVALID_URI); } return fileStream; }
@Override public Enumeration<URL> loadAllResourcesAsURL(String uri) { ObjectHelper.notEmpty(uri, "uri"); Vector<URL> answer = new Vector<>(); try { String resolvedName = resolveUriPath(uri); Enumeration<URL> e = bundleContext.getBundle().getResources(resolvedName); while (e != null && e.hasMoreElements()) { answer.add(e.nextElement()); } String path = FileUtil.onlyPath(uri); String name = FileUtil.stripPath(uri); if (path != null && name != null) { for (Bundle bundle : bundleContext.getBundles()) { LOG.trace("Finding all entries in path: {} with pattern: {}", path, name); e = bundle.findEntries(path, name, false); while (e != null && e.hasMoreElements()) { answer.add(e.nextElement()); } } } } catch (IOException e) { throw new RuntimeException("Cannot load resource: " + uri, e); } return answer.elements(); }
private OutputStream resolveStreamFromUrl() throws IOException { String u = endpoint.getUrl(); ObjectHelper.notEmpty(u, "url"); LOG.debug("About to write to url: {}", u); URL url = new URL(u); URLConnection c = url.openConnection(); c.setDoOutput(true); if (endpoint.getConnectTimeout() > 0) { c.setConnectTimeout(endpoint.getConnectTimeout()); } if (endpoint.getReadTimeout() > 0) { c.setReadTimeout(endpoint.getReadTimeout()); } if (endpoint.getHttpHeaders() != null) { endpoint.getHttpHeaders().forEach((k, v) -> c.addRequestProperty(k, v.toString())); } return c.getOutputStream(); }
private InputStream resolveStreamFromUrl() throws IOException { String u = endpoint.getUrl(); ObjectHelper.notEmpty(u, "url"); LOG.debug("About to read from url: {}", u); URL url = new URL(u); URLConnection c = url.openConnection(); if (endpoint.getConnectTimeout() > 0) { c.setConnectTimeout(endpoint.getConnectTimeout()); } if (endpoint.getReadTimeout() > 0) { c.setReadTimeout(endpoint.getReadTimeout()); } if (endpoint.getHttpHeaders() != null) { endpoint.getHttpHeaders().forEach((k, v) -> c.addRequestProperty(k, v.toString())); } return c.getInputStream(); }
@Override public InputStream loadResourceAsStream(String uri) { ObjectHelper.notEmpty(uri, "uri"); String resolvedName = resolveUriPath(uri); URL url = loadResourceAsURL(resolvedName); InputStream answer = null; if (url != null) { try { answer = url.openStream(); } catch (IOException ex) { throw new RuntimeException("Cannot load resource: " + uri, ex); } } // fallback to default as OSGi may have issues loading resources if (answer == null) { answer = super.loadResourceAsStream(uri); } return answer; }
public Consumer createConsumer(Processor processor) throws Exception { if (type == GitHubType.COMMIT) { ObjectHelper.notEmpty(branchName, "branchName", this); return new CommitConsumer(this, processor, branchName); } else if (type == GitHubType.PULLREQUEST) { return new PullRequestConsumer(this, processor); } else if (type == GitHubType.PULLREQUESTCOMMENT) { return new PullRequestCommentConsumer(this, processor); } else if (type == GitHubType.TAG) { return new TagConsumer(this, processor); } throw new IllegalArgumentException("Cannot create consumer with type " + type); }
@Override public void process(Exchange exchange) throws Exception { String action = exchange.getIn().getHeader(EtcdConstants.ETCD_ACTION, String.class); String path = exchange.getIn().getHeader(EtcdConstants.ETCD_PATH, String.class); if (path == null) { path = getPath(); } ObjectHelper.notEmpty(path, EtcdConstants.ETCD_PATH); ObjectHelper.notEmpty(action, EtcdConstants.ETCD_ACTION); switch(action) { case EtcdConstants.ETCD_KEYS_ACTION_SET: processSet(getClient(), path, exchange); break; case EtcdConstants.ETCD_KEYS_ACTION_GET: processGet(getClient(), path, exchange); break; case EtcdConstants.ETCD_KEYS_ACTION_DELETE: processDel(getClient(), path, false, exchange); break; case EtcdConstants.ETCD_KEYS_ACTION_DELETE_DIR: processDel(getClient(), path, true, exchange); break; default: throw new IllegalArgumentException("Unknown action " + action); } }
@Override protected void doStart() throws Exception { super.doStart(); ObjectHelper.notNull(camelContext, "CamelContext"); ObjectHelper.notEmpty("groupName", groupName); String path = getCamelClusterPath(groupName); this.groupListener = new ZookeeperGroupListenerSupport(path, route.getEndpoint(), onLockOwned(), onDisconnected()); this.groupListener.setCamelContext(camelContext); this.groupListener.setCurator(curator); this.groupListener.setMaximumConnectionTimeout(maximumConnectionTimeout); this.groupListener.setZooKeeperUrl(zooKeeperUrl); this.groupListener.setZooKeeperPassword(zooKeeperPassword); ServiceHelper.startService(groupListener); log.info("Attempting to become master for endpoint: " + route.getEndpoint() + " in " + getCamelContext() + " with singletonID: " + getGroupName()); thisNodeState = createNodeState(); groupListener.updateState(thisNodeState); }