mirror of https://github.com/apache/jclouds.git
Adding support for @Path and @PathParam to delegate methods to RestAnnotationProcessor
This commit is contained in:
parent
c47017e640
commit
4008407de3
|
@ -409,7 +409,9 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
this.caller = caller;
|
||||
try {
|
||||
callerEndpoint = getEndpointFor(caller.getMethod(), caller.getArgs(), injector);
|
||||
UriBuilder builder = uriBuilderProvider.get().uri(getEndpointFor(caller.getMethod(), caller.getArgs(), injector));
|
||||
Multimap<String, String> tokenValues = addPathAndGetTokens(caller.getMethod().getDeclaringClass(), caller.getMethod(), caller.getArgs(), builder);
|
||||
callerEndpoint = builder.buildFromEncodedMap(Maps2.convertUnsafe(tokenValues));
|
||||
} catch (IllegalStateException e) {
|
||||
} catch (ExecutionException e) {
|
||||
Throwables.propagate(e);
|
||||
|
@ -785,7 +787,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public static URI addHostIfMissing(URI original, URI withHost) {
|
||||
checkNotNull(withHost, "URI witHost cannot be null");
|
||||
checkNotNull(withHost, "URI withHost cannot be null");
|
||||
checkArgument(withHost.getHost() != null, "URI withHost must have host:" + withHost);
|
||||
|
||||
if (original == null)
|
||||
|
|
|
@ -223,6 +223,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@Delegate
|
||||
public Optional<Callee> getOptionalCallee(@EndpointParam URI endpoint);
|
||||
|
||||
@Delegate
|
||||
@Path("/testing/testing/{wibble}")
|
||||
public Callee getCalleeWithPath(@EndpointParam URI endpoint, @PathParam("wibble") String wibble);
|
||||
}
|
||||
|
||||
@Timeout(duration = 10, timeUnit = TimeUnit.NANOSECONDS)
|
||||
|
@ -253,6 +257,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@Delegate
|
||||
public Optional<AsyncCallee> getOptionalCallee(@EndpointParam URI endpoint);
|
||||
|
||||
@Delegate
|
||||
@Path("/testing/testing/{wibble}")
|
||||
public AsyncCallee getCalleeWithPath(@EndpointParam URI endpoint, @PathParam("wibble") String wibble);
|
||||
}
|
||||
|
||||
public void testAsyncDelegateIsLazyLoadedAndRequestIncludesVersionAndPath() throws InterruptedException,
|
||||
|
@ -330,6 +338,30 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
}
|
||||
|
||||
public void testAsyncDelegateWithPathParamIsLazyLoadedAndRequestIncludesEndpointVersionAndPath() throws InterruptedException,
|
||||
ExecutionException {
|
||||
Injector child = injectorForCaller(new HttpCommandExecutorService() {
|
||||
|
||||
@Override
|
||||
public Future<HttpResponse> submit(HttpCommand command) {
|
||||
assertEquals(command.getCurrentRequest().getRequestLine(), "GET http://howdyboys/testing/testing/thepathparam/client/1/foo HTTP/1.1");
|
||||
return Futures.immediateFuture(HttpResponse.builder().build());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
try {
|
||||
child.getInstance(AsyncCallee.class);
|
||||
assert false : "Callee shouldn't be bound yet";
|
||||
} catch (ConfigurationException e) {
|
||||
|
||||
}
|
||||
|
||||
child.getInstance(AsyncCaller.class).getCalleeWithPath(URI.create("http://howdyboys"), "thepathparam").onePath("foo").get();
|
||||
|
||||
assertEquals(child.getInstance(AsyncCaller.class).getURI(), URI.create("http://localhost:1111"));
|
||||
}
|
||||
|
||||
public void testAsyncDelegateIsLazyLoadedAndRequestIncludesEndpointVersionAndPathOptionalPresent()
|
||||
throws InterruptedException, ExecutionException {
|
||||
Injector child = injectorForCaller(new HttpCommandExecutorService() {
|
||||
|
|
Loading…
Reference in New Issue