public static <T> JBossEJBProperties fromResource(final String fileName, final ExceptionFunction<T, InputStream, IOException> streamSupplier, T param) throws IOException { return fromResource(fileName, ExceptionFunction::apply, streamSupplier, param); }
private static long getLongValueFromProperties(final Properties properties, final String propertyName, final long defVal) { final String str = getProperty(properties, propertyName, null, true); if (str == null) { return defVal; } try { return Long.parseLong(str); } catch (NumberFormatException e) { return defVal; } }
public static JBossEJBProperties fromClassPath() throws IOException { return fromClassPath(JBossEJBProperties.class.getClassLoader(), DEFAULT_PATH_NAME); }
final Builder builder = new Builder(); builder.populateFromProperties(properties, "", classLoader, null); builder.setEndpointName(getProperty(properties, PROPERTY_KEY_ENDPOINT_NAME, null, true)); final String defaultCallbackHandlerClassName = getProperty(properties, PROPERTY_KEY_CALLBACK_HANDLER_CLASS, null, true); builder.setCallbackHandlerClassName(defaultCallbackHandlerClassName); builder.setCallbackHandlerSupplier(() -> Class.forName(defaultCallbackHandlerClassName, true, classLoader).asSubclass(CallbackHandler.class).getConstructor().newInstance()); builder.setEndpointCreationOptions(getOptionMapFromProperties(properties, ENDPOINT_CREATION_OPTIONS_PREFIX, classLoader)); builder.setRemoteConnectionProviderCreationOptions(getOptionMapFromProperties(properties, REMOTE_CONNECTION_PROVIDER_CREATE_OPTIONS_PREFIX, classLoader)); builder.setInvocationTimeout(getLongValueFromProperties(properties, PROPERTY_KEY_INVOCATION_TIMEOUT, -1L)); builder.setReconnectTimeout(getLongValueFromProperties(properties, PROPERTY_KEY_RECONNECT_TASKS_TIMEOUT, -1L)); final String deploymentNodeSelectorClassName = getProperty(properties, PROPERTY_KEY_DEPLOYMENT_NODE_SELECTOR, null, true); if (deploymentNodeSelectorClassName != null) { builder.setDeploymentNodeSelectorClassName(deploymentNodeSelectorClassName); builder.setDeploymentNodeSelectorSupplier(() -> Class.forName(deploymentNodeSelectorClassName, true, classLoader).asSubclass(DeploymentNodeSelector.class).getConstructor().newInstance()); final String connectionsString = getProperty(properties, PROPERTY_KEY_REMOTE_CONNECTIONS, "", true).trim(); final List<ConnectionConfiguration> connectionList;
public static void configure(final EJBClientContext.Builder builder) { final JBossEJBProperties properties = JBossEJBProperties.getCurrent(); if (properties != null) { Logs.MAIN.legacyEJBPropertiesEJBConfigurationInUse(); final List<JBossEJBProperties.ConnectionConfiguration> connectionList = properties.getConnectionList(); for (JBossEJBProperties.ConnectionConfiguration connectionConfiguration : connectionList) { final String host = connectionConfiguration.getHost(); if (host == null) { continue; final int port = connectionConfiguration.getPort(); if (port == -1) { continue; final OptionMap connectionOptions = connectionConfiguration.getConnectionOptions(); final URI uri = CommonLegacyConfiguration.getUri(connectionConfiguration, connectionOptions); if (uri == null) { continue; final ExceptionSupplier<DeploymentNodeSelector, ReflectiveOperationException> deploymentNodeSelectorSupplier = properties.getDeploymentNodeSelectorSupplier(); if (deploymentNodeSelectorSupplier != null) { final DeploymentNodeSelector deploymentNodeSelector; deploymentNodeSelector = deploymentNodeSelectorSupplier.get(); } catch (ReflectiveOperationException e) { throw Logs.MAIN.cannotInstantiateDeploymentNodeSelector(properties.getDeploymentNodeSelectorClassName(), e); Map<String, JBossEJBProperties.ClusterConfiguration> clusters = properties.getClusterConfigurations(); if (clusters != null) {
boolean populateFromProperties(final String clusterName, final Properties properties, final String prefix, final ClassLoader classLoader, final CommonSubconfiguration.Builder defaultsBuilder) { if (! super.populateFromProperties(properties, prefix, classLoader, defaultsBuilder)) { return false; return false; setClusterName(clusterName); setMaximumAllowedConnectedNodes(getLongValueFromProperties(properties, prefix + "max-allowed-connected-nodes", 1000L)); final String clusterNodeSelectorClassName = getProperty(properties, prefix + "clusternode.selector", null, true); if (clusterNodeSelectorClassName != null) { setClusterNodeSelectorClassName(clusterNodeSelectorClassName); setClusterNodeSelectorSupplier(() -> Class.forName(clusterNodeSelectorClassName, true, classLoader).asSubclass(ClusterNodeSelector.class).getConstructor().newInstance() ); final ClusterNodeConfiguration.Builder builder = new ClusterNodeConfiguration.Builder(); builder.setNodeName(nodeName); if (builder.populateFromProperties(properties, nodePrefix + nodeName + ".", classLoader, this)) { nodes.add(new ClusterNodeConfiguration(builder)); setNodeConfigurations(nodes); return true;
boolean populateFromProperties(final Properties properties, final String prefix, final ClassLoader classLoader, final Builder defaultsBuilder) { // connection options String connectOptionsPrefix = prefix + "connect.options" + "."; setConnectionOptions(getOptionMapFromProperties(properties, connectOptionsPrefix, classLoader)); // connection timeout setConnectionTimeout(getLongValueFromProperties(properties, prefix + "connect.timeout", defaultsBuilder == null ? 5000L : defaultsBuilder.connectionTimeout)); // connect eagerly setConnectEagerly(Boolean.parseBoolean(getProperty(properties, prefix + "connect.eager", Boolean.toString(defaultsBuilder == null || defaultsBuilder.connectEagerly), true).trim())); // callback handler class final String callbackHandlerClassName = getProperty(properties, prefix + PROPERTY_KEY_CALLBACK_HANDLER_CLASS, null, true); setCallbackHandlerClassName(callbackHandlerClassName); final AuthenticationConfiguration.Builder authBuilder = new AuthenticationConfiguration.Builder(); if (authBuilder.populateFromProperties(properties, prefix, classLoader)) { setAuthenticationConfiguration(new AuthenticationConfiguration(authBuilder)); } else { if (defaultsBuilder != null) { setAuthenticationConfiguration(defaultsBuilder.authenticationConfiguration); } } setChannelOptions(getOptionMapFromProperties(properties, prefix + "channel.options" + ".", classLoader)); final ExceptionSupplier<CallbackHandler, ReflectiveOperationException> callbackHandlerSupplier = () -> Class.forName(callbackHandlerClassName, true, classLoader).asSubclass(CallbackHandler.class).getConstructor().newInstance(); return true; }
final JBossEJBProperties properties = JBossEJBProperties.getCurrent(); for (JBossEJBProperties.ConnectionConfiguration configuration : properties.getConnectionList()) { final String host = configuration.getHost(); if (host == null) { final int port = configuration.getPort(); if (port != -1) { rule = rule.matchPort(port); config = configureCommon(properties, configuration, config); for (Map.Entry<String, JBossEJBProperties.ClusterConfiguration> entry : properties.getClusterConfigurations().entrySet()) { final String clusterName = entry.getKey(); final JBossEJBProperties.ClusterConfiguration configuration = entry.getValue(); defaultRule = defaultRule.matchUrnName(clusterName); defaultConfig = configureCommon(properties, configuration, defaultConfig); final List<JBossEJBProperties.ClusterNodeConfiguration> nodeConfigurations = configuration.getNodeConfigurations(); if (nodeConfigurations != null) { for (JBossEJBProperties.ClusterNodeConfiguration nodeConfiguration : nodeConfigurations) { rule = rule.matchUrnName(nodeConfiguration.getNodeName()); config = configureCommon(properties, nodeConfiguration, config);
private static AuthenticationConfiguration configureCommon(final JBossEJBProperties properties, final JBossEJBProperties.CommonSubconfiguration configuration, AuthenticationConfiguration config) { final JBossEJBProperties.AuthenticationConfiguration authenticationConfiguration = configuration.getAuthenticationConfiguration(); final String userName = authenticationConfiguration == null ? null : authenticationConfiguration.getUserName(); if (userName != null) config = config.useName(userName); final String realm = authenticationConfiguration == null ? null : authenticationConfiguration.getMechanismRealm(); if (realm != null) config = config.useRealm(realm); final ExceptionSupplier<CallbackHandler, ReflectiveOperationException> callbackHandlerSupplier = authenticationConfiguration == null ? null : authenticationConfiguration.getCallbackHandlerSupplier(); CallbackHandler callbackHandler = null; if (callbackHandlerSupplier != null) { callbackHandler = callbackHandlerSupplier.get(); } catch (ReflectiveOperationException e) { throw Logs.MAIN.cannotInstantiateCallbackHandler(properties.getDefaultCallbackHandlerClassName(), e); final String password = authenticationConfiguration == null ? null : authenticationConfiguration.getPassword(); if (password != null) config = config.usePassword(password); OptionMap options = configuration.getConnectionOptions(); if (useQuietAuth != null) { options = setQuietLocalAuth(options, Boolean.valueOf(useQuietAuth).booleanValue()); } else if (callbackHandler != null || userName != null) { options = setQuietLocalAuth(options, false);
public Endpoint getConfiguredEndpoint() { final JBossEJBProperties properties = JBossEJBProperties.getCurrent(); final String endpointName = properties.getEndpointName(); if (endpointName != null) { endpointBuilder.setEndpointName(endpointName); OptionMap endpointCreationOptions = properties.getEndpointCreationOptions(); if (endpointCreationOptions != null && endpointCreationOptions.size() > 0) { if (! endpointCreationOptions.contains(Options.THREAD_DAEMON)) { throw Logs.MAIN.failedToConstructEndpoint(e); final List<JBossEJBProperties.ConnectionConfiguration> connectionList = properties.getConnectionList(); for (JBossEJBProperties.ConnectionConfiguration connectionConfiguration : connectionList) { final OptionMap connectionOptions = connectionConfiguration.getConnectionOptions(); final URI uri = CommonLegacyConfiguration.getUri(connectionConfiguration, connectionOptions); if (uri == null) { continue; if (connectionConfiguration.isConnectEagerly()) { endpoint.getConnection(uri, "ejb", "jboss");
public void configure(final Consumer<DiscoveryProvider> discoveryProviderConsumer, final Consumer<RegistryProvider> registryProviderConsumer) { final JBossEJBProperties ejbProperties = JBossEJBProperties.getCurrent(); if (ejbProperties == null) { return; for (Map.Entry<String, JBossEJBProperties.ClusterConfiguration> entry : ejbProperties.getClusterConfigurations().entrySet()) { final String clusterName = entry.getKey(); final JBossEJBProperties.ClusterConfiguration configuration = entry.getValue(); for (JBossEJBProperties.ClusterNodeConfiguration nodeConfiguration : configuration.getNodeConfigurations()) { final String nodeName = nodeConfiguration.getNodeName();
boolean populateFromProperties(final Properties properties, final String prefix, final ClassLoader classLoader, final CommonSubconfiguration.Builder defaultsBuilder, final String connectionName) { super.populateFromProperties(properties, prefix, classLoader, defaultsBuilder); // connection host name String host = getProperty(properties,prefix + PROPERTY_KEY_HOST, "", true).trim(); if (host.isEmpty()) { Logs.MAIN.skippingConnectionCreationDueToMissingHostOrPort(connectionName); return false; } setHost(host); // connection port# String portStr = getProperty(properties,prefix + PROPERTY_KEY_PORT, "", true).trim(); if (portStr.isEmpty()) { Logs.MAIN.skippingConnectionCreationDueToMissingHostOrPort(connectionName); return false; } int port; try { port = Integer.parseInt(portStr); } catch (NumberFormatException e) { Logs.MAIN.skippingConnectionCreationDueToInvalidPortNumber(portStr, connectionName); return false; } setPort(port); String protocol = getProperty(properties, prefix + PROPERTY_KEY_PROTOCOL, DEFAULT_PROTOCOL, true).trim(); this.protocol = protocol; return true; }
static URI getUri(final JBossEJBProperties.ConnectionConfiguration connectionConfiguration, final OptionMap connectionOptions) { final String host = connectionConfiguration.getHost(); if (host == null) { return null; } final int port = connectionConfiguration.getPort(); if (port == -1) { return null; } final String scheme; final String protocol = connectionConfiguration.getProtocol(); if (protocol == null) { if (connectionOptions.get(Options.SECURE, false) && connectionOptions.get(Options.SSL_ENABLED, false)) { scheme = "remote+https"; } else { scheme = "remote+http"; } } else { scheme = protocol; } try { return new URI(scheme, null, NetworkUtil.formatPossibleIpv6Address(host), port, null, null, null); } catch (URISyntaxException e) { return null; } } }
/** * Get the context manager. * * @return the context manager (not {@code null}) */ @NotNull public ContextManager<JBossEJBProperties> getInstanceContextManager() { return getContextManager(); }
private static JBossEJBProperties fromResource(String fileName, InputStream stream) throws IOException { try (InputStream inputStream = stream) { try (BufferedInputStream bis = new BufferedInputStream(inputStream)) { try (InputStreamReader reader = new InputStreamReader(bis, StandardCharsets.UTF_8)) { final Properties properties = new Properties(); properties.load(reader); return fromProperties(fileName, properties); } } } }
public static JBossEJBProperties fromResource(final String fileName, final ExceptionSupplier<InputStream, IOException> streamSupplier) throws IOException { return fromResource(fileName, ExceptionSupplier::get, streamSupplier); }
public static JBossEJBProperties fromClassPath(final ClassLoader classLoader, final String pathName) throws IOException { if (classLoader == null) { return fromResource(pathName, ClassLoader.getSystemResourceAsStream(pathName)); } return fromResource(pathName, ClassLoader::getResourceAsStream, classLoader, pathName); }
public static JBossEJBProperties fromPath(final Path propertiesFile) throws IOException { Assert.checkNotNullParam("propertiesFile", propertiesFile); return fromResource(propertiesFile.toString(), Files::newInputStream, propertiesFile); }
public static JBossEJBProperties fromFile(final File propertiesFile) throws IOException { Assert.checkNotNullParam("propertiesFile", propertiesFile); return fromResource(propertiesFile.getPath(), FileInputStream::new, propertiesFile); }
public static <T, U> JBossEJBProperties fromResource(final String fileName, final ExceptionBiFunction<T, U, InputStream, IOException> streamSupplier, T param1, U param2) throws IOException { Assert.checkNotNullParam("fileName", fileName); Assert.checkNotNullParam("streamSupplier", streamSupplier); final InputStream stream; try { stream = streamSupplier.apply(param1, param2); } catch (FileNotFoundException | NoSuchFileException e) { return null; } if (stream == null) { return null; } return fromResource(fileName, stream); }