Skip to content

Commit

Permalink
Initial implementation of JAX_RS_SPEC-523 and changes to rely on RxIn…
Browse files Browse the repository at this point in the history
…vokerProvider for using a custom RxInvoker
  • Loading branch information
asoldano committed Apr 21, 2017
1 parent f79a70a commit 994080d
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jboss.resteasy.client.jaxrs.internal.ClientConfiguration;
import org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.spi.NotImplementedYetException;
import org.jboss.resteasy.spi.ResteasyProviderFactory;

import javax.net.ssl.HostnameVerifier;
Expand All @@ -48,6 +49,7 @@
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -128,7 +130,9 @@ public ResteasyClientBuilder providerFactory(ResteasyProviderFactory providerFac
*
* @param asyncExecutor
* @return
* @deprecated use {@link ResteasyClientBuilder#executorService(ExecutorService)} instead
*/
@Deprecated
public ResteasyClientBuilder asyncExecutor(ExecutorService asyncExecutor)
{
return asyncExecutor(asyncExecutor, false);
Expand Down Expand Up @@ -674,4 +678,16 @@ public ResteasyClientBuilder withConfig(Configuration config)
}
return this;
}

@Override
public ClientBuilder executorService(ExecutorService executorService)
{
return asyncExecutor(executorService, false);
}

@Override
public ClientBuilder scheduledExecutorService(ScheduledExecutorService scheduledExecutorService)
{
throw new NotImplementedYetException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public interface Messages
@Message(id = BASE + 150, value = "templateValues was null")
String templateValuesWasNull();

@Message(id = BASE + 152, value = "Unable to instantation: %s")
@Message(id = BASE + 152, value = "Unable to create new instance of %s")
String unableToInstantiate(Class<?> clazz);

@Message(id = BASE + 155, value = "Unable to invoke request")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import javax.ws.rs.RuntimeType;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.client.RxInvoker;
import javax.ws.rs.client.RxInvokerProvider;
import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.core.Configurable;
import javax.ws.rs.core.Configuration;
Expand All @@ -19,7 +21,6 @@
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Providers;
import javax.ws.rs.ext.ReaderInterceptor;
import javax.ws.rs.ext.RuntimeDelegate;
import javax.ws.rs.ext.WriterInterceptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
Expand Down Expand Up @@ -279,4 +280,9 @@ public Map<Class<?>, Integer> getContracts(Class<?> componentClass)
{
return providerFactory.getContracts(componentClass);
}

public <I extends RxInvoker<?>> RxInvokerProvider<I> getRxInvokerProvider(Class<I> clazz)
{
return providerFactory.getRxInvokerProvider(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.RxInvoker;
import javax.ws.rs.client.RxInvokerProvider;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.Locale;
import java.util.concurrent.ExecutorService;

/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
* @version $Revision: 1 $
*/
public class ClientInvocationBuilder implements Invocation.Builder
Expand Down Expand Up @@ -319,58 +319,34 @@ public Invocation.Builder property(String name, Object value)
@Override
public CompletionStageRxInvoker rx()
{
return new CompletionStageRxInvokerImpl(this);
return new CompletionStageRxInvokerImpl(this, invocation.getClient().asyncInvocationExecutor());
}

@Override
public CompletionStageRxInvoker rx(ExecutorService executorService)
public <T extends RxInvoker> T rx(Class<T> clazz)
{
return new CompletionStageRxInvokerImpl(this, executorService);
RxInvokerProvider<T> provider = invocation.getClientConfiguration().getRxInvokerProvider(clazz);
if (provider == null) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiate(clazz));
}
return provider.getRxInvoker(this, invocation.getClient().asyncInvocationExecutor());
}

@Override
public <T extends RxInvoker> T rx(Class<T> clazz)
public Response patch()
{
try
{
return clazz.getConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e)
{
throw new RuntimeException(Messages.MESSAGES.unableToInstantiate(clazz), e);
}
throw new NotImplementedYetException();
}

@Override
public <T extends RxInvoker> T rx(Class<T> clazz, ExecutorService executorService)
public <T> T patch(Class<T> responseType)
{
try
{
return clazz.getConstructor(ExecutorService.class).newInstance(executorService);
}
catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e)
{
throw new RuntimeException(Messages.MESSAGES.unableToInstantiate(clazz), e);
}
throw new NotImplementedYetException();
}

@Override
public Response patch() {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> T patch(Class<T> responseType) {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> T patch(GenericType<T> responseType) {
// TODO Auto-generated method stub
return null;
}
@Override
public <T> T patch(GenericType<T> responseType)
{
throw new NotImplementedYetException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,30 @@

import javax.ws.rs.client.CompletionStageRxInvoker;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.SyncInvoker;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.spi.NotImplementedYetException;

/**
*
* @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
* @date March 9, 2016
*/
public class CompletionStageRxInvokerImpl implements CompletionStageRxInvoker
{
private Builder builder;

private ExecutorService executor;

public CompletionStageRxInvokerImpl()
{
}
private final SyncInvoker builder;

public CompletionStageRxInvokerImpl(ExecutorService executor)
{
this.executor = executor;
}
private final ExecutorService executor;

public CompletionStageRxInvokerImpl(ClientInvocationBuilder builder)
public CompletionStageRxInvokerImpl(SyncInvoker builder)
{
this.builder = builder;
this(builder, null);
}

public CompletionStageRxInvokerImpl(ClientInvocationBuilder builder, ExecutorService executor)
public CompletionStageRxInvokerImpl(SyncInvoker builder, ExecutorService executor)
{
this.builder = builder;
this.executor = executor;
Expand Down Expand Up @@ -365,43 +359,26 @@ public <T> CompletionStage<T> method(String name, Entity<?> entity, GenericType<
}
}

public Builder getBuilder()
public ExecutorService getExecutor()
{
return builder;
return executor;
}

public CompletionStageRxInvoker builder(Builder builder)
@Override
public CompletionStage<Response> patch()
{
this.builder = builder;
return this;
throw new NotImplementedYetException();
}

public ExecutorService getExecutor()
@Override
public <T> CompletionStage<T> patch(Class<T> responseType)
{
return executor;
throw new NotImplementedYetException();
}

public CompletionStageRxInvoker executor(ExecutorService executor)
@Override
public <T> CompletionStage<T> patch(GenericType<T> responseType)
{
this.executor = executor;
return this;
throw new NotImplementedYetException();
}

@Override
public CompletionStage<Response> patch() {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> CompletionStage<T> patch(Class<T> responseType) {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> CompletionStage<T> patch(GenericType<T> responseType) {
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.jboss.resteasy.util.PickConstructor;
import org.jboss.resteasy.util.ThreadLocalStack;
import org.jboss.resteasy.util.Types;
import org.jboss.resteasy.resteasy_jaxrs.i18n.*;

import javax.annotation.Priority;
import javax.ws.rs.ConstrainedTo;
Expand All @@ -39,6 +38,8 @@
import javax.ws.rs.RuntimeType;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.client.RxInvoker;
import javax.ws.rs.client.RxInvokerProvider;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.DynamicFeature;
Expand Down Expand Up @@ -73,6 +74,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
Expand Down Expand Up @@ -1581,6 +1583,11 @@ protected void processProviderContracts(Class provider, Integer priorityOverride
newContracts.put(Feature.class, priority);

}
if (isA(provider, RxInvokerProvider.class, contracts))
{
int priority = getPriority(priorityOverride, contracts, RxInvokerProvider.class, provider);
newContracts.put(RxInvokerProvider.class, priority);
}
}

/**
Expand Down Expand Up @@ -2387,4 +2394,16 @@ public Link.Builder createLinkBuilder()
{
return new LinkBuilderImpl();
}

public <I extends RxInvoker> RxInvokerProvider<I> getRxInvokerProvider(Class<I> clazz) {
for (Entry<Class<?>, Map<Class<?>, Integer>> entry : classContracts.entrySet()) {
if (entry.getValue().containsKey(RxInvokerProvider.class)) {
RxInvokerProvider<?> rip = (RxInvokerProvider<?>)createProviderInstance(entry.getKey());
if (rip.isProviderFor(clazz)) {
return (RxInvokerProvider<I>)rip;
}
}
}
return null;
}
}

0 comments on commit 994080d

Please sign in to comment.