Skip to content

Commit

Permalink
Merge pull request #9711 from maeste/WFLY-8074
Browse files Browse the repository at this point in the history
Wfly 8074
  • Loading branch information
kabir committed Feb 28, 2017
2 parents db5d46d + bb6b047 commit 145ef59
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 2 deletions.
Expand Up @@ -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<MessageDrivenComponentInstance> factory = new StatelessObjectFactory<MessageDrivenComponentInstance>() {
Expand All @@ -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<Object>() {
@Override
Expand Down
Expand Up @@ -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);
Expand Down
@@ -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<String> 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);
}
}
@@ -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;
}
}
@@ -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();
}
@@ -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<SimpleActivationSpec, SimpleActivation> activations;

public SimpleResourceAdapter() {
this.activations = Collections.synchronizedMap(new HashMap<SimpleActivationSpec, SimpleActivation>());
}

@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() {
}
}
}
@@ -0,0 +1,32 @@
<connector xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
version="1.5">

<description>Simple Resource Adapter</description>
<display-name>Simple Resource Adapter</display-name>

<vendor-name>JBoss</vendor-name>

<eis-type>Simple Adapter</eis-type>

<resourceadapter-version>1.0</resourceadapter-version>

<resourceadapter id="SimpleResourceAdapter">

<resourceadapter-class>org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleResourceAdapter</resourceadapter-class>

<inbound-resourceadapter>
<messageadapter>
<messagelistener>
<messagelistener-type>org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleListener</messagelistener-type>
<activationspec>
<activationspec-class>org.jboss.as.test.integration.ejb.mdb.activationname.adapter.SimpleActivationSpec</activationspec-class>
</activationspec>
</messagelistener>
</messageadapter>
</inbound-resourceadapter>

</resourceadapter>
</connector>

0 comments on commit 145ef59

Please sign in to comment.