Java Code Examples for org.apache.logging.log4j.util.Strings#isBlank()
The following examples show how to use
org.apache.logging.log4j.util.Strings#isBlank() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JaegerReceiverProvider.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void prepare() throws ServiceNotProvidedException, ModuleStartException { if (config.getGRPCPort() > 0) { grpcServer = new GRPCServer(Strings.isBlank(config.getGRPCHost()) ? "0.0.0.0" : config.getGRPCHost(), config .getGRPCPort()); if (config.getMaxMessageSize() > 0) { grpcServer.setMaxMessageSize(config.getMaxMessageSize()); } if (config.getMaxConcurrentCallsPerConnection() > 0) { grpcServer.setMaxConcurrentCallsPerConnection(config.getMaxConcurrentCallsPerConnection()); } if (config.getGRPCThreadPoolQueueSize() > 0) { grpcServer.setThreadPoolQueueSize(config.getGRPCThreadPoolQueueSize()); } if (config.getGRPCThreadPoolSize() > 0) { grpcServer.setThreadPoolSize(config.getGRPCThreadPoolSize()); } grpcServer.initialize(); } }
Example 2
Source File: JsonTemplateLayout.java From logging-log4j2 with Apache License 2.0 | 6 votes |
private void validate() { Objects.requireNonNull(configuration, "config"); if (Strings.isBlank(eventTemplate) && Strings.isBlank(eventTemplateUri)) { throw new IllegalArgumentException( "both eventTemplate and eventTemplateUri are blank"); } Objects.requireNonNull(eventTemplateAdditionalFields, "eventTemplateAdditionalFields"); if (stackTraceEnabled && Strings.isBlank(stackTraceElementTemplate) && Strings.isBlank(stackTraceElementTemplateUri)) { throw new IllegalArgumentException( "both stackTraceElementTemplate and stackTraceElementTemplateUri are blank"); } if (maxStringLength <= 0) { throw new IllegalArgumentException( "was expecting a non-zero positive maxStringLength: " + maxStringLength); } Objects.requireNonNull(truncatedStringSuffix, "truncatedStringSuffix"); Objects.requireNonNull(recyclerFactory, "recyclerFactory"); }
Example 3
Source File: PatternResolver.java From logging-log4j2 with Apache License 2.0 | 6 votes |
PatternResolver( final EventResolverContext context, final TemplateResolverConfig config) { final String pattern = config.getString("pattern"); if (Strings.isBlank(pattern)) { throw new IllegalArgumentException("blank pattern: " + config); } final PatternLayout patternLayout = PatternLayout .newBuilder() .setConfiguration(context.getConfiguration()) .setCharset(context.getCharset()) .setPattern(pattern) .build(); this.emitter = (final StringBuilder stringBuilder, final LogEvent logEvent) -> patternLayout.serialize(logEvent, stringBuilder); }
Example 4
Source File: StringParameterParser.java From logging-log4j2 with Apache License 2.0 | 6 votes |
public static Map<String, Value> parse( final String input, final Set<String> allowedKeys) { if (Strings.isBlank(input)) { return Collections.emptyMap(); } final Map<String, Value> map = new Parser(input).call(); final Set<String> actualKeys = map.keySet(); for (final String actualKey : actualKeys) { final boolean allowed = allowedKeys == null || allowedKeys.contains(actualKey); if (!allowed) { final String message = String.format( "unknown key \"%s\" is found in input: %s", actualKey, input); throw new IllegalArgumentException(message); } } return map; }
Example 5
Source File: Configurator.java From logging-log4j2 with Apache License 2.0 | 6 votes |
/** * Initializes the Logging Context. * @param name The Context name. * @param loader The ClassLoader for the Context (or null). * @param configLocation The configuration for the logging context (or null, or blank). * @param externalContext The external context to be attached to the LoggerContext * @return The LoggerContext or null if an error occurred (check the status logger). */ public static LoggerContext initialize(final String name, final ClassLoader loader, final String configLocation, final Object externalContext) { if (Strings.isBlank(configLocation)) { return initialize(name, loader, (URI) null, externalContext); } if (configLocation.contains(",")) { final String[] parts = configLocation.split(","); String scheme = null; final List<URI> uris = new ArrayList<>(parts.length); for (final String part : parts) { final URI uri = NetUtils.toURI(scheme != null ? scheme + ":" + part.trim() : part.trim()); if (scheme == null && uri.getScheme() != null) { scheme = uri.getScheme(); } uris.add(uri); } return initialize(name, loader, uris, externalContext); } return initialize(name, loader, NetUtils.toURI(configLocation), externalContext); }
Example 6
Source File: Feature.java From anomaly-detection with Apache License 2.0 | 5 votes |
/** * Constructor function. * @param id feature id * @param name feature name * @param enabled feature enabled or not * @param aggregation feature aggregation query */ public Feature(String id, String name, Boolean enabled, AggregationBuilder aggregation) { if (Strings.isBlank(name)) { throw new IllegalArgumentException("Feature name should be set"); } if (aggregation == null) { throw new IllegalArgumentException("Feature aggregation query should be set"); } this.id = id; this.name = name; this.enabled = enabled; this.aggregation = aggregation; }
Example 7
Source File: TestHelpers.java From anomaly-detection with Apache License 2.0 | 5 votes |
public static Response makeRequest( RestClient client, String method, String endpoint, Map<String, String> params, String jsonEntity, List<Header> headers ) throws IOException { HttpEntity httpEntity = Strings.isBlank(jsonEntity) ? null : new NStringEntity(jsonEntity, ContentType.APPLICATION_JSON); return makeRequest(client, method, endpoint, params, httpEntity, headers); }
Example 8
Source File: PluginManager.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Adds a package name to be scanned for plugins. Must be invoked prior to plugins being collected. * * @param p The package name. Ignored if {@code null} or empty. */ public static void addPackage(final String p) { if (Strings.isBlank(p)) { return; } PACKAGES.addIfAbsent(p); }
Example 9
Source File: JsonTemplateLayout.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private static String readTemplate( final String template, final String templateUri, final Charset charset) { return Strings.isBlank(template) ? Uris.readUri(templateUri, charset) : template; }
Example 10
Source File: JsonTemplateLayout.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private void validate() { if (Strings.isBlank(key)) { throw new IllegalArgumentException("blank key"); } if (Strings.isBlank(value)) { throw new IllegalArgumentException("blank value"); } Objects.requireNonNull(type, "type"); }
Example 11
Source File: AnomalyDetector.java From anomaly-detection with Apache License 2.0 | 4 votes |
/** * Constructor function. * * @param detectorId detector identifier * @param version detector document version * @param name detector name * @param description description of detector * @param timeField time field * @param indices indices used as detector input * @param features detector feature attributes * @param filterQuery detector filter query * @param detectionInterval detecting interval * @param windowDelay max delay window for realtime data * @param uiMetadata metadata used by Kibana * @param schemaVersion anomaly detector index mapping version * @param lastUpdateTime detector's last update time */ public AnomalyDetector( String detectorId, Long version, String name, String description, String timeField, List<String> indices, List<Feature> features, QueryBuilder filterQuery, TimeConfiguration detectionInterval, TimeConfiguration windowDelay, Map<String, Object> uiMetadata, Integer schemaVersion, Instant lastUpdateTime ) { if (Strings.isBlank(name)) { throw new IllegalArgumentException("Detector name should be set"); } if (timeField == null) { throw new IllegalArgumentException("Time field should be set"); } if (indices == null || indices.isEmpty()) { throw new IllegalArgumentException("Indices should be set"); } if (detectionInterval == null) { throw new IllegalArgumentException("Detection interval should be set"); } this.detectorId = detectorId; this.version = version; this.name = name; this.description = description; this.timeField = timeField; this.indices = indices; this.featureAttributes = features; this.filterQuery = filterQuery; this.detectionInterval = detectionInterval; this.windowDelay = windowDelay; this.uiMetadata = uiMetadata; this.schemaVersion = schemaVersion; this.lastUpdateTime = lastUpdateTime; }
Example 12
Source File: PrefixBasedDatabaseMappingService.java From waggle-dance with Apache License 2.0 | 4 votes |
private DatabaseMapping createDatabaseMapping(MetaStoreMapping metaStoreMapping) { if (Strings.isBlank(metaStoreMapping.getDatabasePrefix())) { return new IdentityMapping(metaStoreMapping); } return new DatabaseMappingImpl(metaStoreMapping, queryMapping); }
Example 13
Source File: SharingServerModuleProvider.java From skywalking with Apache License 2.0 | 4 votes |
@Override public void prepare() { if (config.getRestPort() != 0) { jettyServer = new JettyServer(Strings.isBlank(config.getRestHost()) ? "0.0.0.0" : config.getRestHost(), config .getRestPort(), config.getRestContextPath()); jettyServer.initialize(); this.registerServiceImplementation(JettyHandlerRegister.class, new JettyHandlerRegisterImpl(jettyServer)); } else { this.receiverJettyHandlerRegister = new ReceiverJettyHandlerRegister(); this.registerServiceImplementation(JettyHandlerRegister.class, receiverJettyHandlerRegister); } if (config.getGRPCPort() != 0) { if (config.isGRPCSslEnabled()) { grpcServer = new GRPCServer(Strings.isBlank(config.getGRPCHost()) ? "0.0.0.0" : config.getGRPCHost(), config.getGRPCPort(), Paths.get(config.getGRPCSslCertChainPath()).toFile(), Paths.get(config.getGRPCSslKeyPath()).toFile()); } else { grpcServer = new GRPCServer(Strings.isBlank(config.getGRPCHost()) ? "0.0.0.0" : config.getGRPCHost(), config.getGRPCPort()); } if (config.getMaxMessageSize() > 0) { grpcServer.setMaxMessageSize(config.getMaxMessageSize()); } if (config.getMaxConcurrentCallsPerConnection() > 0) { grpcServer.setMaxConcurrentCallsPerConnection(config.getMaxConcurrentCallsPerConnection()); } if (config.getGRPCThreadPoolQueueSize() > 0) { grpcServer.setThreadPoolQueueSize(config.getGRPCThreadPoolQueueSize()); } if (config.getGRPCThreadPoolSize() > 0) { grpcServer.setThreadPoolSize(config.getGRPCThreadPoolSize()); } grpcServer.initialize(); this.registerServiceImplementation(GRPCHandlerRegister.class, new GRPCHandlerRegisterImpl(grpcServer)); } else { this.receiverGRPCHandlerRegister = new ReceiverGRPCHandlerRegister(); if (StringUtil.isNotEmpty(config.getAuthentication())) { receiverGRPCHandlerRegister.addFilter(new AuthenticationInterceptor(config.getAuthentication())); } this.registerServiceImplementation(GRPCHandlerRegister.class, receiverGRPCHandlerRegister); } }
Example 14
Source File: CIBARegisterParamsValidatorService.java From oxAuth with MIT License | 4 votes |
public boolean validateParams( BackchannelTokenDeliveryMode backchannelTokenDeliveryMode, String backchannelClientNotificationEndpoint, AsymmetricSignatureAlgorithm backchannelAuthenticationRequestSigningAlg, Boolean backchannelUserCodeParameter, List<GrantType> grantTypes, SubjectType subjectType, String sectorIdentifierUri, String jwks, String jwksUri) { try { // Not CIBA Registration if (backchannelTokenDeliveryMode == null && Strings.isBlank(backchannelClientNotificationEndpoint) && backchannelAuthenticationRequestSigningAlg == null) { return true; } // Required parameter. if (backchannelTokenDeliveryMode == null || !appConfiguration.getBackchannelTokenDeliveryModesSupported().contains(backchannelTokenDeliveryMode.getValue())) { return false; } // Required if the token delivery mode is set to ping or push. if ((backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == PUSH) && Strings.isBlank(backchannelClientNotificationEndpoint)) { return false; } // Grant type urn:openid:params:grant-type:ciba is required if the token delivery mode is set to ping or poll. if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) { if (!appConfiguration.getGrantTypesSupported().contains(CIBA) || !grantTypes.contains(CIBA)) { return false; } } // If the server does not support backchannel_user_code_parameter_supported, the default value is false. if (appConfiguration.getBackchannelUserCodeParameterSupported() == null || appConfiguration.getBackchannelUserCodeParameterSupported() == false) { backchannelUserCodeParameter = false; } if (subjectType != null && subjectType == SubjectType.PAIRWISE) { if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) { if (Strings.isBlank(jwks) && Strings.isBlank(jwksUri)) { return false; } } if (Strings.isNotBlank(sectorIdentifierUri)) { ClientRequest clientRequest = new ClientRequest(sectorIdentifierUri); clientRequest.setHttpMethod(HttpMethod.GET); ClientResponse<String> clientResponse = clientRequest.get(String.class); int status = clientResponse.getStatus(); if (status != 200) { return false; } String entity = clientResponse.getEntity(String.class); JSONArray sectorIdentifierJsonArray = new JSONArray(entity); if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) { // If a sector_identifier_uri is explicitly provided, then the jwks_uri must be included in the list of // URIs pointed to by the sector_identifier_uri. if (!Strings.isBlank(jwksUri) && !Util.asList(sectorIdentifierJsonArray).contains(jwksUri)) { return false; } } else if (backchannelTokenDeliveryMode == PUSH) { // In case a sector_identifier_uri is explicitly provided, then the backchannel_client_notification_endpoint // must be included in the list of URIs pointed to by the sector_identifier_uri. if (!Util.asList(sectorIdentifierJsonArray).contains(backchannelClientNotificationEndpoint)) { return false; } } } } } catch (Exception e) { log.trace(e.getMessage(), e); return false; } return true; }
Example 15
Source File: PluginRegistry.java From logging-log4j2 with Apache License 2.0 | 4 votes |
/** * Load plugin types from a package. * @param pkg The package name. * @return A Map of the lists of plugin types organized by category. * @since 2.1 */ public Map<String, List<PluginType<?>>> loadFromPackage(final String pkg) { if (Strings.isBlank(pkg)) { // happens when splitting an empty string return Collections.emptyMap(); } Map<String, List<PluginType<?>>> existing = pluginsByCategoryByPackage.get(pkg); if (existing != null) { // already loaded this package return existing; } final long startTime = System.nanoTime(); final ResolverUtil resolver = new ResolverUtil(); final ClassLoader classLoader = LoaderUtil.getClassLoader(); if (classLoader != null) { resolver.setClassLoader(classLoader); } resolver.findInPackage(new PluginTest(), pkg); final Map<String, List<PluginType<?>>> newPluginsByCategory = new HashMap<>(); for (final Class<?> clazz : resolver.getClasses()) { final Plugin plugin = clazz.getAnnotation(Plugin.class); final String categoryLowerCase = plugin.category().toLowerCase(); List<PluginType<?>> list = newPluginsByCategory.get(categoryLowerCase); if (list == null) { newPluginsByCategory.put(categoryLowerCase, list = new ArrayList<>()); } final PluginEntry mainEntry = new PluginEntry(); final String mainElementName = plugin.elementType().equals( Plugin.EMPTY) ? plugin.name() : plugin.elementType(); mainEntry.setKey(plugin.name().toLowerCase()); mainEntry.setName(plugin.name()); mainEntry.setCategory(plugin.category()); mainEntry.setClassName(clazz.getName()); mainEntry.setPrintable(plugin.printObject()); mainEntry.setDefer(plugin.deferChildren()); final PluginType<?> mainType = new PluginType<>(mainEntry, clazz, mainElementName); list.add(mainType); final PluginAliases pluginAliases = clazz.getAnnotation(PluginAliases.class); if (pluginAliases != null) { for (final String alias : pluginAliases.value()) { final PluginEntry aliasEntry = new PluginEntry(); final String aliasElementName = plugin.elementType().equals( Plugin.EMPTY) ? alias.trim() : plugin.elementType(); aliasEntry.setKey(alias.trim().toLowerCase()); aliasEntry.setName(plugin.name()); aliasEntry.setCategory(plugin.category()); aliasEntry.setClassName(clazz.getName()); aliasEntry.setPrintable(plugin.printObject()); aliasEntry.setDefer(plugin.deferChildren()); final PluginType<?> aliasType = new PluginType<>(aliasEntry, clazz, aliasElementName); list.add(aliasType); } } } LOGGER.debug(() -> { final long endTime = System.nanoTime(); StringBuilder sb = new StringBuilder("Took "); final DecimalFormat numFormat = new DecimalFormat("#0.000000"); sb.append(numFormat.format((endTime - startTime) * 1e-9)); sb.append(" seconds to load ").append(resolver.getClasses().size()); sb.append(" plugins from package ").append(pkg); return sb.toString(); }); // Note multiple threads could be calling this method concurrently. Both will do the work, // but only one will be allowed to store the result in the outer map. // Return the inner map produced by whichever thread won the race, so all callers will get the same result. existing = pluginsByCategoryByPackage.putIfAbsent(pkg, newPluginsByCategory); if (existing != null) { return existing; } return newPluginsByCategory; }