openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1786929 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/container/ main/java/org/apache/webbeans/inject/impl/ test/java/org/apache/webbeans/test/injection/injectionpoint/beans/ test/java/org/apache/webbeans/test/t...
Date Tue, 14 Mar 2017 17:10:12 GMT
Author: struberg
Date: Tue Mar 14 17:10:12 2017
New Revision: 1786929

URL: http://svn.apache.org/viewvc?rev=1786929&view=rev
Log:
OWB-1173 InjectionPoint with no ownerBean fails on serialisation

txs to Alexander Falb for debugging and reporting the issue!

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/UnmanagedClassWithInjectionPoints.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/FieldInjectionPointOwner.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/InjectionPointInjectionTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java?rev=1786929&r1=1786928&r2=1786929&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
Tue Mar 14 17:10:12 2017
@@ -33,7 +33,6 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -73,12 +72,7 @@ public class InjectionTargetFactoryImpl<
 
     public Set<InjectionPoint> createInjectionPoints(Bean<T> bean)
     {
-        Set<InjectionPoint> injectionPoints = new HashSet<InjectionPoint>();
-        for (InjectionPoint injectionPoint: webBeansContext.getInjectionPointFactory().buildInjectionPoints(bean,
annotatedType))
-        {
-            injectionPoints.add(injectionPoint);
-        }
-        return injectionPoints;
+        return webBeansContext.getInjectionPointFactory().buildInjectionPoints(bean, annotatedType);
     }
 
     public AnnotatedType<T> getAnnotatedType()

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java?rev=1786929&r1=1786928&r2=1786929&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
Tue Mar 14 17:10:12 2017
@@ -19,6 +19,7 @@
 package org.apache.webbeans.inject.impl;
 
 import java.io.IOException;
+import java.io.NotSerializableException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
@@ -39,6 +40,7 @@ import javax.decorator.Delegate;
 import javax.enterprise.inject.spi.Annotated;
 import javax.enterprise.inject.spi.AnnotatedConstructor;
 import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMember;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.AnnotatedType;
@@ -46,6 +48,7 @@ import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.event.EventUtil;
 import org.apache.webbeans.portable.AnnotatedElementFactory;
 import org.apache.webbeans.util.Asserts;
@@ -173,17 +176,33 @@ class InjectionPointImpl implements Inje
     {
         ObjectOutputStream out = new ObjectOutputStream(op);
 
-        //Write the owning bean class
-        out.writeObject(ownerBean.getBeanClass());
 
-        Set<Annotation> qualifiers = ownerBean.getQualifiers();
-        for(Annotation qualifier : qualifiers)
+        if (ownerBean != null)
         {
-            out.writeObject(Character.valueOf('-')); // throw-away delimiter so alternating
annotations don't get swallowed in the read.
-            out.writeObject(qualifier);
-            
+            //Write the owning bean class
+            out.writeObject(ownerBean.getBeanClass());
+
+            // and it's Qualifiers
+            Set<Annotation> qualifiers = ownerBean.getQualifiers();
+            for (Annotation qualifier : qualifiers)
+            {
+                out.writeObject(Character.valueOf('-')); // throw-away delimiter so alternating
annotations don't get swallowed in the read.
+                out.writeObject(qualifier);
+            }
         }
-        
+        else
+        {
+            if (annotated instanceof AnnotatedMember)
+            {
+                Class<?> beanClass = ((AnnotatedMember) annotated).getDeclaringType().getJavaClass();
+                out.writeObject(beanClass);
+            }
+            else
+            {
+                throw new NotSerializableException("Cannot detect bean class of InjetionPoint");
+            }
+        }
+
         out.writeObject(Character.valueOf('~'));
         
         if(injectionMember instanceof Field)
@@ -202,7 +221,6 @@ class InjectionPointImpl implements Inje
             
             AnnotatedParameter<?> ap = (AnnotatedParameter<?>) annotated;
             out.writeByte(ap.getPosition());
-            
         }
         
         if(injectionMember instanceof Constructor)
@@ -214,7 +232,6 @@ class InjectionPointImpl implements Inje
             
             AnnotatedParameter<?> ap = (AnnotatedParameter<?>) annotated;
             out.writeByte(ap.getPosition());
-            
         }
         
         out.writeBoolean(delegate);
@@ -230,7 +247,7 @@ class InjectionPointImpl implements Inje
         ObjectInputStream in = new OwbCustomObjectInputStream(inp, WebBeansUtil.getCurrentClassLoader());
 
         Class<?> beanClass = (Class<?>)in.readObject();
-        Set<Annotation> anns = new HashSet<Annotation>();
+        Set<Annotation> anns = new HashSet<>();
         WebBeansContext webBeansContext = WebBeansContext.currentInstance();
         AnnotatedElementFactory annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
 
@@ -241,9 +258,14 @@ class InjectionPointImpl implements Inje
         }
         
         //process annotations
-        ownerBean = webBeansContext.getBeanManagerImpl().getBeans(beanClass, anns.toArray(new
Annotation[anns.size()])).iterator().next();
-        qualifierAnnotations = anns;
-        
+        BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
+        Set<Bean<?>> beans = beanManager.getBeans(beanClass, anns.toArray(new
Annotation[anns.size()]));
+        ownerBean = beanManager.resolve(beans);
+        if (ownerBean != null)
+        {
+            qualifierAnnotations = anns;
+        }
+
         // determine type of injection point member (0=field, 1=method, 2=constructor) and
