ARTEMIS-1020 Fixing CDI client

Observe process bean when finding eligible bean classes to allow producer methods.

This closes #1066
This commit is contained in:
John D. Ament 2017-03-06 13:34:50 -05:00 committed by Clebert Suconic
parent d12330f151
commit ffb7c5654a
4 changed files with 110 additions and 10 deletions

View File

@ -22,7 +22,7 @@ package org.apache.artemis.client.cdi.extension;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.ProcessBean;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration;
@ -33,14 +33,18 @@ public class ArtemisExtension implements Extension {
private boolean foundEmbeddedConfig = false;
private boolean foundConfiguration = false;
<T extends ArtemisClientConfiguration> void foundClientConfig(@Observes ProcessAnnotatedType<T> pat) {
ActiveMQCDILogger.LOGGER.discoveredConfiguration(pat);
foundConfiguration = true;
void foundClientConfig(@Observes ProcessBean<?> processBean) {
if (processBean.getBean().getTypes().contains(ArtemisClientConfiguration.class)) {
ActiveMQCDILogger.LOGGER.discoveredConfiguration(processBean);
foundConfiguration = true;
}
}
<T extends Configuration> void foundEmbeddedConfig(@Observes ProcessAnnotatedType<T> pat) {
ActiveMQCDILogger.LOGGER.discoveredClientConfiguration(pat);
foundEmbeddedConfig = true;
void foundEmbeddedConfig(@Observes ProcessBean<?> processBean) {
if (processBean.getBean().getTypes().contains(Configuration.class)) {
ActiveMQCDILogger.LOGGER.discoveredClientConfiguration(processBean);
foundEmbeddedConfig = true;
}
}
void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery) {

View File

@ -19,7 +19,7 @@
package org.apache.artemis.client.cdi.logger;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.ProcessBean;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
@ -48,11 +48,11 @@ public interface ActiveMQCDILogger extends BasicLogger {
@LogMessage
@Message(id = 571000, value = "Discovered configuration class {0}", format = Message.Format.MESSAGE_FORMAT)
void discoveredConfiguration(ProcessAnnotatedType<?> pat);
void discoveredConfiguration(ProcessBean<?> pb);
@LogMessage
@Message(id = 571001, value = "Discovered client configuration class {0}", format = Message.Format.MESSAGE_FORMAT)
void discoveredClientConfiguration(ProcessAnnotatedType<?> pat);
void discoveredClientConfiguration(ProcessBean<?> pb);
@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 573000, value = "Configuration found, not using built in configuration")

View File

@ -0,0 +1,61 @@
/*
* 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.activemq.artemis.cdi.bootstrap;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.Extension;
import javax.inject.Inject;
import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration;
import org.apache.artemis.client.cdi.extension.ArtemisExtension;
import org.apache.artemis.client.cdi.factory.ConnectionFactoryProvider;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(Arquillian.class)
public class CDIBootstrapProducerTest {
@Deployment
public static Archive<?> createArchive() {
return ShrinkWrap.create(JavaArchive.class)
.addAsServiceProviderAndClasses(Extension.class, ArtemisExtension.class)
.addClasses(ConnectionFactoryProvider.class, CDIProducers.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Inject
private Instance<ArtemisClientConfiguration> artemisClientConfigurations;
@Test
public void shouldStartJMS() throws Exception {
assertFalse(artemisClientConfigurations.isAmbiguous());
assertFalse(artemisClientConfigurations.isUnsatisfied());
assertTrue(artemisClientConfigurations.iterator().hasNext());
}
}

View File

@ -0,0 +1,35 @@
/*
* 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.activemq.artemis.cdi.bootstrap;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration;
import org.apache.artemis.client.cdi.configuration.DefaultArtemisClientConfigurationImpl;
@ApplicationScoped
public class CDIProducers {
@Produces
@ApplicationScoped
public ArtemisClientConfiguration createConfig() {
return new DefaultArtemisClientConfigurationImpl();
}
}