hstaudacher / osgi-jax-rs-connector

An OSGi - JAX-RS 2.0 Connector, software repository available on the link below
http://hstaudacher.github.io/osgi-jax-rs-connector
Other
190 stars 98 forks source link

Add functionality to register JAX RS components to the Client (JAX RS consumer) #13

Closed glatuske closed 10 years ago

glatuske commented 10 years ago

The JAX RS consumer should provide a functionality to register JAX RS components (e.g. HttpBasicAuthFilter) to the Client.

There are at least two possibilites:

1) The components can be added to the custom providers array in the ConsumerFactory. ResourceInvocationHandler.registerProviders() must not throw IllegalArgumentException. A new method ResourceInvocationHandler.registerComponents() will add the components to the created client.

2) The CosumerFactory provides a method to create e.g. a ConsumerHolder. The ConsumerHolder allows acces to the JAX RS Client and the service proxy.

The first possiblity is quite easy to use but does not allow to register all kind of components (e.g. it is not possible to set the priority).

The second possibility is more flexible, but a bit more complex to use.

glatuske commented 10 years ago

public class ConsumerHolder {

private ResourceInvocationHandler resourceInvocationHandler;
private Object                    proxy;

public ConsumerHolder(ResourceInvocationHandler resourceInvocationHandler, Object proxy) {
    this.resourceInvocationHandler = resourceInvocationHandler;
    this.proxy = proxy;
    }

public Client getClient() {
    return this.resourceInvocationHandler.getClient();
    }

@SuppressWarnings("unchecked")
public T getConsumer() {
    return (T)this.proxy;
    }
}
hstaudacher commented 10 years ago

The ConsumerHolder approach sounds good but I can't implement it. It would break the current API because the create methods from the ConsumerFactory returning the proxy objects. So, this is a dead end.

In JAX-RS 2.0 client API an Interface was added called Configuration. This can be used to configure the Client objects. I have added another createConsumer method that takes such a Configuration. The default implementation of the configuration is a jersey ClientConfig. On such a configuration any type of component can be registered and any property can be set. I think this solution is sufficient for the moment. Do you agree?

glatuske commented 10 years ago

That sounds good. I will test 3.1 tomorrow.