diff --git a/ejb3/src/main/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenComponent.java b/ejb3/src/main/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenComponent.java index 2e06f5514ae8..1dad0b4954c6 100644 --- a/ejb3/src/main/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenComponent.java +++ b/ejb3/src/main/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenComponent.java @@ -118,7 +118,7 @@ public void resume() { * @param ejbComponentCreateService the component configuration * @param deliveryActive true if the component must start delivering messages as soon as it is started */ - protected MessageDrivenComponent(final MessageDrivenComponentCreateService ejbComponentCreateService, final Class messageListenerInterface, final ActivationSpec activationSpec, final boolean deliveryActive, final ServiceName deliveryControllerName) { + protected MessageDrivenComponent(final MessageDrivenComponentCreateService ejbComponentCreateService, final Class messageListenerInterface, final ActivationSpec activationSpec, final boolean deliveryActive, final ServiceName deliveryControllerName, final String activeResourceAdapterName) { super(ejbComponentCreateService); StatelessObjectFactory factory = new StatelessObjectFactory() { @@ -145,6 +145,7 @@ public void destroy(MessageDrivenComponentInstance obj) { this.classLoader = ejbComponentCreateService.getModuleClassLoader(); this.suspendController = ejbComponentCreateService.getSuspendControllerInjectedValue().getValue(); this.activationSpec = activationSpec; + this.activationName = activeResourceAdapterName + messageListenerInterface.getName(); final ClassLoader componentClassLoader = doPrivileged(new GetClassLoaderAction(ejbComponentCreateService.getComponentClass())); final MessageEndpointService service = new MessageEndpointService() { @Override diff --git a/ejb3/src/main/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenComponentCreateService.java b/ejb3/src/main/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenComponentCreateService.java index b25270a95156..b525da7a805a 100644 --- a/ejb3/src/main/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenComponentCreateService.java +++ b/ejb3/src/main/java/org/jboss/as/ejb3/component/messagedriven/MessageDrivenComponentCreateService.java @@ -101,7 +101,7 @@ protected BasicComponent createComponent() { final ActivationSpec activationSpec = getEndpointDeployer().createActivationSpecs(activeResourceAdapterName, messageListenerInterface, activationProps, getDeploymentClassLoader()); - final MessageDrivenComponent component = new MessageDrivenComponent(this, messageListenerInterface, activationSpec, deliveryActive, deliveryControllerName); + final MessageDrivenComponent component = new MessageDrivenComponent(this, messageListenerInterface, activationSpec, deliveryActive, deliveryControllerName, activeResourceAdapterName); // set the endpoint final EJBUtilities ejbUtilities = this.ejbUtilitiesInjectedValue.getValue(); final Endpoint endpoint = ejbUtilities.getEndpoint(activeResourceAdapterName); diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/ActivationNameTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/ActivationNameTestCase.java new file mode 100644 index 000000000000..704e4d956e2c --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/ActivationNameTestCase.java @@ -0,0 +1,92 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.mdb.activationname; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.connector.util.ConnectorServices; +import org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleListener; +import org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleResourceAdapter; +import org.jboss.as.test.integration.ejb.mdb.activationname.mdb.SimpleMdb; +import org.jboss.jca.core.spi.rar.Endpoint; +import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; +import org.jboss.msc.service.ServiceContainer; +import org.jboss.msc.service.ServiceController; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * This tests if IronJacamar follows JCA 1.7 and properly defines {@code activation name} on {@code MessageEndpointFactory}. + * For details see {@link SimpleResourceAdapter#endpointActivation(MessageEndpointFactory, ActivationSpec)} and WFLY-8074. + * + * @author Ivo Studensky + */ +@RunWith(Arquillian.class) +public class ActivationNameTestCase { + + @Deployment + public static Archive createDeplyoment() { + final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "ear-with-simple-adapter.ear") + .addAsModule(ShrinkWrap.create(JavaArchive.class, "simple-adapter.rar") + .addAsManifestResource(SimpleResourceAdapter.class.getPackage(), "ra.xml", "ra.xml") + .addPackage(SimpleResourceAdapter.class.getPackage())) + .addAsModule(ShrinkWrap.create(JavaArchive.class, "mdb.jar") + .addClasses(SimpleMdb.class, ActivationNameTestCase.class) + .addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.connector, org.jboss.ironjacamar.api\n"), "MANIFEST.MF")); + + return ear; + } + + @ArquillianResource + ServiceContainer serviceContainer; + + @Test + public void testSimpleResourceAdapterAvailability() throws Exception { + ServiceController controller = serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE); + assertNotNull(controller); + ResourceAdapterRepository repository = (ResourceAdapterRepository) controller.getValue(); + assertNotNull(repository); + Set ids = repository.getResourceAdapters(SimpleListener.class); + assertNotNull(ids); + assertEquals(1, ids.size()); + + String piId = ids.iterator().next(); + assertTrue(piId.indexOf("SimpleResourceAdapter") != -1); + + Endpoint endpoint = repository.getEndpoint(piId); + assertNotNull(endpoint); + } +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleActivationSpec.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleActivationSpec.java new file mode 100644 index 000000000000..9f472064f2b8 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleActivationSpec.java @@ -0,0 +1,53 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.mdb.activationname.adapter; + +import javax.resource.ResourceException; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.InvalidPropertyException; +import javax.resource.spi.ResourceAdapter; + +/** + * @author Ivo Studensky + */ +public class SimpleActivationSpec implements ActivationSpec { + + private ResourceAdapter resourceAdapter; + + public SimpleActivationSpec() { + } + + @Override + public void validate() throws InvalidPropertyException { + // nothing to validate here + } + + @Override + public ResourceAdapter getResourceAdapter() { + return resourceAdapter; + } + + @Override + public void setResourceAdapter(ResourceAdapter ra) throws ResourceException { + this.resourceAdapter = ra; + } +} \ No newline at end of file diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleListener.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleListener.java new file mode 100644 index 000000000000..e72b5fecfa1a --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleListener.java @@ -0,0 +1,29 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.mdb.activationname.adapter; + +/** + * @author Ivo Studensky + */ +public interface SimpleListener { + void onMessage(); +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleResourceAdapter.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleResourceAdapter.java new file mode 100644 index 000000000000..1b7b1d698e80 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/SimpleResourceAdapter.java @@ -0,0 +1,123 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.mdb.activationname.adapter; + +import javax.resource.ResourceException; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.ResourceAdapterInternalException; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.transaction.xa.XAResource; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Ivo Studensky + */ +public class SimpleResourceAdapter implements ResourceAdapter { + + private Map activations; + + public SimpleResourceAdapter() { + this.activations = Collections.synchronizedMap(new HashMap()); + } + + @Override + public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException { + } + + @Override + public void stop() { + } + + @Override + public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException { + final String activationName = messageEndpointFactory.getActivationName(); + if (activationName == null) { + throw new ResourceException("MessageEndpointFactory#getActivationName() cannot be null [WFLY-8074]."); + } + SimpleActivation activation = new SimpleActivation(this, messageEndpointFactory, (SimpleActivationSpec) activationSpec); + activations.put((SimpleActivationSpec) activationSpec, activation); + activation.start(); + } + + @Override + public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) { + SimpleActivation activation = activations.remove(activationSpec); + if (activation != null) { activation.stop(); } + } + + @Override + public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException { + return new XAResource[0]; + } + + @Override + public int hashCode() { + int result = 17; + return result; + } + + @Override + public boolean equals(final Object other) { + if (other == null) { return false; } + + if (other == this) { return true; } + + if (!(other instanceof SimpleResourceAdapter)) { return false; } + + SimpleResourceAdapter obj = (SimpleResourceAdapter) other; + boolean result = true; + return result; + } + + class SimpleActivation { + private SimpleResourceAdapter ra; + private SimpleActivationSpec spec; + private MessageEndpointFactory endpointFactory; + + public SimpleActivation(SimpleResourceAdapter ra, + MessageEndpointFactory endpointFactory, + SimpleActivationSpec spec) + throws ResourceException { + this.ra = ra; + this.endpointFactory = endpointFactory; + this.spec = spec; + } + + public SimpleActivationSpec getActivationSpec() { + return spec; + } + + public MessageEndpointFactory getMessageEndpointFactory() { + return endpointFactory; + } + + public void start() throws ResourceException { + } + + public void stop() { + } + } +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/ra.xml b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/ra.xml new file mode 100644 index 000000000000..2c7039ab227e --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/adapter/ra.xml @@ -0,0 +1,32 @@ + + + Simple Resource Adapter + Simple Resource Adapter + + JBoss + + Simple Adapter + + 1.0 + + + + org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleResourceAdapter + + + + + org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleListener + + org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleActivationSpec + + + + + + + diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/mdb/SimpleMdb.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/mdb/SimpleMdb.java new file mode 100644 index 000000000000..8354a50aa475 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/activationname/mdb/SimpleMdb.java @@ -0,0 +1,41 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.mdb.activationname.mdb; + +import org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleListener; +import org.jboss.ejb3.annotation.ResourceAdapter; + +import javax.ejb.MessageDriven; + +/** + * @author Ivo Studensky + */ +@MessageDriven +@ResourceAdapter("ear-with-simple-adapter.ear#simple-adapter.rar") +public class SimpleMdb implements SimpleListener { + + @Override + public void onMessage() { + // nothing to do here + } + +} \ No newline at end of file