From 50fc3cb9132495c8ef6b1eaee372fb7aa44658e4 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Sat, 10 Oct 2009 21:55:18 +0000 Subject: [PATCH] Issue 74: refactored logging including addition of new trace and header logs. These remove the need for separate json and xml debugging, as it is seen in wire logs git-svn-id: http://jclouds.googlecode.com/svn/trunk@1968 3d8758e0-26b5-11de-8745-db77d3ebf521 --- aws/core/src/test/resources/log4j.xml | 48 ++++- .../org/jclouds/aws/s3/S3ContextBuilder.java | 10 - .../aws/s3/integration/S3TestInitializer.java | 4 +- .../storage/blob/AzureBlobContextBuilder.java | 20 +- .../storage/blob/AzureBlobConnectionTest.java | 7 + .../storage/blob/AzureBlobStoreTest.java | 7 + .../integration/AzureBlobTestInitializer.java | 4 +- .../storage/core/src/test/resources/log4j.xml | 48 ++++- .../queue/AzureQueueContextBuilder.java | 11 -- .../queue/AzureQueueConnectionLiveTest.java | 2 +- .../queue/AzureQueueConnectionTest.java | 7 + .../blobstore/BlobStoreContextBuilder.java | 21 +- .../jclouds/cloud/CloudContextBuilder.java | 17 +- .../java/org/jclouds/http/HttpConstants.java | 4 +- .../java/org/jclouds/http/HttpRequest.java | 17 +- .../java/org/jclouds/http/HttpResponse.java | 16 +- .../main/java/org/jclouds/http/HttpUtils.java | 21 ++ ...formingHttpCommandExecutorServiceImpl.java | 7 +- .../http/TransformingHttpCommandImpl.java | 4 +- .../jclouds/http/TransformingHttpUtils.java | 53 ----- .../org/jclouds/http/functions/ParseJson.java | 19 +- .../org/jclouds/http/functions/ParseSax.java | 17 +- .../BaseHttpCommandExecutorService.java | 33 +++- .../JavaUrlHttpCommandExecutorService.java | 8 +- .../java/org/jclouds/http/internal/Wire.java | 166 ++++++++++++++++ ...ransformingHttpCommandExecutorService.java | 48 +++-- .../http/pool/HttpCommandConnectionPool.java | 31 +-- .../org/jclouds/lifecycle/BaseLifeCycle.java | 2 +- .../java/org/jclouds/logging/BaseLogger.java | 74 +++---- .../BindLoggersAnnotatedWithResource.java | 33 ++-- .../jclouds/logging/config/LoggingModule.java | 19 +- .../internal/RestAnnotationProcessor.java | 6 +- .../rest/internal/RestClientProxy.java | 24 +-- .../BackoffLimitedRetryHandlerTest.java | 15 +- .../jclouds/http/internal/WireLiveTest.java | 181 ++++++++++++++++++ .../org/jclouds/http/internal/WireTest.java | 149 ++++++++++++++ .../BindLoggersAnnotatedWithResourceTest.java | 163 ++++++++-------- .../rest/RestAnnotationProcessorTest.java | 16 +- .../gae/GaeHttpCommandExecutorService.java | 22 +-- .../GaeHttpCommandExecutorServiceTest.java | 3 +- ...eHttpCommandExecutorServiceModuleTest.java | 7 + .../pool/NioHttpCommandConnectionPool.java | 56 ++---- .../pool/NioHttpCommandExecutionHandler.java | 36 +++- ...ransformingHttpCommandExecutorService.java | 16 +- .../http/httpnio/util/NioHttpUtils.java | 1 + .../jclouds/mezeo/pcs2/PCSContextBuilder.java | 12 +- .../jclouds/mezeo/pcs2/PCSBlobStoreTest.java | 7 + .../jclouds/mezeo/pcs2/PCSConnectionTest.java | 7 + .../mezeo/pcs2/PCSContextModuleTest.java | 7 + .../pcs2/config/PCSContextModuleTest.java | 7 + .../pcs2/integration/PCSTestInitializer.java | 4 +- mezeo/pcs2/core/src/test/resources/log4j.xml | 48 ++++- .../nirvanix/sdn/SDNContextBuilder.java | 10 - .../sdn/SDNAuthenticationLiveTest.java | 3 - .../nirvanix/sdn/SDNAuthenticationTest.java | 7 + .../nirvanix/sdn/SDNConnectionLiveTest.java | 10 +- .../nirvanix/sdn/SDNConnectionTest.java | 7 + .../sdn/core/src/test/resources/log4j.xml | 48 ++++- project/pom.xml | 18 ++ .../cloudfiles/CloudFilesContextBuilder.java | 15 +- .../CloudServersContextBuilder.java | 9 - .../CloudServersConnectionLiveTest.java | 2 +- .../CloudServersConnectionTest.java | 7 + .../RackspaceAuthenticationTest.java | 7 + rackspace/core/src/test/resources/log4j.xml | 48 ++++- 65 files changed, 1195 insertions(+), 561 deletions(-) delete mode 100644 core/src/main/java/org/jclouds/http/TransformingHttpUtils.java create mode 100644 core/src/main/java/org/jclouds/http/internal/Wire.java create mode 100644 core/src/test/java/org/jclouds/http/internal/WireLiveTest.java create mode 100644 core/src/test/java/org/jclouds/http/internal/WireTest.java diff --git a/aws/core/src/test/resources/log4j.xml b/aws/core/src/test/resources/log4j.xml index a97df723b7..23deb5a816 100644 --- a/aws/core/src/test/resources/log4j.xml +++ b/aws/core/src/test/resources/log4j.xml @@ -33,6 +33,28 @@ + + + + + + + + + + + + + + + + + + @@ -58,22 +80,36 @@ - + + + + + - - + + + + + + + + - + + + + + + - - + \ No newline at end of file diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/S3ContextBuilder.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/S3ContextBuilder.java index 2ded8eccf3..355e21cf9a 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/S3ContextBuilder.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/S3ContextBuilder.java @@ -110,11 +110,6 @@ public class S3ContextBuilder extends return (S3ContextBuilder) super.withHttpMaxRetries(httpMaxRetries); } - @Override - public S3ContextBuilder withJsonDebug() { - return (S3ContextBuilder) super.withJsonDebug(); - } - @Override public S3ContextBuilder withModule(Module module) { return (S3ContextBuilder) super.withModule(module); @@ -150,11 +145,6 @@ public class S3ContextBuilder extends return (S3ContextBuilder) super.withPoolRequestInvokerThreads(poolRequestInvokerThreads); } - @Override - public S3ContextBuilder withSaxDebug() { - return (S3ContextBuilder) (S3ContextBuilder) super.withSaxDebug(); - } - @Override public S3ContextBuilder withEndpoint(URI endpoint) { properties.setProperty(S3Constants.PROPERTY_S3_ENDPOINT, checkNotNull(endpoint, "endpoint") diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/integration/S3TestInitializer.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/integration/S3TestInitializer.java index ce742c7632..becf33a6a7 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/integration/S3TestInitializer.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/integration/S3TestInitializer.java @@ -48,8 +48,8 @@ public class S3TestInitializer extends protected BlobStoreContext createLiveContext( Module configurationModule, String url, String app, String account, String key) { BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true; - return new S3ContextBuilder(account, key).withSaxDebug().relaxSSLHostname().withModules( - configurationModule, new Log4JLoggingModule()).buildContext(); + return new S3ContextBuilder(account, key).relaxSSLHostname().withModules(configurationModule, + new Log4JLoggingModule()).buildContext(); } @Override diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobContextBuilder.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobContextBuilder.java index 4106928262..9478f1a270 100755 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobContextBuilder.java +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobContextBuilder.java @@ -78,11 +78,11 @@ public class AzureBlobContextBuilder extends "https://{account}.blob.core.windows.net"); } -// @Override -// protected void addBlobStoreModule(List modules) { -// modules.add(BlobStoreMapsModule.Builder.newBuilder(containerMetadataType, blobMetadataType, -// blobType).withClearContainerStrategy(RecreateClearContainerStrategy.class).build()); -// } + // @Override + // protected void addBlobStoreModule(List modules) { + // modules.add(BlobStoreMapsModule.Builder.newBuilder(containerMetadataType, blobMetadataType, + // blobType).withClearContainerStrategy(RecreateClearContainerStrategy.class).build()); + // } public AzureBlobContextBuilder(String id, String secret) { this(new Properties()); @@ -115,11 +115,6 @@ public class AzureBlobContextBuilder extends return (AzureBlobContextBuilder) super.withHttpMaxRetries(httpMaxRetries); } - @Override - public AzureBlobContextBuilder withJsonDebug() { - return (AzureBlobContextBuilder) super.withJsonDebug(); - } - @Override public AzureBlobContextBuilder withModule(Module module) { return (AzureBlobContextBuilder) super.withModule(module); @@ -161,11 +156,6 @@ public class AzureBlobContextBuilder extends .withPoolRequestInvokerThreads(poolRequestInvokerThreads); } - @Override - public AzureBlobContextBuilder withSaxDebug() { - return (AzureBlobContextBuilder) super.withSaxDebug(); - } - @Override public AzureBlobContextBuilder withEndpoint(URI endpoint) { properties.setProperty(AzureBlobConstants.PROPERTY_AZUREBLOB_ENDPOINT, checkNotNull(endpoint, diff --git a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobConnectionTest.java b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobConnectionTest.java index 3b8bf7bca9..ca18226fdc 100644 --- a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobConnectionTest.java +++ b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobConnectionTest.java @@ -53,6 +53,8 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueOn404; import org.jclouds.http.functions.ReturnVoidIf2xx; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.config.RestModule; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Jsr330; @@ -350,6 +352,11 @@ public class AzureBlobConnectionTest { bindConstant().annotatedWith( Jsr330.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to( "x-ms-meta-"); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); } }, new RestModule(), new ExecutorServiceModule(new WithinThreadExecutorService()), new JavaUrlHttpCommandExecutorServiceModule()); diff --git a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobStoreTest.java b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobStoreTest.java index 6b133b9e07..916e459940 100644 --- a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobStoreTest.java +++ b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobStoreTest.java @@ -49,6 +49,8 @@ import org.jclouds.http.functions.ParseETagHeader; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnVoidIf2xx; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.config.RestModule; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Jsr330; @@ -181,6 +183,11 @@ public class AzureBlobStoreTest { HttpUtils.toBase64String("key".getBytes())); bindConstant().annotatedWith( Jsr330.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("prefix"); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); } @SuppressWarnings("unused") diff --git a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/integration/AzureBlobTestInitializer.java b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/integration/AzureBlobTestInitializer.java index b35489223d..71577c2c48 100644 --- a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/integration/AzureBlobTestInitializer.java +++ b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/integration/AzureBlobTestInitializer.java @@ -46,8 +46,8 @@ public class AzureBlobTestInitializer extends @Override protected BlobStoreContext createLiveContext( Module configurationModule, String url, String app, String account, String key) { - return new AzureBlobContextBuilder(account, key).withSaxDebug().relaxSSLHostname() - .withModules(configurationModule, new Log4JLoggingModule()).buildContext(); + return new AzureBlobContextBuilder(account, key).relaxSSLHostname().withModules( + configurationModule, new Log4JLoggingModule()).buildContext(); } @Override diff --git a/azure/storage/core/src/test/resources/log4j.xml b/azure/storage/core/src/test/resources/log4j.xml index a97df723b7..23deb5a816 100755 --- a/azure/storage/core/src/test/resources/log4j.xml +++ b/azure/storage/core/src/test/resources/log4j.xml @@ -33,6 +33,28 @@ + + + + + + + + + + + + + + + + + + @@ -58,22 +80,36 @@ - + + + + + - - + + + + + + + + - + + + + + + - - + \ No newline at end of file diff --git a/azure/storage/queue/core/src/main/java/org/jclouds/azure/storage/queue/AzureQueueContextBuilder.java b/azure/storage/queue/core/src/main/java/org/jclouds/azure/storage/queue/AzureQueueContextBuilder.java index 4db521f949..838213b3c9 100755 --- a/azure/storage/queue/core/src/main/java/org/jclouds/azure/storage/queue/AzureQueueContextBuilder.java +++ b/azure/storage/queue/core/src/main/java/org/jclouds/azure/storage/queue/AzureQueueContextBuilder.java @@ -126,11 +126,6 @@ public class AzureQueueContextBuilder extends CloudContextBuilder withRequestTimeout(long milliseconds) { - properties.setProperty(BlobStoreConstants.PROPERTY_BLOBSTORE_TIMEOUT, Long.toString(milliseconds)); + public BlobStoreContextBuilder withRequestTimeout(long milliseconds) { + properties.setProperty(BlobStoreConstants.PROPERTY_BLOBSTORE_TIMEOUT, Long + .toString(milliseconds)); return this; } - - @SuppressWarnings("unchecked") - @Override - public BlobStoreContextBuilder withHttpMaxRetries(int httpMaxRetries) { - return (BlobStoreContextBuilder) super.withHttpMaxRetries(httpMaxRetries); - } @SuppressWarnings("unchecked") @Override - public BlobStoreContextBuilder withJsonDebug() { - return (BlobStoreContextBuilder) super.withJsonDebug(); + public BlobStoreContextBuilder withHttpMaxRetries(int httpMaxRetries) { + return (BlobStoreContextBuilder) super.withHttpMaxRetries(httpMaxRetries); } @SuppressWarnings("unchecked") @@ -122,12 +117,6 @@ public abstract class BlobStoreContextBuilder withSaxDebug() { - return (BlobStoreContextBuilder) super.withSaxDebug(); - } - @SuppressWarnings("unchecked") @Override public BlobStoreContextBuilder relaxSSLHostname() { diff --git a/core/src/main/java/org/jclouds/cloud/CloudContextBuilder.java b/core/src/main/java/org/jclouds/cloud/CloudContextBuilder.java index ab94c74206..7f317decaf 100644 --- a/core/src/main/java/org/jclouds/cloud/CloudContextBuilder.java +++ b/core/src/main/java/org/jclouds/cloud/CloudContextBuilder.java @@ -27,8 +27,6 @@ import static com.google.common.base.Preconditions.checkNotNull; 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_RELAX_HOSTNAME; -import static org.jclouds.http.HttpConstants.PROPERTY_JSON_DEBUG; -import static org.jclouds.http.HttpConstants.PROPERTY_SAX_DEBUG; import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_IO_WORKER_THREADS; import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTIONS; import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTION_REUSE; @@ -91,16 +89,6 @@ public abstract class CloudContextBuilder { this.properties = properties; } - public CloudContextBuilder withSaxDebug() { - properties.setProperty(PROPERTY_SAX_DEBUG, "true"); - return this; - } - - public CloudContextBuilder withJsonDebug() { - properties.setProperty(PROPERTY_JSON_DEBUG, "true"); - return this; - } - /** * allow mismatches between the certificate and the hostname of ssl requests. */ @@ -266,9 +254,6 @@ public abstract class CloudContextBuilder { public CloudContext buildContext() { Injector injector = buildInjector(); return (CloudContext) injector.getInstance(Key.get(Types.newParameterizedType( - CloudContext.class, connectionType.getType()))); - // return (CloudContext) this.buildInjector().getInstance( - // Key.get(new TypeLiteral>() { - // })); + CloudContext.class, connectionType.getType()))); } } diff --git a/core/src/main/java/org/jclouds/http/HttpConstants.java b/core/src/main/java/org/jclouds/http/HttpConstants.java index aea6ded902..9555567e63 100644 --- a/core/src/main/java/org/jclouds/http/HttpConstants.java +++ b/core/src/main/java/org/jclouds/http/HttpConstants.java @@ -31,8 +31,8 @@ package org.jclouds.http; public interface HttpConstants { 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"; - public static final String PROPERTY_JSON_DEBUG = "jclouds.http.json.debug"; + public static final String HTTP_HEADERS_LOGGER = "jclouds.http.headers"; + public static final String HTTP_WIRE_LOGGER = "jclouds.http.wire"; /** * longest time a single request can take before throwing an exception. diff --git a/core/src/main/java/org/jclouds/http/HttpRequest.java b/core/src/main/java/org/jclouds/http/HttpRequest.java index af59e2b411..272dddd4a6 100644 --- a/core/src/main/java/org/jclouds/http/HttpRequest.java +++ b/core/src/main/java/org/jclouds/http/HttpRequest.java @@ -88,21 +88,8 @@ public class HttpRequest extends HttpMessage implements Request { setEntity(entity); } - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("HttpRequest"); - sb.append("{endPoint='").append(endpoint).append('\''); - sb.append(", method='").append(method).append('\''); - sb.append(", headers=").append(headers); - sb.append(", filters=").append(requestFilters); - if (entity != null && entity instanceof String) { - sb.append(", entity=").append(entity); - } else { - sb.append(", entity set=").append(entity != null); - } - sb.append('}'); - return sb.toString(); + public String getRequestLine() { + return String.format("%s %s HTTP/1.1", getMethod(), endpoint.toASCIIString()); } /** diff --git a/core/src/main/java/org/jclouds/http/HttpResponse.java b/core/src/main/java/org/jclouds/http/HttpResponse.java index 777c083d51..d540b728c3 100644 --- a/core/src/main/java/org/jclouds/http/HttpResponse.java +++ b/core/src/main/java/org/jclouds/http/HttpResponse.java @@ -35,18 +35,6 @@ public class HttpResponse extends HttpMessage { private String message; private InputStream content; - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("HttpResponse"); - sb.append("{statusCode=").append(statusCode); - sb.append(", headers=").append(headers); - sb.append(", message='").append(message).append('\''); - sb.append(", content set=").append(content != null); - sb.append('}'); - return sb.toString(); - } - public int getStatusCode() { return statusCode; } @@ -71,4 +59,8 @@ public class HttpResponse extends HttpMessage { this.content = content; } + public String getStatusLine() { + return String.format("HTTP/1.1 %d %s", getStatusCode(), getMessage()); + } + } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/http/HttpUtils.java b/core/src/main/java/org/jclouds/http/HttpUtils.java index ea830b7f21..3aa88d6ad7 100644 --- a/core/src/main/java/org/jclouds/http/HttpUtils.java +++ b/core/src/main/java/org/jclouds/http/HttpUtils.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -177,6 +178,26 @@ public class HttpUtils { } + + + public static void copy(InputStream input, OutputStream output) throws IOException { + byte[] buffer = new byte[1024]; + long length = 0; + int numRead = -1; + try { + do { + numRead = input.read(buffer); + if (numRead > 0) { + length += numRead; + output.write(buffer, 0, numRead); + } + } while (numRead != -1); + } finally { + output.close(); + IOUtils.closeQuietly(input); + } + } + public static MD5InputStreamResult generateMD5Result(InputStream toEncode) throws IOException { MD5Digest eTag = new MD5Digest(); byte[] resBuf = new byte[eTag.getDigestSize()]; diff --git a/core/src/main/java/org/jclouds/http/TransformingHttpCommandExecutorServiceImpl.java b/core/src/main/java/org/jclouds/http/TransformingHttpCommandExecutorServiceImpl.java index b578282637..10078dd82f 100644 --- a/core/src/main/java/org/jclouds/http/TransformingHttpCommandExecutorServiceImpl.java +++ b/core/src/main/java/org/jclouds/http/TransformingHttpCommandExecutorServiceImpl.java @@ -28,6 +28,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import org.jclouds.concurrent.FutureFunctionCallable; +import org.jclouds.logging.Logger.LoggerFactory; import com.google.common.base.Function; import javax.inject.Inject; @@ -42,12 +43,14 @@ public class TransformingHttpCommandExecutorServiceImpl implements TransformingHttpCommandExecutorService { private final HttpCommandExecutorService client; private final ExecutorService executorService; + private final LoggerFactory logFactory; @Inject public TransformingHttpCommandExecutorServiceImpl(HttpCommandExecutorService client, - ExecutorService executorService) { + ExecutorService executorService, LoggerFactory logFactory) { this.client = client; this.executorService = executorService; + this.logFactory = logFactory; } /** @@ -57,7 +60,7 @@ public class TransformingHttpCommandExecutorServiceImpl implements Function exceptionTransformer) { Future responseFuture = client.submit(command); Callable valueCallable = new FutureFunctionCallable(responseFuture, - responseTransformer); + responseTransformer, logFactory.getLogger(responseTransformer.getClass().getName())); return executorService.submit(valueCallable); } diff --git a/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java b/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java index 0613680ca9..425cb46fcc 100644 --- a/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java +++ b/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java @@ -30,13 +30,13 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import javax.annotation.Resource; +import javax.inject.Inject; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriBuilder; import org.jclouds.logging.Logger; import com.google.common.base.Function; -import javax.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.internal.Nullable; @@ -66,7 +66,7 @@ public class TransformingHttpCommandImpl implements TransformingHttpCommand - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * ==================================================================== - */ -package org.jclouds.http; - -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.SynchronousQueue; - -import com.google.common.base.Function; - -public class TransformingHttpUtils { - - public static HttpCommandRendezvous submitHttpCommand(HttpCommand command, - final Function responseTransformer, ExecutorService executorService) { - final SynchronousQueue channel = new SynchronousQueue(); - - // should block and immediately parse the response on exit. - Future future = executorService.submit(new Callable() { - public T call() throws Exception { - Object o = channel.take(); - if (o instanceof Exception) - throw (Exception) o; - return responseTransformer.apply((HttpResponse) o); - } - }); - - HttpCommandRendezvous rendezvous = new HttpCommandRendezvous(command, channel, future); - return rendezvous; - } - -} diff --git a/core/src/main/java/org/jclouds/http/functions/ParseJson.java b/core/src/main/java/org/jclouds/http/functions/ParseJson.java index 233b143f16..1b37c21f62 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseJson.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseJson.java @@ -23,8 +23,6 @@ */ package org.jclouds.http.functions; -import static org.jclouds.http.HttpConstants.PROPERTY_JSON_DEBUG; - import java.io.InputStream; import javax.annotation.Resource; @@ -36,8 +34,6 @@ import org.jclouds.logging.Logger; import com.google.common.base.Function; import com.google.gson.Gson; -import javax.inject.Inject; -import javax.inject.Named; /** * This object will parse the body of an HttpResponse and return the result of type back to the @@ -47,9 +43,6 @@ import javax.inject.Named; */ public abstract class ParseJson implements Function { - @Inject(optional = true) - @Named(PROPERTY_JSON_DEBUG) - private boolean suckFirst = false; @Resource protected Logger logger = Logger.NULL; protected final Gson gson; @@ -63,23 +56,13 @@ public abstract class ParseJson implements Function { */ public T apply(HttpResponse from) { InputStream gson = from.getContent(); - String response = null; try { - if (suckFirst) { - response = IOUtils.toString(gson); - logger.trace("received content %n%s", response); - IOUtils.closeQuietly(gson); - gson = IOUtils.toInputStream(response); - } return apply(gson); } catch (Exception e) { StringBuilder message = new StringBuilder(); message.append("Error parsing input"); - if (response != null) { - message.append("\n").append(response); - } logger.error(e, message.toString()); - throw new HttpResponseException(message.toString()+"\n"+from, null, from, e); + throw new HttpResponseException(message.toString() + "\n" + from, null, from, e); } finally { IOUtils.closeQuietly(gson); } diff --git a/core/src/main/java/org/jclouds/http/functions/ParseSax.java b/core/src/main/java/org/jclouds/http/functions/ParseSax.java index be75b6ed01..abefa48d3a 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseSax.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseSax.java @@ -24,11 +24,11 @@ package org.jclouds.http.functions; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.http.HttpConstants.PROPERTY_SAX_DEBUG; import java.io.InputStream; import javax.annotation.Resource; +import javax.inject.Inject; import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpException; @@ -41,9 +41,7 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import com.google.common.base.Function; -import javax.inject.Inject; import com.google.inject.assistedinject.Assisted; -import javax.inject.Named; /** * This object will parse the body of an HttpResponse and return the result of type back to the @@ -55,9 +53,6 @@ public class ParseSax implements Function { private final XMLReader parser; private final HandlerWithResult handler; - @Inject(optional = true) - @Named(PROPERTY_SAX_DEBUG) - private boolean suckFirst = false; @Resource protected Logger logger = Logger.NULL; @@ -93,14 +88,7 @@ public class ParseSax implements Function { } private void parseAndCloseStream(InputStream xml, ContentHandler handler) throws HttpException { - String response = null; try { - if (suckFirst) { - response = IOUtils.toString(xml); - logger.trace("received content %n%s", response); - IOUtils.closeQuietly(xml); - xml = IOUtils.toInputStream(response); - } parser.setContentHandler(handler); // This method should accept documents with a BOM (Byte-order mark) InputSource input = new InputSource(xml); @@ -108,9 +96,6 @@ public class ParseSax implements Function { } catch (Exception e) { StringBuilder message = new StringBuilder(); message.append("Error parsing input for ").append(handler); - if (response != null) { - message.append("\n").append(response); - } logger.error(e, message.toString()); if (!(e instanceof NullPointerException)) Utils. rethrowIfRuntimeOrSameType(e); diff --git a/core/src/main/java/org/jclouds/http/internal/BaseHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/BaseHttpCommandExecutorService.java index d3a1924691..53fe3d9cb5 100644 --- a/core/src/main/java/org/jclouds/http/internal/BaseHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/BaseHttpCommandExecutorService.java @@ -24,14 +24,17 @@ package org.jclouds.http.internal; import java.io.IOException; +import java.util.Map.Entry; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import javax.annotation.Resource; +import javax.inject.Named; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommandExecutorService; +import org.jclouds.http.HttpConstants; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpResponse; @@ -47,12 +50,18 @@ public abstract class BaseHttpCommandExecutorService implements HttpCommandEx @Resource protected Logger logger = Logger.NULL; + @Resource + @Named(HttpConstants.HTTP_HEADERS_LOGGER) + protected Logger headerLog = Logger.NULL; + + private final Wire wire; protected BaseHttpCommandExecutorService(ExecutorService executorService, - DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler) { + DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, Wire wire) { this.retryHandler = retryHandler; this.errorHandler = errorHandler; this.executorService = executorService; + this.wire = wire; } public Future submit(HttpCommand command) { @@ -73,13 +82,31 @@ public abstract class BaseHttpCommandExecutorService implements HttpCommandEx HttpRequest request = command.getRequest(); Q nativeRequest = null; try { - logger.trace("%s - filtering request %s", request.getEndpoint(), request); for (HttpRequestFilter filter : request.getFilters()) { request = filter.filter(request); } - logger.trace("%s - request now %s", request.getEndpoint(), request); + logger.debug("Sending request: %s", request.getRequestLine()); + if (request.getEntity() != null && wire.enabled()) + request.setEntity(wire.output(request.getEntity())); nativeRequest = convert(request); + if (headerLog.isDebugEnabled()) { + headerLog.debug(">> %s", request.getRequestLine().toString()); + for (Entry header : request.getHeaders().entries()) { + if (header.getKey() != null) + headerLog.debug(">> %s: %s", header.getKey(), header.getValue()); + } + } response = invoke(nativeRequest); + logger.debug("Receiving response: " + response.getStatusLine()); + if (headerLog.isDebugEnabled()) { + headerLog.debug("<< " + response.getStatusLine().toString()); + for (Entry header : response.getHeaders().entries()) { + if (header.getKey() != null) + headerLog.debug("<< %s: %s", header.getKey(), header.getValue()); + } + } + if (response.getContent() != null && wire.enabled()) + response.setContent(wire.input(response.getContent())); int statusCode = response.getStatusCode(); if (statusCode >= 300) { if (retryHandler.shouldRetryRequest(command, response)) { diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index d02b76231f..e114ecf706 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -66,8 +66,8 @@ public class JavaUrlHttpCommandExecutorService extends @Inject public JavaUrlHttpCommandExecutorService(ExecutorService executorService, - DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler) { - super(executorService, retryHandler, errorHandler); + DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, Wire wire) { + super(executorService, retryHandler, errorHandler, wire); sslMap = Maps.newHashMap(); } @@ -88,8 +88,6 @@ public class JavaUrlHttpCommandExecutorService extends @Override protected HttpResponse invoke(HttpURLConnection connection) throws IOException { - logger.trace("%s - submitting request %s; %s", connection.getURL().getHost(), connection - .getURL(), connection.getHeaderFields().toString()); HttpResponse response = new HttpResponse(); InputStream in; try { @@ -97,8 +95,6 @@ public class JavaUrlHttpCommandExecutorService extends } catch (IOException e) { in = connection.getErrorStream(); } - logger.trace("%s - received response code %s, headers: %s", connection.getURL().getHost(), - connection.getResponseCode(), connection.getHeaderFields()); if (in != null) { response.setContent(in); } diff --git a/core/src/main/java/org/jclouds/http/internal/Wire.java b/core/src/main/java/org/jclouds/http/internal/Wire.java new file mode 100644 index 0000000000..a27d83e1c8 --- /dev/null +++ b/core/src/main/java/org/jclouds/http/internal/Wire.java @@ -0,0 +1,166 @@ +package org.jclouds.http.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.concurrent.ExecutorService; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.input.TeeInputStream; +import org.jclouds.concurrent.SingleThreaded; +import org.jclouds.http.HttpConstants; +import org.jclouds.logging.Logger; + +/** + * Logs data to the wire LOG. + * + * @author Adrian Cole + * @see org.apache.http.impl.conn.Wire + */ +public class Wire { + + @Resource + @Named(HttpConstants.HTTP_WIRE_LOGGER) + protected Logger wireLog = Logger.NULL; + @Resource + protected Logger logger = Logger.NULL; + + private final ExecutorService exec; + + @Inject + public Wire(ExecutorService exec) { + this.exec = checkNotNull(exec, "executor"); + } + + private void wire(String header, InputStream instream) { + StringBuilder buffer = new StringBuilder(); + int ch; + try { + while ((ch = instream.read()) != -1) { + if (ch == 13) { + buffer.append("[\\r]"); + } else if (ch == 10) { + buffer.append("[\\n]\""); + buffer.insert(0, "\""); + buffer.insert(0, header); + wireLog.debug(buffer.toString()); + buffer.setLength(0); + } else if ((ch < 32) || (ch > 127)) { + buffer.append("[0x"); + buffer.append(Integer.toHexString(ch)); + buffer.append("]"); + } else { + buffer.append((char) ch); + } + } + if (buffer.length() > 0) { + buffer.append('\"'); + buffer.insert(0, '\"'); + buffer.insert(0, header); + wireLog.debug(buffer.toString()); + } + } catch (IOException e) { + logger.error(e, "Error tapping line"); + } + } + + public boolean enabled() { + return wireLog.isDebugEnabled(); + } + + public InputStream copy(final String header, InputStream instream) { + try { + byte[] data = IOUtils.toByteArray(instream); + wire(header, new ByteArrayInputStream(data)); + return new ByteArrayInputStream(data); + } catch (IOException e) { + throw new RuntimeException("Error tapping line", e); + } finally { + IOUtils.closeQuietly(instream); + } + } + + public InputStream tapAsynch(final String header, InputStream instream) { + PipedOutputStream out = new PipedOutputStream(); + InputStream toReturn = new TeeInputStream(instream, out, true); + final InputStream line; + try { + line = new PipedInputStream(out); + exec.submit(new Runnable() { + public void run() { + try { + wire(header, line); + } finally { + IOUtils.closeQuietly(line); + } + } + }); + } catch (IOException e) { + logger.error(e, "Error tapping line"); + } + return toReturn; + } + + public InputStream input(InputStream instream) { + return copy("<< ", checkNotNull(instream, "input")); + } + + @SuppressWarnings("unchecked") + public T output(T data) { + checkNotNull(data, "data must be set before calling generateETag()"); + if (data instanceof InputStream) { + if (exec.getClass().isAnnotationPresent(SingleThreaded.class)) + return (T) copy(">> ", (InputStream) data); + else + return (T) tapAsynch(">> ", (InputStream) data); + } else if (data instanceof byte[]) { + output((byte[]) data); + return data; + } else if (data instanceof String) { + output((String) data); + return data; + } else if (data instanceof File) { + output(((File) data)); + return data; + } else { + throw new UnsupportedOperationException("Content not supported " + data.getClass()); + } + } + + private void output(final File out) { + checkNotNull(out, "output"); + exec.submit(new Runnable() { + public void run() { + InputStream in = null; + try { + in = new FileInputStream(out); + wire(">> ", in); + } catch (FileNotFoundException e) { + logger.error(e, "Error tapping file: %s", out); + } finally { + IOUtils.closeQuietly(in); + } + } + }); + } + + private void output(byte[] b) { + wire(">> ", new ByteArrayInputStream(checkNotNull(b, "output"))); + } + + private void output(final String s) { + output(checkNotNull(s, "output").getBytes()); + } + +} diff --git a/core/src/main/java/org/jclouds/http/pool/ConnectionPoolTransformingHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/pool/ConnectionPoolTransformingHttpCommandExecutorService.java index 02081eb62d..0060747df7 100644 --- a/core/src/main/java/org/jclouds/http/pool/ConnectionPoolTransformingHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/pool/ConnectionPoolTransformingHttpCommandExecutorService.java @@ -36,17 +36,20 @@ import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import javax.inject.Inject; + import org.jclouds.concurrent.FutureExceptionParser; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommandRendezvous; import org.jclouds.http.HttpResponse; import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.lifecycle.BaseLifeCycle; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.util.Utils; import com.google.common.base.Function; import com.google.common.collect.MapMaker; -import javax.inject.Inject; /** * // TODO: Adrian: Document this! @@ -59,11 +62,12 @@ public class ConnectionPoolTransformingHttpCommandExecutorService extends Bas private final ConcurrentMap> poolMap; private final BlockingQueue> commandQueue; private final HttpCommandConnectionPool.Factory poolFactory; + private final LoggerFactory logFactory; @Inject public ConnectionPoolTransformingHttpCommandExecutorService(ExecutorService executor, HttpCommandConnectionPool.Factory pf, - BlockingQueue> commandQueue) { + BlockingQueue> commandQueue, LoggerFactory logFactory) { super(executor); this.poolFactory = pf; // TODO inject this. @@ -82,6 +86,7 @@ public class ConnectionPoolTransformingHttpCommandExecutorService extends Bas } }); this.commandQueue = commandQueue; + this.logFactory = logFactory; } /** @@ -120,7 +125,7 @@ public class ConnectionPoolTransformingHttpCommandExecutorService extends Bas invoke(rendezvous); } catch (Exception e) { Utils. rethrowIfRuntimeOrSameType(e); - logger.error(e, "Error processing command %s", rendezvous); + logger.error(e, "Error processing command %s", rendezvous.getCommand()); } } } @@ -135,14 +140,18 @@ public class ConnectionPoolTransformingHttpCommandExecutorService extends Bas Function exceptionTransformer) { exceptionIfNotActive(); final SynchronousQueue channel = new SynchronousQueue(); - // should block and immediately parse the response on exit. Future future = executorService.submit(new Callable() { + Logger transformerLogger = logFactory.getLogger(responseTransformer.getClass().getName()); public T call() throws Exception { Object o = channel.take(); - if (o instanceof Exception) + if (o instanceof Exception) { throw (Exception) o; - return responseTransformer.apply((HttpResponse) o); + } + transformerLogger.debug("Processing intermediate result for: %s", o); + T result = responseTransformer.apply((HttpResponse) o); + transformerLogger.debug("Processed intermediate result for: %s", o); + return result; } }); @@ -169,7 +178,7 @@ public class ConnectionPoolTransformingHttpCommandExecutorService extends Bas HttpCommandConnectionPool pool = poolMap.get(endpoint); if (pool == null) { // TODO limit; - logger.warn("pool not available for command %s; retrying", command); + logger.warn("pool not available for command %s; retrying", command.getCommand()); commandQueue.add(command); return; } @@ -178,24 +187,25 @@ public class ConnectionPoolTransformingHttpCommandExecutorService extends Bas try { connectionHandle = pool.getHandle(command); } catch (InterruptedException e) { - logger.warn(e, "Interrupted getting a connection for command %s; retrying", command); + logger.warn(e, "Interrupted getting a connection for command %s; retrying", command + .getCommand()); commandQueue.add(command); return; } catch (TimeoutException e) { - logger.warn(e, "Timeout getting a connection for command %s on pool %s; retrying", - command, pool); + logger.warn(e, "Timeout getting a connection for command %s on pool %s; retrying", command + .getCommand(), pool); commandQueue.add(command); return; } catch (RuntimeException e) { - logger.warn(e, "Error getting a connection for command %s on pool %s; retrying", command, - pool); + logger.warn(e, "Error getting a connection for command %s on pool %s; retrying", command + .getCommand(), pool); discardPool(endpoint, pool); commandQueue.add(command); return; } if (connectionHandle == null) { - logger.error("Failed to obtain connection for command %s; retrying", command); + logger.error("Failed to obtain connection for command %s; retrying", command.getCommand()); commandQueue.add(command); return; } @@ -221,16 +231,4 @@ public class ConnectionPoolTransformingHttpCommandExecutorService extends Bas endpoint.getPort())); } } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("ConnectionPoolTransformingHttpCommandExecutorService"); - sb.append("{status=").append(status); - sb.append(", commandQueue=").append((commandQueue != null) ? commandQueue.size() : 0); - sb.append(", poolMap=").append(poolMap); - sb.append('}'); - return sb.toString(); - } - } diff --git a/core/src/main/java/org/jclouds/http/pool/HttpCommandConnectionPool.java b/core/src/main/java/org/jclouds/http/pool/HttpCommandConnectionPool.java index 041bd6d395..3e39414911 100644 --- a/core/src/main/java/org/jclouds/http/pool/HttpCommandConnectionPool.java +++ b/core/src/main/java/org/jclouds/http/pool/HttpCommandConnectionPool.java @@ -46,18 +46,6 @@ import com.google.inject.assistedinject.Assisted; */ public abstract class HttpCommandConnectionPool extends BaseLifeCycle { - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("HttpCommandConnectionPool"); - sb.append("{endPoint=").append(endPoint); - sb.append(", available=").append(available); - sb.append(", currentSessionFailures=").append(currentSessionFailures); - sb.append(", hitBottom=").append(hitBottom); - sb.append('}'); - return sb.toString(); - } - protected final Semaphore allConnections; protected final BlockingQueue available; @@ -110,20 +98,18 @@ public abstract class HttpCommandConnectionPool extends BaseLifeCycle { if (!hitBottom) { hitBottom = available.size() == 0 && allConnections.availablePermits() == 0; if (hitBottom) - logger.warn("%1$s - saturated connection pool", this); + logger.warn("saturated connection pool"); } - logger.debug("%s - attempting to acquire connection; %s currently available", this, available - .size()); + logger.trace("Blocking up to %ds for a connection to %s", 5, getEndPoint()); C conn = available.poll(5, TimeUnit.SECONDS); if (conn == null) - throw new TimeoutException("could not obtain a pooled connection within 5 seconds"); + throw new TimeoutException(String.format("Timeout after %ds for a connection to %s", 5, + getEndPoint())); - logger.trace("%1$s - %2$d - aquired", conn, conn.hashCode()); if (connectionValid(conn)) { - logger.debug("%1$s - %2$d - reusing", conn, conn.hashCode()); return conn; } else { - logger.debug("%1$s - %2$d - unusable", conn, conn.hashCode()); + logger.debug("Connection %s unusable for endpoint %s", conn.hashCode(), getEndPoint()); shutdownConnection(conn); allConnections.release(); return getConnection(); @@ -156,7 +142,8 @@ public abstract class HttpCommandConnectionPool extends BaseLifeCycle { HttpCommandRendezvous rendezvous = getCommandFromConnection(connection); if (rendezvous != null) { if (isReplayable(rendezvous)) { - logger.info("resubmitting rendezvous: %1$s", rendezvous); + logger.info("resubmitting request: %s", rendezvous.getCommand().getRequest() + .getRequestLine()); resubmitQueue.add(rendezvous); } else { setExceptionOnCommand(e, rendezvous); @@ -182,11 +169,11 @@ public abstract class HttpCommandConnectionPool extends BaseLifeCycle { } protected void setExceptionOnCommand(Exception e, HttpCommandRendezvous rendezvous) { - logger.warn(e, "exception in rendezvous: %s", rendezvous); + logger.warn(e, "Exception processing command: %s", rendezvous.getCommand()); try { rendezvous.setException(e); } catch (InterruptedException e1) { - logger.error(e, "interrupted setting exception on command", rendezvous); + logger.error(e, "interrupted setting exception on command", rendezvous.getCommand()); } } diff --git a/core/src/main/java/org/jclouds/lifecycle/BaseLifeCycle.java b/core/src/main/java/org/jclouds/lifecycle/BaseLifeCycle.java index edc2c21f04..9098063e4d 100644 --- a/core/src/main/java/org/jclouds/lifecycle/BaseLifeCycle.java +++ b/core/src/main/java/org/jclouds/lifecycle/BaseLifeCycle.java @@ -100,7 +100,7 @@ public abstract class BaseLifeCycle implements Runnable, LifeCycle { @PostConstruct public void start() { - logger.info("starting %1$s", this); + logger.info("Starting %s", this); synchronized (this.statusLock) { if (this.status.compareTo(Status.SHUTDOWN_REQUEST) >= 0) { doShutdown(); diff --git a/core/src/main/java/org/jclouds/logging/BaseLogger.java b/core/src/main/java/org/jclouds/logging/BaseLogger.java index f668c37aab..9adf35bde1 100644 --- a/core/src/main/java/org/jclouds/logging/BaseLogger.java +++ b/core/src/main/java/org/jclouds/logging/BaseLogger.java @@ -31,53 +31,57 @@ package org.jclouds.logging; */ public abstract class BaseLogger implements Logger { - protected abstract void logError(String message, Throwable e); + protected abstract void logError(String message, Throwable e); - protected abstract void logError(String message); + protected abstract void logError(String message); - protected abstract void logWarn(String message, Throwable e); + protected abstract void logWarn(String message, Throwable e); - protected abstract void logWarn(String message); + protected abstract void logWarn(String message); - protected abstract void logInfo(String message); + protected abstract void logInfo(String message); - protected abstract void logDebug(String message); + protected abstract void logDebug(String message); - protected abstract void logTrace(String message); + protected abstract void logTrace(String message); - public void trace(String message, Object... args) { - if (isTraceEnabled()) - logTrace(String.format(message, args)); - } + public void trace(String message, Object... args) { + if (isTraceEnabled()) + logTrace(formatIfArgs(message, args)); + } - public void debug(String message, Object... args) { - if (isDebugEnabled()) - logDebug(String.format(message, args)); - } + private String formatIfArgs(String message, Object... args) { + return args.length == 0 ? message : String.format(message, args); + } - public void info(String message, Object... args) { - if (isInfoEnabled()) - logInfo(String.format(message, args)); - } + public void debug(String message, Object... args) { + if (isDebugEnabled()) + logDebug(formatIfArgs(message, args)); + } - public void warn(String message, Object... args) { - if (isWarnEnabled()) - logWarn(String.format(message, args)); - } + public void info(String message, Object... args) { + if (isInfoEnabled()) + logInfo(formatIfArgs(message, args)); + } - public void warn(Throwable e, String message, Object... args) { - if (isWarnEnabled()) - logWarn(String.format(message, args), e); - } + public void warn(String message, Object... args) { + if (isWarnEnabled()) + logWarn(formatIfArgs(message, args)); + } - public void error(String message, Object... args) { - if (isErrorEnabled()) - logError(String.format(message, args)); - } + public void warn(Throwable e, String message, Object... args) { + if (isWarnEnabled()) + logWarn(formatIfArgs(message, args), e); + } - public void error(Throwable e, String message, Object... args) { - if (isErrorEnabled()) - logError(String.format(message, args), e); - } + public void error(String message, Object... args) { + if (isErrorEnabled()) + logError(formatIfArgs(message, args)); + } + + public void error(Throwable e, String message, Object... args) { + if (isErrorEnabled()) + logError(formatIfArgs(message, args), e); + } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResource.java b/core/src/main/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResource.java index fcb634f99e..1d9064512d 100644 --- a/core/src/main/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResource.java +++ b/core/src/main/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResource.java @@ -23,25 +23,29 @@ */ package org.jclouds.logging.config; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Predicate; import static com.google.common.collect.Sets.filter; -import javax.inject.Inject; -import com.google.inject.ProvisionException; -import com.google.inject.TypeLiteral; -import com.google.inject.spi.InjectionListener; -import com.google.inject.spi.TypeEncounter; -import com.google.inject.spi.TypeListener; -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import javax.annotation.Resource; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; + +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Predicate; +import com.google.inject.ProvisionException; +import com.google.inject.TypeLiteral; +import com.google.inject.spi.InjectionListener; +import com.google.inject.spi.TypeEncounter; +import com.google.inject.spi.TypeListener; + /** * TypeListener that will bind {@link org.jclouds.logging.Logger} to members annotated with * {@link javax.annotation.Resource} @@ -119,7 +123,12 @@ public class BindLoggersAnnotatedWithResource implements TypeListener { Logger logger = loggerFactory.getLogger(type.getName()); for (Field field : loggerFields) { - encounter.register(new AssignLoggerToField(logger, field)); + if (field.isAnnotationPresent(Named.class)){ + Named name = field.getAnnotation(Named.class); + encounter.register(new AssignLoggerToField(loggerFactory.getLogger(name.value()), field)); + } else { + encounter.register(new AssignLoggerToField(logger, field)); + } } } diff --git a/core/src/main/java/org/jclouds/logging/config/LoggingModule.java b/core/src/main/java/org/jclouds/logging/config/LoggingModule.java index 7681203161..d502504af0 100644 --- a/core/src/main/java/org/jclouds/logging/config/LoggingModule.java +++ b/core/src/main/java/org/jclouds/logging/config/LoggingModule.java @@ -25,25 +25,28 @@ package org.jclouds.logging.config; import static com.google.inject.matcher.Matchers.any; +import javax.inject.Singleton; + import org.jclouds.logging.Logger; import com.google.inject.AbstractModule; +import com.google.inject.Provides; /** - * Creates a post-injection listener that binds Loggers named the same as the - * enclosing class. + * Creates a post-injection listener that binds Loggers named the same as the enclosing class. * * @author Adrian Cole * */ public abstract class LoggingModule extends AbstractModule { - @Override - protected void configure() { - bindListener(any(), new BindLoggersAnnotatedWithResource( - createLoggerFactory())); - } + @Override + protected void configure() { + bindListener(any(), new BindLoggersAnnotatedWithResource(createLoggerFactory())); + } - public abstract Logger.LoggerFactory createLoggerFactory(); + @Provides + @Singleton + public abstract Logger.LoggerFactory createLoggerFactory(); } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 1231ed50c4..7e9b25c901 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -243,7 +243,7 @@ public class RestAnnotationProcessor { } else if (isConstantDeclaration(method)) { bindConstant(method); } else if (!method.getDeclaringClass().equals(declaring)) { - logger.debug("skipping potentially overridden method", method); + logger.debug("skipping potentially overridden method %s", method); } else { throw new RuntimeException("Method is not annotated as either http or constant: " + method); @@ -422,7 +422,7 @@ public class RestAnnotationProcessor { RequestFilters.class).value()) { HttpRequestFilter instance = injector.getInstance(clazz); request.getFilters().add(instance); - logger.debug("%s - adding filter %s from annotation on %s", request, instance, + logger.trace("%s - adding filter %s from annotation on %s", request, instance, declaring.getName()); } } @@ -431,7 +431,7 @@ public class RestAnnotationProcessor { .value()) { HttpRequestFilter instance = injector.getInstance(clazz); request.getFilters().add(instance); - logger.debug("%s - adding filter %s from annotation on %s", request, instance, method + logger.trace("%s - adding filter %s from annotation on %s", request, instance, method .getName()); } } diff --git a/core/src/main/java/org/jclouds/rest/internal/RestClientProxy.java b/core/src/main/java/org/jclouds/rest/internal/RestClientProxy.java index 0c05d742d2..5b2db0c28e 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestClientProxy.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestClientProxy.java @@ -69,8 +69,8 @@ public class RestClientProxy implements InvocationHandler { @SuppressWarnings("unchecked") @Inject - public RestClientProxy(TransformingHttpCommand.Factory factory, - RestAnnotationProcessor util, TypeLiteral typeLiteral) { + public RestClientProxy(TransformingHttpCommand.Factory factory, RestAnnotationProcessor util, + TypeLiteral typeLiteral) { this.util = util; this.declaring = (Class) typeLiteral.getRawType(); this.commandFactory = factory; @@ -84,7 +84,7 @@ public class RestClientProxy implements InvocationHandler { return this.hashCode(); } else if (util.getDelegateOrNull(method) != null) { method = util.getDelegateOrNull(method); - logger.trace("%s - converting method to request", method); + logger.trace("Converting %s.%s", declaring.getSimpleName(), method.getName()); Function exceptionParser = util .createExceptionParserOrNullIfNotFound(method); // in case there is an exception creating the request, we should at least pass in args @@ -133,27 +133,27 @@ public class RestClientProxy implements InvocationHandler { } throw e; } - - logger.trace("%s - converted method to request %s", method, request); + logger.debug("Converted %s.%s to %s", declaring.getSimpleName(), method.getName(), request + .getRequestLine()); Function transformer = util.createResponseParser(method, request, args); + logger.trace("Response from %s.%s is parsed by %s", declaring.getSimpleName(), method + .getName(), transformer.getClass().getSimpleName()); - logger.trace("%s - creating command for request %s, transformer %s, exceptionParser %s", - method, request, transformer, exceptionParser); + logger.debug("Invoking %s.%s", declaring.getSimpleName(), method.getName()); Future result = commandFactory.create(request, transformer, exceptionParser).execute(); if (exceptionParser != null) { - logger.trace("%s - wrapping future for request %s in exceptionParser %s", method, - request, exceptionParser); + logger.trace("Exceptions from %s.%s are parsed by %s", declaring.getSimpleName(), + method.getName(), exceptionParser.getClass().getSimpleName()); result = new FutureExceptionParser(result, exceptionParser); } if (method.getReturnType().isAssignableFrom(Future.class)) { return result; } else { - logger - .trace("%s - invoking request synchronously %s", method, request, - exceptionParser); + logger.debug("Blocking up to %dms for %s.%s to complete", requestTimeoutMilliseconds, + declaring.getSimpleName(), method.getName()); return result.get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); } } else { diff --git a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java index 9a8182d5c9..0b9bd8a543 100644 --- a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java @@ -39,6 +39,9 @@ import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl; import org.jclouds.http.TransformingHttpCommandImpl; import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService; +import org.jclouds.http.internal.Wire; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -91,8 +94,16 @@ public class BackoffLimitedRetryHandlerTest { void setupExecutorService() throws Exception { ExecutorService execService = Executors.newCachedThreadPool(); JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService( - execService, new DelegatingRetryHandler(), new DelegatingErrorHandler()); - executorService = new TransformingHttpCommandExecutorServiceImpl(httpService, execService); + execService, new DelegatingRetryHandler(), new DelegatingErrorHandler(), new Wire( + Executors.newCachedThreadPool())); + executorService = new TransformingHttpCommandExecutorServiceImpl(httpService, execService, + new LoggerFactory() { + + public Logger getLogger(String category) { + return Logger.NULL; + } + + }); } @Test diff --git a/core/src/test/java/org/jclouds/http/internal/WireLiveTest.java b/core/src/test/java/org/jclouds/http/internal/WireLiveTest.java new file mode 100644 index 0000000000..c704e4f4c3 --- /dev/null +++ b/core/src/test/java/org/jclouds/http/internal/WireLiveTest.java @@ -0,0 +1,181 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * ==================================================================== + */ +package org.jclouds.http.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.io.IOUtils; +import org.jclouds.concurrent.WithinThreadExecutorService; +import org.jclouds.http.HttpUtils; +import org.jclouds.http.HttpUtils.MD5InputStreamResult; +import org.jclouds.logging.Logger; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true, testName = "core.WireLiveTest") +public class WireLiveTest { + + private static final String sysHttpStreamUrl = System.getProperty("jclouds.wire.httpstream.url"); + private static final String sysHttpStreamMd5 = System.getProperty("jclouds.wire.httpstream.md5"); + + private static class ConnectionTester implements Callable { + private final InputStream fromServer; + + private ConnectionTester(InputStream fromServer) { + this.fromServer = fromServer; + } + + public Void call() throws Exception { + Wire wire = setUp(); + InputStream in = wire.input(fromServer); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + IOUtils.copy(in, out); + MD5InputStreamResult compare = HttpUtils.generateMD5Result(new ByteArrayInputStream(out + .toByteArray())); + Thread.sleep(100); + assertEquals(HttpUtils.toHexString(compare.eTag), checkNotNull(sysHttpStreamMd5, + sysHttpStreamMd5)); + assertEquals(((BufferLogger) wire.wireLog).buff.toString().getBytes().length, 3331484); + return null; + } + } + + static class BufferLogger implements Logger { + StringBuffer buff = new StringBuffer(); + + public void debug(String message, Object... args) { + buff.append(message); + } + + public void error(String message, Object... args) { + } + + public void error(Throwable throwable, String message, Object... args) { + } + + public String getCategory() { + return null; + } + + public void info(String message, Object... args) { + } + + public boolean isDebugEnabled() { + return true; + } + + public boolean isErrorEnabled() { + return false; + } + + public boolean isInfoEnabled() { + return false; + } + + public boolean isTraceEnabled() { + return false; + } + + public boolean isWarnEnabled() { + return false; + } + + public void trace(String message, Object... args) { + } + + public void warn(String message, Object... args) { + } + + public void warn(Throwable throwable, String message, Object... args) { + } + + } + + public static Wire setUp() throws Exception { + ExecutorService service = Executors.newCachedThreadPool(); + BufferLogger bufferLogger = new BufferLogger(); + Wire wire = new Wire(service); + wire.wireLog = bufferLogger; + return wire; + } + + public Wire setUpSynch() throws Exception { + ExecutorService service = new WithinThreadExecutorService(); + BufferLogger bufferLogger = new BufferLogger(); + Wire wire = new Wire(service); + wire.wireLog = bufferLogger; + return wire; + } + + @Test(groups = "live") + public void testRemoteInputInputStream() throws Exception { + URL url = new URL(checkNotNull(sysHttpStreamUrl, "sysHttpStreamUrl")); + URLConnection connection = url.openConnection(); + Wire wire = setUp(); + InputStream in = wire.input(connection.getInputStream()); + MD5InputStreamResult compare = HttpUtils.generateMD5Result(in); + Thread.sleep(100); + assertEquals(HttpUtils.toHexString(compare.eTag), checkNotNull(sysHttpStreamMd5, + sysHttpStreamMd5)); + assertEquals(((BufferLogger) wire.wireLog).buff.toString().getBytes().length, 3331484); + } + + @Test(groups = "live") + public void testCopyRemoteInputInputStream() throws Exception { + URL url = new URL(checkNotNull(sysHttpStreamUrl, "sysHttpStreamUrl")); + URLConnection connection = url.openConnection(); + Callable callable = new ConnectionTester(connection.getInputStream()); + Future result = Executors.newCachedThreadPool().submit(callable); + result.get(30, TimeUnit.SECONDS); + } + + @Test(groups = "live") + public void testRemoteInputInputStreamSynch() throws Exception { + URL url = new URL(checkNotNull(sysHttpStreamUrl, "sysHttpStreamUrl")); + URLConnection connection = url.openConnection(); + Wire wire = setUpSynch(); + InputStream in = wire.input(connection.getInputStream()); + MD5InputStreamResult compare = HttpUtils.generateMD5Result(in); + Thread.sleep(100); + assertEquals(HttpUtils.toHexString(compare.eTag), checkNotNull(sysHttpStreamMd5, + sysHttpStreamMd5)); + assertEquals(((BufferLogger) wire.wireLog).buff.toString().getBytes().length, 3331484); + } + +} diff --git a/core/src/test/java/org/jclouds/http/internal/WireTest.java b/core/src/test/java/org/jclouds/http/internal/WireTest.java new file mode 100644 index 0000000000..a5757a07c4 --- /dev/null +++ b/core/src/test/java/org/jclouds/http/internal/WireTest.java @@ -0,0 +1,149 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * ==================================================================== + */ +package org.jclouds.http.internal; + +import static org.testng.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.jclouds.concurrent.WithinThreadExecutorService; +import org.jclouds.logging.Logger; +import org.jclouds.util.Utils; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", sequential = true, testName = "core.WireTest") +public class WireTest { + + class BufferLogger implements Logger { + StringBuffer buff = new StringBuffer(); + + public void debug(String message, Object... args) { + buff.append(message); + } + + public void error(String message, Object... args) { + } + + public void error(Throwable throwable, String message, Object... args) { + } + + public String getCategory() { + return null; + } + + public void info(String message, Object... args) { + } + + public boolean isDebugEnabled() { + return true; + } + + public boolean isErrorEnabled() { + return false; + } + + public boolean isInfoEnabled() { + return false; + } + + public boolean isTraceEnabled() { + return false; + } + + public boolean isWarnEnabled() { + return false; + } + + public void trace(String message, Object... args) { + } + + public void warn(String message, Object... args) { + } + + public void warn(Throwable throwable, String message, Object... args) { + } + + } + + public Wire setUp() throws Exception { + ExecutorService service = Executors.newCachedThreadPool(); + BufferLogger bufferLogger = new BufferLogger(); + Wire wire = new Wire(service); + wire.wireLog = bufferLogger; + return wire; + } + + public Wire setUpSynch() throws Exception { + ExecutorService service = new WithinThreadExecutorService(); + BufferLogger bufferLogger = new BufferLogger(); + Wire wire = new Wire(service); + wire.wireLog = bufferLogger; + return wire; + } + + public void testInputInputStream() throws Exception { + Wire wire = setUp(); + InputStream in = wire.input(new ByteArrayInputStream("foo".getBytes())); + String compare = Utils.toStringAndClose(in); + Thread.sleep(100); + assertEquals(compare, "foo"); + assertEquals(((BufferLogger) wire.wireLog).buff.toString(), "<< \"foo\""); + } + + public void testInputInputStreamSynch() throws Exception { + Wire wire = setUpSynch(); + InputStream in = wire.input(new ByteArrayInputStream("foo".getBytes())); + String compare = Utils.toStringAndClose(in); + assertEquals(compare, "foo"); + assertEquals(((BufferLogger) wire.wireLog).buff.toString(), "<< \"foo\""); + } + + public void testOutputInputStream() throws Exception { + Wire wire = setUp(); + InputStream in = wire.output(new ByteArrayInputStream("foo".getBytes())); + String compare = Utils.toStringAndClose(in); + Thread.sleep(100); + assertEquals(compare, "foo"); + assertEquals(((BufferLogger) wire.wireLog).buff.toString(), ">> \"foo\""); + } + + public void testOutputBytes() throws Exception { + Wire wire = setUp(); + wire.output("foo".getBytes()); + assertEquals(((BufferLogger) wire.wireLog).buff.toString(), ">> \"foo\""); + } + + public void testOutputString() throws Exception { + Wire wire = setUp(); + wire.output("foo"); + assertEquals(((BufferLogger) wire.wireLog).buff.toString(), ">> \"foo\""); + } +} diff --git a/core/src/test/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResourceTest.java b/core/src/test/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResourceTest.java index 51314df183..d1ce1eceec 100644 --- a/core/src/test/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResourceTest.java +++ b/core/src/test/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResourceTest.java @@ -31,6 +31,8 @@ import java.lang.reflect.Field; import java.util.Set; import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; import org.jclouds.logging.Logger; import org.jclouds.logging.config.BindLoggersAnnotatedWithResource.AssignLoggerToField; @@ -41,110 +43,105 @@ import org.testng.annotations.Test; import com.google.inject.AbstractModule; import com.google.inject.Guice; -import javax.inject.Inject; import com.google.inject.Injector; @Test public class BindLoggersAnnotatedWithResourceTest { - private BindLoggersAnnotatedWithResource blawr; + private BindLoggersAnnotatedWithResource blawr; - public static class A { - @Resource - private Logger logger = Logger.NULL; - } + public static class A { + @Resource + private Logger logger = Logger.NULL; + } - private static class B { - @Resource - private Logger logger = Logger.NULL; - } + private static class B { + @Resource + private Logger logger = Logger.NULL; - @BeforeMethod - void createBlawr() { - blawr = new BindLoggersAnnotatedWithResource( - new JDKLogger.JDKLoggerFactory()); - } + @Resource + @Named("blogger") + private Logger blogger = Logger.NULL; + } - @Test - void testHear() { - Injector i = Guice.createInjector(new AbstractModule() { + @BeforeMethod + void createBlawr() { + blawr = new BindLoggersAnnotatedWithResource(new JDKLogger.JDKLoggerFactory()); + } - @Override - protected void configure() { - bindListener(any(), blawr); - } + @Test + void testHear() { + Injector i = Guice.createInjector(new AbstractModule() { - }); - assertEquals(i.getInstance(A.class).logger.getCategory(), getClass() - .getName() - + "$A"); - assertEquals(i.getInstance(B.class).logger.getCategory(), getClass() - .getName() - + "$B"); + @Override + protected void configure() { + bindListener(any(), blawr); + } - } + }); + assertEquals(i.getInstance(A.class).logger.getCategory(), getClass().getName() + "$A"); + assertEquals(i.getInstance(B.class).logger.getCategory(), getClass().getName() + "$B"); + assertEquals(i.getInstance(B.class).blogger.getCategory(), "blogger"); + } - @Test - public void testAssignLoggerToField() throws SecurityException, - NoSuchFieldException, IllegalArgumentException, - IllegalAccessException { - Logger logger = createMock(Logger.class); - A a = new A(); - Field field = A.class.getDeclaredField("logger"); - AssignLoggerToField assigner = new AssignLoggerToField(logger, - field); - assigner.afterInjection(a); - assert field.get(a).equals(logger); - } + @Test + public void testAssignLoggerToField() throws SecurityException, NoSuchFieldException, + IllegalArgumentException, IllegalAccessException { + Logger logger = createMock(Logger.class); + A a = new A(); + Field field = A.class.getDeclaredField("logger"); + AssignLoggerToField assigner = new AssignLoggerToField(logger, field); + assigner.afterInjection(a); + assert field.get(a).equals(logger); + } - @Test - public void testLoggerFieldsAnnotatedWithResource() - throws SecurityException, NoSuchFieldException { - LoggerFieldsAnnotatedWithResource predicate = new LoggerFieldsAnnotatedWithResource(); - assert predicate.apply(A.class.getDeclaredField("logger")); - } + @Test + public void testLoggerFieldsAnnotatedWithResource() throws SecurityException, + NoSuchFieldException { + LoggerFieldsAnnotatedWithResource predicate = new LoggerFieldsAnnotatedWithResource(); + assert predicate.apply(A.class.getDeclaredField("logger")); + } - public static class C { - @SuppressWarnings("unused") - @Inject - private Logger logger = Logger.NULL; - } + public static class C { + @SuppressWarnings("unused") + @Inject + private Logger logger = Logger.NULL; + } - @Test - public void testLoggerFieldsAnnotatedWithInjectReturnsNull() - throws SecurityException, NoSuchFieldException { - LoggerFieldsAnnotatedWithResource predicate = new LoggerFieldsAnnotatedWithResource(); - assert ! predicate.apply(C.class.getDeclaredField("logger")); - } + @Test + public void testLoggerFieldsAnnotatedWithInjectReturnsNull() throws SecurityException, + NoSuchFieldException { + LoggerFieldsAnnotatedWithResource predicate = new LoggerFieldsAnnotatedWithResource(); + assert !predicate.apply(C.class.getDeclaredField("logger")); + } - public static class D { - @SuppressWarnings("unused") - @Resource - private Logger logger = Logger.NULL; + public static class D { + @SuppressWarnings("unused") + @Resource + private Logger logger = Logger.NULL; - @SuppressWarnings("unused") - @Resource - private Logger blogger; + @SuppressWarnings("unused") + @Resource + private Logger blogger; - } + } - @Test - public void testGetLoggerFieldsAnnotatedWithResourceNoLogger() { - Set fields = blawr.getLoggerFieldsAnnotatedWithResource(this - .getClass()); - assertEquals(fields.size(), 0); - } + @Test + public void testGetLoggerFieldsAnnotatedWithResourceNoLogger() { + Set fields = blawr.getLoggerFieldsAnnotatedWithResource(this.getClass()); + assertEquals(fields.size(), 0); + } - @Test - public void testGetLoggerFieldsAnnotatedWithResourceOneLogger() { - Set fields = blawr.getLoggerFieldsAnnotatedWithResource(A.class); - assertEquals(fields.size(), 1); - } + @Test + public void testGetLoggerFieldsAnnotatedWithResourceOneLogger() { + Set fields = blawr.getLoggerFieldsAnnotatedWithResource(A.class); + assertEquals(fields.size(), 1); + } - @Test - public void testGetLoggerFieldsAnnotatedWithResourceTwoLoggers() { - Set fields = blawr.getLoggerFieldsAnnotatedWithResource(D.class); - assertEquals(fields.size(), 2); - } + @Test + public void testGetLoggerFieldsAnnotatedWithResourceTwoLoggers() { + Set fields = blawr.getLoggerFieldsAnnotatedWithResource(D.class); + assertEquals(fields.size(), 2); + } } diff --git a/core/src/test/java/org/jclouds/rest/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/RestAnnotationProcessorTest.java index acbafbe321..269ec72609 100755 --- a/core/src/test/java/org/jclouds/rest/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/RestAnnotationProcessorTest.java @@ -70,7 +70,8 @@ import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.options.BaseHttpRequestOptions; import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.HttpRequestOptions; -import org.jclouds.rest.InvocationContext; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.annotations.DecoratorParam; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.Headers; @@ -438,7 +439,7 @@ public class RestAnnotationProcessorTest { .singletonList(expected.getBytes().length + "")); assertEquals(httpMethod.getEntity(), expected); } - + public void testCreatePutWithMethodProduces() throws SecurityException, NoSuchMethodException { Method method = TestPut.class.getMethod("putWithMethodBinderProduces", String.class); HttpRequest httpMethod = factory(TestPut.class).createRequest(method, @@ -453,7 +454,7 @@ public class RestAnnotationProcessorTest { .singletonList("data".getBytes().length + "")); assertEquals(httpMethod.getEntity(), "data"); } - + public void testCreatePutWithMethodConsumes() throws SecurityException, NoSuchMethodException { Method method = TestPut.class.getMethod("putWithMethodBinderConsumes", String.class); HttpRequest httpMethod = factory(TestPut.class).createRequest(method, @@ -472,7 +473,6 @@ public class RestAnnotationProcessorTest { assertEquals(httpMethod.getEntity(), expected); } - static class TestRequestFilter1 implements HttpRequestFilter { public HttpRequest filter(HttpRequest request) throws HttpException { return null; @@ -963,7 +963,8 @@ public class RestAnnotationProcessorTest { assertEquals(transformer, ParseURIList.class); } - public static class ReturnStringIf200Context extends ReturnStringIf200 implements InvocationContext { + public static class ReturnStringIf200Context extends ReturnStringIf200 implements + InvocationContext { private Object[] args; private HttpRequest request; @@ -1452,6 +1453,11 @@ public class RestAnnotationProcessorTest { URI.create("http://localhost:8080")); bind(URI.class).annotatedWith(Localhost2.class).toInstance( URI.create("http://localhost:8081")); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); } }, new RestModule(), new ExecutorServiceModule(new WithinThreadExecutorService()), new JavaUrlHttpCommandExecutorServiceModule()); diff --git a/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java b/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java index 29d6f2a4a4..043048b892 100644 --- a/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java +++ b/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java @@ -31,7 +31,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; @@ -47,6 +46,7 @@ import org.jclouds.http.HttpResponse; import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.internal.BaseHttpCommandExecutorService; +import org.jclouds.http.internal.Wire; import com.google.appengine.api.urlfetch.FetchOptions; import com.google.appengine.api.urlfetch.HTTPHeader; @@ -68,8 +68,8 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic @Inject public GaeHttpCommandExecutorService(URLFetchService urlFetchService, ExecutorService executorService, DelegatingRetryHandler retryHandler, - DelegatingErrorHandler errorHandler) { - super(executorService, retryHandler, errorHandler); + DelegatingErrorHandler errorHandler, Wire wire) { + super(executorService, retryHandler, errorHandler, wire); this.urlFetchService = urlFetchService; } @@ -169,20 +169,6 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic @Override protected HttpResponse invoke(HTTPRequest request) throws IOException { - logger.trace("%s - submitting request %s, headers: %s", request.getURL().getHost(), request - .getURL(), headersAsString(request.getHeaders())); - HTTPResponse response = urlFetchService.fetch(request); - logger.trace("%s - received response code %s, headers: %s", request.getURL().getHost(), - response.getResponseCode(), headersAsString(response.getHeaders())); - return convert(response); + return convert(urlFetchService.fetch(request)); } - - String headersAsString(List headers) { - StringBuilder builder = new StringBuilder(""); - for (HTTPHeader header : headers) - builder.append("[").append(header.getName()).append("=").append(header.getValue()).append( - "],"); - return builder.toString(); - } - } diff --git a/extensions/gae/src/test/java/org/jclouds/gae/GaeHttpCommandExecutorServiceTest.java b/extensions/gae/src/test/java/org/jclouds/gae/GaeHttpCommandExecutorServiceTest.java index de1a9fb054..c38f22b815 100644 --- a/extensions/gae/src/test/java/org/jclouds/gae/GaeHttpCommandExecutorServiceTest.java +++ b/extensions/gae/src/test/java/org/jclouds/gae/GaeHttpCommandExecutorServiceTest.java @@ -47,6 +47,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; +import org.jclouds.http.internal.Wire; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -70,7 +71,7 @@ public class GaeHttpCommandExecutorServiceTest { endPoint = URI.create("http://localhost:80/foo"); client = new GaeHttpCommandExecutorService(createNiceMock(URLFetchService.class), createNiceMock(ExecutorService.class), createNiceMock(DelegatingRetryHandler.class), - createNiceMock(DelegatingErrorHandler.class)); + createNiceMock(DelegatingErrorHandler.class), createNiceMock(Wire.class)); } @Test diff --git a/extensions/gae/src/test/java/org/jclouds/gae/config/GaeHttpCommandExecutorServiceModuleTest.java b/extensions/gae/src/test/java/org/jclouds/gae/config/GaeHttpCommandExecutorServiceModuleTest.java index bb548d36df..d33e9cf515 100644 --- a/extensions/gae/src/test/java/org/jclouds/gae/config/GaeHttpCommandExecutorServiceModuleTest.java +++ b/extensions/gae/src/test/java/org/jclouds/gae/config/GaeHttpCommandExecutorServiceModuleTest.java @@ -32,6 +32,8 @@ import org.jclouds.concurrent.WithinThreadExecutorService; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.gae.GaeHttpCommandExecutorService; import org.jclouds.http.HttpCommandExecutorService; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.util.Jsr330; import org.testng.annotations.Test; @@ -55,6 +57,11 @@ public class GaeHttpCommandExecutorServiceModuleTest { @Override protected void configure() { Jsr330.bindProperties(binder(), properties); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); super.configure(); } }); diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/NioHttpCommandConnectionPool.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/NioHttpCommandConnectionPool.java index e97e54f70d..4ff8c694b0 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/NioHttpCommandConnectionPool.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/NioHttpCommandConnectionPool.java @@ -31,6 +31,7 @@ import java.net.InetSocketAddress; import java.net.URI; import java.nio.charset.UnmappableCharacterException; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -53,7 +54,6 @@ import org.apache.http.nio.reactor.SessionRequestCallback; import org.apache.http.params.HttpParams; import org.jclouds.http.HttpCommandRendezvous; import org.jclouds.http.TransformingHttpCommand; -import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.pool.HttpCommandConnectionHandle; import org.jclouds.http.pool.HttpCommandConnectionPool; @@ -68,6 +68,12 @@ import com.google.inject.assistedinject.Assisted; public class NioHttpCommandConnectionPool extends HttpCommandConnectionPool implements EventListener { + @Override + public String toString() { + return "NioHttpCommandConnectionPool [ target=" + target + ", endPoint=" + getEndPoint() + + ", hashCode=" + hashCode() + " ]"; + } + private final NHttpClientConnectionPoolSessionRequestCallback sessionCallback; private final DefaultConnectingIOReactor ioReactor; private final IOEventDispatch dispatch; @@ -152,9 +158,6 @@ public class NioHttpCommandConnectionPool extends HttpCommandConnectionPool= maxConnectionReuse) - logger.debug("%1$s - %2$d - closing connection due to overuse %1$s/%2$s", conn, conn - .hashCode(), conn.getMetrics().getRequestCount(), maxConnectionReuse); if (conn.getStatus() == NHttpConnection.ACTIVE) { try { conn.shutdown(); @@ -182,7 +185,7 @@ public class NioHttpCommandConnectionPool extends HttpCommandConnectionPool%2$s[%3$s] - SessionRequest complete", request.getLocalAddress(), - request.getRemoteAddress(), request.getAttachment()); + } public void cancelled(SessionRequest request) { - logger.trace("%1$s->%2$s[%3$s] - SessionRequest cancelled", request.getLocalAddress(), - request.getRemoteAddress(), request.getAttachment()); - releaseConnectionAndCancelResponse(request); - } - - private void releaseConnectionAndCancelResponse(SessionRequest request) { - allConnections.release(); - TransformingHttpCommandExecutorService frequest = (TransformingHttpCommandExecutorService) request - .getAttachment(); - if (frequest != null) { - logger.error("%1$s->%2$s[%3$s] - Cancelling FutureCommand", request.getLocalAddress(), - request.getRemoteAddress(), frequest); - // TODO frequest.cancel(true); - } + releaseConnectionAndSetResponseException(request, new CancellationException( + "Cancelled request: " + request.getRemoteAddress())); } private void releaseConnectionAndSetResponseException(SessionRequest request, Exception e) { allConnections.release(); TransformingHttpCommand frequest = (TransformingHttpCommand) request.getAttachment(); if (frequest != null) { - logger.error(e, "%1$s->%2$s[%3$s] - Setting Exception on FutureCommand", request - .getLocalAddress(), request.getRemoteAddress(), frequest); frequest.setException(e); } } public void failed(SessionRequest request) { int count = currentSessionFailures.getAndIncrement(); - logger.warn("%1$s->%2$s[%3$s] - SessionRequest failed", request.getLocalAddress(), request - .getRemoteAddress(), request.getAttachment()); releaseConnectionAndSetResponseException(request, request.getException()); if (count >= maxSessionFailures) { logger.error(request.getException(), - "%1$s->%2$s[%3$s] - SessionRequest failures: %4$s, Disabling pool for %5$s", - request.getLocalAddress(), request.getRemoteAddress(), maxSessionFailures, - getTarget()); + "Exceeded maximum Session failures: %d, Disabling pool for %s", + maxSessionFailures, getTarget()); exception.set(request.getException()); } } public void timeout(SessionRequest request) { - logger.warn("%1$s->%2$s[%3$s] - SessionRequest timeout", request.getLocalAddress(), - request.getRemoteAddress(), request.getAttachment()); - releaseConnectionAndCancelResponse(request); + releaseConnectionAndSetResponseException(request, new TimeoutException("Timeout on: " + + request.getRemoteAddress())); } } @@ -262,22 +246,22 @@ public class NioHttpCommandConnectionPool extends HttpCommandConnectionPool rendezvous = getCommandFromConnection(conn); if (rendezvous != null) { /** @@ -293,7 +277,7 @@ public class NioHttpCommandConnectionPool extends HttpCommandConnectionPool> resubmitQueue, - DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler) { + DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, Wire wire) { this.entityFactory = entityFactory; this.resubmitQueue = resubmitQueue; this.retryHandler = retryHandler; this.errorHandler = errorHandler; + this.wire = wire; } public interface ConsumingNHttpEntityFactory { @@ -87,10 +96,19 @@ public class NioHttpCommandExecutionHandler implements NHttpRequestExecutionHand for (HttpRequestFilter filter : request.getFilters()) { request = filter.filter(request); } - return NioHttpUtils.convertToApacheRequest(request); + logger.debug("Sending request: %s", request.getRequestLine()); + if (request.getEntity() != null && wire.enabled()) + request.setEntity(wire.output(request.getEntity())); + HttpEntityEnclosingRequest nativeRequest = NioHttpUtils.convertToApacheRequest(request); + if (headerLog.isDebugEnabled()) { + headerLog.debug(">> %s", request.getRequestLine().toString()); + for (Entry header : request.getHeaders().entries()) { + headerLog.debug(">> %s: %s", header.getKey(), header.getValue()); + } + } + return nativeRequest; } return null; - } public ConsumingNHttpEntity responseEntity(HttpResponse response, HttpContext context) @@ -107,9 +125,16 @@ public class NioHttpCommandExecutionHandler implements NHttpRequestExecutionHand HttpCommand command = rendezvous.getCommand(); org.jclouds.http.HttpResponse response = NioHttpUtils .convertToJavaCloudsResponse(apacheResponse); + logger.debug("Receiving response: %s", response.getStatusLine()); + if (headerLog.isDebugEnabled()) { + headerLog.debug("<< %s", response.getStatusLine().toString()); + for (Entry header : response.getHeaders().entries()) { + headerLog.debug("<< %s: %s", header.getKey(), header.getValue()); + } + } + if (response.getContent() != null && wire.enabled()) + response.setContent(wire.input(response.getContent())); int statusCode = response.getStatusCode(); - // TODO determine how to get the original request here so we don't need to build each - // time if (statusCode >= 300) { if (retryHandler.shouldRetryRequest(command, response)) { resubmitQueue.add(rendezvous); @@ -119,7 +144,6 @@ public class NioHttpCommandExecutionHandler implements NHttpRequestExecutionHand rendezvous.setException(command.getException()); } } else { - logger.trace("submitting response task %s", command); rendezvous.setResponse(response); } } catch (InterruptedException e) { diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/NioTransformingHttpCommandExecutorService.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/NioTransformingHttpCommandExecutorService.java index cb4753ecf7..cd236fb690 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/NioTransformingHttpCommandExecutorService.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/NioTransformingHttpCommandExecutorService.java @@ -26,12 +26,13 @@ package org.jclouds.http.httpnio.pool; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; +import javax.inject.Inject; +import javax.inject.Singleton; + import org.apache.http.nio.NHttpConnection; import org.jclouds.http.HttpCommandRendezvous; import org.jclouds.http.pool.ConnectionPoolTransformingHttpCommandExecutorService; - -import javax.inject.Inject; -import javax.inject.Singleton; +import org.jclouds.logging.Logger.LoggerFactory; /** * // TODO: Adrian: Document this! @@ -42,11 +43,16 @@ import javax.inject.Singleton; public class NioTransformingHttpCommandExecutorService extends ConnectionPoolTransformingHttpCommandExecutorService { + @Override + public String toString() { + return String.format("NioTransformingHttpCommandExecutorService [ hashCode=%d ]", hashCode()); + } + @Inject public NioTransformingHttpCommandExecutorService(ExecutorService executor, NioHttpCommandConnectionPool.Factory poolFactory, - BlockingQueue> commandQueue) { - super(executor, poolFactory, commandQueue); + BlockingQueue> commandQueue, LoggerFactory logFactory) { + super(executor, poolFactory, commandQueue, logFactory); } } diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/util/NioHttpUtils.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/util/NioHttpUtils.java index 781adc0c45..0ff80ee103 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/util/NioHttpUtils.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/util/NioHttpUtils.java @@ -114,6 +114,7 @@ public class NioHttpUtils { response.getHeaders().put(header.getName(), header.getValue()); } response.setStatusCode(apacheResponse.getStatusLine().getStatusCode()); + response.setMessage(apacheResponse.getStatusLine().getReasonPhrase()); return response; } } \ No newline at end of file diff --git a/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/PCSContextBuilder.java b/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/PCSContextBuilder.java index 66e60f0062..843a41f0cb 100755 --- a/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/PCSContextBuilder.java +++ b/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/PCSContextBuilder.java @@ -113,11 +113,6 @@ public class PCSContextBuilder extends return (PCSContextBuilder) super.withHttpMaxRetries(httpMaxRetries); } - @Override - public PCSContextBuilder withJsonDebug() { - return (PCSContextBuilder) super.withJsonDebug(); - } - @Override public PCSContextBuilder withModule(Module module) { return (PCSContextBuilder) super.withModule(module); @@ -127,7 +122,7 @@ public class PCSContextBuilder extends public PCSContextBuilder withRequestTimeout(long milliseconds) { return (PCSContextBuilder) super.withRequestTimeout(milliseconds); } - + @Override public PCSContextBuilder withModules(Module... modules) { return (PCSContextBuilder) super.withModules(modules); @@ -157,9 +152,4 @@ public class PCSContextBuilder extends public PCSContextBuilder withPoolRequestInvokerThreads(int poolRequestInvokerThreads) { return (PCSContextBuilder) super.withPoolRequestInvokerThreads(poolRequestInvokerThreads); } - - @Override - public PCSContextBuilder withSaxDebug() { - return (PCSContextBuilder) super.withSaxDebug(); - } } diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSBlobStoreTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSBlobStoreTest.java index caddd68155..5523119721 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSBlobStoreTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSBlobStoreTest.java @@ -54,6 +54,8 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.options.GetOptions; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.mezeo.pcs2.domain.ContainerMetadata; import org.jclouds.mezeo.pcs2.domain.FileMetadata; import org.jclouds.mezeo.pcs2.domain.PCSFile; @@ -434,6 +436,11 @@ public class PCSBlobStoreTest { bind(URI.class).annotatedWith(WebDAV.class).toInstance( URI.create("http://localhost:8080/webdav")); bind(PCSConnection.class).to(StubPCSConnection.class).asEagerSingleton(); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); } @SuppressWarnings("unused") diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSConnectionTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSConnectionTest.java index 6f1a8bd259..9744519eb4 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSConnectionTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSConnectionTest.java @@ -50,6 +50,8 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseURIList; import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.http.functions.ReturnVoidIf2xx; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.mezeo.pcs2.domain.FileMetadata; import org.jclouds.mezeo.pcs2.domain.PCSFile; import org.jclouds.mezeo.pcs2.endpoints.RootContainer; @@ -225,6 +227,11 @@ public class PCSConnectionTest { URI.create("http://localhost:8080")); bind(URI.class).annotatedWith(RootContainer.class).toInstance( URI.create("http://localhost:8080/root")); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); } @SuppressWarnings("unused") diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSContextModuleTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSContextModuleTest.java index fc7988f0cb..0beb2ac803 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSContextModuleTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSContextModuleTest.java @@ -26,6 +26,8 @@ package org.jclouds.mezeo.pcs2; import static org.testng.Assert.assertEquals; import org.jclouds.blobstore.BlobStoreMapsModule; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.mezeo.pcs2.config.PCSContextModule; import org.jclouds.mezeo.pcs2.config.StubPCSBlobStoreModule; import org.jclouds.mezeo.pcs2.config.PCSContextModule.PCSContextImpl; @@ -58,6 +60,11 @@ public class PCSContextModuleTest { "key"); bindConstant().annotatedWith(Jsr330.named(PCSConstants.PROPERTY_PCS2_ENDPOINT)).to( "http://localhost"); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); super.configure(); } }); diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/config/PCSContextModuleTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/config/PCSContextModuleTest.java index 86d51d7021..943a18a115 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/config/PCSContextModuleTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/config/PCSContextModuleTest.java @@ -34,6 +34,8 @@ import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler; import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.mezeo.pcs2.domain.ContainerMetadata; import org.jclouds.mezeo.pcs2.domain.FileMetadata; import org.jclouds.mezeo.pcs2.domain.PCSFile; @@ -65,6 +67,11 @@ public class PCSContextModuleTest { "key"); bindConstant().annotatedWith(Jsr330.named(PCSConstants.PROPERTY_PCS2_ENDPOINT)).to( "http://localhost"); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); super.configure(); } }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/integration/PCSTestInitializer.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/integration/PCSTestInitializer.java index 631972a3db..b13c87e2dc 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/integration/PCSTestInitializer.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/integration/PCSTestInitializer.java @@ -49,8 +49,8 @@ public class PCSTestInitializer extends protected PCSContext createLiveContext(Module configurationModule, String url, String app, String account, String key) { return new PCSContextBuilder(URI.create(url), account, key).withRequestTimeout(60000) - .relaxSSLHostname().withSaxDebug().withModules(configurationModule, - new Log4JLoggingModule()).buildContext(); + .relaxSSLHostname().withModules(configurationModule, new Log4JLoggingModule()) + .buildContext(); } @Override diff --git a/mezeo/pcs2/core/src/test/resources/log4j.xml b/mezeo/pcs2/core/src/test/resources/log4j.xml index a97df723b7..23deb5a816 100755 --- a/mezeo/pcs2/core/src/test/resources/log4j.xml +++ b/mezeo/pcs2/core/src/test/resources/log4j.xml @@ -33,6 +33,28 @@ + + + + + + + + + + + + + + + + + + @@ -58,22 +80,36 @@ - + + + + + - - + + + + + + + + - + + + + + + - - + \ No newline at end of file diff --git a/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/SDNContextBuilder.java b/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/SDNContextBuilder.java index bd0252febe..bd7a475c5b 100755 --- a/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/SDNContextBuilder.java +++ b/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/SDNContextBuilder.java @@ -106,11 +106,6 @@ public class SDNContextBuilder extends CloudContextBuilder { return (SDNContextBuilder) super.withHttpMaxRetries(httpMaxRetries); } - @Override - public SDNContextBuilder withJsonDebug() { - return (SDNContextBuilder) super.withJsonDebug(); - } - @Override public SDNContextBuilder withModule(Module module) { return (SDNContextBuilder) super.withModule(module); @@ -146,11 +141,6 @@ public class SDNContextBuilder extends CloudContextBuilder { return (SDNContextBuilder) super.withPoolRequestInvokerThreads(poolRequestInvokerThreads); } - @Override - public SDNContextBuilder withSaxDebug() { - return (SDNContextBuilder) super.withSaxDebug(); - } - @Override public SDNContextBuilder withEndpoint(URI endpoint) { return (SDNContextBuilder) (SDNContextBuilder) withEndpoint(this, endpoint); diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationLiveTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationLiveTest.java index d7160beab2..145e07fe1b 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationLiveTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationLiveTest.java @@ -24,7 +24,6 @@ package org.jclouds.nirvanix.sdn; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.http.HttpConstants.PROPERTY_JSON_DEBUG; import static org.testng.Assert.assertNotNull; import java.net.URI; @@ -37,7 +36,6 @@ import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.config.RestModule; -import org.jclouds.util.Jsr330; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -73,7 +71,6 @@ public class SDNAuthenticationLiveTest { protected void configure() { bind(URI.class).annotatedWith(SDN.class).toInstance( URI.create("http://services.nirvanix.com/ws")); - bindConstant().annotatedWith(Jsr330.named(PROPERTY_JSON_DEBUG)).to(true); } @SuppressWarnings("unused") diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java index 2de285acfb..6748218f56 100755 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java @@ -34,6 +34,8 @@ import org.jclouds.concurrent.WithinThreadExecutorService; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpRequest; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.nirvanix.sdn.functions.ParseSessionTokenFromJsonResponse; import org.jclouds.rest.config.RestModule; import org.jclouds.rest.internal.RestAnnotationProcessor; @@ -78,6 +80,11 @@ public class SDNAuthenticationTest { protected void configure() { bind(URI.class).annotatedWith(SDN.class) .toInstance(URI.create("http://localhost:8080")); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); } }, new RestModule(), new ExecutorServiceModule(new WithinThreadExecutorService()), new JavaUrlHttpCommandExecutorServiceModule()); diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNConnectionLiveTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNConnectionLiveTest.java index 9c75c403e4..ae9fea2ae0 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNConnectionLiveTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNConnectionLiveTest.java @@ -16,9 +16,6 @@ import org.jclouds.nirvanix.sdn.domain.UploadInfo; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - /** * Tests behavior of {@code SDNConnection} * @@ -40,7 +37,7 @@ public class SDNConnectionLiveTest { String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); connection = new SDNContextBuilder(app, user, password).withModules(new Log4JLoggingModule()) - .withJsonDebug().buildContext().getApi(); + .buildContext().getApi(); } public void testUploadToken() throws InterruptedException, ExecutionException, TimeoutException { @@ -53,7 +50,8 @@ public class SDNConnectionLiveTest { connection.upload(uploadInfo.getHost(), uploadInfo.getToken(), "container", new Blob("key", "value")).get(30, TimeUnit.SECONDS); - // Multimap metadata = ImmutableMultimap.of("chef", "sushi"); - // who knows... 403 error; connection.setMetadata("container", "key", metadata).get(30, TimeUnit.SECONDS); + // Multimap metadata = ImmutableMultimap.of("chef", "sushi"); + // who knows... 403 error; connection.setMetadata("container", "key", metadata).get(30, + // TimeUnit.SECONDS); } } diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNConnectionTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNConnectionTest.java index adf55c22b7..cb8d0e9325 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNConnectionTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNConnectionTest.java @@ -42,6 +42,8 @@ import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpRequest; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.functions.ReturnVoidIf2xx; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.nirvanix.sdn.functions.ParseUploadInfoFromJsonResponse; import org.jclouds.rest.config.RestModule; import org.jclouds.rest.internal.RestAnnotationProcessor; @@ -130,6 +132,11 @@ public class SDNConnectionTest { protected void configure() { bind(URI.class).annotatedWith(SDN.class) .toInstance(URI.create("http://localhost:8080")); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); } @SuppressWarnings("unused") diff --git a/nirvanix/sdn/core/src/test/resources/log4j.xml b/nirvanix/sdn/core/src/test/resources/log4j.xml index a97df723b7..23deb5a816 100755 --- a/nirvanix/sdn/core/src/test/resources/log4j.xml +++ b/nirvanix/sdn/core/src/test/resources/log4j.xml @@ -33,6 +33,28 @@ + + + + + + + + + + + + + + + + + + @@ -58,22 +80,36 @@ - + + + + + - - + + + + + + + + - + + + + + + - - + \ No newline at end of file diff --git a/project/pom.xml b/project/pom.xml index bf0e5b2f05..d7404b2e72 100644 --- a/project/pom.xml +++ b/project/pom.xml @@ -146,6 +146,8 @@ true http://mirror.cloudera.com/apache/maven/binaries/apache-maven-2.2.1-bin.tar.bz2 c581a15cb0001d9b771ad6df7c8156f8 + http://apache.opensourceresources.org/commons/logging/binaries/commons-logging-1.1.1-bin.tar.gz + e5de09672af9b386c30a311654d8541a org.jclouds.test.testng.UnitTestStatusListener @@ -217,6 +219,14 @@ jclouds.test.initializer ${jclouds.test.initializer} + + jclouds.wire.httpstream.url + ${jclouds.wire.httpstream.url} + + + jclouds.wire.httpstream.md5 + ${jclouds.wire.httpstream.md5} + jclouds.blobstore.httpstream.url ${jclouds.blobstore.httpstream.url} @@ -422,6 +432,14 @@ pageTracker._trackPageview(); jclouds.blobstore.httpstream.md5 ${jclouds.blobstore.httpstream.md5} + + jclouds.wire.httpstream.url + ${jclouds.wire.httpstream.url} + + + jclouds.wire.httpstream.md5 + ${jclouds.wire.httpstream.md5} + diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextBuilder.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextBuilder.java index 0862a2f955..f75d639caf 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextBuilder.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextBuilder.java @@ -75,7 +75,7 @@ public class CloudFilesContextBuilder public CloudFilesContextBuilder withRequestTimeout(long milliseconds) { return (CloudFilesContextBuilder) super.withRequestTimeout(milliseconds); } - + @Override public CloudFilesContextBuilder withExecutorService(ExecutorService service) { return (CloudFilesContextBuilder) super.withExecutorService(service); @@ -91,11 +91,6 @@ public class CloudFilesContextBuilder return (CloudFilesContextBuilder) super.withHttpMaxRetries(httpMaxRetries); } - @Override - public CloudFilesContextBuilder withJsonDebug() { - return (CloudFilesContextBuilder) super.withJsonDebug(); - } - @Override public CloudFilesContextBuilder withModule(Module module) { return (CloudFilesContextBuilder) super.withModule(module); @@ -132,11 +127,6 @@ public class CloudFilesContextBuilder .withPoolRequestInvokerThreads(poolRequestInvokerThreads); } - @Override - public CloudFilesContextBuilder withSaxDebug() { - return (CloudFilesContextBuilder) super.withSaxDebug(); - } - public CloudFilesContextBuilder(Properties props) { super(new TypeLiteral() { }, new TypeLiteral() { @@ -165,8 +155,7 @@ public class CloudFilesContextBuilder @Override public CloudFilesContextBuilder withEndpoint(URI endpoint) { - return (CloudFilesContextBuilder) RackspaceContextBuilder - .withEndpoint(this, endpoint); + return (CloudFilesContextBuilder) RackspaceContextBuilder.withEndpoint(this, endpoint); } } diff --git a/rackspace/cloudservers/core/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersContextBuilder.java b/rackspace/cloudservers/core/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersContextBuilder.java index d77b3de7cd..8fe76db65a 100755 --- a/rackspace/cloudservers/core/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersContextBuilder.java +++ b/rackspace/cloudservers/core/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersContextBuilder.java @@ -107,11 +107,6 @@ public class CloudServersContextBuilder extends RackspaceContextBuilder + + + + + + + + + + + + + + + + + + @@ -58,22 +80,36 @@ - + + + + + - - + + + + + + + + - + + + + + + - - + \ No newline at end of file