You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2020/10/26 15:15:10 UTC
[tomee] branch master updated: TOMEE-2913 attempt to resolve
message destination in other modules in an EAR
This is an automated email from the ASF dual-hosted git repository.
jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/master by this push:
new 4e39eae TOMEE-2913 attempt to resolve message destination in other modules in an EAR
new e483450 Merge remote-tracking branch 'apache/master'
4e39eae is described below
commit 4e39eae3b0ff450459bfccf42f9ef5f9b81a8bbc
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Mon Oct 26 15:12:05 2020 +0000
TOMEE-2913 attempt to resolve message destination in other modules in an EAR
---
.../java/org/apache/openejb/config/AutoConfig.java | 28 ++++-
.../openejb/config/MessageDestinationTest.java | 121 +++++++++++++++++++++
2 files changed, 144 insertions(+), 5 deletions(-)
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java b/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
index 00be44a..32aef85 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
@@ -584,7 +584,7 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
for (final MessageDestinationRef ref : bean.getMessageDestinationRef()) {
// skip destination refs with a resource link already assigned
if (ref.getMappedName() == null && ejbDeployment.getResourceLink(ref.getName()) == null) {
- final String destinationId = resolveDestinationId(ref, moduleUri, destinationResolver, destinationTypes);
+ final String destinationId = resolveDestinationId(ref, appModule, moduleUri, destinationResolver, destinationTypes);
if (destinationId != null) {
// build the link and add it
final ResourceLink resourceLink = new ResourceLink();
@@ -601,7 +601,7 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
for (final ClientModule clientModule : appModule.getClientModules()) {
final URI moduleUri = clientModule.getModuleUri();
for (final MessageDestinationRef ref : clientModule.getApplicationClient().getMessageDestinationRef()) {
- final String destinationId = resolveDestinationId(ref, moduleUri, destinationResolver, destinationTypes);
+ final String destinationId = resolveDestinationId(ref, appModule, moduleUri, destinationResolver, destinationTypes);
if (destinationId != null) {
// for client modules we put the destinationId in the mapped name
ref.setMappedName(destinationId);
@@ -612,7 +612,7 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
for (final WebModule webModule : appModule.getWebModules()) {
final URI moduleUri = URLs.uri(webModule.getModuleId());
for (final MessageDestinationRef ref : webModule.getWebApp().getMessageDestinationRef()) {
- final String destinationId = resolveDestinationId(ref, moduleUri, destinationResolver, destinationTypes);
+ final String destinationId = resolveDestinationId(ref, appModule, moduleUri, destinationResolver, destinationTypes);
if (destinationId != null) {
// for web modules we put the destinationId in the mapped name
ref.setMappedName(destinationId);
@@ -706,7 +706,7 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
}
private String resolveDestinationId(final MessageDestinationRef ref,
- final URI moduleUri,
+ AppModule appModule, final URI moduleUri,
final LinkResolver<MessageDestination> destinationResolver,
final Map<MessageDestination, String> destinationTypes) throws OpenEJBException {
// skip destination refs without a destination link
@@ -716,7 +716,25 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
}
// resolve the destination... if we don't find one it is a configuration bug
- final MessageDestination destination = destinationResolver.resolveLink(link, moduleUri);
+ MessageDestination destination = destinationResolver.resolveLink(link, moduleUri);
+
+ if (destination == null && link.contains("#")) {
+ // try the app module URI + "/" + link instead
+
+ final List<EjbModule> ejbModules = appModule.getEjbModules();
+ for (final EjbModule ejbModule : ejbModules) {
+ final String shortModuleName = link.substring(0, link.indexOf("#"));
+ if (ejbModule.getModuleUri().toString().endsWith(shortModuleName)) {
+ final String appModuleLink = ejbModule.getModuleUri() + "#" + link.substring(link.indexOf("#") + 1);
+ destination = destinationResolver.resolveLink(appModuleLink, moduleUri);
+
+ if (destination != null) {
+ break;
+ }
+ }
+ }
+ }
+
if (destination == null) {
throw new OpenEJBException("Message destination " + link + " for message-destination-ref " + ref.getMessageDestinationRefName() + " not found");
}
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/config/MessageDestinationTest.java b/container/openejb-core/src/test/java/org/apache/openejb/config/MessageDestinationTest.java
new file mode 100644
index 0000000..eb9429b
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/config/MessageDestinationTest.java
@@ -0,0 +1,121 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import junit.framework.TestCase;
+import org.apache.openejb.OpenEJB;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.ResourceEnvReferenceInfo;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.core.LocalInitialContextFactory;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.MessageDestination;
+import org.apache.openejb.jee.MessageDestinationRef;
+import org.apache.openejb.jee.MessageDestinationUsage;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.junit.AfterClass;
+import org.junit.Assert;
+
+import javax.jms.Queue;
+import javax.naming.NamingException;
+import java.util.List;
+
+public class MessageDestinationTest extends TestCase {
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ OpenEJB.destroy();
+ }
+
+ public void test() throws Exception {
+ System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
+
+ final ConfigurationFactory config = new ConfigurationFactory();
+ final Assembler assembler = new Assembler();
+
+ assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+ assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+ final ClassLoader cl = this.getClass().getClassLoader();
+ final AppModule app = new AppModule(cl, "app");
+
+ final MessageDestinationRef webMessageDestRef = new MessageDestinationRef();
+ webMessageDestRef.setMessageDestinationRefName("jms/myqueue");
+ webMessageDestRef.setMessageDestinationType("javax.jms.Queue");
+ webMessageDestRef.setMessageDestinationUsage(MessageDestinationUsage.PRODUCES);
+ webMessageDestRef.setMessageDestinationLink("ejb.jar#myqueue");
+
+ final WebApp webApp = new WebApp();
+ webApp.setMetadataComplete(true);
+ webApp.getMessageDestinationRef().add(webMessageDestRef);
+ final WebModule webModule = new WebModule(webApp, "web", cl, "war", "web");
+
+ app.getWebModules().add(webModule);
+
+ final EjbJar ejbJar = new EjbJar();
+ final StatelessBean statelessBean = new StatelessBean(GreenBean.class);
+ final MessageDestinationRef ejbMessageDestRef = new MessageDestinationRef();
+ ejbMessageDestRef.setMessageDestinationRefName("jms/myqueue");
+ ejbMessageDestRef.setMessageDestinationType("javax.jms.Queue");
+ ejbMessageDestRef.setMessageDestinationUsage(MessageDestinationUsage.PRODUCES);
+ ejbMessageDestRef.setMessageDestinationLink("myqueue");
+
+ statelessBean.getMessageDestinationRef().add(ejbMessageDestRef);
+ ejbJar.addEnterpriseBean(statelessBean);
+
+ final MessageDestination queue = new MessageDestination();
+ queue.setMessageDestinationName("myqueue");
+ ejbJar.getAssemblyDescriptor().getMessageDestination().add(queue);
+
+ final EjbModule ejbModule = new EjbModule(cl, "ejb.jar", ejbJar, new OpenejbJar());
+ app.getEjbModules().add(ejbModule);
+
+
+ final AppInfo info = config.configureApplication(app);
+ assembler.createApplication(info);
+
+ final Object beanQueue = assembler.getContainerSystem().getBeanContext("GreenBean").getJndiContext().lookup("comp/env/jms/myqueue");
+ Assert.assertTrue(beanQueue instanceof Queue);
+
+ Assert.assertEquals(1, info.webApps.size());
+ final List<ResourceEnvReferenceInfo> resourceEnvRefs = info.webApps.get(0).jndiEnc.resourceEnvRefs;
+
+ boolean found = false;
+ for (final ResourceEnvReferenceInfo resourceEnvRef : resourceEnvRefs) {
+ if (! "comp/env/jms/myqueue".equals(resourceEnvRef.referenceName)) continue;
+
+ found = true;
+ Assert.assertEquals("jms/myqueue", resourceEnvRef.resourceID);
+ Assert.assertEquals("javax.jms.Queue", resourceEnvRef.resourceEnvRefType);
+ }
+
+ Assert.assertTrue(found);
+ }
+
+ public static interface Color {
+ public void test() throws NamingException;
+ }
+
+ public static class GreenBean implements Color {
+ public void test() throws NamingException {
+ }
+ }
+}