set sax parse debug as a supported option

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1470 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-27 17:17:41 +00:00
parent 27f360e88e
commit 8da58cc24d
4 changed files with 107 additions and 99 deletions

View File

@ -32,10 +32,11 @@ import static org.jclouds.command.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTIO
import static org.jclouds.command.pool.PoolConstants.PROPERTY_POOL_MAX_SESSION_FAILURES;
import static org.jclouds.command.pool.PoolConstants.PROPERTY_POOL_REQUEST_INVOKER_THREADS;
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_ADDRESS;
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_RETRIES;
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_REDIRECTS;
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_RETRIES;
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_PORT;
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_SECURE;
import static org.jclouds.http.HttpConstants.PROPERTY_SAX_DEBUG;
import java.util.ArrayList;
import java.util.Arrays;
@ -94,6 +95,7 @@ public class S3ContextFactory {
properties.setProperty(PROPERTY_AWS_SECRETACCESSKEY, checkNotNull(awsSecretAccessKey,
"awsSecretAccessKey"));
properties.setProperty(PROPERTY_SAX_DEBUG, "false");
properties.setProperty(PROPERTY_HTTP_ADDRESS, "s3.amazonaws.com");
properties.setProperty(PROPERTY_HTTP_SECURE, "true");
properties.setProperty(PROPERTY_HTTP_MAX_RETRIES, "5");
@ -165,6 +167,11 @@ public class S3ContextFactory {
return this;
}
public S3ContextFactory withSaxDebug() {
properties.setProperty(PROPERTY_SAX_DEBUG, "true");
return this;
}
public S3ContextFactory withHttpMaxRetries(int httpMaxRetries) {
properties.setProperty(PROPERTY_HTTP_MAX_RETRIES, Integer.toString(httpMaxRetries));
return this;
@ -175,7 +182,6 @@ public class S3ContextFactory {
return this;
}
public S3ContextFactory withHttpPort(int httpPort) {
properties.setProperty(PROPERTY_HTTP_PORT, Integer.toString(httpPort));
return this;
@ -230,15 +236,8 @@ public class S3ContextFactory {
}
private Injector createInjector() {
/* Use 80 or 443 as the default port if one hasn't been set? */
if (!properties.containsKey(PROPERTY_HTTP_PORT)) {
if (Boolean.parseBoolean(properties.getProperty(PROPERTY_HTTP_SECURE))) {
properties.setProperty(PROPERTY_HTTP_PORT, DEFAULT_SECURE_HTTP_PORT);
} else {
properties.setProperty(PROPERTY_HTTP_PORT, DEFAULT_NON_SECURE_HTTP_PORT);
}
}
useDefaultPortIfNotPresent(properties);
addLoggingModuleIfNotPresent(modules);
@ -259,6 +258,17 @@ public class S3ContextFactory {
return Guice.createInjector(modules);
}
private void useDefaultPortIfNotPresent(Properties properties) {
/* Use 80 or 443 as the default port if one hasn't been set? */
if (!properties.containsKey(PROPERTY_HTTP_PORT)) {
if (Boolean.parseBoolean(properties.getProperty(PROPERTY_HTTP_SECURE))) {
properties.setProperty(PROPERTY_HTTP_PORT, DEFAULT_SECURE_HTTP_PORT);
} else {
properties.setProperty(PROPERTY_HTTP_PORT, DEFAULT_NON_SECURE_HTTP_PORT);
}
}
}
@VisibleForTesting
static void addS3ParserModuleIfNotPresent(List<Module> modules) {
if (!Iterables.any(modules, new Predicate<Module>() {

View File

@ -243,22 +243,21 @@ public class S3IntegrationTest {
bucketNames.add(bucketName);
/*
* Ensure that any returned bucket name actually exists on the server.
* Return of a non-existent bucket introduces subtle testing bugs, where later
* unrelated tests will fail.
* Ensure that any returned bucket name actually exists on the server. Return of a
* non-existent bucket introduces subtle testing bugs, where later unrelated tests will
* fail.
*
* NOTE: This sanity check should only be run for Stub-based Integration testing --
* it will *substantially* slow down tests on a real server over a network.
* NOTE: This sanity check should only be run for Stub-based Integration testing -- it will
* *substantially* slow down tests on a real server over a network.
*/
if (SANITY_CHECK_RETURNED_BUCKET_NAME) {
if (!Iterables.any(client.listOwnedBuckets().get(), new Predicate<Metadata>() {
public boolean apply(Metadata md) {
return bucketName.equals(md.getName());
}
}))
{
throw new IllegalStateException(
"Test returned the name of a non-existent bucket: " + bucketName);
})) {
throw new IllegalStateException("Test returned the name of a non-existent bucket: "
+ bucketName);
}
}
}
@ -307,8 +306,8 @@ public class S3IntegrationTest {
}
protected S3ContextFactory buildS3ContextFactory(String AWSAccessKeyId, String AWSSecretAccessKey) {
return S3ContextFactory.createContext(AWSAccessKeyId, AWSSecretAccessKey).withHttpSecure(
false).withHttpPort(80);
return S3ContextFactory.createContext(AWSAccessKeyId, AWSSecretAccessKey).withSaxDebug()
.withHttpSecure(false).withHttpPort(80);
}
protected Module createHttpModule() {

View File

@ -34,4 +34,5 @@ public interface HttpConstants extends HttpHeaders, ContentTypes {
public static final String PROPERTY_HTTP_ADDRESS = "jclouds.http.address";
public static final String PROPERTY_HTTP_MAX_RETRIES = "jclouds.http.max-retries";
public static final String PROPERTY_HTTP_MAX_REDIRECTS = "jclouds.http.max-redirects";
public static final String PROPERTY_SAX_DEBUG = "jclouds.http.sax.debug";
}

View File

@ -35,14 +35,15 @@ import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import static org.jclouds.http.HttpConstants.PROPERTY_SAX_DEBUG;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* This object will parse the body of an HttpResponse and return the result of
* type <T> back to the caller.
* This object will parse the body of an HttpResponse and return the result of type <T> back to the
* caller.
*
* @author Adrian Cole
*/
@ -51,7 +52,7 @@ public class ParseSax<T> extends HttpFutureCommand.ResponseCallable<T> {
private final XMLReader parser;
private final HandlerWithResult<T> handler;
@Inject(optional = true)
@Named("jclouds.http.sax.debug")
@Named(PROPERTY_SAX_DEBUG)
private boolean suckFirst = false;
@Inject
@ -72,8 +73,7 @@ public class ParseSax<T> extends HttpFutureCommand.ResponseCallable<T> {
}
} catch (Exception e) {
Utils.<HttpException> rethrowIfRuntimeOrSameType(e);
throw new HttpException("Error parsing input for " + getResponse(),
e);
throw new HttpException("Error parsing input for " + getResponse(), e);
}
}
@ -82,8 +82,7 @@ public class ParseSax<T> extends HttpFutureCommand.ResponseCallable<T> {
return getHandler().getResult();
}
private void parseAndCloseStream(InputStream xml, ContentHandler handler)
throws HttpException {
private void parseAndCloseStream(InputStream xml, ContentHandler handler) throws HttpException {
parser.setContentHandler(handler);
String response = null;
try {
@ -113,8 +112,7 @@ public class ParseSax<T> extends HttpFutureCommand.ResponseCallable<T> {
}
/**
* Handler that produces a useable domain object accessible after parsing
* completes.
* Handler that produces a useable domain object accessible after parsing completes.
*
* @author Adrian Cole
*/