Alkis Kalogeris
Alkis Kalogeris

Reputation: 17745

Add interceptor programmatically on server

although I've searched in the documentation it seems I'm missing something. I'm publishing a web service through a configuration file. Ok the service is up and running. Now I'm trying to add some custom interceptors programmatically. Let's say the class that is my main class that has the enpoint method is called TestImpl, and the web service method testWS(). If I wanted to add ingoing and outgoing interceptors for this service where should I do that? In the constructor? How would I do that? In which provider? Service, Endpoint, Bus, Binding? Thank you for your help.

Right now I'm doing

    ServerFactoryBean serverFactoryBean = new ServerFactoryBean();

    Server server = serverFactoryBean.create();

    server.getEndpoint().getOutInterceptors().add(new CustomLoggingInInterceptor());
    server.getEndpoint().getOutInterceptors().add(new CustomLoggingOutInterceptor());   

In the constructor of my class but I'm receiving a NullPointerException in Server server = serverFactoryBean.create();

Upvotes: 0

Views: 1843

Answers (1)

Willem Jiang
Willem Jiang

Reputation: 3291

CXF support to setup the interceptors from the Bus, Binding, and endpoint.

When you call the serverFactoryBean.create(), the server is created and open for business. You can setup the intercepter directly on the serverFactoryBean before calling the create method.

BTW, you need also setup address and serviceClass() if you are using ServerFactoryBean.

Upvotes: 1

Related Questions