Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Weld1110 #192

Closed
wants to merge 10 commits into from

3 participants

Marko Lukša Aslak Knutsen Aleš Justin
Marko Lukša

No description provided.

Aslak Knutsen
Collaborator

Exception moved..

Caused by: org.jboss.weld.exceptions.CreationException: WELD-000079 Could not find the EJB in JNDI:  class org.jboss.weld.tests.decorators.weld1110.MessageSender$Proxy$_$$_Weld$Proxy$
    at org.jboss.weld.bean.SessionBean.create(SessionBean.java:307) [weld-core.jar:2012-04-18 14:26]
    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:107) [weld-core.jar:2012-04-18 14:26]
    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90) [weld-core.jar:2012-04-18 14:26]
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79) [weld-core.jar:2012-04-18 14:26]
    at org.jboss.weld.tests.decorators.weld1110.MessageSender$Proxy$_$$_WeldClientProxy.send(MessageSender$Proxy$_$$_WeldClientProxy.java) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_22]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.6.0_22]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.6.0_22]
    at java.lang.reflect.Method.invoke(Method.java:616) [rt.jar:1.6.0_22]
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525) [resteasy-jaxrs-2.3.2.Final.jar:]
    ... 22 more
Caused by: java.lang.NullPointerException
    at org.jboss.weld.bean.proxy.DecoratorProxyMethodHandler.<init>(DecoratorProxyMethodHandler.java:51) [weld-core.jar:2012-04-18 14:26]
    at org.jboss.weld.bean.proxy.DecorationHelper.createMethodHandler(DecorationHelper.java:96) [weld-core.jar:2012-04-18 14:26]
    at org.jboss.weld.bean.proxy.DecorationHelper.getNextDelegate(DecorationHelper.java:107) [weld-core.jar:2012-04-18 14:26]
    at org.jboss.weld.bean.SessionBean.applyDecorators(SessionBean.java:321) [weld-core.jar:2012-04-18 14:26]
    at org.jboss.weld.bean.SessionBean.create(SessionBean.java:299) [weld-core.jar:2012-04-18 14:26]
    ... 35 more
Aleš Justin
Owner

What to do with this pull-request?
I guess it should be still merged, due to those minor fixes.

Marko Lukša

Perhaps I should make a new pullreq with just the fixes, and we'll merge the rest when WELD-1110 is fully fixed?

Aleš Justin
Owner

Yes, that would be better.
As from reading Stuart' comments on WELD-1110, it looks like we'll need an API / SPI changes to make it work properly.

Aleš Justin
Owner

Marko, what's the status of this pull-request?

Aleš Justin
Owner

Merged, while @Ignore tests atm.

Aleš Justin alesj closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 265 additions and 100 deletions.
  1. +15 −7 impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
  2. +1 −1  impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
  3. +8 −19 impl/src/main/java/org/jboss/weld/bean/SessionBean.java
  4. +25 −18 impl/src/main/java/org/jboss/weld/bean/proxy/DecorationHelper.java
  5. +17 −20 impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyMethodHandler.java
  6. +10 −8 impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java
  7. +14 −14 impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
  8. +7 −0 pom.xml
  9. +5 −0 tests-arquillian/pom.xml
  10. +2 −2 tests-arquillian/src/main/java/org/jboss/shrinkwrap/impl/BeansXml.java
  11. +2 −0  tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/SimpleBean.java
  12. +4 −0 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/SimpleBeanImpl.java
  13. +15 −11 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/SimpleDecoratorTest.java
  14. +20 −0 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/MessageDecorator.java
  15. +12 −0 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/MessageSender.java
  16. +17 −0 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/MessageSenderImpl.java
  17. +66 −0 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/MessageSenderTest.java
  18. +21 −0 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/RestFacade.java
  19. +4 −0 tests-arquillian/src/test/resources/arquillian.xml
