Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EJBCLIENT-364] Standalone EJB-over-HTTP invocation #446

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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")
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
@@ -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();
@@ -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;
@@ -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() {
@@ -216,6 +224,10 @@ public List<ConnectionConfiguration> getConnectionList() {
return connectionList;
}

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

public ExceptionSupplier<CallbackHandler, ReflectiveOperationException> 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<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);
}

@@ -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;
@@ -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 {
@@ -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
@@ -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<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;