Hello everybody!
I am trying to get the client-side interceptor working within Spring
framework.
Here are the details worth mentioning:

*1)* There is no access to the web.xml configuration file from my
module.Until recently, i have successfully used the
RestClientProxyFactoryBean registered within spring context as follows:

*<bean id="client"
class="org.jboss.resteasy.client.spring.RestClientProxyFactoryBean"
    p:serviceInterface="someInterface" p:baseUri="http://some.uri"; />*

2) But recently, for the internal purposes i have added a client-side
interceptor.
*@Provider
@ClientInterceptor
@EncoderPrecedence
public class Interceptor implements
MessageBodyWriterInterceptor,ClientExecutionInterceptor,AcceptedByMethod{

    @Override
    public void write(MessageBodyWriterContext context) throws IOException,
WebApplicationException {
        context.proceed();
    }

    @Override
    public ClientResponse execute(ClientExecutionContext ctx) throws
Exception {
        return ctx.proceed();
    }

    @Override
    public boolean accept(Class declaring, Method method) {
        return true;
    }
}*

*3) *As i have already said there is now way for me to register a provider
in the web.xml. For that reason there came a Spring BeanPostProcessor where
i get the already initialized ResteasyProviderFactory, register my
MessageBodyWriterInterceptor and return it to the context:

*public class RestClientPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String
beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String
beanName) throws BeansException {
        if(bean.getClass()==RestClientProxyFactoryBean.class &&
beanName.equals("client")){
            RestClientProxyFactoryBean restClient =
(RestClientProxyFactoryBean)bean;
            ResteasyProviderFactory providerFactory =
restClient.getResteasyProviderFactory();
            providerFactory.registerProvider(Interceptor.class);

            //Need i do here something in addition, namely somehow alter the
already initialized client proxy or something

        }
        return bean;
    }*

*4) *After that the interceptor gets sucessfully registered and appears in
the providers factory list. But, as it appeared to be after debugging the
client proxy methods do not have the newly registered interceptor, *but only
those that where registered during the default initialization*.

*5)* Continuing debugging i found out that while invoking the client proxy
method and post processing the request the method
ClientRequest#writeRequestBody being invoked which in turn refer to
getWriterInterceptors() which in turn return only the default
GZIPEncodingInterceptor because ClientInterceptorRepositoryImpl doesn't
contain my sucessfully registered interceptor.

*After all, *How do i get the interceptor which was successfully registered
programmatically within the currently initialized ResteasyProviderFactory be
invoked after each client proxy method call?

Thanx
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to