read...
         int c = in.readByte();
         if(c == 0)
@@ -256,7 +278,6 @@ class InjectionPointImpl implements Inje
             AnnotatedType<?> annotatedType = annotatedElementFactory.newAnnotatedType(beanClass);
             annotated = annotatedElementFactory.newAnnotatedField(field, annotatedType);
             injectionType = field.getGenericType();
-            
         }
         else if(c == 1)
         {
@@ -273,7 +294,6 @@ class InjectionPointImpl implements Inje
 
             annotated = annParameters.get(in.readByte());
             injectionType = annotated.getBaseType();
-            
         }
         else if(c == 2)
         {
@@ -299,7 +319,6 @@ class InjectionPointImpl implements Inje
 
         delegate = in.readBoolean();
         transientt = in.readBoolean();
-         
     }
 
 
@@ -315,7 +334,6 @@ class InjectionPointImpl implements Inje
         {
             Method method = (Method) injectionMember;
             buffer.append("Method Injection Point, method name :  ").append(method.getName()).append(",
Bean Owner : [").append(ownerBean).append("]");
-            
         }
         else if(injectionMember instanceof Field)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/FieldInjectionPointOwner.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/FieldInjectionPointOwner.java?rev=1786929&r1=1786928&r2=1786929&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/FieldInjectionPointOwner.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/FieldInjectionPointOwner.java
Tue Mar 14 17:10:12 2017
@@ -18,8 +18,10 @@ package org.apache.webbeans.test.injecti
 import javax.annotation.PostConstruct;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.inject.Inject;
+import java.io.Serializable;
 
-public class FieldInjectionPointOwner extends AbstractInjectionPointOwner {
+public class FieldInjectionPointOwner extends AbstractInjectionPointOwner implements Serializable
+{
 
     @Inject
     private InjectionPoint ip;

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/UnmanagedClassWithInjectionPoints.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/UnmanagedClassWithInjectionPoints.java?rev=1786929&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/UnmanagedClassWithInjectionPoints.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/UnmanagedClassWithInjectionPoints.java
Tue Mar 14 17:10:12 2017
@@ -0,0 +1,34 @@
+/*
+ * 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.test.injection.injectionpoint.beans;
+
+import javax.inject.Inject;
+import java.io.Serializable;
+
+/**
+ * An unmanaged class with some InjectionPoints
+ */
+public class UnmanagedClassWithInjectionPoints implements Serializable
+{
+    private @Inject FieldInjectionPointOwner someField;
+
+
+    public FieldInjectionPointOwner getSomeField()
+    {
+        return someField;
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/injectionpoint/beans/UnmanagedClassWithInjectionPoints.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/InjectionPointInjectionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/InjectionPointInjectionTest.java?rev=1786929&r1=1786928&r2=1786929&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/InjectionPointInjectionTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/InjectionPointInjectionTest.java
Tue Mar 14 17:10:12 2017
@@ -29,11 +29,12 @@ import javax.enterprise.context.Dependen
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
 import javax.inject.Inject;
 
-import junit.framework.Assert;
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.apache.webbeans.test.injection.injectionpoint.beans.AbstractInjectionPointOwner;
@@ -46,6 +47,9 @@ import org.apache.webbeans.test.injectio
 import org.apache.webbeans.test.injection.injectionpoint.beans.MethodInjectionPointOwner;
 import org.apache.webbeans.test.injection.injectionpoint.beans.ProducerInjectionPointInstanceOwner;
 import org.apache.webbeans.test.injection.injectionpoint.beans.ProducerMethodInjectionPointOwner;
+import org.apache.webbeans.test.injection.injectionpoint.beans.UnmanagedClassWithInjectionPoints;
+import org.apache.webbeans.test.util.Serializations;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class InjectionPointInjectionTest extends AbstractUnitTest {
@@ -156,6 +160,28 @@ public class InjectionPointInjectionTest
         Assert.assertNotNull(owner.getConstructorInjectionPointOwner().getName());
     }
 
+    @Test
+    public void testManualCreateInjectionTargetWithInjectionPointsSerialisation() throws
Exception
+    {
+        startContainer(FieldInjectionPointOwner.class);
+        AnnotatedType<UnmanagedClassWithInjectionPoints> at = getBeanManager().createAnnotatedType(UnmanagedClassWithInjectionPoints.class);
+        InjectionTarget<UnmanagedClassWithInjectionPoints> injectionTarget = getBeanManager().createInjectionTarget(at);
+
+        UnmanagedClassWithInjectionPoints instance = new UnmanagedClassWithInjectionPoints();
+        Assert.assertNull(instance.getSomeField());
+
+        CreationalContext cc = getBeanManager().createCreationalContext(null);
+        injectionTarget.inject(instance, cc);
+
+        Assert.assertNotNull(instance.getSomeField());
+        Assert.assertNotNull(instance.getSomeField().getInjectionPoint());
+
+        byte[] bytes = Serializations.serialize(instance);
+        Assert.assertNotNull(bytes);
+        UnmanagedClassWithInjectionPoints instance2 = (UnmanagedClassWithInjectionPoints)
Serializations.deserialize(bytes);
+        Assert.assertNotNull(instance2);
+    }
+
     @Dependent
     public static class ConstructorInjectionOwner
     {



Mime
View raw message