Return-Path: X-Original-To: apmail-openwebbeans-commits-archive@www.apache.org Delivered-To: apmail-openwebbeans-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 251AC18C76 for ; Thu, 11 Feb 2016 17:27:45 +0000 (UTC) Received: (qmail 80672 invoked by uid 500); 11 Feb 2016 17:27:45 -0000 Delivered-To: apmail-openwebbeans-commits-archive@openwebbeans.apache.org Received: (qmail 80648 invoked by uid 500); 11 Feb 2016 17:27:45 -0000 Mailing-List: contact commits-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwebbeans.apache.org Delivered-To: mailing list commits@openwebbeans.apache.org Received: (qmail 80637 invoked by uid 99); 11 Feb 2016 17:27:45 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Feb 2016 17:27:45 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 9FE031A03D9 for ; Thu, 11 Feb 2016 17:27:44 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.471 X-Spam-Level: * X-Spam-Status: No, score=1.471 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.329] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id PcMEC_1ulpBL for ; Thu, 11 Feb 2016 17:27:43 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTP id CFF00429C4 for ; Thu, 11 Feb 2016 17:27:42 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id DA04AE0099 for ; Thu, 11 Feb 2016 17:27:41 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 48B8A3A023C for ; Thu, 11 Feb 2016 17:27:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1729867 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/portable/ProducerFieldProducer.java test/java/org/apache/webbeans/test/profields/InterceptedProducerFieldTest.java Date: Thu, 11 Feb 2016 17:27:42 -0000 To: commits@openwebbeans.apache.org From: rmannibucau@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160211172742.48B8A3A023C@svn01-us-west.apache.org> Author: rmannibucau Date: Thu Feb 11 17:27:42 2016 New Revision: 1729867 URL: http://svn.apache.org/viewvc?rev=1729867&view=rev Log: OWB-1118 unwrapping intercepted beans for producer fields Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/profields/InterceptedProducerFieldTest.java Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java?rev=1729867&r1=1729866&r2=1729867&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java Thu Feb 11 17:27:42 2016 @@ -22,6 +22,9 @@ import org.apache.webbeans.component.Abs import org.apache.webbeans.config.WebBeansContext; import org.apache.webbeans.context.creational.CreationalContextImpl; import org.apache.webbeans.exception.WebBeansException; +import org.apache.webbeans.intercept.DefaultInterceptorHandler; +import org.apache.webbeans.proxy.InterceptorHandler; +import org.apache.webbeans.proxy.OwbInterceptorProxy; import org.apache.webbeans.util.Asserts; import org.apache.webbeans.util.WebBeansUtil; @@ -80,7 +83,16 @@ public class ProducerFieldProducer else { parentInstance = getParentInstanceFromContext(parentCreational); - + + if (OwbInterceptorProxy.class.isInstance(parentInstance)) + { + final InterceptorHandler handler = webBeansContext.getInterceptorDecoratorProxyFactory() + .getInterceptorHandler(OwbInterceptorProxy.class.cast(parentInstance)); + if (DefaultInterceptorHandler.class.isInstance(handler)) + { + parentInstance = (P) DefaultInterceptorHandler.class.cast(handler).getTarget(); + } + } instance = (T) field.get(parentInstance); } } Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/profields/InterceptedProducerFieldTest.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/profields/InterceptedProducerFieldTest.java?rev=1729867&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/profields/InterceptedProducerFieldTest.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/profields/InterceptedProducerFieldTest.java Thu Feb 11 17:27:42 2016 @@ -0,0 +1,92 @@ +/* + * 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.profields; + +import org.apache.webbeans.test.AbstractUnitTest; +import org.apache.webbeans.test.profields.beans.classproducer.MyProductBean; +import org.junit.Test; + +import javax.enterprise.inject.Produces; +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.Collections; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class InterceptedProducerFieldTest extends AbstractUnitTest { + @Inject + private MyProductBean bean; + + @Test + public void testProductProducer() { + addInterceptor(BoundInterceptor.class); + startContainer(Collections.>singletonList(Producing.class), Collections.emptyList(), true); + + BoundInterceptor.CALLED.set(false); + + assertEquals(1234, bean.getI()); + assertFalse(BoundInterceptor.CALLED.get()); // we access the field so no interception + getInstance(Producing.class).intercepted(); + assertTrue(BoundInterceptor.CALLED.get()); // ensure interceptors were correctly setup + } + + @Bound + public static class Producing { + @Produces + MyProductBean product = new MyProductBean() { + @Override + public int getI() { + return 1234; + } + }; + + public void intercepted() { + } + } + + + @InterceptorBinding + @Target({ElementType.METHOD, ElementType.TYPE}) + @Retention(RetentionPolicy.RUNTIME) + public @interface Bound { + } + + @Bound + @Interceptor + public static class BoundInterceptor implements Serializable { + private static final AtomicBoolean CALLED = new AtomicBoolean(); + + @AroundInvoke + public Object measure(final InvocationContext ctx) throws Exception { + CALLED.set(true); + return ctx.proceed(); + } + } +}