Cool, that worked, I don't understand why though?

The whole point of me moving the property definition for exception mappers at 
the @Config level is so I can I have some generic pre configured test class 
which all tests can subclass. This pre configured test class would have some 
generic method to create some default properties, in here I would add all my 
exeption mappers to the providers property. So I can do this once and forget 
about it.

So something like

public class PreSetupTest {

        public Properties createDefaultConfig() {
                Properties p = new Properties();
                ...
                p.setProperty("openejb.cxf.jax-rs.providers", 
GoodExceptionMapper.class.getName() + "," + BadExceptionMapper.class.getName());
                p.setProperty("openejb.jaxrs.providers.auto", "true");
                …
                return p;
        }

}

public class Test1 extends PresSetupTest {
        
        @Configuration
        public Properties props() {
                Properties p = super.createDefaultConfig();
                p.add…
                p.add…
                return p;
        }

        @Module
        public EjbModule module() {
                ….
        }
}

But If I have to have @Classes annotated alongside @Module in which i have to 
define all the exception mappers again, then what's the point? I might as well 
just stick to applying the exception mappers on the deployment beans in the 
OpenejbJar property.

I don't really understand what that @Classes annotation does? Why do I need it 
for ExceptionMapperAtConfigTest and not ExceptionMapperAtDeploymentTest?


Chris Christo

Twitter: https://twitter.com/ChrisChristo7
Tumblr: http://chrischristo7.tumblr.com
LinkedIn: http://uk.linkedin.com/in/chrischristo

On 12 May 2013, at 22:26, Romain Manni-Bucau <[email protected]> wrote:

