mirror of https://github.com/apache/jclouds.git
Issue 337: support non-standard http methods
This commit is contained in:
parent
0394c29394
commit
8efea1b42d
|
@ -29,10 +29,12 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.net.Authenticator;
|
import java.net.Authenticator;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.PasswordAuthentication;
|
import java.net.PasswordAuthentication;
|
||||||
|
import java.net.ProtocolException;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.ProxySelector;
|
import java.net.ProxySelector;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
@ -60,6 +62,7 @@ import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
import com.google.common.collect.LinkedHashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
|
@ -75,16 +78,20 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
private final HostnameVerifier verifier;
|
private final HostnameVerifier verifier;
|
||||||
|
private final Field methodField;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public JavaUrlHttpCommandExecutorService(HttpUtils utils,
|
public JavaUrlHttpCommandExecutorService(HttpUtils utils,
|
||||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
||||||
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
|
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
|
||||||
DelegatingErrorHandler errorHandler, HttpWire wire, HostnameVerifier verifier) {
|
DelegatingErrorHandler errorHandler, HttpWire wire, HostnameVerifier verifier) throws SecurityException,
|
||||||
|
NoSuchFieldException {
|
||||||
super(utils, ioWorkerExecutor, retryHandler, ioRetryHandler, errorHandler, wire);
|
super(utils, ioWorkerExecutor, retryHandler, ioRetryHandler, errorHandler, wire);
|
||||||
if (utils.getMaxConnections() > 0)
|
if (utils.getMaxConnections() > 0)
|
||||||
System.setProperty("http.maxConnections", String.valueOf(checkNotNull(utils, "utils").getMaxConnections()));
|
System.setProperty("http.maxConnections", String.valueOf(checkNotNull(utils, "utils").getMaxConnections()));
|
||||||
this.verifier = checkNotNull(verifier, "verifier");
|
this.verifier = checkNotNull(verifier, "verifier");
|
||||||
|
this.methodField = HttpURLConnection.class.getDeclaredField("method");
|
||||||
|
methodField.setAccessible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -163,7 +170,17 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
||||||
// ex. Caused by: java.io.IOException: HTTPS hostname wrong: should be
|
// ex. Caused by: java.io.IOException: HTTPS hostname wrong: should be
|
||||||
// <adriancole.s3int0.s3-external-3.amazonaws.com>
|
// <adriancole.s3int0.s3-external-3.amazonaws.com>
|
||||||
connection.setInstanceFollowRedirects(false);
|
connection.setInstanceFollowRedirects(false);
|
||||||
connection.setRequestMethod(request.getMethod().toString());
|
try {
|
||||||
|
connection.setRequestMethod(request.getMethod());
|
||||||
|
} catch (ProtocolException e) {
|
||||||
|
try {
|
||||||
|
methodField.set(connection, request.getMethod());
|
||||||
|
} catch (Exception e1) {
|
||||||
|
logger.error(e, "could not set request method: ", request.getMethod());
|
||||||
|
Throwables.propagate(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String header : request.getHeaders().keySet()) {
|
for (String header : request.getHeaders().keySet()) {
|
||||||
for (String value : request.getHeaders().get(header)) {
|
for (String value : request.getHeaders().get(header)) {
|
||||||
connection.setRequestProperty(header, value);
|
connection.setRequestProperty(header, value);
|
||||||
|
|
|
@ -64,13 +64,19 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
|
|
||||||
// TODO: filtering redirect test
|
// TODO: filtering redirect test
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testGetStringWithHeader() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetStringWithHeader() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
assertEquals(client.download("", "test").trim(), "test");
|
assertEquals(client.download("", "test").trim(), "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 1, timeOut = 5000)
|
||||||
|
public void testAlternateMethod() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
|
TimeoutException {
|
||||||
|
assertEquals(client.rowdy("").trim(), XML);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testGetString() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
public void testGetString() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.download("").trim(), XML);
|
assertEquals(client.download("").trim(), XML);
|
||||||
}
|
}
|
||||||
|
@ -80,26 +86,26 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
return new Object[][] { { "object" }, { "/path" }, { "sp ace" }, { "unic₪de" }, { "qu?stion" } };
|
return new Object[][] { { "object" }, { "/path" }, { "sp ace" }, { "unic₪de" }, { "qu?stion" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000, dataProvider = "gets")
|
@Test(invocationCount = 5, timeOut = 5000, dataProvider = "gets")
|
||||||
public void testGetStringSynch(String uri) throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetStringSynch(String uri) throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
// TODO why need trim?
|
// TODO why need trim?
|
||||||
assertEquals(client.synch(uri).trim(), XML);
|
assertEquals(client.synch(uri).trim(), XML);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testGetException() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetException() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
assertEquals(client.downloadException("", GetOptions.Builder.tail(1)).trim(), "foo");
|
assertEquals(client.downloadException("", GetOptions.Builder.tail(1)).trim(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testGetSynchException() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetSynchException() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
assertEquals(client.synchException("", "").trim(), "foo");
|
assertEquals(client.synchException("", "").trim(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testGetStringRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetStringRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
assertEquals(client.download("redirect").trim(), XML2);
|
assertEquals(client.download("redirect").trim(), XML2);
|
||||||
|
@ -128,7 +134,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false, invocationCount = 25, timeOut = 5000)
|
@Test(enabled = false, invocationCount = 5, timeOut = 5000)
|
||||||
public void testGetStringPermanentRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetStringPermanentRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
// GetString get = factory.createGetString("permanentredirect");
|
// GetString get = factory.createGetString("permanentredirect");
|
||||||
|
@ -139,12 +145,12 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
// remembered.
|
// remembered.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testPost() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
public void testPost() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.post("", "foo").trim(), "fooPOST");
|
assertEquals(client.post("", "foo").trim(), "fooPOST");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 10000)
|
@Test(invocationCount = 5, timeOut = 10000)
|
||||||
public void testPostAsInputStream() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testPostAsInputStream() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
try {
|
try {
|
||||||
|
@ -215,35 +221,35 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
assert postFailures.get() > 0;
|
assert postFailures.get() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testPostBinder() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testPostBinder() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
assertEquals(client.postJson("", "foo").trim(), "{\"key\":\"foo\"}POST");
|
assertEquals(client.postJson("", "foo").trim(), "{\"key\":\"foo\"}POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testPut() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
public void testPut() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.upload("", "foo").trim(), "fooPUT");
|
assertEquals(client.upload("", "foo").trim(), "fooPUT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testPutRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testPutRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
assertEquals(client.upload("redirect", "foo").trim(), "fooPUTREDIRECT");
|
assertEquals(client.upload("redirect", "foo").trim(), "fooPUTREDIRECT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testKillRobotSlowly() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testKillRobotSlowly() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
assertEquals(client.action("robot", "kill", ImmutableMap.of("death", "slow")).trim(), "robot->kill:{death=slow}");
|
assertEquals(client.action("robot", "kill", ImmutableMap.of("death", "slow")).trim(), "robot->kill:{death=slow}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testHead() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
public void testHead() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
||||||
assert client.exists("");
|
assert client.exists("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 5, timeOut = 5000)
|
||||||
public void testGetAndParseSax() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetAndParseSax() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
assertEquals(client.downloadAndParse(""), "whoppers");
|
assertEquals(client.downloadAndParse(""), "whoppers");
|
||||||
|
|
|
@ -20,11 +20,16 @@
|
||||||
package org.jclouds.http;
|
package org.jclouds.http;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.HEAD;
|
import javax.ws.rs.HEAD;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
|
import javax.ws.rs.HttpMethod;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
@ -53,6 +58,15 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public interface IntegrationTestAsyncClient {
|
public interface IntegrationTestAsyncClient {
|
||||||
|
@Target( { ElementType.METHOD })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@HttpMethod("ROWDY")
|
||||||
|
public @interface ROWDY {
|
||||||
|
}
|
||||||
|
|
||||||
|
@ROWDY
|
||||||
|
@Path("objects/{id}")
|
||||||
|
ListenableFuture<String> rowdy(@PathParam("id") String path);
|
||||||
|
|
||||||
@HEAD
|
@HEAD
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
|
@ -82,18 +96,15 @@ public interface IntegrationTestAsyncClient {
|
||||||
@GET
|
@GET
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
@ExceptionParser(FooOnException.class)
|
@ExceptionParser(FooOnException.class)
|
||||||
ListenableFuture<String> synchException(@PathParam("id") String id,
|
ListenableFuture<String> synchException(@PathParam("id") String id, @HeaderParam("Range") String header);
|
||||||
@HeaderParam("Range") String header);
|
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
ListenableFuture<String> upload(@PathParam("id") String id,
|
ListenableFuture<String> upload(@PathParam("id") String id, @BinderParam(BindToStringPayload.class) String toPut);
|
||||||
@BinderParam(BindToStringPayload.class) String toPut);
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
ListenableFuture<String> post(@PathParam("id") String id,
|
ListenableFuture<String> post(@PathParam("id") String id, @BinderParam(BindToStringPayload.class) String toPut);
|
||||||
@BinderParam(BindToStringPayload.class) String toPut);
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
|
@ -111,8 +122,7 @@ public interface IntegrationTestAsyncClient {
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
ListenableFuture<String> postWithMd5(@PathParam("id") String id,
|
ListenableFuture<String> postWithMd5(@PathParam("id") String id, @HeaderParam("Content-MD5") String base64MD5,
|
||||||
@HeaderParam("Content-MD5") String base64MD5,
|
|
||||||
@BinderParam(BindToFilePayload.class) File file);
|
@BinderParam(BindToFilePayload.class) File file);
|
||||||
|
|
||||||
static class BindToFilePayload implements Binder {
|
static class BindToFilePayload implements Binder {
|
||||||
|
@ -126,8 +136,7 @@ public interface IntegrationTestAsyncClient {
|
||||||
@POST
|
@POST
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
@MapBinder(BindToJsonPayload.class)
|
@MapBinder(BindToJsonPayload.class)
|
||||||
ListenableFuture<String> postJson(@PathParam("id") String id,
|
ListenableFuture<String> postJson(@PathParam("id") String id, @MapPayloadParam("key") String toPut);
|
||||||
@MapPayloadParam("key") String toPut);
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("objects/{id}/action/{action}")
|
@Path("objects/{id}/action/{action}")
|
||||||
|
@ -137,8 +146,7 @@ public interface IntegrationTestAsyncClient {
|
||||||
@GET
|
@GET
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
@RequestFilters(Filter.class)
|
@RequestFilters(Filter.class)
|
||||||
ListenableFuture<String> downloadFilter(@PathParam("id") String id,
|
ListenableFuture<String> downloadFilter(@PathParam("id") String id, @HeaderParam("filterme") String header);
|
||||||
@HeaderParam("filterme") String header);
|
|
||||||
|
|
||||||
static class Filter implements HttpRequestFilter {
|
static class Filter implements HttpRequestFilter {
|
||||||
public void filter(HttpRequest request) throws HttpException {
|
public void filter(HttpRequest request) throws HttpException {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.http.options.HttpRequestOptions;
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 40, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 40, timeUnit = TimeUnit.SECONDS)
|
||||||
public interface IntegrationTestClient {
|
public interface IntegrationTestClient {
|
||||||
|
String rowdy(String path);
|
||||||
|
|
||||||
boolean exists(String path);
|
boolean exists(String path);
|
||||||
|
|
||||||
|
|
|
@ -770,12 +770,31 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Unwrap
|
@Unwrap
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
ListenableFuture<? extends Set<String>> testUnwrap4();
|
ListenableFuture<? extends Set<String>> testUnwrap4();
|
||||||
|
|
||||||
|
@Target( { ElementType.METHOD })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@HttpMethod("ROWDY")
|
||||||
|
public @interface ROWDY {
|
||||||
|
}
|
||||||
|
|
||||||
|
@ROWDY
|
||||||
|
@Path("objects/{id}")
|
||||||
|
ListenableFuture<Boolean> rowdy(@PathParam("id") String path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Wrapper {
|
static class Wrapper {
|
||||||
String foo;
|
String foo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAlternateHttpMethod() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
Method method = TestPut.class.getMethod("rowdy", String.class);
|
||||||
|
HttpRequest request = factory(TestPut.class).createRequest(method, "data");
|
||||||
|
|
||||||
|
assertRequestLineEquals(request, "ROWDY http://localhost:9999/objects/data HTTP/1.1");
|
||||||
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException, IOException {
|
public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestPut.class.getMethod("putWithMethodBinder", String.class);
|
Method method = TestPut.class.getMethod("putWithMethodBinder", String.class);
|
||||||
HttpRequest request = factory(TestPut.class).createRequest(method, "data");
|
HttpRequest request = factory(TestPut.class).createRequest(method, "data");
|
||||||
|
@ -2024,7 +2043,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -32,10 +32,12 @@ import javax.ws.rs.core.HttpHeaders;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpEntityEnclosingRequest;
|
import org.apache.http.HttpEntityEnclosingRequest;
|
||||||
import org.apache.http.client.methods.HttpDelete;
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
|
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpHead;
|
import org.apache.http.client.methods.HttpHead;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.client.methods.HttpPut;
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.client.methods.HttpRequestBase;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.entity.ByteArrayEntity;
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
import org.apache.http.entity.FileEntity;
|
import org.apache.http.entity.FileEntity;
|
||||||
|
@ -73,7 +75,26 @@ public class ApacheHCUtils {
|
||||||
} else if (request.getMethod().equals(HttpMethod.POST)) {
|
} else if (request.getMethod().equals(HttpMethod.POST)) {
|
||||||
apacheRequest = new HttpPost(request.getEndpoint());
|
apacheRequest = new HttpPost(request.getEndpoint());
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException(request.getMethod());
|
final String method = request.getMethod();
|
||||||
|
if (request.getPayload() != null)
|
||||||
|
apacheRequest = new HttpEntityEnclosingRequestBase() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
else
|
||||||
|
apacheRequest = new HttpRequestBase() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
HttpRequestBase.class.cast(apacheRequest).setURI(request.getEndpoint());
|
||||||
}
|
}
|
||||||
Payload payload = request.getPayload();
|
Payload payload = request.getPayload();
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
public void testPerformanceVsNothing() {
|
public void testPerformanceVsNothing() {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
int count = 50;
|
int count = 5;
|
||||||
final URI fetch = URI.create("http://www.google.com");
|
final URI fetch = URI.create("http://www.google.com");
|
||||||
|
|
||||||
final URLFetchService service = URLFetchServiceFactory.getURLFetchService();
|
final URLFetchService service = URLFetchServiceFactory.getURLFetchService();
|
||||||
|
@ -172,7 +172,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testKillRobotSlowly() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testKillRobotSlowly() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -180,7 +180,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testPostAsInputStream() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testPostAsInputStream() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -196,7 +196,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testPostBinder() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testPostBinder() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -209,7 +209,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testGetAndParseSax() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetAndParseSax() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -217,14 +217,14 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testGetString() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
public void testGetString() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
super.testGetString();
|
super.testGetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000, dataProvider = "gets")
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000, dataProvider = "gets")
|
||||||
public void testGetStringSynch(String path) throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetStringSynch(String path) throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -232,7 +232,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testGetStringRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetStringRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -240,7 +240,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testGetException() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetException() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -248,7 +248,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testGetStringPermanentRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetStringPermanentRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -256,7 +256,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testGetSynchException() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetSynchException() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -264,21 +264,21 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testPost() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
public void testPost() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
super.testPost();
|
super.testPost();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testPut() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
public void testPut() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
super.testPut();
|
super.testPut();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testPutRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testPutRedirect() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -286,7 +286,7 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testGetStringWithHeader() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testGetStringWithHeader() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -294,14 +294,14 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testHead() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
public void testHead() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
super.testHead();
|
super.testHead();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(enabled = true, invocationCount = 50, timeOut = 3000)
|
@Test(enabled = true, invocationCount = 5, timeOut = 3000)
|
||||||
public void testRequestFilter() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testRequestFilter() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
setupApiProxy();
|
setupApiProxy();
|
||||||
|
@ -344,4 +344,13 @@ public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpC
|
||||||
// disabled since test data is too big
|
// disabled since test data is too big
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://code.google.com/p/googleappengine/issues/detail?id=3599
|
||||||
|
@Override
|
||||||
|
@Test(enabled = true, expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testAlternateMethod() throws MalformedURLException, ExecutionException, InterruptedException,
|
||||||
|
TimeoutException {
|
||||||
|
setupApiProxy();
|
||||||
|
super.testAlternateMethod();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue