Skip to content

Commit

Permalink
Merge pull request #446 from tadamski/EJBCLIENT-364
Browse files Browse the repository at this point in the history
[EJBCLIENT-364] Standalone EJB-over-HTTP invocation
  • Loading branch information
tadamski authored Jan 13, 2020
2 parents a9e94e1 + 0fc3e1e commit 1d41329
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/jboss/ejb/_private/Logs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public final class JBossEJBProperties implements Contextual<JBossEJBProperties>
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>) () ->
Boolean.valueOf(System.getProperty("jboss-ejb-client.expandPasswords", "false"))).booleanValue();
Expand Down Expand Up @@ -176,6 +180,9 @@ public final class JBossEJBProperties implements Contextual<JBossEJBProperties>
private final String deploymentNodeSelectorClassName;
private final boolean defaultConnectEagerly;

// HTTP connections
private final List<HttpConnectionConfiguration> httpConnectionList;

JBossEJBProperties(final Builder builder) {
this.endpointName = builder.endpointName;
this.defaultCallbackHandlerClassName = builder.callbackHandlerClassName;
Expand All @@ -190,6 +197,7 @@ public final class JBossEJBProperties implements Contextual<JBossEJBProperties>
this.deploymentNodeSelectorClassName = builder.deploymentNodeSelectorClassName;
this.connectionList = builder.connectionList;
this.defaultConnectEagerly = builder.connectEagerly;
this.httpConnectionList = builder.httpConnectionList;
}

public String getEndpointName() {
Expand All @@ -216,6 +224,10 @@ public List<ConnectionConfiguration> getConnectionList() {
return connectionList;
}

public List<HttpConnectionConfiguration> getHttpConnectionList() {
return httpConnectionList;
}

public ExceptionSupplier<CallbackHandler, ReflectiveOperationException> getDefaultCallbackHandlerSupplier() {
return callbackHandlerSupplier;
}
Expand Down Expand Up @@ -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<HttpConnectionConfiguration> httpConnectionList;

if (!httpConnectionsString.isEmpty()) {
final ArrayList<HttpConnectionConfiguration> 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);
}

Expand Down Expand Up @@ -468,6 +515,7 @@ static final class Builder extends CommonSubconfiguration.Builder {
OptionMap endpointCreationOptions;
OptionMap remoteConnectionProviderCreationOptions;
List<ConnectionConfiguration> connectionList;
List<HttpConnectionConfiguration> httpConnectionList;
Map<String, ClusterConfiguration> clusterConfigurations;
long invocationTimeout;
long reconnectTimeout;
Expand Down Expand Up @@ -521,6 +569,11 @@ Builder setDeploymentNodeSelectorSupplier(final ExceptionSupplier<DeploymentNode
this.deploymentNodeSelectorSupplier = deploymentNodeSelectorSupplier;
return this;
}

Builder setHttpConnectionList(final List<HttpConnectionConfiguration> httpConnectionList) {
this.httpConnectionList = httpConnectionList;
return this;
}
}

abstract static class CommonSubconfiguration {
Expand Down Expand Up @@ -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;
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +64,21 @@ public static void configure(final EJBClientContext.Builder builder) {
builder.addClientConnection(connectionBuilder.build());
}

final List<JBossEJBProperties.HttpConnectionConfiguration> 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<DeploymentNodeSelector, ReflectiveOperationException> deploymentNodeSelectorSupplier = properties.getDeploymentNodeSelectorSupplier();
if (deploymentNodeSelectorSupplier != null) {
final DeploymentNodeSelector deploymentNodeSelector;
Expand Down

0 comments on commit 1d41329

Please sign in to comment.