22 impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
View
@@ -208,22 +208,30 @@ public boolean hasDecorators() {
}
protected T applyDecorators(T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint) {
+ T outerDelegate = getOuterDelegate(instance, creationalContext, originalInjectionPoint);
+ registerOuterDecorator((ProxyObject) instance, outerDelegate);
+ return instance;
+ }
+
+ protected T getOuterDelegate(T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint) {
assert hasDecorators() : "Bean does not have decorators";
TargetBeanInstance beanInstance = new TargetBeanInstance(this, instance);
DecorationHelper<T> decorationHelper = new DecorationHelper<T>(beanInstance, this, decoratorProxyFactory.getProxyClass(), beanManager, getContextualStore(), decorators);
DecorationHelper.push(decorationHelper);
- final T outerDelegate;
try {
- outerDelegate = decorationHelper.getNextDelegate(originalInjectionPoint, creationalContext);
+ final T outerDelegate = decorationHelper.getNextDelegate(originalInjectionPoint, creationalContext);
+ if (outerDelegate == null) {
+ throw new WeldException(PROXY_INSTANTIATION_FAILED, this);
+ }
+ return outerDelegate;
} finally {
DecorationHelper.pop();
}
- if (outerDelegate == null) {
- throw new WeldException(PROXY_INSTANTIATION_FAILED, this);
- }
- CombinedInterceptorAndDecoratorStackMethodHandler wrapperMethodHandler = (CombinedInterceptorAndDecoratorStackMethodHandler) ((ProxyObject) instance).getHandler();
+ }
+
+ private void registerOuterDecorator(ProxyObject instance, T outerDelegate) {
+ CombinedInterceptorAndDecoratorStackMethodHandler wrapperMethodHandler = (CombinedInterceptorAndDecoratorStackMethodHandler) instance.getHandler();
wrapperMethodHandler.setOuterDecorator(outerDelegate);
- return instance;
}
public List<Decorator<?>> getDecorators() {
2  impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
View
@@ -107,7 +107,7 @@
private Set<Type> decoratedTypes;
protected DecoratorImpl(WeldClass<T> type, BeanManagerImpl beanManager, ServiceRegistry services) {
- super(type, new StringBuilder().append(Decorator.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(type.getName()).toString(), beanManager, services);
+ super(type, Decorator.class.getSimpleName() + BEAN_ID_SEPARATOR + type.getName(), beanManager, services);
}
@Override
27 impl/src/main/java/org/jboss/weld/bean/SessionBean.java
View
@@ -17,14 +17,12 @@
package org.jboss.weld.bean;
import org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter;
-import org.jboss.weld.bean.proxy.DecorationHelper;
import org.jboss.weld.bean.proxy.EnterpriseBeanInstance;
import org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler;
import org.jboss.weld.bean.proxy.EnterpriseProxyFactory;
import org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance;
import org.jboss.weld.bean.proxy.Marker;
import org.jboss.weld.bean.proxy.ProxyFactory;
-import org.jboss.weld.bean.proxy.TargetBeanInstance;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.ejb.InternalEjbDescriptor;
@@ -45,7 +43,6 @@
import org.jboss.weld.introspector.jlr.MethodSignatureImpl;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.ClassTransformer;
-import org.jboss.weld.serialization.spi.ContextualStore;
import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.BeansClosure;
@@ -294,7 +291,7 @@ public T create(final CreationalContext<T> creationalContext) {
try {
T instance = SecureReflections.newInstance(proxyClass);
creationalContext.push(instance);
- ProxyFactory.setBeanInstance(instance, new EnterpriseTargetBeanInstance(getWeldAnnotated().getJavaClass(), new EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, creationalContext)), this);
+ ProxyFactory.setBeanInstance(instance, createEnterpriseTargetBeanInstance(creationalContext), this);
if (hasDecorators()) {
instance = applyDecorators(instance, creationalContext, null);
}
@@ -309,24 +306,16 @@ public T create(final CreationalContext<T> creationalContext) {
}
+ private EnterpriseTargetBeanInstance createEnterpriseTargetBeanInstance(CreationalContext<T> creationalContext) {
+ return new EnterpriseTargetBeanInstance(
+ getWeldAnnotated().getJavaClass(),
+ new EnterpriseBeanProxyMethodHandler<T>(this, creationalContext));
+ }
+
@Override
protected T applyDecorators(T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint) {
- assert hasDecorators() : "Bean does not have decorators";
//for EJBs, we apply decorators through a proxy
- T proxy = null;
- TargetBeanInstance beanInstance = new TargetBeanInstance(this, instance);
- DecorationHelper<T> decorationHelper = new DecorationHelper<T>(beanInstance, this, decoratorProxyFactory.getProxyClass(), beanManager, getServices().get(ContextualStore.class), getDecorators());
- DecorationHelper.push(decorationHelper);
- try {
- proxy = decorationHelper.getNextDelegate(originalInjectionPoint, creationalContext);
- } finally {
- DecorationHelper.pop();
- }
-
- if (proxy == null) {
- throw new WeldException(PROXY_INSTANTIATION_FAILED, this);
- }
- return proxy;
+ return getOuterDelegate(instance, creationalContext, originalInjectionPoint);
}
public void destroy(T instance, CreationalContext<T> creationalContext) {
43 impl/src/main/java/org/jboss/weld/bean/proxy/DecorationHelper.java
View
@@ -90,31 +90,38 @@ public static void pop() {
}
}
- public DecoratorProxyMethodHandler createMethodHandler(InjectionPoint injectionPoint, CreationalContext<?> creationalContext, Decorator<Object> decorator) {
- Object decoratorInstance = beanManager.getReference(injectionPoint, decorator, creationalContext);
- SerializableContextualInstanceImpl<Decorator<Object>, Object> serializableContextualInstance = new SerializableContextualInstanceImpl<Decorator<Object>, Object>(decorator, decoratorInstance, null, contextualStore);
- return new DecoratorProxyMethodHandler(serializableContextualInstance, previousDelegate);
- }
-
public T getNextDelegate(InjectionPoint injectionPoint, CreationalContext<?> creationalContext) {
if (counter == decorators.size()) {
previousDelegate = originalInstance;
return originalInstance;
} else {
- try {
- T proxy = SecureReflections.newInstance(proxyClassForDecorator);
- TargetBeanInstance newTargetBeanInstance = new TargetBeanInstance(targetBeanInstance);
- newTargetBeanInstance.setInterceptorsHandler(createMethodHandler(injectionPoint, creationalContext, Reflections.<Decorator<Object>>cast(decorators.get(counter++))));
- ProxyFactory.setBeanInstance(proxy, newTargetBeanInstance, bean);
- previousDelegate = proxy;
- return proxy;
- } catch (InstantiationException e) {
- throw new WeldException(PROXY_INSTANTIATION_FAILED, e, this);
- } catch (IllegalAccessException e) {
- throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
- }
+ T proxy = createProxy(injectionPoint, creationalContext);
+ previousDelegate = proxy;
+ return proxy;
+ }
+ }
+ private T createProxy(InjectionPoint injectionPoint, CreationalContext<?> creationalContext) {
+ try {
+ T proxy = SecureReflections.newInstance(proxyClassForDecorator);
+ TargetBeanInstance newTargetBeanInstance = new TargetBeanInstance(targetBeanInstance);
+ Decorator<Object> decorator = Reflections.cast(decorators.get(counter++));
+ DecoratorProxyMethodHandler methodHandler = createMethodHandler(injectionPoint, creationalContext, decorator);
+ newTargetBeanInstance.setInterceptorsHandler(methodHandler);
+ ProxyFactory.setBeanInstance(proxy, newTargetBeanInstance, bean);
+ return proxy;
+ } catch (InstantiationException e) {
+ throw new WeldException(PROXY_INSTANTIATION_FAILED, e, this);
+ } catch (IllegalAccessException e) {
+ throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
}
}
+ public DecoratorProxyMethodHandler createMethodHandler(InjectionPoint injectionPoint, CreationalContext<?> creationalContext, Decorator<Object> decorator) {
+ Object decoratorInstance = beanManager.getReference(injectionPoint, decorator, creationalContext);
+ assert previousDelegate != null : "previousDelegate should have been set when calling beanManager.getReference(), but it wasn't!";
+ SerializableContextualInstanceImpl<Decorator<Object>, Object> serializableContextualInstance = new SerializableContextualInstanceImpl<Decorator<Object>, Object>(decorator, decoratorInstance, null, contextualStore);
+ return new DecoratorProxyMethodHandler(serializableContextualInstance, previousDelegate);
+ }
+
}
37 impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyMethodHandler.java
View
@@ -41,12 +41,6 @@
private final SerializableContextualInstance<Decorator<Object>, Object> decoratorInstance;
- /**
- * Constructor
- *
- * @param removeMethods
- * @param proxy The generic proxy
- */
public DecoratorProxyMethodHandler(SerializableContextualInstance<Decorator<Object>, Object> decoratorInstance, Object delegateInstance) {
super(delegateInstance, delegateInstance.getClass());
this.decoratorInstance = decoratorInstance;
@@ -68,23 +62,26 @@ public DecoratorProxyMethodHandler(SerializableContextualInstance<Decorator<Obje
*/
@Override
protected Object doInvoke(Object self, Method method, Method proceed, Object[] args) throws Throwable {
- SerializableContextualInstance<Decorator<Object>, Object> beanInstance = decoratorInstance;
- if (beanInstance.getContextual().get() instanceof WeldDecorator<?>) {
- WeldDecorator<?> decorator = (WeldDecorator<?>) beanInstance.getContextual().get();
- if (!method.isAnnotationPresent(Inject.class)) {
- WeldMethod<?, ?> decoratorMethod = decorator.getDecoratorMethod(method);
- if (decoratorMethod != null) {
- try {
- return decoratorMethod.invokeOnInstance(beanInstance.getInstance(), args);
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
- }
+ Decorator<Object> decorator = decoratorInstance.getContextual().get();
+ if (decorator instanceof WeldDecorator<?>) {
+ WeldDecorator<?> weldDecorator = (WeldDecorator<?>) decorator;
+ return doInvoke(weldDecorator, decoratorInstance.getInstance(), method, args);
} else {
- throw new IllegalStateException(UNEXPECTED_UNWRAPPED_CUSTOM_DECORATOR, beanInstance.getContextual().get());
+ throw new IllegalStateException(UNEXPECTED_UNWRAPPED_CUSTOM_DECORATOR, decorator);
}
+ }
+ private Object doInvoke(WeldDecorator<?> weldDecorator, Object decoratorInstance, Method method, Object[] args) throws Throwable {
+ if (!method.isAnnotationPresent(Inject.class)) {
+ WeldMethod<?, ?> decoratorMethod = weldDecorator.getDecoratorMethod(method);
+ if (decoratorMethod != null) {
+ try {
+ return decoratorMethod.invokeOnInstance(decoratorInstance, args);
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+ }
return SecureReflections.invoke(getTargetInstance(), method, args);
}
}
18 impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java
View
@@ -59,8 +59,8 @@
/**
* Constructor
*
- * @param removeMethods
- * @param proxy The generic proxy
+ * @param bean the session bean
+ * @param creationalContext
*/
public EnterpriseBeanProxyMethodHandler(SessionBean<T> bean, CreationalContext<T> creationalContext) {
this.objectInterface = bean.getEjbDescriptor().getObjectInterface();
@@ -98,12 +98,8 @@ public Object invoke(Object self, Method method, Method proceed, Object[] args)
return null;
}
- if (!clientCanCallRemoveMethods) {
- // TODO we can certainly optimize this search algorithm!
- MethodSignature methodSignature = new MethodSignatureImpl(method);
- if (removeMethodSignatures.contains(methodSignature)) {
- throw new UnsupportedOperationException(INVALID_REMOVE_METHOD_INVOCATION, method);
- }
+ if (!clientCanCallRemoveMethods && isRemoveMethod(method)) {
+ throw new UnsupportedOperationException(INVALID_REMOVE_METHOD_INVOCATION, method);
}
Class<?> businessInterface = getBusinessInterface(method);
Object proxiedInstance = reference.getBusinessObject(businessInterface);
@@ -120,6 +116,12 @@ public Object invoke(Object self, Method method, Method proceed, Object[] args)
}
}
+ private boolean isRemoveMethod(Method method) {
+ // TODO we can certainly optimize this search algorithm!
+ MethodSignature methodSignature = new MethodSignatureImpl(method);
+ return removeMethodSignatures.contains(methodSignature);
+ }
+
private Class<?> getBusinessInterface(Method method) {
Class<?> businessInterface = method.getDeclaringClass();
if (businessInterface.equals(Object.class)) {
28 impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
View
@@ -476,11 +476,9 @@ public boolean isBeanEnabled(Bean<?> bean) {
CurrentInjectionPoint currentInjectionPoint = null;
if (registerInjectionPoint) {
currentInjectionPoint = services.get(CurrentInjectionPoint.class);
+ currentInjectionPoint.push(injectionPoint);
}
try {
- if (registerInjectionPoint) {
- currentInjectionPoint.push(injectionPoint);
- }
// We always cache, we assume that people don't use inline annotation literal declarations, a little risky but FAQd
return beanResolver.resolve(new ResolvableBuilder(injectionPoint, this).create(), true);
} finally {
@@ -640,7 +638,7 @@ public Object getReference(Bean<?> bean, CreationalContext<?> creationalContext,
private boolean isProxyRequired(Bean<?> bean) {
if (bean instanceof RIBean<?>) {
return ((RIBean<?>) bean).isProxyRequired();
- } else if (getMetaAnnotationStore().getScopeModel(bean.getScope()).isNormal()) {
+ } else if (isNormalScoped(bean)) {
return true;
} else {
return false;
@@ -679,17 +677,16 @@ public Object getReference(InjectionPoint injectionPoint, Bean<?> resolvedBean,
if (creationalContext == null) {
throw new IllegalArgumentException(NULL_CREATIONAL_CONTEXT_ARGUMENT);
}
- boolean registerInjectionPoint = (injectionPoint != null && !injectionPoint.getType().equals(InjectionPoint.class));
+ boolean registerInjectionPoint = injectionPoint != null && !injectionPoint.getType().equals(InjectionPoint.class);
boolean delegateInjectionPoint = injectionPoint != null && injectionPoint.isDelegate();
+
CurrentInjectionPoint currentInjectionPoint = null;
if (registerInjectionPoint) {
currentInjectionPoint = services.get(CurrentInjectionPoint.class);
+ currentInjectionPoint.push(injectionPoint);
}
try {
- if (registerInjectionPoint) {
- currentInjectionPoint.push(injectionPoint);
- }
- if (getMetaAnnotationStore().getScopeModel(resolvedBean.getScope()).isNormal() && !Proxies.isTypeProxyable(injectionPoint.getType())) {
+ if (injectionPoint != null && isNormalScoped(resolvedBean) && !Proxies.isTypeProxyable(injectionPoint.getType())) {
throw new UnproxyableResolutionException(UNPROXYABLE_RESOLUTION, resolvedBean, injectionPoint);
}
// TODO Can we move this logic to getReference?
@@ -712,11 +709,11 @@ public Object getReference(InjectionPoint injectionPoint, Bean<?> resolvedBean,
}
public Object getInjectableReference(InjectionPoint injectionPoint, CreationalContext<?> creationalContext) {
- if (!injectionPoint.isDelegate()) {
+ if (injectionPoint.isDelegate()) {
+ return DecorationHelper.peek().getNextDelegate(injectionPoint, creationalContext);
+ } else {
Bean<?> resolvedBean = getBean(new ResolvableBuilder(injectionPoint, this).create());
return getReference(injectionPoint, resolvedBean, creationalContext);
- } else {
- return DecorationHelper.peek().getNextDelegate(injectionPoint, creationalContext);
}
}
@@ -727,13 +724,16 @@ public Object getInjectableReference(InjectionPoint injectionPoint, CreationalCo
throw new UnsatisfiedResolutionException(UNRESOLVABLE_ELEMENT, resolvable);
}
- boolean normalScoped = getMetaAnnotationStore().getScopeModel(bean.getScope()).isNormal();
- if (normalScoped && !Beans.isBeanProxyable(bean)) {
+ if (isNormalScoped(bean) && !Beans.isBeanProxyable(bean)) {
throw Proxies.getUnproxyableTypesException(bean);
}
return bean;
}
+ private boolean isNormalScoped(Bean<?> bean) {
+ return getMetaAnnotationStore().getScopeModel(bean.getScope()).isNormal();
+ }
+
public Set<Bean<?>> getBeans(String name) {
return nameBasedResolver.resolve(name);
}
7 pom.xml
View
@@ -59,6 +59,7 @@
<jboss.shrinkwrap.descriptors.version>1.1.0-beta-1</jboss.shrinkwrap.descriptors.version>
<jboss.spec.ejb.version>1.0.0.CR2</jboss.spec.ejb.version>
<jboss.spec.servlet.version>1.0.0.Beta2</jboss.spec.servlet.version>
+ <jboss.spec.jaxrs.version>1.0.0.Final</jboss.spec.jaxrs.version>
<jboss.test.harness.version>1.1.0-CR9</jboss.test.harness.version>
<jboss.vfs.version>2.1.3.SP1</jboss.vfs.version>
<jnp-client.version>4.0.2</jnp-client.version>
@@ -350,6 +351,12 @@
</dependency>
<dependency>
+ <groupId>org.jboss.spec.javax.ws.rs</groupId>
+ <artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
+ <version>${jboss.spec.jaxrs.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.test-harness</groupId>
<artifactId>jboss-test-harness</artifactId>
<version>${jboss.test.harness.version}</version>
5 tests-arquillian/pom.xml
View
@@ -117,6 +117,11 @@
</dependency>
<dependency>
+ <groupId>org.jboss.spec.javax.ws.rs</groupId>
+ <artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
4 tests-arquillian/src/main/java/org/jboss/shrinkwrap/impl/BeansXml.java
View
@@ -8,13 +8,13 @@
import java.util.Arrays;
import java.util.List;
-class BeansXml implements Asset {
+public class BeansXml implements Asset {
private List<Class<?>> alternatives = new ArrayList<Class<?>>();
private List<Class<?>> interceptors = new ArrayList<Class<?>>();
private List<Class<?>> decorators = new ArrayList<Class<?>>();
private List<Class<?>> stereotypes = new ArrayList<Class<?>>();
- BeansXml() {
+ public BeansXml() {
}
2  tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/SimpleBean.java
View
@@ -30,4 +30,6 @@
int echo4(int i);
boolean isInvoked();
+
+ void resetInvokedFlag();
}
4 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/SimpleBeanImpl.java
View
@@ -47,4 +47,8 @@ public int echo4(int i) {
public boolean isInvoked() {
return invoked;
}
+
+ public void resetInvokedFlag() {
+ invoked = false;
+ }
}
26 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/SimpleDecoratorTest.java
View
@@ -34,32 +34,35 @@
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(BeanArchive.class)
- .decorate(SimpleDecorator1.class, SimpleDecorator2.class)
- .addPackage(SimpleDecoratorTest.class.getPackage());
+ .decorate(SimpleDecorator1.class, SimpleDecorator2.class)
+ .addPackage(SimpleDecoratorTest.class.getPackage());
}
@Test
public void testSimpleDecorator(SimpleBean simpleBean) {
resetDecorators();
+ simpleBean.resetInvokedFlag();
Assert.assertEquals(1, simpleBean.echo1(1));
- assertDecorators(true, false, false);
+ assertDecoratorsInvoked(true, false, false, false);
Assert.assertTrue(simpleBean.isInvoked());
resetDecorators();
+ simpleBean.resetInvokedFlag();
Assert.assertEquals(2, simpleBean.echo2(2));
- assertDecorators(false, true, false);
+ assertDecoratorsInvoked(false, false, true, false);
Assert.assertTrue(simpleBean.isInvoked());
- //Only SimpleDecorator1 gets invoked, although I think SimpleDecorator2 should get invoked too
resetDecorators();
+ simpleBean.resetInvokedFlag();
Assert.assertEquals(3, simpleBean.echo3(3));
- assertDecorators(false, false, true);
+ assertDecoratorsInvoked(false, true, false, true);
Assert.assertTrue(simpleBean.isInvoked());
resetDecorators();
+ simpleBean.resetInvokedFlag();
Assert.assertEquals(4, simpleBean.echo4(4));
- assertDecorators(false, false, false);
+ assertDecoratorsInvoked(false, false, false, false);
Assert.assertTrue(simpleBean.isInvoked());
}
@@ -69,9 +72,10 @@ private void resetDecorators() {
SimpleDecorator2.reset();
}
- private void assertDecorators(boolean echo1, boolean echo2, boolean echo3) {
- Assert.assertEquals(echo1, SimpleDecorator1.echo1);
- Assert.assertEquals(echo2, SimpleDecorator2.echo2);
- Assert.assertEquals(echo3, SimpleDecorator2.echo3);
+ private void assertDecoratorsInvoked(boolean decorator1Echo1, boolean decorator1Echo3, boolean decorator2Echo2, boolean decorator2Echo3) {
+ Assert.assertEquals(decorator1Echo1, SimpleDecorator1.echo1);
+ Assert.assertEquals(decorator1Echo3, SimpleDecorator1.echo3);
+ Assert.assertEquals(decorator2Echo2, SimpleDecorator2.echo2);
+ Assert.assertEquals(decorator2Echo3, SimpleDecorator2.echo3);
}
}
20 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/MessageDecorator.java
View
@@ -0,0 +1,20 @@
+package org.jboss.weld.tests.decorators.weld1110;
+
+import java.io.Serializable;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.inject.Inject;
+
+
+@Decorator
+public abstract class MessageDecorator implements MessageSender, Serializable {
+
+ @Inject @Delegate
+ private MessageSender sender;
+
+ public String send(String message) {
+ String msg = "Decorated " + message;
+ return sender.send(msg);
+ }
+}
12 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/MessageSender.java
View
@@ -0,0 +1,12 @@
+package org.jboss.weld.tests.decorators.weld1110;
+
+import javax.ejb.Local;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+public interface MessageSender {
+
+ String send(String message);
+
+}
17 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/MessageSenderImpl.java
View
@@ -0,0 +1,17 @@
+package org.jboss.weld.tests.decorators.weld1110;
+
+import javax.ejb.Stateful;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+@Stateful
+@Path("message/{message}")
+public class MessageSenderImpl implements MessageSender {
+
+ @GET
+ public String send(@PathParam("message") String message) {
+ return message;
+ }
+
+}
66 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/MessageSenderTest.java
View
@@ -0,0 +1,66 @@
+package org.jboss.weld.tests.decorators.weld1110;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.Assert;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.impl.BeansXml;
+import org.jboss.weld.tests.category.Integration;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+
+@RunWith(Arquillian.class)
+@Category(Integration.class)
+public class MessageSenderTest {
+
+ @Deployment(testable = false)
+ public static WebArchive create() {
+ return ShrinkWrap.create(WebArchive.class)
+ .addPackage(MessageSenderTest.class.getPackage())
+ .setWebXML(new StringAsset(
+ "<web-app>" +
+ "<display-name>jax</display-name>" +
+ "<servlet-mapping>" +
+ "<servlet-name>javax.ws.rs.core.Application</servlet-name>" +
+ "<url-pattern>/rest/*</url-pattern>" +
+ "</servlet-mapping>" +
+ "</web-app>"))
+ .addAsWebInfResource(
+ new BeansXml().decorators(MessageDecorator.class), "beans.xml");
+ }
+
+ @ArquillianResource
+ private URL base;
+
+ @Test
+ public void testImpl() throws Exception {
+ String response = getWebServiceResponse("rest/message/Hello");
+ Assert.assertEquals("Decorated Hello", response);
+ }
+
+ @Test
+ public void testFacade() throws Exception {
+ String response = getWebServiceResponse("rest/facade/Hello");
+ Assert.assertEquals("Decorated Hello", response);
+ }
+
+ private String getWebServiceResponse(String urlPath) throws IOException {
+ URL url = new URL(base, urlPath);
+ BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
+ try {
+ return in.readLine();
+ } finally {
+ in.close();
+ }
+ }
+}
21 tests-arquillian/src/test/java/org/jboss/weld/tests/decorators/weld1110/RestFacade.java
View
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.decorators.weld1110;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+/**
+ *
+ */
+@Path("facade/{message}")
+public class RestFacade {
+
+ @Inject
+ private MessageSender messageSender;
+
+ @GET
+ public String send(@PathParam("message") String message) {
+ return messageSender.send(message);
+ }
+}
4 tests-arquillian/src/test/resources/arquillian.xml
View
@@ -4,6 +4,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+ <engine>
+ <property name="deploymentExportPath">target/</property>
+ </engine>
+
<container qualifier="weld" default="true">
<configuration>
<property name="enableConversationScope">true</property>
Something went wrong with that request. Please try again.