From 0fc3e1e5e40fec0a16982b3be1a31093c00fa43d Mon Sep 17 00:00:00 2001 From: Tomasz Adamski Date: Mon, 13 Jan 2020 01:28:19 +0100 Subject: [PATCH] [EJBCLIENT-364] Standalone EJB-over-HTTP invocation --- .../java/org/jboss/ejb/_private/Logs.java | 8 ++ .../ejb/client/legacy/JBossEJBProperties.java | 91 +++++++++++++++++++ .../legacy/LegacyPropertiesConfiguration.java | 16 ++++ 3 files changed, 115 insertions(+) diff --git a/src/main/java/org/jboss/ejb/_private/Logs.java b/src/main/java/org/jboss/ejb/_private/Logs.java index 2f11d8551..c14c5136a 100644 --- a/src/main/java/org/jboss/ejb/_private/Logs.java +++ b/src/main/java/org/jboss/ejb/_private/Logs.java @@ -436,6 +436,14 @@ public interface Logs extends BasicLogger { @Message(id = 513, value = "Exception occurred when trying to close the transport provider") void exceptionDuringTransportProviderClose(@Cause Exception e); + @LogMessage(level = INFO) + @Message(id = 514, value = "No URI configured for HTTP connection named %s. Skipping connection creation") + void skippingHttpConnectionCreationDueToMissingUri(final String name); + + @LogMessage(level = INFO) + @Message(id = 515, value = "HTTP connection was configured with invalid URI: %s .") + void skippingHttpConnectionCreationDueToInvalidUri(final String uri); + // Remote messages; no ID for brevity but should be translated @Message(value = "No such EJB: %s") diff --git a/src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java b/src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java index fc8254308..248ccc506 100644 --- a/src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java +++ b/src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java @@ -113,6 +113,10 @@ public final class JBossEJBProperties implements Contextual private static final boolean expandPasswords; private static final String CONFIGURED_PATH_NAME; + private static final String PROPERTY_KEY_HTTP_CONNECTIONS = "http.connections"; + + private static final String PROPERTY_KEY_URI = "uri"; + static { expandPasswords = doPrivileged((PrivilegedAction) () -> Boolean.valueOf(System.getProperty("jboss-ejb-client.expandPasswords", "false"))).booleanValue(); @@ -176,6 +180,9 @@ public final class JBossEJBProperties implements Contextual private final String deploymentNodeSelectorClassName; private final boolean defaultConnectEagerly; + // HTTP connections + private final List httpConnectionList; + JBossEJBProperties(final Builder builder) { this.endpointName = builder.endpointName; this.defaultCallbackHandlerClassName = builder.callbackHandlerClassName; @@ -190,6 +197,7 @@ public final class JBossEJBProperties implements Contextual this.deploymentNodeSelectorClassName = builder.deploymentNodeSelectorClassName; this.connectionList = builder.connectionList; this.defaultConnectEagerly = builder.connectEagerly; + this.httpConnectionList = builder.httpConnectionList; } public String getEndpointName() { @@ -216,6 +224,10 @@ public List getConnectionList() { return connectionList; } + public List getHttpConnectionList() { + return httpConnectionList; + } + public ExceptionSupplier getDefaultCallbackHandlerSupplier() { return callbackHandlerSupplier; } @@ -399,6 +411,41 @@ public static JBossEJBProperties fromProperties(final String fileName, final Pro } builder.setClusterConfigurations(clusterMap); + //http-connections + final String httpConnectionsString = getProperty(properties, PROPERTY_KEY_HTTP_CONNECTIONS, "", true).trim(); + final List httpConnectionList; + + if (!httpConnectionsString.isEmpty()) { + final ArrayList mutableList = new ArrayList<>(); + + // Parse this the same way as the legacy code. + final StringTokenizer tokenizer = new StringTokenizer(httpConnectionsString, ","); + while (tokenizer.hasMoreTokens()) { + final String connectionName = tokenizer.nextToken().trim(); + if (!connectionName.isEmpty()) { + final HttpConnectionConfiguration.Builder connBuilder = new HttpConnectionConfiguration.Builder(); + + String prefix = "http.connection." + connectionName + "."; + + if (!connBuilder.populateFromProperties(properties, prefix, connectionName)) { + continue; + } + + mutableList.add(new HttpConnectionConfiguration(connBuilder)); + } + } + + if (mutableList.isEmpty()) { + httpConnectionList = Collections.emptyList(); + } else { + mutableList.trimToSize(); + httpConnectionList = Collections.unmodifiableList(mutableList); + } + } else { + httpConnectionList = Collections.emptyList(); + } + builder.setHttpConnectionList(httpConnectionList); + return new JBossEJBProperties(builder); } @@ -468,6 +515,7 @@ static final class Builder extends CommonSubconfiguration.Builder { OptionMap endpointCreationOptions; OptionMap remoteConnectionProviderCreationOptions; List connectionList; + List httpConnectionList; Map clusterConfigurations; long invocationTimeout; long reconnectTimeout; @@ -521,6 +569,11 @@ Builder setDeploymentNodeSelectorSupplier(final ExceptionSupplier httpConnectionList) { + this.httpConnectionList = httpConnectionList; + return this; + } } abstract static class CommonSubconfiguration { @@ -980,4 +1033,42 @@ boolean populateFromProperties(final Properties properties, final String prefix, } } } + + public static class HttpConnectionConfiguration { + + private final String uri; + + HttpConnectionConfiguration(Builder builder) { + this.uri = builder.uri; + } + + public String getUri() { + return uri; + } + + static final class Builder { + String uri; + + Builder() { + } + + boolean populateFromProperties(final Properties properties, final String prefix, final String connectionName) { + + // connection host name + String uri = getProperty(properties, prefix + PROPERTY_KEY_URI, "", true).trim(); + if (uri.isEmpty()) { + Logs.MAIN.skippingHttpConnectionCreationDueToMissingUri(connectionName); + return false; + } + setUri(uri); + return true; + } + + Builder setUri(final String uri) { + this.uri = uri; + return this; + } + + } + } } diff --git a/src/main/java/org/jboss/ejb/client/legacy/LegacyPropertiesConfiguration.java b/src/main/java/org/jboss/ejb/client/legacy/LegacyPropertiesConfiguration.java index 88858af6d..8be8b9828 100644 --- a/src/main/java/org/jboss/ejb/client/legacy/LegacyPropertiesConfiguration.java +++ b/src/main/java/org/jboss/ejb/client/legacy/LegacyPropertiesConfiguration.java @@ -19,6 +19,7 @@ package org.jboss.ejb.client.legacy; import java.net.URI; +import java.net.URISyntaxException; import java.util.List; import java.util.Map; import java.util.Properties; @@ -63,6 +64,21 @@ public static void configure(final EJBClientContext.Builder builder) { builder.addClientConnection(connectionBuilder.build()); } + final List httpConnectionList = properties.getHttpConnectionList(); + for (JBossEJBProperties.HttpConnectionConfiguration httpConnection : httpConnectionList) { + final String uriString = httpConnection.getUri(); + final URI uri; + try { + uri = new URI(uriString); + } catch (URISyntaxException e) { + Logs.MAIN.skippingHttpConnectionCreationDueToInvalidUri(uriString); + continue; + } + final EJBClientConnection.Builder connectionBuilder = new EJBClientConnection.Builder(); + connectionBuilder.setDestination(uri); + builder.addClientConnection(connectionBuilder.build()); + } + final ExceptionSupplier deploymentNodeSelectorSupplier = properties.getDeploymentNodeSelectorSupplier(); if (deploymentNodeSelectorSupplier != null) { final DeploymentNodeSelector deploymentNodeSelector;