Return-Path: X-Original-To: apmail-openwebbeans-user-archive@www.apache.org Delivered-To: apmail-openwebbeans-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E9E7C109E0 for ; Thu, 6 Feb 2014 12:49:56 +0000 (UTC) Received: (qmail 26315 invoked by uid 500); 6 Feb 2014 12:49:56 -0000 Delivered-To: apmail-openwebbeans-user-archive@openwebbeans.apache.org Received: (qmail 26222 invoked by uid 500); 6 Feb 2014 12:49:56 -0000 Mailing-List: contact user-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@openwebbeans.apache.org Delivered-To: mailing list user@openwebbeans.apache.org Received: (qmail 26207 invoked by uid 99); 6 Feb 2014 12:49:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Feb 2014 12:49:55 +0000 X-ASF-Spam-Status: No, hits=0.3 required=5.0 tests=FREEMAIL_REPLY,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of rmannibucau@gmail.com designates 209.85.216.173 as permitted sender) Received: from [209.85.216.173] (HELO mail-qc0-f173.google.com) (209.85.216.173) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Feb 2014 12:49:49 +0000 Received: by mail-qc0-f173.google.com with SMTP id i8so2990956qcq.32 for ; Thu, 06 Feb 2014 04:49:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=1dHs+xY8MsOfSV7TS4W27yGDxp6i/GvzrYSQ2nzkvzY=; b=WiwezLeAiNeLAwrTh0FMYpLI0M9MeDYomw1w1GyQqsKeMMz24pOywMJuhVw07FfvX5 WQEk/e05/mx1j3wZFEb/DP63dr8tLpA/6pjHAUteMuOmJL8j63CXLr+aydEy44mRKR+5 qv8Arnt8CaCL/sa4w64CUW3PtQ0vj8qlynBbOsHpiiiB/f4mjf4gMZjAjG6P6wsSaSsg 1y1lIv0hs0ww88REZXAnUspTk+cEdkqp0Z1ESdjC+1WQtS1Us6j1sYTjaeyX3biQ89oW PPRvLTyV9dY6xay4bTUtBG5PhQMHZ7QSyCw7JdlM0Y7Oc3BkVYajLi77XRd2LpcJNK0M aUog== X-Received: by 10.140.31.247 with SMTP id f110mr11309381qgf.58.1391690968666; Thu, 06 Feb 2014 04:49:28 -0800 (PST) MIME-Version: 1.0 Received: by 10.96.123.6 with HTTP; Thu, 6 Feb 2014 04:49:08 -0800 (PST) In-Reply-To: References: From: Romain Manni-Bucau Date: Thu, 6 Feb 2014 13:49:08 +0100 Message-ID: Subject: Re: Interceptors and @PostConstruct methods To: "user@openwebbeans.apache.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org My code catches the exception of @PostConstruct method of the bean so i should be missing sthg Romain Manni-Bucau Twitter: @rmannibucau Blog: http://rmannibucau.wordpress.com/ LinkedIn: http://fr.linkedin.com/in/rmannibucau Github: https://github.com/rmannibucau 2014-02-06 Lars-Fredrik Smedberg : > Hi > > The reason I didn't see any calls to the target method annotated > @PostConstruct was that it always threw an exception (since I wanted to t= ry > to catch that). > When the target method annotated @PostConstruct does not throw an excepti= on > I see a call to the interceptors @PostConstruct method... > > I was not however able to catch any exception thrown by the @PostConstruc= t > method as you show in your example (I also had to remove the checked > exception and set void as a return type in the interceptor method to be a= ble > to pass the verification) > > Did I misundertand you or is it not possible to catch exceptions thrown i= n > the @PostConstruct in the same was as exceptions thrown from a business > method? > > Regards > Fredrik > > > > > On Thu, Feb 6, 2014 at 12:07 PM, Romain Manni-Bucau > wrote: >> >> not using interceptor spec AFAIK but constructors shouldn't throw an >> exception, it should be in a @PostConstruct: >> >> @CatchMe >> @Interceptor >> public class Inter { >> @PostConstruct >> public Object post(final InvocationContext ic) throws Exception { >> System.out.println(">>> ok"); >> System.out.println(">>> ok"); >> System.out.println(">>> ok"); >> System.out.println(">>> ok"); >> try { >> return ic.proceed(); >> } catch (Exception e) { >> e.printStackTrace(); >> return null; >> } >> } >> } >> >> >> @CatchMe >> public class Foo { >> @PostConstruct >> public void Foo() { >> throw new RuntimeException(); >> } >> >> public void run() {} >> } >> >> Romain Manni-Bucau >> Twitter: @rmannibucau >> Blog: http://rmannibucau.wordpress.com/ >> LinkedIn: http://fr.linkedin.com/in/rmannibucau >> Github: https://github.com/rmannibucau >> >> >> >> 2014-02-06 Lars-Fredrik Smedberg : >> > so there is no need to call ic.proceed either then? >> > >> > Is there any way to intercept the exceptions thrown from the >> > @PostConstruct >> > method in the same way I can with business methods....? >> > >> > Regards >> > Fredrik >> > >> > >> > On Thu, Feb 6, 2014 at 11:59 AM, Romain Manni-Bucau >> > >> > wrote: >> >> >> >> after the bean construction so it will likely not work >> >> Romain Manni-Bucau >> >> Twitter: @rmannibucau >> >> Blog: http://rmannibucau.wordpress.com/ >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau >> >> Github: https://github.com/rmannibucau >> >> >> >> >> >> >> >> 2014-02-06 Lars-Fredrik Smedberg : >> >> > Hi Romain >> >> > >> >> > Maybe I misunderstood something about the use of it... some >> >> > questions: >> >> > >> >> > 1. When is the interceptor method called? Before the @PostConstruct >> >> > method >> >> > of the target bean I assume? >> >> > 2. Do I need to call ic.proceed() for the target been method to be >> >> > called? >> >> > >> >> > I'm looking for a way to intercept any runtime exceptions thrown by >> >> > the >> >> > @PostContstruct method of the target bean. >> >> > >> >> > Regards >> >> > Fredrik >> >> > >> >> > >> >> > >> >> > On Thu, Feb 6, 2014 at 11:50 AM, Romain Manni-Bucau >> >> > >> >> > wrote: >> >> >> >> >> >> seems it works for me: >> >> >> >> >> >> @CatchMe >> >> >> @Interceptor >> >> >> public class Inter { >> >> >> @PostConstruct >> >> >> public void post(final InvocationContext ic) { >> >> >> System.out.println(">>> ok"); >> >> >> System.out.println(">>> ok"); >> >> >> System.out.println(">>> ok"); >> >> >> System.out.println(">>> ok"); >> >> >> } >> >> >> } >> >> >> >> >> >> >> >> >> @InterceptorBinding >> >> >> @Target(ElementType.TYPE) >> >> >> @Retention(RetentionPolicy.RUNTIME) >> >> >> public @interface CatchMe { >> >> >> } >> >> >> >> >> >> >> >> >> Romain Manni-Bucau >> >> >> Twitter: @rmannibucau >> >> >> Blog: http://rmannibucau.wordpress.com/ >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau >> >> >> Github: https://github.com/rmannibucau >> >> >> >> >> >> >> >> >> >> >> >> 2014-02-06 Lars-Fredrik Smedberg : >> >> >> > Hi Romain >> >> >> > >> >> >> > In the Interceptor I tried: >> >> >> > >> >> >> > @PostConstruct >> >> >> > public void interceptPostConstructMethod(InvocationContext ctx) = { >> >> >> > ... >> >> >> > } >> >> >> > >> >> >> > >> >> >> > On Thu, Feb 6, 2014 at 11:08 AM, Romain Manni-Bucau >> >> >> > >> >> >> > wrote: >> >> >> >> >> >> >> >> Hi >> >> >> >> >> >> >> >> what's the signature you used for your @PostContruct method? >> >> >> >> Romain Manni-Bucau >> >> >> >> Twitter: @rmannibucau >> >> >> >> Blog: http://rmannibucau.wordpress.com/ >> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau >> >> >> >> Github: https://github.com/rmannibucau >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> 2014-02-06 Lars-Fredrik Smedberg : >> >> >> >> > Hi >> >> >> >> > >> >> >> >> > When looking at >> >> >> >> > http://docs.oracle.com/javaee/6/tutorial/doc/gkigq.html >> >> >> >> > it >> >> >> >> > looks like I could create an Interceptor with a method >> >> >> >> > annotated >> >> >> >> > @PostConstruct which would get called when the annotated targ= et >> >> >> >> > class >> >> >> >> > @PostConstruct annoted method is called. >> >> >> >> > >> >> >> >> > I cannot get this to work, however an Interceptor having a >> >> >> >> > method >> >> >> >> > annotated >> >> >> >> > @AroundInvoke works fine when calling business methods in the >> >> >> >> > annotated >> >> >> >> > target class. >> >> >> >> > >> >> >> >> > Can anyone point me in the right direction to get it to work >> >> >> >> > (or >> >> >> >> > maybe >> >> >> >> > tell >> >> >> >> > it is not supposed to work as I think it should :)) >> >> >> >> > >> >> >> >> > Regards >> >> >> >> > Fredrik >> >> >> >> > >> >> >> >> > -- >> >> >> >> > Med v=E4nlig h=E4lsning / Best regards >> >> >> >> > >> >> >> >> > Lars-Fredrik Smedberg >> >> >> >> > >> >> >> >> > STATEMENT OF CONFIDENTIALITY: >> >> >> >> > The information contained in this electronic message and any >> >> >> >> > attachments to this message are intended for the exclusive us= e >> >> >> >> > of >> >> >> >> > the >> >> >> >> > address(es) and may contain confidential or privileged >> >> >> >> > information. >> >> >> >> > If >> >> >> >> > you are not the intended recipient, please notify Lars-Fredri= k >> >> >> >> > Smedberg >> >> >> >> > immediately at itsmeden@gmail.com, and destroy all copies of >> >> >> >> > this >> >> >> >> > message and any attachments. >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > -- >> >> >> > Med v=E4nlig h=E4lsning / Best regards >> >> >> > >> >> >> > Lars-Fredrik Smedberg >> >> >> > >> >> >> > STATEMENT OF CONFIDENTIALITY: >> >> >> > The information contained in this electronic message and any >> >> >> > attachments to this message are intended for the exclusive use o= f >> >> >> > the >> >> >> > address(es) and may contain confidential or privileged >> >> >> > information. >> >> >> > If >> >> >> > you are not the intended recipient, please notify Lars-Fredrik >> >> >> > Smedberg >> >> >> > immediately at itsmeden@gmail.com, and destroy all copies of thi= s >> >> >> > message and any attachments. >> >> > >> >> > >> >> > >> >> > >> >> > -- >> >> > Med v=E4nlig h=E4lsning / Best regards >> >> > >> >> > Lars-Fredrik Smedberg >> >> > >> >> > STATEMENT OF CONFIDENTIALITY: >> >> > The information contained in this electronic message and any >> >> > attachments to this message are intended for the exclusive use of t= he >> >> > address(es) and may contain confidential or privileged information. >> >> > If >> >> > you are not the intended recipient, please notify Lars-Fredrik >> >> > Smedberg >> >> > immediately at itsmeden@gmail.com, and destroy all copies of this >> >> > message and any attachments. >> > >> > >> > >> > >> > -- >> > Med v=E4nlig h=E4lsning / Best regards >> > >> > Lars-Fredrik Smedberg >> > >> > STATEMENT OF CONFIDENTIALITY: >> > The information contained in this electronic message and any >> > attachments to this message are intended for the exclusive use of the >> > address(es) and may contain confidential or privileged information. If >> > you are not the intended recipient, please notify Lars-Fredrik Smedber= g >> > immediately at itsmeden@gmail.com, and destroy all copies of this >> > message and any attachments. > > > > > -- > Med v=E4nlig h=E4lsning / Best regards > > Lars-Fredrik Smedberg > > STATEMENT OF CONFIDENTIALITY: > The information contained in this electronic message and any > attachments to this message are intended for the exclusive use of the > address(es) and may contain confidential or privileged information. If > you are not the intended recipient, please notify Lars-Fredrik Smedberg > immediately at itsmeden@gmail.com, and destroy all copies of this > message and any attachments.