How to replace DefaultRequestExecution.class in VRaptor3

5 respostas
H

hi,all

As we know DefaultRequestExecution class responsible for the request execution process,

but I want to change the default execution process,

I implemented the RequestExecution interface, but how can I register to the framework to use my

own RequestExecution.

any idea, pls give me, thank you all.

5 Respostas

G

Hi haiker.

You can override any vraptor3 component. DefaultRequestExecution too. Vraptor scan all classes avaliable in you classes and check if has the annotation @Component and override with satisfy the dependency.

You can do this code bellow. I was implements the interface RequestExecution to change execution proccess. As you see I comment the MultipartInterceptor and create a customized ExecuteMethodInterceptor.

@Component
@RequestScoped
public class CustomRequestExecution
    implements RequestExecution {
    private final InterceptorStack interceptorStack;
    private final InstantiateInterceptor instantiator;

    public CustomRequestExecution(InterceptorStack interceptorStack, InstantiateInterceptor instantiator) {
        this.interceptorStack = interceptorStack;
        this.instantiator = instantiator;
    }

    public void execute()
        throws InterceptionException {
        interceptorStack.add(ResourceLookupInterceptor.class);
        interceptorStack.add(FlashInterceptor.class);
        interceptorStack.add(InterceptorListPriorToExecutionExtractor.class);
        // interceptorStack.add(MultipartInterceptor.class);
        interceptorStack.add(instantiator);
        interceptorStack.add(ParametersInstantiatorInterceptor.class);
        interceptorStack.add(CustomExecuteMethodInterceptor.class);
        interceptorStack.add(OutjectResult.class);
        interceptorStack.add(DownloadInterceptor.class);
        interceptorStack.add(ForwardToDefaultViewInterceptor.class);
        interceptorStack.next(null, null);
    }
}

Regards

Lucas_Cavalcanti

you can implement your class like garcia-jj said, but eventually you will get a NullPointerException when forwarding to a page that doesn’t exist.

It is a bug, that is already fixed, but this fix was not released yet. When the new version (3.0.3) is available, you must change @RequestScoped to @PrototypeScoped.

Regardds

G

Lucas, what’s the prototype scope?

Regards

H

thank you all for your warmhearted help~

is there any English documents about VRaptor3!

I’m a Chinese, so I can only understand English as a foreign language.

but I still very pleased every question I asked have been replied. :slight_smile:

Lucas_Cavalcanti

here: http://vraptor.caelum.com.br/en

keep asking :wink:

@garcia-jj
a prototype scope component is instantiated every time it is needed… No two components share the same instance of a prototype scoped component.

Criado 10 de dezembro de 2009
Ultima resposta 10 de dez. de 2009
Respostas 5
Participantes 3