> take care using @Classes you specify explicitely the "application classpath"
> 
> so use:
> 
> @Classes({ GoodExceptionMapper.class, BadExceptionMapper.class,
> ExampleRest.class, ExampleService.class })
> 
> *Romain Manni-Bucau*
> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
> *Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> *Github: https://github.com/rmannibucau*
> 
> 
> 
> 2013/5/12 Chris.Christo <[email protected]>
> 
>> Hey,
>> 
>> Ok so I've attached a maven project with pretty much what I described
>> before.
>> 
>> unzip and run a mvn test.
>> 
>> There are two tests.
>> 
>> The one that is failing is 'ExceptionMapperAtConfigTest'. It fails because
>> the @EJB is not being injected in the Rest class.
>> 
>> 
>> 
>> 
>> 
>> Chris Christo
>> 
>> Twitter: https://twitter.com/ChrisChristo7
>> Tumblr: http://chrischristo7.tumblr.com
>> LinkedIn: http://uk.linkedin.com/in/chrischristo
>> 
>> On 10 May 2013, at 21:07, Romain Manni-Bucau <[email protected]>
>> wrote:
>> 
>> Right,
>> 
>> Git clone X && mvn test -> error
>> Le 10 mai 2013 22:04, "Chris.Christo" <[email protected]> a écrit :
>> 
>> Thanks Romain, tried it but no luck :(
>> 
>> What's the best way to share a sample so I know? I'm guessing some pre
>> setup maven project on github or something in which you can git clone and
>> mvn install?
>> 
>> 
>> 
>> 
>> On 10 May 2013, at 20:42, Romain Manni-Bucau <[email protected]>
>> wrote:
>> 
>> Maybe try adding ejb in @classes
>> 
>> Sharing a sample for next week.can help too ;)
>> Le 10 mai 2013 20:41, "Chris.Christo" <[email protected]> a écrit :
>> 
>> 4.6.0-SNAPSHOT of the standalone
>> 
>> 
>> On 10 May 2013, at 19:39, Romain Manni-Bucau <[email protected]>
>> wrote:
>> 
>> Which version do you use?
>> Le 10 mai 2013 20:33, "Chris.Christo" <[email protected]> a
>> 
>> écrit :
>> 
>> 
>> sorry, where on trunk?
>> 
>> Regardless, I played around with this and managed to get it working.
>> 
>> However I have stumbled on something a little strange.
>> 
>> Basically when the exception mappers are defined at the @Config level,
>> 
>> any
>> 
>> @EJB's within the rest class, that is being tested, do not get
>> 
>> injected.
>> 
>> 
>> To explain a little better, here (on pastebin) we have to classes.
>> 
>> They
>> 
>> are practically identical except for where the ExceptionMapper classes
>> 
>> are
>> 
>> loaded, one at the @Config level and one within the @Module level
>> 
>> defined
>> 
>> on the EjbDeployment of the OpenejbJar.
>> 
>> They both pass the test, which basically means that that the exception
>> mapping was setup correctly. However the second class
>> (ExceptionMapperAtConfigTest) passes on the basis that the service
>> 
>> marked
>> 
>> @EJB is not injected i.e null. So basically we want this test to fail.
>> 
>> ExceptionMapperAtDeploymentTest: http://pastebin.com/aWQjjePD
>> 
>> ExceptionMapperAtConfigTest: http://pastebin.com/GFcKYWzs
>> 
>> 
>> On a side note, to have the exception mappers picked up at the @Config
>> level, you have to have the '@Classes({ GoodExceptionMapper.class,
>> BadExceptionMapper.class })' annotation defined on the method. I have
>> 
>> no
>> 
>> idea why??
>> 
>> 
>> 
>> On 10 May 2013, at 17:35, Romain Manni-Bucau <[email protected]>
>> wrote:
>> 
>> Hi
>> 
>> on trunk it is set once by jaxrs application only which is far ore
>> 
>> easier
>> 
>> to handle
>> 
>> *Romain Manni-Bucau*
>> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
>> *Blog: **http://rmannibucau.wordpress.com/*<
>> 
>> http://rmannibucau.wordpress.com/>
>> 
>> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
>> *Github: https://github.com/rmannibucau*
>> 
>> 
>> 
>> 2013/5/10 Chris.Christo <[email protected]>
>> 
>> Hi
>> 
>> Hey I was just wondering if I can set my exception mappers in the
>> properties part of my test under the @Configuration, rather than
>> 
>> having
>> 
>> to
>> 
>> apply an exception mapper to each EjbDeployment of the OpenejbJar.
>> 
>> So right now I have something like this link:
>> 
>> 
>> 
>> 
>> 
>> 
>> https://svn.apache.org/repos/asf/tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CheckedExceptionMapperTest.java
>> 
>> 
>> To pick out the specific point in the link:
>> 
>> @Module
>> @Classes({ ExampleExceptionMapper.class })
>> public EjbModule module() {
>> final SingletonBean bean = new SingletonBean(ExampleRest.class);
>> bean.setRestService(true);
>> 
>> final EjbJar ejbJar = new EjbJar("beans");
>> ejbJar.addEnterpriseBean(bean);
>> 
>> final OpenejbJar openejbJar = new OpenejbJar();
>> openejbJar.addEjbDeployment(new EjbDeployment(bean));
>> 
>> final Properties properties =
>> openejbJar.getEjbDeployment().iterator().next().getProperties();
>> properties.setProperty("cxf.jaxrs.providers",
>> 
>> 
>> 
>> 
>> "org.apache.openejb.server.cxf.rs.CheckedExceptionMapperTest$ExampleExceptionMapper");
>> 
>> 
>> final EjbModule module = new EjbModule(ejbJar);
>> module.setOpenejbJar(openejbJar);
>> 
>> return module;
>> }
>> 
>> So here I define the exception mapper (ExampleExceptionMapper) on
>> 
>> the
>> 
>> properties of the specific EjbDeployment of the ExampleRest class in
>> 
>> the
>> 
>> OpenejbJar.
>> 
>> Is there a way to just define it in the global properties with
>> @Configuration? I've tried something like this to no avail:
>> 
>> @Configuration
>> public Properties config() {
>>    final Properties props = new Properties();
>>    ...
>>    props.setProperty("openejb.cxf.jax-rs.providers",
>> ExampleExceptionMapper.class.getName());
>>    props.setProperty("openejb.jaxrs.providers.auto", "true");
>>    ...
>>    return props;
>> }
>> 
>> 
>> 
>> Thanks,
>> 
>> Chris
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 

Reply via email to