You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2013/08/06 16:09:01 UTC
svn commit: r1510964 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/component/
main/java/org/apache/webbeans/intercept/
main/java/org/apache/webbeans/portable/
test/java/org/apache/webbeans/newtests/proxy/ test/java/org/apach...
Author: rmannibucau
Date: Tue Aug 6 14:09:01 2013
New Revision: 1510964
URL: http://svn.apache.org/r1510964
Log:
OWB-889 making DefaultInterceptorHandler and DecoratorHandler serializable
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorInterceptorProxySerializationTest.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorProxySerializationTest.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/InterceptorProxySerializationTest.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/util/Serializations.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java?rev=1510964&r1=1510963&r2=1510964&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java Tue Aug 6 14:09:01 2013
@@ -20,6 +20,7 @@ package org.apache.webbeans.component;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.PassivationCapable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
@@ -35,7 +36,7 @@ import org.apache.webbeans.config.WebBea
* This is Interceptors which got defined using
* @{@link javax.interceptor.InterceptorBinding}.</p>
*/
-public class CdiInterceptorBean<T> extends InterceptorBean<T>
+public class CdiInterceptorBean<T> extends InterceptorBean<T> implements PassivationCapable
{
private Set<Annotation> interceptorBindings;
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java?rev=1510964&r1=1510963&r2=1510964&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java Tue Aug 6 14:09:01 2013
@@ -20,6 +20,7 @@ package org.apache.webbeans.component;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.inject.spi.PassivationCapable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Set;
@@ -31,7 +32,7 @@ import org.apache.webbeans.container.Dec
/**
* Decorator Bean implementation.
*/
-public class DecoratorBean<T> extends InjectionTargetBean<T> implements Decorator<T>
+public class DecoratorBean<T> extends InjectionTargetBean<T> implements Decorator<T>, PassivationCapable
{
/**
* The Types the decorator itself implements
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java?rev=1510964&r1=1510963&r2=1510964&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java Tue Aug 6 14:09:01 2013
@@ -21,6 +21,7 @@ package org.apache.webbeans.component;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.InterceptionType;
import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.PassivationCapable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collections;
@@ -34,7 +35,7 @@ import org.apache.webbeans.config.WebBea
* This is Interceptors which got defined by being referenced via
* @{@link javax.interceptor.Interceptors}.</p>
*/
-public class EjbInterceptorBean<T> extends InterceptorBean<T> implements Interceptor<T>
+public class EjbInterceptorBean<T> extends InterceptorBean<T> implements Interceptor<T>, PassivationCapable
{
public EjbInterceptorBean(WebBeansContext webBeansContext,
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java?rev=1510964&r1=1510963&r2=1510964&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java Tue Aug 6 14:09:01 2013
@@ -18,24 +18,38 @@
*/
package org.apache.webbeans.intercept;
+import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
+import org.apache.webbeans.intercept.InterceptorResolutionService.BusinessMethodInterceptorInfo;
+import org.apache.webbeans.portable.InjectionTargetImpl;
+import org.apache.webbeans.proxy.InterceptorHandler;
+import org.apache.webbeans.util.ExceptionUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.inject.spi.Producer;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
-import javax.enterprise.inject.spi.Decorator;
-
-import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
-import org.apache.webbeans.intercept.InterceptorResolutionService.BusinessMethodInterceptorInfo;
-import org.apache.webbeans.proxy.InterceptorHandler;
-import org.apache.webbeans.util.ExceptionUtil;
+import java.util.concurrent.CopyOnWriteArrayList;
/**
* InterceptorHandler which handles all the Decorators on the InjectionTarget.
* This one always gets added at the last position in the interceptor chain.
*/
-public class DecoratorHandler implements InterceptorHandler
+public class DecoratorHandler implements InterceptorHandler, Externalizable
{
private BeanInterceptorInfo interceptorInfo;
@@ -43,14 +57,21 @@ public class DecoratorHandler implements
private Map<Decorator<?>, ?> instances;
private int index;
private Object target;
+ private String passivationId;
- public DecoratorHandler(BeanInterceptorInfo interceptorInfo, Map<Decorator<?>, ?> instances, int index, Object target)
+ public DecoratorHandler(BeanInterceptorInfo interceptorInfo, Map<Decorator<?>, ?> instances, int index, Object target, String passivationId)
{
this.interceptorInfo = interceptorInfo;
this.decorators = interceptorInfo.getDecorators();
this.instances = instances;
this.index = index;
this.target = target;
+ this.passivationId = passivationId;
+ }
+
+ public DecoratorHandler()
+ {
+ // no-op: for serialization
}
@Override
@@ -102,4 +123,96 @@ public class DecoratorHandler implements
return ExceptionUtil.throwAsRuntimeException(e);
}
}
+
+ @Override
+ public void writeExternal(final ObjectOutput out) throws IOException
+ {
+ out.writeInt(index);
+ out.writeObject(target);
+
+ out.writeInt(instances.size());
+ for (final Map.Entry<Decorator<?>, ?> entry : instances.entrySet())
+ {
+ final Decorator<?> key = entry.getKey();
+ serializeDecorator(out, key);
+ out.writeObject(entry.getValue());
+ }
+
+ out.writeInt(decorators.size());
+ for (final Decorator<?> decorator : decorators)
+ {
+ serializeDecorator(out, decorator);
+ }
+
+ out.writeUTF(passivationId);
+ }
+
+ Object readResolve() throws ObjectStreamException
+ {
+ final WebBeansContext webBeansContext = WebBeansContext.getInstance();
+ final BeanManager beanManager = webBeansContext.getBeanManagerImpl();
+ final Bean<?> bean = beanManager.getPassivationCapableBean(passivationId);
+
+ return webBeansContext.getInterceptorDecoratorProxyFactory().createProxyInstance(
+ webBeansContext.getInterceptorDecoratorProxyFactory().getCachedProxyClass(bean),
+ target,
+ this
+ );
+ }
+
+ @Override
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ index = in.readInt();
+ target = in.readObject();
+
+ final int instancesSize = in.readInt();
+ final WebBeansContext webBeansContext = WebBeansContext.getInstance();
+ final BeanManager beanManager = webBeansContext.getBeanManagerImpl();
+
+ final Map<Decorator<?>, Object> tmpInstances = new HashMap<Decorator<?>, Object>();
+ for (int i = 0; i < instancesSize; i++)
+ {
+ final Decorator<?> bean = (Decorator<?>) beanManager.getPassivationCapableBean(in.readUTF());
+ final Object value = in.readObject();
+ tmpInstances.put(bean, value);
+ }
+ instances = tmpInstances;
+
+ final int decoratorsSize = in.readInt();
+ decorators = new CopyOnWriteArrayList<Decorator<?>>();
+ for (int i = 0; i < decoratorsSize; i++)
+ {
+ decorators.add((Decorator<?>) beanManager.getPassivationCapableBean(in.readUTF()));
+ }
+
+ passivationId = in.readUTF();
+ final Bean<?> bean = beanManager.getPassivationCapableBean(passivationId);
+ if (OwbBean.class.isInstance(bean))
+ {
+ final Producer injectionTarget = OwbBean.class.cast(bean).getProducer();
+ if (InjectionTargetImpl.class.isInstance(injectionTarget))
+ {
+ interceptorInfo = InjectionTargetImpl.class.cast(injectionTarget).getInterceptorInfo();
+ }
+ else
+ {
+ // TODO
+ }
+ }
+ else
+ {
+ // TODO
+ }
+ }
+
+ private static void serializeDecorator(final ObjectOutput out, final Decorator<?> key) throws IOException
+ {
+ final String id = WebBeansUtil.getPassivationId(key);
+ if (id == null)
+ {
+ throw new NotSerializableException(key + " is not serializable");
+ }
+ out.writeUTF(id);
+ }
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java?rev=1510964&r1=1510963&r2=1510964&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java Tue Aug 6 14:09:01 2013
@@ -18,22 +18,29 @@
*/
package org.apache.webbeans.intercept;
-import java.io.ObjectStreamException;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.proxy.InterceptorHandler;
+import org.apache.webbeans.util.ExceptionUtil;
+import org.apache.webbeans.util.WebBeansUtil;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InterceptionType;
import javax.enterprise.inject.spi.Interceptor;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.proxy.InterceptorHandler;
-import org.apache.webbeans.util.ExceptionUtil;
-
-public class DefaultInterceptorHandler<T> implements InterceptorHandler
+public class DefaultInterceptorHandler<T> implements InterceptorHandler, Externalizable
{
/**
* The native contextual instance target instance.
@@ -82,6 +89,11 @@ public class DefaultInterceptorHandler<T
this.beanPassivationId = beanPassivationId;
}
+ public DefaultInterceptorHandler()
+ {
+ // no-op: for serialization
+ }
+
public T getTarget()
{
return target;
@@ -141,11 +153,118 @@ public class DefaultInterceptorHandler<T
@SuppressWarnings("unused")
Object readResolve() throws ObjectStreamException
{
- WebBeansContext webBeansContext = WebBeansContext.getInstance();
- BeanManager beanManager = webBeansContext.getBeanManagerImpl();
- Bean<?> bean = beanManager.getPassivationCapableBean(beanPassivationId);
+ final WebBeansContext webBeansContext = WebBeansContext.getInstance();
+ final BeanManager beanManager = webBeansContext.getBeanManagerImpl();
+ final Bean<T> bean = (Bean<T>) beanManager.getPassivationCapableBean(beanPassivationId);
+
+ return webBeansContext.getInterceptorDecoratorProxyFactory().createProxyInstance(
+ webBeansContext.getInterceptorDecoratorProxyFactory().getCachedProxyClass(bean),
+ target,
+ this
+ );
+ }
+
+ @Override
+ public void writeExternal(final ObjectOutput out) throws IOException
+ {
+ out.writeObject(target);
+
+ final boolean noDecorator = target == delegate;
+ out.writeBoolean(noDecorator);
+ if (!noDecorator)
+ {
+ out.writeObject(delegate);
+ }
+
+ out.writeInt(instances.size());
+ for (final Map.Entry<Interceptor<?>, ?> entry : instances.entrySet())
+ {
+ final Interceptor<?> key = entry.getKey();
+ serializeInterceptor(out, key);
+ out.writeObject(entry.getValue());
+ }
+
+ out.writeInt(interceptors.size());
+ for (final Map.Entry<Method, List<Interceptor<?>>> entry : interceptors.entrySet())
+ {
+ final Method key = entry.getKey();
+ out.writeObject(key.getDeclaringClass());
+ out.writeUTF(key.getName());
+ out.writeObject(key.getParameterTypes());
+
+ final List<Interceptor<?>> value = entry.getValue();
+ out.writeInt(value.size());
+ for (final Interceptor<?> i : value)
+ {
+ serializeInterceptor(out, i);
+ }
+ }
+
+ out.writeUTF(beanPassivationId);
+ }
+
+ @Override
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ target = (T) in.readObject();
+ if (in.readBoolean())
+ {
+ delegate = target;
+ }
+ else
+ {
+ delegate = (T) in.readObject();
+ }
+
+ final int instancesSize = in.readInt();
+ final WebBeansContext webBeansContext = WebBeansContext.getInstance();
+ final BeanManager beanManager = webBeansContext.getBeanManagerImpl();
- return webBeansContext.getInterceptorDecoratorProxyFactory().getCachedProxyClass(bean);
+ final Map<Interceptor<?>, Object> tmpInstances = new HashMap<Interceptor<?>, Object>();
+ for (int i = 0; i < instancesSize; i++)
+ {
+ final Interceptor<?> bean = (Interceptor<?>) beanManager.getPassivationCapableBean(in.readUTF());
+ final Object value = in.readObject();
+ tmpInstances.put(bean, value);
+ }
+ instances = tmpInstances;
+
+ final int interceptorsSize = in.readInt();
+ interceptors = new HashMap<Method, List<Interceptor<?>>>(interceptorsSize);
+ for (int i = 0; i < interceptorsSize; i++)
+ {
+ final Class<?> declaringClass = (Class<?>) in.readObject();
+ final String name = in.readUTF();
+ final Class<?>[] parameters = (Class<?>[]) in.readObject();
+ final Method method;
+ try
+ {
+ method = declaringClass.getDeclaredMethod(name, parameters);
+ }
+ catch (final NoSuchMethodException e)
+ {
+ throw new NotSerializableException(target.getClass().getName());
+ }
+
+ final int interceptorListSize = in.readInt();
+ final List<Interceptor<?>> interceptorList = new ArrayList<Interceptor<?>>(interceptorListSize);
+ for (int j = 0; j < interceptorListSize; j++)
+ {
+ interceptorList.add((Interceptor<?>) beanManager.getPassivationCapableBean(in.readUTF()));
+ }
+ interceptors.put(method, interceptorList);
+ }
+
+ beanPassivationId = in.readUTF();
}
+ private static void serializeInterceptor(final ObjectOutput out, final Interceptor<?> key) throws IOException
+ {
+ final String id = WebBeansUtil.getPassivationId(key);
+ if (id == null)
+ {
+ throw new NotSerializableException(key + " is not serializable");
+ }
+ out.writeUTF(id);
+ }
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java?rev=1510964&r1=1510963&r2=1510964&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java Tue Aug 6 14:09:01 2013
@@ -258,7 +258,7 @@ public class InjectionTargetImpl<T> exte
creationalContextImpl.putDelegate(delegate);
Object decoratorInstance = decorator.create((CreationalContext) creationalContext);
instances.put(decorator, decoratorInstance);
- delegate = pf.createProxyInstance(proxyClass, instance, new DecoratorHandler(interceptorInfo, instances, i - 1, instance));
+ delegate = pf.createProxyInstance(proxyClass, instance, new DecoratorHandler(interceptorInfo, instances, i - 1, instance, beanPassivationId));
}
}
InterceptorHandler interceptorHandler = new DefaultInterceptorHandler<T>(instance, delegate, methodInterceptors, interceptorInstances, beanPassivationId);
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorInterceptorProxySerializationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorInterceptorProxySerializationTest.java?rev=1510964&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorInterceptorProxySerializationTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorInterceptorProxySerializationTest.java Tue Aug 6 14:09:01 2013
@@ -0,0 +1,174 @@
+/*
+ * 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.webbeans.newtests.proxy;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InterceptorBinding;
+import javax.interceptor.InvocationContext;
+import java.io.Serializable;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+
+import static org.apache.webbeans.newtests.util.Serializations.deserialize;
+import static org.apache.webbeans.newtests.util.Serializations.serialize;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class DecoratorInterceptorProxySerializationTest extends AbstractUnitTest
+{
+ @Inject
+ private Main client;
+
+ @Test
+ public void testProxyMappingConfig() throws Exception
+ {
+ addDecorator(MyDecorator.class);
+ addInterceptor(IBInterceptor.class);
+ startContainer(new ArrayList<Class<?>>() {{ add(Main.class); }}, null, true);
+
+ try
+ {
+ final Main deserializeInit = Main.class.cast(deserialize(serialize(client)));
+ assertFalse(deserializeInit.isCalled());
+ assertFalse(deserializeInit.isDecoratorCalled());
+ assertFalse(deserializeInit.isInterceptorCalled());
+
+ client.aMethod();
+
+ final Main deserializeState = Main.class.cast(deserialize(serialize(client)));
+ assertTrue(deserializeState.isCalled());
+ assertTrue(deserializeState.isDecoratorCalled());
+ assertTrue(deserializeState.isInterceptorCalled());
+ }
+ finally
+ {
+ shutDownContainer();
+ }
+ }
+
+ public static interface StupidClass
+ {
+ void aMethod();
+ boolean isCalled();
+ boolean isDecoratorCalled();
+ boolean isInterceptorCalled();
+ }
+
+ @InterceptorBinding
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface IB
+ {
+ }
+
+ @Interceptor
+ @IB
+ public static class IBInterceptor implements Serializable
+ {
+ private boolean called = false; // just here to represent a state in the serialization
+
+ @AroundInvoke
+ public Object intercept(final InvocationContext ctx) throws Exception
+ {
+ final String name = ctx.getMethod().getName();
+
+ if (name.equals("isInterceptorCalled"))
+ {
+ return called;
+ }
+ else if (!name.startsWith("is"))
+ {
+ called = true;
+ }
+
+ return ctx.proceed();
+ }
+ }
+
+ @Decorator
+ public static class MyDecorator implements Serializable, StupidClass
+ {
+ private boolean called = false; // just here to represent a state in the serialization
+
+ @Inject @Delegate
+ private StupidClass delegate;
+
+ @Override
+ public void aMethod() {
+ called = true;
+ delegate.aMethod();
+ }
+
+ @Override
+ public boolean isCalled() {
+ return delegate.isCalled();
+ }
+
+ @Override
+ public boolean isDecoratorCalled() {
+ return called;
+ }
+
+ @Override
+ public boolean isInterceptorCalled()
+ {
+ return false;
+ }
+ }
+
+ @IB
+ public static class Main implements StupidClass, Serializable
+ {
+ private boolean called = false; // just here to represent a state in the serialization
+
+ @Override
+ public void aMethod()
+ {
+ called = true;
+ }
+
+ @Override
+ public boolean isCalled()
+ {
+ return called;
+ }
+
+ @Override
+ public boolean isDecoratorCalled()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isInterceptorCalled()
+ {
+ return false;
+ }
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorProxySerializationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorProxySerializationTest.java?rev=1510964&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorProxySerializationTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/DecoratorProxySerializationTest.java Tue Aug 6 14:09:01 2013
@@ -0,0 +1,120 @@
+/*
+ * 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.webbeans.newtests.proxy;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import static org.apache.webbeans.newtests.util.Serializations.deserialize;
+import static org.apache.webbeans.newtests.util.Serializations.serialize;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class DecoratorProxySerializationTest extends AbstractUnitTest
+{
+ @Inject
+ private Main client;
+
+ @Test
+ public void testProxyMappingConfig() throws Exception
+ {
+ addDecorator(MyDecorator.class);
+ startContainer(new ArrayList<Class<?>>() {{ add(Main.class); }}, null, true);
+
+ try
+ {
+ final Main deserializeInit = Main.class.cast(deserialize(serialize(client)));
+ assertFalse(deserializeInit.isCalled());
+ assertFalse(deserializeInit.isDecoratorCalled());
+
+ client.aMethod();
+
+ final Main deserializeState = Main.class.cast(deserialize(serialize(client)));
+ assertTrue(deserializeState.isCalled());
+ assertTrue(deserializeState.isDecoratorCalled());
+ }
+ finally
+ {
+ shutDownContainer();
+ }
+ }
+
+ public static interface StupidClass
+ {
+ void aMethod();
+ boolean isCalled();
+ boolean isDecoratorCalled();
+ }
+
+ @Decorator
+ public static class MyDecorator implements Serializable, StupidClass
+ {
+ private boolean called = false; // just here to represent a state in the serialization
+
+ @Inject @Delegate
+ private StupidClass delegate;
+
+ @Override
+ public void aMethod() {
+ called = true;
+ delegate.aMethod();
+ }
+
+ @Override
+ public boolean isCalled() {
+ return delegate.isCalled();
+ }
+
+ @Override
+ public boolean isDecoratorCalled() {
+ return called;
+ }
+ }
+
+ public static class Main implements StupidClass, Serializable
+ {
+ private boolean called = false; // just here to represent a state in the serialization
+
+ @Override
+ public void aMethod()
+ {
+ called = true;
+ }
+
+ @Override
+ public boolean isCalled()
+ {
+ return called;
+ }
+
+ @Override
+ public boolean isDecoratorCalled()
+ {
+ return false;
+ }
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/InterceptorProxySerializationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/InterceptorProxySerializationTest.java?rev=1510964&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/InterceptorProxySerializationTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/proxy/InterceptorProxySerializationTest.java Tue Aug 6 14:09:01 2013
@@ -0,0 +1,120 @@
+/*
+ * 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.webbeans.newtests.proxy;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InterceptorBinding;
+import javax.interceptor.InvocationContext;
+import java.io.Serializable;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+
+import static org.apache.webbeans.newtests.util.Serializations.deserialize;
+import static org.apache.webbeans.newtests.util.Serializations.serialize;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class InterceptorProxySerializationTest extends AbstractUnitTest
+{
+ @Inject
+ private Intercepted client;
+
+ @Test
+ public void testProxyMappingConfig() throws Exception
+ {
+ addInterceptor(IBInterceptor.class);
+ startContainer(new ArrayList<Class<?>>() {{ add(Intercepted.class); }}, null, true);
+
+ try
+ {
+ final Intercepted deserializeInit = Intercepted.class.cast(deserialize(serialize(client)));
+ assertFalse(deserializeInit.isCalled());
+ assertFalse(deserializeInit.isInterceptorCalled());
+
+ client.intercepted();
+
+ final Intercepted deserializeState = Intercepted.class.cast(deserialize(serialize(client)));
+ assertTrue(deserializeState.isCalled());
+ assertTrue(deserializeState.isInterceptorCalled());
+ }
+ finally
+ {
+ shutDownContainer();
+ }
+ }
+
+ @InterceptorBinding
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface IB
+ {
+ }
+
+ @Interceptor @IB
+ public static class IBInterceptor implements Serializable
+ {
+ private boolean called = false; // just here to represent a state in the serialization
+
+ @AroundInvoke
+ public Object intercept(final InvocationContext ctx) throws Exception
+ {
+ final String name = ctx.getMethod().getName();
+
+ if (name.equals("isInterceptorCalled"))
+ {
+ return called;
+ }
+ else if (!name.startsWith("is"))
+ {
+ called = true;
+ }
+
+ return ctx.proceed();
+ }
+ }
+
+ @IB
+ public static class Intercepted implements Serializable
+ {
+ private boolean called = false; // just here to represent a state in the serialization
+
+ public void intercepted()
+ {
+ called = true;
+ }
+
+ public boolean isCalled()
+ {
+ return called;
+ }
+
+ public boolean isInterceptorCalled()
+ {
+ return false;
+ }
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/util/Serializations.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/util/Serializations.java?rev=1510964&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/util/Serializations.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/util/Serializations.java Tue Aug 6 14:09:01 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.webbeans.newtests.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+public final class Serializations
+{
+ private Serializations() {
+ // no-op
+ }
+
+ public static byte[] serialize(final Object o) throws IOException
+ {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(o);
+ return baos.toByteArray();
+ }
+
+ public static Object deserialize(final byte[] serial) throws IOException, ClassNotFoundException
+ {
+ return new ObjectInputStream(new ByteArrayInputStream(serial)).readObject();
+ }
+}