How do I call the intercept() method of an Intercept class, in another project method?

Asked

Viewed 205 times

1

All right, guys?

Well, I’m having a hard time and I’d like a little help.

I have the following method from my Acessarintercept class:

@Intercepts
@RequestScoped
public class AcessarIntercept {
    @AroundCall
    public void intercepta(SimpleInterceptorStack stack) {
        // Conteúdo do método que redireciona a página
        // após fazer as verificações de interceptação.
    }

}

And I would like to invoke that method in my Controller or another class. How do I do that?

  • I didn’t quite understand your question, it wouldn’t just be to insert the class into an object and call the intercept, it would be?

1 answer

2


Correction

You could pass as parameter of your constructor the instantiation of the class you want to run:

public class Controller {
     private AcessarIntercept acessar;

     public Controller(AcessarIntercept acessar) {
         this.acessar = acessar; 
     }
}

And so execute your method with acessar.intercept(). Just remember to allocate memory to your "access" object before creating your Controller.

  • I just don’t understand the part "Just remember to allocate memory before creating your Controller.", since Java has automatic memory management and there is nothing the programmer needs to do for it.

  • 1

    Java manages memory displacement through the Garbage Collector, the allocation part is performed by the programmer when using the new operator. Basically said not to forget to allocate the "access" object that you pass as constructor parameter.

  • 1

    I mean, what you meant to say is that it’s not to pass null in the builder. A Objects.requireNonNull(acessar); or a if (acessar == null) throw new IllegalArgumentException(); at the beginning of the builder would solve this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.