Skip to content

Commit

Permalink
[EJBCLIENT-252] Fix bug where the peer endpoint might be anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Jul 28, 2017
1 parent b1a4c5d commit 9323574
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Expand Up @@ -383,7 +383,7 @@ private List<Throwable> doAnyDiscovery(AbstractInvocationContext context, final
}

context.setDestination(location);
context.setTargetAffinity(new NodeAffinity(nodeName));
if (nodeName != null) context.setTargetAffinity(new NodeAffinity(nodeName));
return problems;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jboss/ejb/client/EJBRootContext.java
Expand Up @@ -149,7 +149,7 @@ protected Object lookupNative(final Name name) throws NamingException {
} else {
proxy = EJBClient.createProxy(statelessLocator, authenticationConfiguration, sslContext);
}
EJBClient.putProxyAttachment(proxy, NAMING_PROVIDER_ATTACHMENT_KEY, namingProvider);
if (namingProvider != null) EJBClient.putProxyAttachment(proxy, NAMING_PROVIDER_ATTACHMENT_KEY, namingProvider);

// if "invocation.timeout" is set in environment properties, set this value to created proxy
Long invocationTimeout = getLongValueFromEnvironment(PROPERTY_KEY_INVOCATION_TIMEOUT);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jboss/ejb/client/NodeAffinity.java
Expand Up @@ -21,6 +21,8 @@
import java.net.URI;
import java.net.URISyntaxException;

import org.wildfly.common.Assert;

/**
* A single node affinity specification.
*
Expand All @@ -35,9 +37,10 @@ public final class NodeAffinity extends Affinity {
/**
* Construct a new instance.
*
* @param nodeName the associated node name
* @param nodeName the associated node name (must not be {@code null})
*/
public NodeAffinity(final String nodeName) {
Assert.checkNotNullParam("nodeName", nodeName);
this.nodeName = nodeName;
}

Expand Down
Expand Up @@ -36,8 +36,10 @@ final class ProtocolV3ObjectResolver implements ObjectResolver {
private final boolean preferUri;

ProtocolV3ObjectResolver(final Connection connection, final boolean preferUri) {
peerNodeAffinity = new NodeAffinity(connection.getRemoteEndpointName());
selfNodeAffinity = new NodeAffinity(connection.getEndpoint().getName());
final String remoteEndpointName = connection.getRemoteEndpointName();
peerNodeAffinity = remoteEndpointName == null ? null : new NodeAffinity(remoteEndpointName);
final String localEndpointName = connection.getEndpoint().getName();
selfNodeAffinity = localEndpointName == null ? null : new NodeAffinity(localEndpointName);
this.preferUri = preferUri;
final URI peerURI = connection.getPeerURI();
peerUriAffinity = peerURI == null ? null : (URIAffinity) Affinity.forUri(peerURI);
Expand All @@ -46,11 +48,11 @@ final class ProtocolV3ObjectResolver implements ObjectResolver {
public Object readResolve(final Object replacement) {
if (replacement == Affinity.LOCAL) {
// This shouldn't be possible. If it happens though, we will guess that it is the peer talking about itself
return preferUri && peerUriAffinity != null ? peerUriAffinity : peerNodeAffinity;
return preferUri && peerUriAffinity != null ? peerUriAffinity : peerNodeAffinity != null ? peerNodeAffinity : Affinity.NONE;
} else if (replacement instanceof NodeAffinity) {
if (replacement.equals(selfNodeAffinity)) {
if (selfNodeAffinity != null && replacement.equals(selfNodeAffinity)) {
return Affinity.LOCAL;
} else if (preferUri && peerUriAffinity != null && replacement.equals(peerNodeAffinity)) {
} else if (preferUri && peerUriAffinity != null && peerNodeAffinity != null && replacement.equals(peerNodeAffinity)) {
// the peer is talking about itself; use the more specific URI if we have one
return peerUriAffinity;
}
Expand All @@ -59,10 +61,10 @@ public Object readResolve(final Object replacement) {
}

public Object writeReplace(final Object original) {
if (original == Affinity.LOCAL) {
if (original == Affinity.LOCAL && selfNodeAffinity != null) {
// we don't know the peer's view URI of us, if there even is one, so switch it to node affinity and let the peer sort it out
return selfNodeAffinity;
} else if (peerUriAffinity != null && original instanceof URIAffinity && original.equals(peerUriAffinity)) {
} else if (peerUriAffinity != null && original instanceof URIAffinity && original.equals(peerUriAffinity) && peerNodeAffinity != null) {
// it's the peer node; the peer won't know its own URI though, so send its node affinity instead
return peerNodeAffinity;
}
Expand Down

0 comments on commit 9323574

Please sign in to comment.