Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

AroundInvoke

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package pack;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

public class AccountCreatorLogger {


@PostConstruct
public void initialize(InvocationContext ic) throws Exception{
System.out.println("Entering the method name " + ic.getMethod().getName());
System.out.println("Getting the parameters " + ic.getParameters());
System.out.println("Getting the target " + ic.getTarget());
System.out.println("Getting the context data " + ic.getContextData());
ic.proceed();
}

@PreDestroy
public void cleanUp(InvocationContext context){

}




@AroundInvoke
public Object logMethodEntry(InvocationContext ic)throws Exception{
System.out.println("Entering the method name " + ic.getMethod().getName());
System.out.println("Getting the parameters " + ic.getParameters());
System.out.println("Getting the target " + ic.getTarget());
System.out.println("Getting the context data " + ic.getContextData());
return ic.proceed();


}
}

-------------
my doubt here is why do the compiler complain's if i add annotated method @AroundInvoke before @PostConstruct or @PreDestroy.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

my doubt here is why do the compiler complain's if i add annotated method @AroundInvoke before @PostConstruct or @PreDestroy.


Are you using an IDE ? It should not be a problem to declare it before the others.
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, i am using an Eclipse IDE.

Christophe how you do normally run in your code in IDE or where ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Eclipse, and have no compile error with this interceptor, whether AroundInvoke is before or after PostConstruct. What compile error do you have ?
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christophe,

if i use like this in order

-------------
@AroundInvoke
public Object logMethodEntry(InvocationContext ic)throws Exception{
System.out.println("Entering the method name " + ic.getMethod().getName());
System.out.println("Getting the parameters " + ic.getParameters());
System.out.println("Getting the target " + ic.getTarget());
System.out.println("Getting the context data " + ic.getContextData());

return ic.proceed();

@PostConstruct
public void initialize(InvocationContext ic) throws Exception{
System.out.println("@PostConstruct Entering the method name " + ic.getMethod().getName());
System.out.println("Getting the parameters " + ic.getParameters());
System.out.println("Getting the target " + ic.getTarget());
System.out.println("Getting the context data " + ic.getContextData());
ic.proceed();
}

@PreDestroy
public void cleanUp(InvocationContext ic) throws Exception{
System.out.println("@PreDestroy Entering the method name " + ic.getMethod().getName());
System.out.println("Getting the parameters " + ic.getParameters());
System.out.println("Getting the target " + ic.getTarget());
System.out.println("Getting the context data " + ic.getContextData());
ic.proceed();
}
-------------------------

the complier complains about the following error's


1) public void initialize(InvocationContext ic) throws Exception{

void is an invalid type for the variable initialize

2) public void cleanUp(InvocationContext ic) throws Exception{

Syntax error on token "(", ; expected
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amandeep Singh:
Christophe,

if i use like this in order

-------------
@AroundInvoke
public Object logMethodEntry(InvocationContext ic)throws Exception{
System.out.println("Entering the method name " + ic.getMethod().getName());
System.out.println("Getting the parameters " + ic.getParameters());
System.out.println("Getting the target " + ic.getTarget());
System.out.println("Getting the context data " + ic.getContextData());

return ic.proceed();

@PostConstruct
public void initialize(InvocationContext ic) throws Exception{
System.out.println("@PostConstruct Entering the method name " + ic.getMethod().getName());
System.out.println("Getting the parameters " + ic.getParameters());
System.out.println("Getting the target " + ic.getTarget());
System.out.println("Getting the context data " + ic.getContextData());
ic.proceed();
}

@PreDestroy
public void cleanUp(InvocationContext ic) throws Exception{
System.out.println("@PreDestroy Entering the method name " + ic.getMethod().getName());
System.out.println("Getting the parameters " + ic.getParameters());
System.out.println("Getting the target " + ic.getTarget());
System.out.println("Getting the context data " + ic.getContextData());
ic.proceed();
}
-------------------------

the complier complains about the following error's


1) public void initialize(InvocationContext ic) throws Exception{

void is an invalid type for the variable initialize

2) public void cleanUp(InvocationContext ic) throws Exception{

Syntax error on token "(", ; expected



I dont see the method close of AroundInvoke. may be you have missed it when you copy to here.

I tested in my end without any issue. post the whole code and full stactrace.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You forgot to close the logMethodEntry method.
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry guys, i did such a silly mistake, as everytime i copied the logMethodEntry method evrytime, it's curly brace was down over the screen, i forget to copy.

Can you imagine such a silly mistake can be done by a person who has cleared the SCWCD and is doing preparation for the SCBCD.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A certificate can't face to realworld problem. Only experience can

i passed both scjp and wcd without writing any code at all. i wanted do that for bcd as well. but transaction and exception was doubtful, so i had to write some test code.

and mistakes everywhere whether certified or experienced.. so dont worry abt those..
reply
    Bookmark Topic Watch Topic
  • New Topic