mirror of https://github.com/apache/jclouds.git
fixed built-in http client
This commit is contained in:
parent
0a769ca6f5
commit
1df15209ec
|
@ -47,6 +47,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
String container = getContainerName();
|
||||
try {
|
||||
context.getBlobStore().putBlob(container, blob);
|
||||
assertConsistencyAwareContainerSize(container, 1);
|
||||
HttpRequest request = context.getSigner().signRemoveBlob(container, name);
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
context.utils().http().invoke(request);
|
||||
|
@ -67,6 +68,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
String container = getContainerName();
|
||||
try {
|
||||
context.getBlobStore().putBlob(container, blob);
|
||||
assertConsistencyAwareContainerSize(container, 1);
|
||||
HttpRequest request = context.getSigner().signGetBlob(container, name);
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
assertEquals(Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput()), text);
|
||||
|
@ -88,7 +90,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
HttpRequest request = context.getSigner().signPutBlob(container, blob);
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput());
|
||||
assert context.getBlobStore().blobExists(container, name);
|
||||
assertConsistencyAwareContainerSize(container, 1);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
}
|
||||
|
|
|
@ -435,6 +435,8 @@ public class RestAnnotationProcessor<T> {
|
|||
Multimap<String, String> queryParams = addQueryParams(tokenValues.entries(), method, args);
|
||||
Multimap<String, String> matrixParams = addMatrixParams(tokenValues.entries(), method, args);
|
||||
Multimap<String, String> headers = buildHeaders(tokenValues.entries(), method, args);
|
||||
if (r != null)
|
||||
headers.putAll(r.getHeaders());
|
||||
|
||||
if (shouldAddHostHeader(method))
|
||||
headers.put(HOST, endpoint.getHost());
|
||||
|
|
|
@ -209,8 +209,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDelegateAsyncIncludesVersion() throws SecurityException, NoSuchMethodException, InterruptedException,
|
||||
ExecutionException {
|
||||
public void testDelegateAsyncIncludesVersion() throws SecurityException, NoSuchMethodException,
|
||||
InterruptedException, ExecutionException {
|
||||
Injector child = injectorForClient();
|
||||
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
||||
|
||||
|
@ -224,8 +224,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
AsyncCaller caller = child.getInstance(AsyncCaller.class);
|
||||
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/1/foo HTTP/1.1"), eq(function))).andReturn(
|
||||
createNiceMock(ListenableFuture.class)).atLeastOnce();
|
||||
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/1/foo HTTP/1.1"), eq(function)))
|
||||
.andReturn(createNiceMock(ListenableFuture.class)).atLeastOnce();
|
||||
replay(mock);
|
||||
|
||||
caller.getCallee().onePath("foo");
|
||||
|
@ -268,8 +268,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
Caller caller = child.getInstance(Caller.class);
|
||||
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/1/foo HTTP/1.1"), eq(function))).andReturn(
|
||||
Futures.<Void> immediateFuture(null)).atLeastOnce();
|
||||
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/1/foo HTTP/1.1"), eq(function)))
|
||||
.andReturn(Futures.<Void> immediateFuture(null)).atLeastOnce();
|
||||
replay(mock);
|
||||
|
||||
caller.getCallee().onePath("foo");
|
||||
|
@ -281,8 +281,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
private Injector injectorForClient() {
|
||||
|
||||
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo",
|
||||
null, Caller.class, AsyncCaller.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new CallerCalleeModule()));
|
||||
null, Caller.class, AsyncCaller.class, ImmutableSet.<Module> of(new MockModule(),
|
||||
new NullLoggingModule(), new CallerCalleeModule()));
|
||||
|
||||
return createContextBuilder(contextSpec).buildInjector();
|
||||
|
||||
|
@ -836,8 +836,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -852,8 +852,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -868,8 +868,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -979,9 +979,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
public void testRequestFilterOverrideOnRequest() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestRequestFilter.class.getMethod("getOverride", HttpRequest.class);
|
||||
HttpRequest request = factory(TestRequestFilter.class).createRequest(method,
|
||||
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build());
|
||||
HttpRequest request = factory(TestRequestFilter.class).createRequest(
|
||||
method,
|
||||
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).headers(
|
||||
ImmutableMultimap.of("foo", "bar")).build());
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class);
|
||||
}
|
||||
|
||||
|
@ -1224,8 +1227,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@Test
|
||||
public void testQueryInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneQuery = TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class);
|
||||
String query = factory(TestQueryReplace.class)
|
||||
.createRequest(oneQuery, new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery,
|
||||
new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1321,8 +1324,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
Method twoQuerysOutOfOrder = TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class);
|
||||
String query = factory(TestQueryReplace.class)
|
||||
.createRequest(twoQuerysOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
||||
String query = factory(TestQueryReplace.class).createRequest(twoQuerysOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
|
@ -1336,8 +1339,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("matrixInOptions", String.class,
|
||||
TestReplaceMatrixOptions.class);
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(oneMatrix, new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix,
|
||||
new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1420,8 +1423,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
UnsupportedEncodingException {
|
||||
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
||||
String.class);
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(twoMatrixsOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixsOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
|
@ -1483,8 +1486,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(
|
||||
newInputStreamPayload(Strings2.toInputStream("whoops")));
|
||||
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newInputStreamPayload(Strings2
|
||||
.toInputStream("whoops")));
|
||||
|
||||
calculateMD5(payloadEnclosing, crypto.md5());
|
||||
HttpRequest request = factory(TestQuery.class).createRequest(method, payloadEnclosing);
|
||||
|
@ -1626,8 +1629,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
||||
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
||||
GeneratedHttpRequest<TestTransformers> request = GeneratedHttpRequest.<TestTransformers> builder().method("GET")
|
||||
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method)
|
||||
.args(new Object[] {}).build();
|
||||
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method).args(
|
||||
new Object[] {}).build();
|
||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
|
||||
assertEquals(((ReturnStringIf200Context) transformer).request, request);
|
||||
|
@ -1694,8 +1697,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 2);
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
||||
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
||||
.rfc822DateFormat(date)));
|
||||
}
|
||||
|
||||
public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
||||
|
@ -1708,8 +1711,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 2);
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
||||
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
||||
.rfc822DateFormat(date)));
|
||||
}
|
||||
|
||||
public class PrefixOptions extends BaseHttpRequestOptions {
|
||||
|
@ -2098,12 +2101,13 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
|
||||
String.class, Integer.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||
String.class, Integer.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||
new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(Localhost2.class).toInstance(URI.create("http://localhost:1111"));
|
||||
bind(URI.class).annotatedWith(Localhost2.class).toInstance(
|
||||
URI.create("http://localhost:1111"));
|
||||
}
|
||||
|
||||
}));
|
||||
|
|
Loading…
Reference in New Issue