mirror of
https://github.com/apache/jclouds.git
synced 2025-02-17 15:35:44 +00:00
Issue 318: updated to gae 1.3.5
This commit is contained in:
parent
318e9b9071
commit
9bffee1135
@ -16,7 +16,7 @@
|
||||
limitations under the License.
|
||||
====================================================================
|
||||
====
|
||||
This samples uses the Google App Engine for Java SDK located at http://googleappengine.googlecode.com/files/appengine-java-sdk-1.2.5.zip
|
||||
This samples uses the Google App Engine for Java SDK located at http://googleappengine.googlecode.com/files/appengine-java-sdk-1.3.5.zip
|
||||
|
||||
Please unzip the above file and modify your maven settings.xml like below before attempting to run 'mvn -Plive install'
|
||||
|
||||
@ -26,7 +26,7 @@ Please unzip the above file and modify your maven settings.xml like below before
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.2.5</appengine.home>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.3.5</appengine.home>
|
||||
</properties>
|
||||
</profile>
|
||||
|
||||
|
@ -101,7 +101,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-tools-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${appengine.home}/lib/appengine-tools-api.jar</systemPath>
|
||||
</dependency>
|
||||
|
@ -54,7 +54,7 @@ public class GoogleDevServer {
|
||||
|
||||
});
|
||||
server.start();
|
||||
Thread.sleep(15 * 1000);
|
||||
Thread.sleep(30 * 1000);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -36,7 +36,7 @@ attempting to run 'mvn -Plive install'
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.2.5</appengine.home>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.3.5</appengine.home>
|
||||
<appengine.applicationid>yourappid</appengine.applicationid>
|
||||
</properties>
|
||||
</profile>
|
||||
|
@ -41,6 +41,7 @@
|
||||
<appengine.applicationid>jclouds-tweetstore-spring</appengine.applicationid>
|
||||
<devappserver.address>localhost</devappserver.address>
|
||||
<devappserver.port>8088</devappserver.port>
|
||||
<jclouds.tweetstore.blobstores>googlestorage,s3,azureblob</jclouds.tweetstore.blobstores>
|
||||
<jclouds.tweetstore.container>jclouds-tweetstore-spring</jclouds.tweetstore.container>
|
||||
</properties>
|
||||
|
||||
@ -168,12 +169,12 @@
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api-labs</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-tools-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${appengine.home}/lib/appengine-tools-api.jar</systemPath>
|
||||
</dependency>
|
||||
@ -305,6 +306,10 @@
|
||||
<name>devappserver.port</name>
|
||||
<value>${devappserver.port}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.blobstores</name>
|
||||
<value>${jclouds.tweetstore.blobstores}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.container</name>
|
||||
<value>${jclouds.tweetstore.container}</value>
|
||||
|
@ -63,10 +63,9 @@ public class StoreTweetsController extends HttpServlet {
|
||||
|
||||
public Blob apply(Status from) {
|
||||
Blob to = map.newBlob(from.getId() + "");
|
||||
to.getMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||
to.setPayload(from.getText());
|
||||
to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME,
|
||||
from.getUser().getScreenName());
|
||||
to.getPayload().setContentType(MediaType.TEXT_PLAIN);
|
||||
to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName());
|
||||
return to;
|
||||
}
|
||||
}
|
||||
@ -84,8 +83,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||
@Inject
|
||||
@VisibleForTesting
|
||||
public StoreTweetsController(Map<String, BlobStoreContext> contexts,
|
||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container,
|
||||
TwitterClient client) {
|
||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, TwitterClient client) {
|
||||
this.container = container;
|
||||
this.contexts = contexts;
|
||||
this.client = client;
|
||||
@ -93,8 +91,8 @@ public class StoreTweetsController extends HttpServlet {
|
||||
|
||||
@VisibleForTesting
|
||||
public void addMyTweets(String contextName, Set<Status> allAboutMe) {
|
||||
BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for "
|
||||
+ contextName + " in " + contexts.keySet());
|
||||
BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in "
|
||||
+ contexts.keySet());
|
||||
BlobMap map = context.createBlobMap(container);
|
||||
for (Status status : allAboutMe) {
|
||||
Blob blob = null;
|
||||
@ -104,20 +102,17 @@ public class StoreTweetsController extends HttpServlet {
|
||||
} catch (AuthorizationException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob,
|
||||
context, container);
|
||||
logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context, container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
if (request.getHeader("X-AppEngine-QueueName") != null
|
||||
&& request.getHeader("X-AppEngine-QueueName").equals("twitter")) {
|
||||
try {
|
||||
String contextName = checkNotNull(request.getHeader("context"),
|
||||
"missing header context");
|
||||
String contextName = checkNotNull(request.getHeader("context"), "missing header context");
|
||||
logger.info("retrieving tweets");
|
||||
addMyTweets(contextName, client.getMyMentions());
|
||||
logger.debug("done storing tweets");
|
||||
|
@ -54,7 +54,7 @@ public class GoogleDevServer {
|
||||
|
||||
});
|
||||
server.start();
|
||||
Thread.sleep(10 * 1000);
|
||||
Thread.sleep(30 * 1000);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -49,13 +49,14 @@ import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Starts up the Google App Engine for Java Development environment and deploys an application which
|
||||
* tests accesses twitter and blobstores.
|
||||
* Starts up the Google App Engine for Java Development environment and deploys
|
||||
* an application which tests accesses twitter and blobstores.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ -67,7 +68,9 @@ public class TweetStoreLiveTest {
|
||||
private Map<String, BlobStoreContext> contexts;
|
||||
private String container;
|
||||
|
||||
private static final Iterable<String> blobstores = ImmutableSet.of("cloudfiles", "googlestorage", "s3", "azureblob");
|
||||
private static final String blobs = System.getProperty("jclouds.tweetstore.blobstores",
|
||||
"cloudfiles,googlestorage,s3,azureblob");
|
||||
private static final Iterable<String> blobstores = Splitter.on(',').split(blobs);
|
||||
private static final Properties props = new Properties();
|
||||
|
||||
@BeforeTest
|
||||
@ -170,7 +173,7 @@ public class TweetStoreLiveTest {
|
||||
public void testPrimeContainers() throws IOException, InterruptedException {
|
||||
URL gurl = new URL(url, "/store/do");
|
||||
// WATCH THIS, you need to add a context each time
|
||||
for (String context : new String[] { "cloudfiles", "s3", "azureblob" }) {
|
||||
for (String context : blobstores) {
|
||||
System.out.println("storing at context: " + context);
|
||||
HttpURLConnection connection = (HttpURLConnection) gurl.openConnection();
|
||||
connection.addRequestProperty("X-AppEngine-QueueName", "twitter");
|
||||
|
@ -28,7 +28,7 @@ attempting to run 'mvn -Plive install'
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.2.5</appengine.home>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.3.5</appengine.home>
|
||||
<appengine.applicationid>yourappid</appengine.applicationid>
|
||||
</properties>
|
||||
</profile>
|
||||
|
@ -2,20 +2,19 @@
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Cloud Conscious, LLC.
|
||||
<info@cloudconscious.com>
|
||||
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you
|
||||
may not use this file except in compliance with the License. You may
|
||||
obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 Unless required by
|
||||
applicable law or agreed to in writing, software distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions
|
||||
and limitations under the License.
|
||||
applicable law or agreed to in writing, software distributed under the
|
||||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied. See the License for
|
||||
the specific language governing permissions and limitations under the
|
||||
License.
|
||||
====================================================================
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
@ -40,6 +39,7 @@
|
||||
<appengine.applicationid>jclouds-tweetstore</appengine.applicationid>
|
||||
<devappserver.address>localhost</devappserver.address>
|
||||
<devappserver.port>8088</devappserver.port>
|
||||
<jclouds.tweetstore.blobstores>googlestorage,s3,azureblob</jclouds.tweetstore.blobstores>
|
||||
<jclouds.tweetstore.container>jclouds-tweetstore</jclouds.tweetstore.container>
|
||||
</properties>
|
||||
|
||||
@ -152,12 +152,12 @@
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api-labs</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-tools-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${appengine.home}/lib/appengine-tools-api.jar</systemPath>
|
||||
</dependency>
|
||||
@ -289,6 +289,10 @@
|
||||
<name>devappserver.port</name>
|
||||
<value>${devappserver.port}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.blobstores</name>
|
||||
<value>${jclouds.tweetstore.blobstores}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.container</name>
|
||||
<value>${jclouds.tweetstore.container}</value>
|
||||
|
@ -63,8 +63,8 @@ public class StoreTweetsController extends HttpServlet {
|
||||
|
||||
public Blob apply(Status from) {
|
||||
Blob to = map.newBlob(from.getId() + "");
|
||||
to.getMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||
to.setPayload(from.getText());
|
||||
to.getPayload().setContentType(MediaType.TEXT_PLAIN);
|
||||
to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName());
|
||||
return to;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class GoogleDevServer {
|
||||
|
||||
});
|
||||
server.start();
|
||||
Thread.sleep(10 * 1000);
|
||||
Thread.sleep(30 * 1000);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -38,6 +38,7 @@ import org.jclouds.blobstore.BlobStoreContextFactory;
|
||||
import org.jclouds.demo.tweetstore.config.GuiceServletConfig;
|
||||
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.twitter.TwitterAsyncClient;
|
||||
@ -49,13 +50,14 @@ import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Starts up the Google App Engine for Java Development environment and deploys an application which
|
||||
* tests accesses twitter and blobstores.
|
||||
* Starts up the Google App Engine for Java Development environment and deploys
|
||||
* an application which tests accesses twitter and blobstores.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ -66,8 +68,9 @@ public class TweetStoreLiveTest {
|
||||
private URL url;
|
||||
private Map<String, BlobStoreContext> contexts;
|
||||
private String container;
|
||||
|
||||
private static final Iterable<String> blobstores = ImmutableSet.of("cloudfiles", "googlestorage", "s3", "azureblob");
|
||||
private static final String blobs = System.getProperty("jclouds.tweetstore.blobstores",
|
||||
"cloudfiles,googlestorage,s3,azureblob");
|
||||
private static final Iterable<String> blobstores = Splitter.on(',').split(blobs);
|
||||
private static final Properties props = new Properties();
|
||||
|
||||
@BeforeTest
|
||||
@ -102,12 +105,16 @@ public class TweetStoreLiveTest {
|
||||
|
||||
boolean deleted = false;
|
||||
for (BlobStoreContext context : contexts.values()) {
|
||||
try {
|
||||
if (context.getBlobStore().containerExists(container)) {
|
||||
System.err.printf("deleting container %s at %s%n", container, context.getProviderSpecificContext()
|
||||
.getEndpoint());
|
||||
context.getBlobStore().deleteContainer(container);
|
||||
deleted = true;
|
||||
}
|
||||
} catch (AuthorizationException e) {
|
||||
throw new AuthorizationException("for context: " + context, e);
|
||||
}
|
||||
}
|
||||
if (deleted) {
|
||||
System.err.println("sleeping 60 seconds to allow containers to clear");
|
||||
|
@ -97,8 +97,7 @@ public class ApacheHCUtils {
|
||||
}
|
||||
|
||||
public static void addEntityForContent(HttpEntityEnclosingRequest apacheRequest, Payload payload) {
|
||||
payload = payload instanceof DelegatingPayload ? DelegatingPayload.class.cast(payload)
|
||||
.getDelegate() : payload;
|
||||
payload = payload instanceof DelegatingPayload ? DelegatingPayload.class.cast(payload).getDelegate() : payload;
|
||||
if (payload instanceof StringPayload) {
|
||||
StringEntity nStringEntity = null;
|
||||
try {
|
||||
@ -109,17 +108,15 @@ public class ApacheHCUtils {
|
||||
nStringEntity.setContentType(payload.getContentType());
|
||||
apacheRequest.setEntity(nStringEntity);
|
||||
} else if (payload instanceof FilePayload) {
|
||||
apacheRequest.setEntity(new FileEntity((File) payload.getRawContent(), payload
|
||||
.getContentType()));
|
||||
apacheRequest.setEntity(new FileEntity((File) payload.getRawContent(), payload.getContentType()));
|
||||
} else if (payload instanceof ByteArrayPayload) {
|
||||
ByteArrayEntity Entity = new ByteArrayEntity((byte[]) payload.getRawContent());
|
||||
Entity.setContentType(payload.getContentType());
|
||||
apacheRequest.setEntity(Entity);
|
||||
} else {
|
||||
InputStream inputStream = payload.getInput();
|
||||
if (!new Long(1).equals(payload.getContentLength()))
|
||||
throw new IllegalArgumentException(
|
||||
"you must specify size when content is an InputStream");
|
||||
if (payload.getContentLength() == null)
|
||||
throw new IllegalArgumentException("you must specify size when content is an InputStream");
|
||||
InputStreamEntity Entity = new InputStreamEntity(inputStream, payload.getContentLength());
|
||||
Entity.setContentType(payload.getContentType());
|
||||
apacheRequest.setEntity(Entity);
|
||||
|
@ -47,24 +47,24 @@
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api-stubs</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-testing</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-local-runtime</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -34,6 +34,7 @@ import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.io.Payload;
|
||||
|
||||
import com.google.appengine.api.urlfetch.FetchOptions;
|
||||
import com.google.appengine.api.urlfetch.HTTPHeader;
|
||||
@ -48,7 +49,7 @@ import com.google.common.base.Function;
|
||||
*/
|
||||
@Singleton
|
||||
public class ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> {
|
||||
public static final String USER_AGENT = "jclouds/1.0 urlfetch/1.3.2";
|
||||
public static final String USER_AGENT = "jclouds/1.0 urlfetch/1.3.5";
|
||||
|
||||
private final EncryptionService encryptionService;
|
||||
|
||||
@ -58,8 +59,8 @@ public class ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> {
|
||||
}
|
||||
|
||||
/**
|
||||
* byte [] content is replayable and the only content type supportable by GAE. As such, we
|
||||
* convert the original request content to a byte array.
|
||||
* byte [] content is replayable and the only content type supportable by
|
||||
* GAE. As such, we convert the original request content to a byte array.
|
||||
*/
|
||||
@Override
|
||||
public HTTPRequest apply(HttpRequest request) {
|
||||
@ -73,8 +74,7 @@ public class ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> {
|
||||
FetchOptions options = disallowTruncate();
|
||||
options.doNotFollowRedirects();
|
||||
|
||||
HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod()
|
||||
.toString()), options);
|
||||
HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options);
|
||||
|
||||
for (String header : request.getHeaders().keySet()) {
|
||||
for (String value : request.getHeaders().get(header)) {
|
||||
@ -84,15 +84,21 @@ public class ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> {
|
||||
}
|
||||
gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT));
|
||||
/**
|
||||
* byte [] content is replayable and the only content type supportable by GAE. As such, we
|
||||
* convert the original request content to a byte array.
|
||||
* byte [] content is replayable and the only content type supportable by
|
||||
* GAE. As such, we convert the original request content to a byte array.
|
||||
*/
|
||||
if (request.getPayload() != null) {
|
||||
InputStream input = request.getPayload().getInput();
|
||||
try {
|
||||
byte[] array = toByteArray(input);
|
||||
if (!request.getPayload().isRepeatable())
|
||||
if (!request.getPayload().isRepeatable()) {
|
||||
Payload oldPayload = request.getPayload();
|
||||
request.setPayload(array);
|
||||
if (oldPayload.getContentMD5() != null)
|
||||
request.getPayload().setContentMD5(oldPayload.getContentMD5());
|
||||
if (oldPayload.getContentType() != null)
|
||||
request.getPayload().setContentType(oldPayload.getContentType());
|
||||
}
|
||||
gaeRequest.setPayload(array);
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
@ -100,16 +106,15 @@ public class ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> {
|
||||
closeQuietly(input);
|
||||
}
|
||||
if (request.getPayload().getContentMD5() != null)
|
||||
gaeRequest.addHeader(new HTTPHeader("Content-MD5", encryptionService.base64(request
|
||||
.getPayload().getContentMD5())));
|
||||
|
||||
Long length = checkNotNull(request.getPayload().getContentLength(),
|
||||
"payload.getContentLength");
|
||||
gaeRequest.addHeader(new HTTPHeader(HttpHeaders.CONTENT_LENGTH, length.toString()));
|
||||
gaeRequest.setHeader(new HTTPHeader("Content-MD5", encryptionService.base64(request.getPayload()
|
||||
.getContentMD5())));
|
||||
if (request.getPayload().getContentType() != null)
|
||||
gaeRequest.setHeader(new HTTPHeader(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentType()));
|
||||
Long length = checkNotNull(request.getPayload().getContentLength(), "payload.getContentLength");
|
||||
gaeRequest.setHeader(new HTTPHeader(HttpHeaders.CONTENT_LENGTH, length.toString()));
|
||||
} else {
|
||||
gaeRequest.addHeader(new HTTPHeader(HttpHeaders.CONTENT_LENGTH, "0"));
|
||||
gaeRequest.setHeader(new HTTPHeader(HttpHeaders.CONTENT_LENGTH, "0"));
|
||||
}
|
||||
return gaeRequest;
|
||||
}
|
||||
|
||||
}
|
@ -37,6 +37,7 @@ import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.appengine.api.urlfetch.HTTPHeader;
|
||||
import com.google.appengine.api.urlfetch.HTTPRequest;
|
||||
import com.google.appengine.repackaged.com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
@ -84,9 +85,10 @@ public class ConvertToGaeRequestTest {
|
||||
HttpRequest request = new HttpRequest(HttpMethod.GET, endPoint);
|
||||
HTTPRequest gaeRequest = req.apply(request);
|
||||
assert gaeRequest.getPayload() == null;
|
||||
assertEquals(gaeRequest.getHeaders().size(), 2);// content length, user agent
|
||||
assertEquals(gaeRequest.getHeaders().size(), 2);// content length, user
|
||||
// agent
|
||||
assertEquals(gaeRequest.getHeaders().get(0).getName(), HttpHeaders.USER_AGENT);
|
||||
assertEquals(gaeRequest.getHeaders().get(0).getValue(), "jclouds/1.0 urlfetch/1.3.2");
|
||||
assertEquals(gaeRequest.getHeaders().get(0).getValue(), "jclouds/1.0 urlfetch/1.3.5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -129,15 +131,16 @@ public class ConvertToGaeRequestTest {
|
||||
}
|
||||
|
||||
private void testHoot(HttpRequest request) throws IOException {
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_TYPE, "text/plain");
|
||||
request.getPayload().setContentType("text/plain");
|
||||
request.getPayload().setContentMD5(new byte[] { 1, 2, 3, 4 });
|
||||
HTTPRequest gaeRequest = req.apply(request);
|
||||
try {
|
||||
assertEquals(gaeRequest.getHeaders().get(0).getName(), HttpHeaders.CONTENT_TYPE);
|
||||
assertEquals(gaeRequest.getHeaders().get(0).getValue(), "text/plain");
|
||||
} catch (AssertionError e) {
|
||||
assertEquals(gaeRequest.getHeaders().get(1).getName(), HttpHeaders.CONTENT_TYPE);
|
||||
assertEquals(gaeRequest.getHeaders().get(1).getValue(), "text/plain");
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (HTTPHeader header : gaeRequest.getHeaders()) {
|
||||
builder.append(header.getName()).append(": ").append(header.getValue()).append("\n");
|
||||
}
|
||||
assertEquals(builder.toString(),
|
||||
"User-Agent: jclouds/1.0 urlfetch/1.3.5\nContent-MD5: AQIDBA==\nContent-Type: text/plain\nContent-Length: 5\n");
|
||||
assertEquals(new String(gaeRequest.getPayload()), "hoot!");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user