String getMetricsName(String remaining) { String name = StringHelper.after(remaining, ":"); return name == null ? remaining : name; }
String getMetricsName(String remaining) { String name = StringHelper.after(remaining, ":"); return name == null ? remaining : name; }
public void setPassword(String password) { // lookup password as either environment or JVM system property if (password.startsWith("sysenv:")) { password = System.getenv(StringHelper.after(password, "sysenv:")); } if (ObjectHelper.isNotEmpty(password) && password.startsWith("sys:")) { password = System.getProperty(StringHelper.after(password, "sys:")); } this.password = password; } }
/** * Gets the charset from the content-type * * @param contentType the content-type * @return the charset, or <tt>null</tt> if no charset existed */ public static String getCharSetFromContentType(String contentType) { if (contentType == null) { return null; } String[] parts = contentType.split(";"); for (String part : parts) { part = part.trim(); if (part.startsWith("charset")) { return StringHelper.after(part, "charset="); } } return null; }
/** * Returns the string between the given tokens * * @param text the text * @param after is the starting token to skip the text before that. * @param before the last token * @return the text between the tokens, or <tt>null</tt> if text does not contain the tokens */ public static String betweenBeforeLast(String text, String after, String beforeLast) { text = StringHelper.after(text, after); if (text == null) { return null; } return beforeLast(text, beforeLast); }
/** * Checks whether the given http status code is within the ok range * * @param statusCode the status code * @param okStatusCodeRange the ok range (inclusive) * @return <tt>true</tt> if ok, <tt>false</tt> otherwise */ public static boolean isStatusCodeOk(int statusCode, String okStatusCodeRange) { String[] ranges = okStatusCodeRange.split(","); for (String range : ranges) { boolean ok; if (range.contains("-")) { int from = Integer.valueOf(StringHelper.before(range, "-")); int to = Integer.valueOf(StringHelper.after(range, "-")); ok = statusCode >= from && statusCode <= to; } else { int exact = Integer.valueOf(range); ok = exact == statusCode; } if (ok) { return true; } } return false; }
/** * Checks whether the given http status code is within the ok range * * @param statusCode the status code * @param okStatusCodeRange the ok range (inclusive) * @return <tt>true</tt> if ok, <tt>false</tt> otherwise */ public static boolean isStatusCodeOk(int statusCode, String okStatusCodeRange) { String[] ranges = okStatusCodeRange.split(","); for (String range : ranges) { boolean ok; if (range.contains("-")) { int from = Integer.valueOf(StringHelper.before(range, "-")); int to = Integer.valueOf(StringHelper.after(range, "-")); ok = statusCode >= from && statusCode <= to; } else { int exact = Integer.valueOf(range); ok = exact == statusCode; } if (ok) { return true; } } return false; }
private static String buildUrl(String scheme, String hostname, Object port, String path, String uri) { // build together from component level and given uri that has additional context path to append String build = scheme + "://" + hostname; if (port != null) { build += ":" + port; } if (path != null) { build = FileUtil.stripTrailingSeparator(build); build += "/" + path; } String query = null; if (uri != null && uri.contains("?")) { query = StringHelper.after(uri, "?"); uri = StringHelper.before(uri, "?"); uri = StringHelper.after(uri, "://"); } // remaining is to be appending if (uri != null) { build = FileUtil.stripTrailingSeparator(build); build += "/" + uri; } if (query != null) { build += "?" + query; } return build; }
private static String endpointPathSummaryError(CamelEndpointDetails detail) { String uri = detail.getEndpointUri(); String p = uri.contains("?") ? StringHelper.before(uri, "?") : uri; String path = StringHelper.after(p, ":"); return path + "\t" + "Sending to non existing " + detail.getEndpointComponentName() + " queue name"; }
public RestSwaggerEndpoint(final String uri, final String remaining, final RestSwaggerComponent component, final Map<String, Object> parameters) { super(notEmpty(uri, "uri"), notNull(component, "component")); this.parameters = parameters; assignedComponentName = before(uri, ":"); final URI componentSpecificationUri = component.getSpecificationUri(); specificationUri = before(remaining, "#", StringHelper::trimToNull).map(URI::create) .orElse(ofNullable(componentSpecificationUri).orElse(RestSwaggerComponent.DEFAULT_SPECIFICATION_URI)); operationId = ofNullable(after(remaining, "#")).orElse(remaining); setExchangePattern(ExchangePattern.InOut); }
/** * Gets the destination name which was configured from the endpoint uri. * * @return the destination name resolved from the endpoint uri */ public String getEndpointConfiguredDestinationName() { String remainder = StringHelper.after(getEndpointKey(), "//"); if (remainder != null && remainder.contains("?")) { // remove parameters remainder = StringHelper.before(remainder, "?"); } return JmsMessageHelper.normalizeDestinationName(remainder); }
private static String buildUrl(String scheme, String hostname, Object port, String path, String uri) { // build together from component level and given uri that has additional context path to append String build = scheme + "://" + hostname; if (port != null) { build += ":" + port; } if (path != null) { build = FileUtil.stripTrailingSeparator(build); build += "/" + path; } String query = null; if (uri != null && uri.contains("?")) { query = StringHelper.after(uri, "?"); uri = StringHelper.before(uri, "?"); uri = StringHelper.after(uri, "://"); } // remaining is to be appending if (uri != null) { build = FileUtil.stripTrailingSeparator(build); build += "/" + uri; } if (query != null) { build += "?" + query; } return build; }
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> params) throws Exception { // we are registering a regular endpoint String namespace = StringHelper.before(remaining, ":"); String delegateUri = StringHelper.after(remaining, ":"); if (ObjectHelper.isEmpty(namespace) || ObjectHelper.isEmpty(delegateUri)) { throw new IllegalArgumentException("Wrong uri syntax : master:namespace:uri, got " + remaining); } // we need to apply the params here if (params != null && params.size() > 0) { delegateUri = delegateUri + "?" + uri.substring(uri.indexOf('?') + 1); } return new MasterEndpoint( uri, this, getClusterService(), namespace, delegateUri ); }
private TriggerKey createTriggerKey(String uri, String remaining, QuartzEndpoint endpoint) throws Exception { // Parse uri for trigger name and group URI u = new URI(uri); String path = StringHelper.after(u.getPath(), "/"); String host = u.getHost(); // host can be null if the uri did contain invalid host characters such as an underscore if (host == null) { host = StringHelper.before(remaining, "/"); if (host == null) { host = remaining; } } // Trigger group can be optional, if so set it to this context's unique name String name; String group; if (ObjectHelper.isNotEmpty(path) && ObjectHelper.isNotEmpty(host)) { group = host; name = path; } else { String camelContextName = QuartzHelper.getQuartzContextName(getCamelContext()); group = camelContextName == null ? "Camel" : "Camel_" + camelContextName; name = host; } if (prefixJobNameWithEndpointId) { name = endpoint.getId() + "_" + name; } return new TriggerKey(name, group); }
/** * Extracts the username and password details from the HTTP basic header Authorization. * <p/> * This requires that the <tt>Authorization</tt> HTTP header is provided, and its using Basic. * Currently Digest is <b>not</b> supported. * * @return {@link HttpPrincipal} with username and password details, or <tt>null</tt> if not possible to extract */ protected static HttpPrincipal extractBasicAuthSubject(HttpRequest request) { String auth = request.headers().get("Authorization"); if (auth != null) { String constraint = StringHelper.before(auth, " "); if (constraint != null) { if ("Basic".equalsIgnoreCase(constraint.trim())) { String decoded = StringHelper.after(auth, " "); // the decoded part is base64 encoded, so we need to decode that ChannelBuffer buf = ChannelBuffers.copiedBuffer(decoded.getBytes()); ChannelBuffer out = Base64.decode(buf); String userAndPw = out.toString(Charset.defaultCharset()); String username = StringHelper.before(userAndPw, ":"); String password = StringHelper.after(userAndPw, ":"); HttpPrincipal principal = new HttpPrincipal(username, password); LOG.debug("Extracted Basic Auth principal from HTTP header: {}", principal); return principal; } } } return null; }
public void configure(URI uri) { // UserInfo can contain both username and password as: user:pwd@sshserver // see: http://en.wikipedia.org/wiki/URI_scheme String username = uri.getUserInfo(); String pw = null; if (username != null && username.contains(":")) { pw = StringHelper.after(username, ":"); username = StringHelper.before(username, ":"); } if (username != null) { setUsername(username); } if (pw != null) { setPassword(pw); } if (getHost() == null && uri.getHost() != null) { setHost(uri.getHost()); } // URI.getPort returns -1 if port not defined, else use default port int uriPort = uri.getPort(); if (getPort() == DEFAULT_SSH_PORT && uriPort != -1) { setPort(uriPort); } }
private CamelCloudServiceFilter createServiceFilter(CamelCloudConfigurationProperties.ServiceFilterConfiguration configuration) { BlacklistServiceFilter blacklist = new BlacklistServiceFilter(); Map<String, List<String>> services = configuration.getBlacklist(); for (Map.Entry<String, List<String>> entry : services.entrySet()) { for (String part : entry.getValue()) { String host = StringHelper.before(part, ":"); String port = StringHelper.after(part, ":"); if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) { blacklist.addServer( DefaultServiceDefinition.builder() .withName(entry.getKey()) .withHost(host) .withPort(Integer.parseInt(port)) .build() ); } } } return new CamelCloudServiceFilter(Arrays.asList(new HealthyServiceFilter(), blacklist)); } }
@Override public Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition, Processor target, Processor nextTarget) throws Exception { if (this.tracker == null) { return target; } if (definition instanceof PipelineDefinition) { final String id = definition.getId(); if (ObjectHelper.isEmpty(id)) { return target; } final String stepId = StringHelper.after(id, "step:"); if (ObjectHelper.isEmpty(stepId)) { return target; } return new EventProcessor(target); } return target; }
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { String ns = StringHelper.before(remaining, "/"); String path = StringHelper.after(remaining, "/"); if (ns == null) { ns = remaining; } if (path == null) { path = remaining; } EtcdNamespace namespace = getCamelContext().getTypeConverter().mandatoryConvertTo(EtcdNamespace.class, ns); EtcdConfiguration configuration = loadConfiguration(parameters); if (namespace != null) { // path must start with leading slash if (!path.startsWith("/")) { path = "/" + path; } switch (namespace) { case stats: return new EtcdStatsEndpoint(uri, this, configuration, namespace, path); case watch: return new EtcdWatchEndpoint(uri, this, configuration, namespace, path); case keys: return new EtcdKeysEndpoint(uri, this, configuration, namespace, path); default: throw new IllegalStateException("No endpoint for " + remaining); } } throw new IllegalStateException("No endpoint for " + remaining); }
port = StringHelper.after(remaining, ":"); hosts = StringHelper.before(remaining, ":"); } else {