log.info("Fetching attachment " + url);
try {
// We could fetch several attachments asynchronously in parallel to save instance
// hours, but let's hope that the connection between App Engine and Google Wave
// is fast enough to make that irrelevant.
HTTPResponse response = urlfetch.fetch(
new HTTPRequest(new URL(url), HTTPMethod.GET));
if (response.getResponseCode() != 200) {
throw new RetryableFailure("Unexpected response code: "
+ response.getResponseCode());
}
byte[] bytes = response.getContent();
if (expectedBytes != null) {
Assert.check(expectedBytes == bytes.length, "Expected %s bytes, got %s: %s",
expectedBytes, bytes.length, prettyBytes(bytes));
}
final AppEngineFile file = dump(mimeType, filename, ByteBuffer.wrap(bytes));