Gio
Gio

Reputation: 33

Get input value to ejb 3.1 throw interceptor

Do you know if there is any way to log, throw an interceptor, the input values of the called method?

my actual interceptor is

public class Interceptor {
@AroundInvoke
public Object interceptor(InvocationContext invocationcontext) throws Exception{
    //Stampa prima del metodo
    long startTime = System.currentTimeMillis();
    log.debug("Invoked method: "+invocationcontext.getMethod().getName());
    //here I would like to log also parameters. 
    try{
        return invocationcontext.proceed();
    } finally{
        log.debug("End of method: " + invocationcontext.getMethod().getName());
        log.debug(" duration: " + (System.currentTimeMillis() - startTime));
    }
}
}

The bean is

@Interceptors({Interceptor.class})

@Stateless public class MrBean implements MrBeanRemote, MrBeanLocal {

/**
 * Default constructor. 
 */
public MrBean() {       
}

public void print(String in){
    System.out.println("Print: " + in);
}
}

So if i call the print method with in = "print that" the interceptor should log "print that". Is it possible? Thanks in advance

Upvotes: 0

Views: 385

Answers (1)

Cédric O.
Cédric O.

Reputation: 101

You want to log the parameters of your method, so you can use the getParameters() method on the InvocationContext : http://docs.oracle.com/javaee/6/api/javax/interceptor/InvocationContext.html#getParameters()

Upvotes: 1

Related Questions