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

Allowing JavaEE <-> JakartaEE interoperability scenarios #543

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions javax/src/main/java/org/jboss/ejb/_private/Logs.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,9 @@ public interface Logs extends BasicLogger {

@Message(value = "Context data under org.jboss.private.data was not of type Set<String>")
IllegalStateException returnedContextDataKeyOfWrongType();

@LogMessage(level = DEBUG)
@Message(id = 524, value = "JavaEE to JakartaEE backward compatibility layer have been installed")
void javaeeToJakartaeeBackwardCompatibilityLayerInstalled();

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.jboss.ejb.client.UserTransactionID;
import org.jboss.ejb.client.XidTransactionID;
import org.jboss.marshalling.ByteInput;
import org.jboss.marshalling.ClassNameTransformer;
import org.jboss.marshalling.Marshaller;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
Expand Down Expand Up @@ -162,6 +163,12 @@ class EJBClientChannel {
configuration.setVersion(4);
// server does not present v3 unless the transaction service is also present
}
if (version < Protocol.JAKARTAEE_PROTOCOL_VERSION && Protocol.LATEST_VERSION >= Protocol.JAKARTAEE_PROTOCOL_VERSION) {
// EJB client uses EJB PROTOCOL version 4 or above but EJB server uses EJB PROTOCOL version 3 or below
// so in this case we need to translate classes from JavaEE API to JakartaEE API and vice versa
configuration.setClassNameTransformer(ClassNameTransformer.JAVAEE_TO_JAKARTAEE);
Logs.REMOTING.javaeeToJakartaeeBackwardCompatibilityLayerInstalled();
}
ropalka marked this conversation as resolved.
Show resolved Hide resolved
transactionContext = RemoteTransactionContext.getInstance();
this.configuration = configuration;
invocationTracker = new InvocationTracker(this.channel, channel.getOption(RemotingOptions.MAX_OUTBOUND_MESSAGES).intValue(), EJBClientChannel::mask);
Expand Down Expand Up @@ -719,7 +726,7 @@ public void handleMessage(final Channel channel, final MessageInputStream messag
final ClassLoader oldCL = getAndSetSafeTCCL();
// receive message body
try {
final int version = min(3, StreamUtils.readInt8(message));
final int version = min(Protocol.LATEST_VERSION, StreamUtils.readInt8(message));
// drain the rest of the message because it's just garbage really
while (message.read() != -1) {
message.skip(Long.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.jboss.ejb.server.Request;
import org.jboss.ejb.server.SessionOpenRequest;
import org.jboss.marshalling.AbstractClassResolver;
import org.jboss.marshalling.ClassNameTransformer;
import org.jboss.marshalling.Marshaller;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
Expand Down Expand Up @@ -138,6 +139,12 @@ final class EJBServerChannel {
configuration.setObjectResolver(new ProtocolV3ObjectResolver(channel.getConnection(), true));
configuration.setVersion(4);
}
if (version < Protocol.JAKARTAEE_PROTOCOL_VERSION && Protocol.LATEST_VERSION >= Protocol.JAKARTAEE_PROTOCOL_VERSION) {
// EJB server uses EJB PROTOCOL version 4 or above but EJB client uses EJB PROTOCOL version 3 or below
// so in this case we need to translate classes from JavaEE API to JakartaEE API and vice versa
configuration.setClassNameTransformer(ClassNameTransformer.JAVAEE_TO_JAKARTAEE);
ropalka marked this conversation as resolved.
Show resolved Hide resolved
Logs.REMOTING.javaeeToJakartaeeBackwardCompatibilityLayerInstalled();
}
marshallerFactory = new RiverMarshallerFactory();
this.configuration = configuration;
this.classResolverFilter = classResolverFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
*/
final class Protocol {

public static final int LATEST_VERSION = 3;
static final int JAVAEE_PROTOCOL_VERSION = 3;
static final int JAKARTAEE_PROTOCOL_VERSION = 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really would like to validate if this is necessary or if a simple attribute in the remote outbound connection could be used to indicate the need for transformation without an upgrade in the protocol version

Copy link
Contributor Author

@ropalka ropalka Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is really necessary. Otherwise Jakarta EE side wouldn't know if communicating oposite side runs in Java EE or in Jakarta EE environment @fl4via .

// Batavia transformer sensible constant - it can start with either "javax." or "jakarta." if transformation was performed
private static final String VARIABLE_CONSTANT = "javax.ejb.FAKE_STRING";
public static final int LATEST_VERSION = VARIABLE_CONSTANT.startsWith("jakarta") ? JAKARTAEE_PROTOCOL_VERSION : JAVAEE_PROTOCOL_VERSION;

// flags field (v3 and up)
public static final int COMPRESS_RESPONSE = 0b0000_1111;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void handleMessage(final Channel channel, final MessageInputStream messag
try {
final int version;
try {
version = min(3, StreamUtils.readInt8(message));
version = min(Protocol.LATEST_VERSION, StreamUtils.readInt8(message));
// drain the rest of the message because it's just garbage really
while (message.read() != -1) {
message.skip(Long.MAX_VALUE);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<!-- 2.1.x also work on JDK9-->
<version.org.jboss.logging.jboss-logging-tools>2.1.0.Final</version.org.jboss.logging.jboss-logging-tools>
<version.org.jboss.logmanager>2.1.10.Final</version.org.jboss.logmanager>
<version.org.jboss.marshalling>2.0.6.Final</version.org.jboss.marshalling>
<version.org.jboss.marshalling>2.1.0.Final</version.org.jboss.marshalling>
<version.org.jboss.modules>1.6.0.Final</version.org.jboss.modules>
<version.org.jboss.narayana>5.12.4.Final</version.org.jboss.narayana>
<version.org.jboss.remoting>5.0.23.Final</version.org.jboss.remoting>
Expand Down