From 6db5727755aff9c573082f6576a5a3d5c7316063 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 1 Nov 2010 22:49:55 -0700 Subject: [PATCH 1/4] Issue 286: terremark ecloud support now works --- .../TerremarkECloudContextBuilder.java | 4 +-- .../TerremarkECloudPropertiesBuilder.java | 3 ++ ...markECloudComputeServiceContextModule.java | 35 +++++++++++++++++++ ...erremarkECloudComputeServiceLiveTest.java} | 6 ++-- 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkECloudComputeServiceContextModule.java rename vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/{TerremarkECloudComputeServiceLiveTestDisabled.java => TerremarkECloudComputeServiceLiveTest.java} (94%) diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudContextBuilder.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudContextBuilder.java index 0660dc110f..9b0d6a59b0 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudContextBuilder.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudContextBuilder.java @@ -25,7 +25,7 @@ import java.util.Properties; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.vcloud.VCloudExpressContextBuilder; -import org.jclouds.vcloud.terremark.compute.config.TerremarkVCloudComputeServiceContextModule; +import org.jclouds.vcloud.terremark.compute.config.TerremarkECloudComputeServiceContextModule; import org.jclouds.vcloud.terremark.config.TerremarkECloudRestClientModule; import com.google.inject.Injector; @@ -52,7 +52,7 @@ public class TerremarkECloudContextBuilder extends VCloudExpressContextBuilder { @Override protected void addContextModule(List modules) { - modules.add(new TerremarkVCloudComputeServiceContextModule()); + modules.add(new TerremarkECloudComputeServiceContextModule()); } @Override diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudPropertiesBuilder.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudPropertiesBuilder.java index 9bec07eb52..547bdaf8f3 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudPropertiesBuilder.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkECloudPropertiesBuilder.java @@ -21,6 +21,7 @@ package org.jclouds.vcloud.terremark; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME; import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION; @@ -39,6 +40,8 @@ public class TerremarkECloudPropertiesBuilder extends TerremarkVCloudPropertiesB properties.setProperty(PROPERTY_ENDPOINT, "https://services.enterprisecloud.terremark.com/api"); properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions"); properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.5"); + // for some reason the centos template is very slow to deploy + properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 720l * 1000l + ""); return properties; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkECloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkECloudComputeServiceContextModule.java new file mode 100644 index 0000000000..017c798f46 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkECloudComputeServiceContextModule.java @@ -0,0 +1,35 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.vcloud.terremark.compute.config; + +import static org.jclouds.compute.domain.OsFamily.CENTOS; + +import org.jclouds.compute.domain.TemplateBuilder; + +import com.google.inject.Injector; + +/** + * @author Adrian Cole + */ +public class TerremarkECloudComputeServiceContextModule extends TerremarkVCloudComputeServiceContextModule { + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + return template.osFamily(CENTOS); + } +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTestDisabled.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java similarity index 94% rename from vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTestDisabled.java rename to vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java index 9c1086b3f5..3be000c4c8 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTestDisabled.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java @@ -44,9 +44,9 @@ import org.testng.annotations.Test; * * @author Adrian Cole */ -@Test(groups = "live", enabled = false, sequential = true, testName = "terremark.TerremarkVCloudComputeServiceLiveTest") -public class TerremarkECloudComputeServiceLiveTestDisabled extends BaseComputeServiceLiveTest { - public TerremarkECloudComputeServiceLiveTestDisabled() { +@Test(groups = "live", enabled = true, sequential = true, testName = "terremark.TerremarkVCloudComputeServiceLiveTest") +public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { + public TerremarkECloudComputeServiceLiveTest() { provider = "trmk-ecloud"; } From 63e4441a1765cf901380f28271bbd77bad052aeb Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 2 Nov 2010 22:47:03 -0700 Subject: [PATCH 2/4] fixed example --- skeletons/standalone-compute/pom.xml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/skeletons/standalone-compute/pom.xml b/skeletons/standalone-compute/pom.xml index 3ef57068aa..d65f9ef182 100644 --- a/skeletons/standalone-compute/pom.xml +++ b/skeletons/standalone-compute/pom.xml @@ -33,9 +33,10 @@ trmkrun-ccc,test.trmk-924 - https://servermanager-compute.com - 1.0 - FIXME + FIXME + https://servermanager.com + 1.0 + FIXME @@ -95,16 +96,16 @@ - test.servermanager-compute.endpoint - ${test.servermanager-compute.endpoint} + test.servermanager.endpoint + ${test.servermanager.endpoint} - test.servermanager-compute.apiversion - ${test.servermanager-compute.apiversion} + test.servermanager.apiversion + ${test.servermanager.apiversion} - test.servermanager-compute.identity - ${test.servermanager-compute.identity} + test.servermanager.identity + ${test.servermanager.identity} jclouds.compute.blacklist.nodes From 0c690f686fa0a386cefdba0402a2aaab3e8144cd Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 6 Nov 2010 09:44:05 +0100 Subject: [PATCH 3/4] Issue 396: added peer1-storage provider --- README.txt | 18 ++++++++++------- atmos/pom.xml | 20 +++++++++++++++++++ .../saas/AtmosStorageAsyncClient.java | 2 ++ .../atmosonline/saas/filters/SignRequest.java | 2 +- .../saas/AtmosStorageAsyncClientTest.java | 2 +- .../main/clojure/org/jclouds/blobstore.clj | 3 ++- .../internal/RestAnnotationProcessor.java | 6 +++++- core/src/main/resources/rest.properties | 6 +++++- .../internal/RestAnnotationProcessorTest.java | 14 ++++++++++++- 9 files changed, 60 insertions(+), 13 deletions(-) diff --git a/README.txt b/README.txt index 4a000b28d2..d5bc557537 100644 --- a/README.txt +++ b/README.txt @@ -19,22 +19,26 @@ Overview: -jclouds is an open source framework that helps you get started in the cloud +jclouds is an open source library that helps you get started in the cloud and reuse your java and clojure development skills. Our api allows you to -freedom to use portable abstractions or cloud-specific features. +freedom to use portable abstractions or cloud-specific features. We have +two abstractions at the moment: compute and blobstore. compute helps you +bootstrap machines in the cloud. blobstore helps you manage key-value +data. our current version is 1.0-beta-7 our dev version is 1.0-SNAPSHOT -our compute api supports: ec2, gogrid, rackspace, rimuhosting, vcloud, trmk-ecloud, - trmk-vcloudexpress, eucalyptus, bluelock-vclouddirector, - bluelock-vcloudexpress, slicehost, stub (in-memory) +our compute api supports: ec2, gogrid, cloudservers (rackspace), rimuhosting, vcloud, + trmk-ecloud, trmk-vcloudexpress, eucalyptus, + bluelock-vclouddirector, slicehost, stub (in-memory) * note * the pom dependency org.jclouds/jclouds-allcompute gives you access to to all of these providers -our blobstore api supports: s3, rackspace, azure, atmos online, att synaptic, - walrus, googlestorage, transient (in-memory), filesystem (on-disk) +our blobstore api supports: s3, cloudfiles (rackspace), azurestorage, atmosonline, + synaptic, peer1-storage, walrus, googlestorage, + transient (in-memory), filesystem (on-disk) * note * the pom dependency org.jclouds/jclouds-allblobstore gives you access to to all of these providers diff --git a/atmos/pom.xml b/atmos/pom.xml index aec222e1a4..3846cd76dd 100644 --- a/atmos/pom.xml +++ b/atmos/pom.xml @@ -36,6 +36,10 @@ 1.3.0 FIXME FIXME + https://cloudonestorage.peer1.com + 1.3.0 + FIXME + FIXME https://storage.synaptic.att.com 1.3.0 FIXME @@ -107,6 +111,22 @@ test.atmosonline.credential ${test.atmosonline.credential} + + test.peer1-storage.endpoint + ${test.peer1-storage.endpoint} + + + test.peer1-storage.apiversion + ${test.peer1-storage.apiversion} + + + test.peer1-storage.identity + ${test.peer1-storage.identity} + + + test.peer1-storage.credential + ${test.peer1-storage.credential} + test.synaptic.endpoint ${test.synaptic.endpoint} diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClient.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClient.java index 2ba7495fb2..ec9a939907 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClient.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClient.java @@ -29,6 +29,7 @@ import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.atmosonline.saas.binders.BindMetadataToHeaders; @@ -103,6 +104,7 @@ public interface AtmosStorageAsyncClient { @POST @Path("/{directoryName}/") @ExceptionParser(ReturnEndpointIfAlreadyExists.class) + @Produces(MediaType.APPLICATION_OCTET_STREAM) @Consumes(MediaType.WILDCARD) ListenableFuture createDirectory(@PathParam("directoryName") String directoryName); diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/filters/SignRequest.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/filters/SignRequest.java index 861f84ed80..23a5ef0c3e 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/filters/SignRequest.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/filters/SignRequest.java @@ -148,7 +148,7 @@ public class SignRequest implements HttpRequestFilter { // TreeSet == Sort the headers alphabetically. Set headers = new TreeSet(request.getHeaders().keySet()); for (String header : headers) { - if (header.startsWith("x-emc-")) { + if (header.startsWith("x-emc-") && !header.equals(AtmosStorageHeaders.SIGNATURE)) { // Convert all header names to lowercase. toSign.append(header.toLowerCase()).append(":"); // For headers with values that span multiple lines, convert them into one line by diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java index d30356c52c..14a229ef48 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java @@ -140,7 +140,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest { payload = new MultipartForm(BOUNDARY, parts); } else if (formParams.size() > 0) { payload = Payloads.newUrlEncodedFormPayload(formParams, skips); + } else if (headers.containsKey(CONTENT_TYPE)) { + payload = Payloads.newByteArrayPayload(new byte[]{}); + payload.getContentMetadata().setContentType(Iterables.get(headers.get(CONTENT_TYPE),0)); } if (payload != null) { request.setPayload(payload); diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index 32844739b3..7fb01d36cc 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -104,7 +104,11 @@ synaptic.contextbuilder=org.jclouds.atmosonline.saas.AtmosStorageContextBuilder synaptic.endpoint=https://storage.synaptic.att.com synaptic.apiversion=1.3.0 -# TODO peer1 and hostedsolutions use atmos +peer1-storage.contextbuilder=org.jclouds.atmosonline.saas.AtmosStorageContextBuilder +peer1-storage.endpoint=https://storage.synaptic.att.com +peer1-storage.apiversion=1.3.0 + +# TODO hostedsolutions use atmos cloudfiles.contextbuilder=org.jclouds.rackspace.cloudfiles.CloudFilesContextBuilder cloudfiles.propertiesbuilder=org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index 7b2d4fa9f0..b107347cb6 100755 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -373,10 +373,22 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @POST @Path("") public void post(HttpRequestOptions options); - + + @POST + @Path("") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public void post(); } public void testHttpRequestOptionsPayloadParam() throws SecurityException, NoSuchMethodException, IOException { + Method method = TestPayloadParamVarargs.class.getMethod("post"); + HttpRequest request = factory(TestQuery.class).createRequest(method); + assertRequestLineEquals(request, "POST http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, "", "application/octet-stream", false); + } + + public void testHttpRequestWithOnlyContentType() throws SecurityException, NoSuchMethodException, IOException { Method method = TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class); verifyTestPostOptions(method); } From 63ca8c1e967d9c2d9ba8c14076304844df78b6d1 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 6 Nov 2010 10:49:58 +0100 Subject: [PATCH 4/4] fixed error parsing in azure --- .../ParseAzureStorageErrorFromXmlContent.java | 1 - .../ParseAzureErrorFromXmlContentTest.java | 9 ++++ .../concurrent/internal/SyncProxy.java | 15 ++++--- .../org/jclouds/http/functions/ParseSax.java | 43 +++++++++++-------- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/azure/src/main/java/org/jclouds/azure/storage/handlers/ParseAzureStorageErrorFromXmlContent.java b/azure/src/main/java/org/jclouds/azure/storage/handlers/ParseAzureStorageErrorFromXmlContent.java index cf0cbd58ce..6a165e8dcd 100644 --- a/azure/src/main/java/org/jclouds/azure/storage/handlers/ParseAzureStorageErrorFromXmlContent.java +++ b/azure/src/main/java/org/jclouds/azure/storage/handlers/ParseAzureStorageErrorFromXmlContent.java @@ -89,7 +89,6 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler { exception = new AuthorizationException(command.getRequest(), message); break; case 404: - if (!command.getRequest().getMethod().equals("DELETE")) { String path = command.getRequest().getEndpoint().getPath(); Matcher matcher = CONTAINER_PATH.matcher(path); diff --git a/azure/src/test/java/org/jclouds/azure/storage/handlers/ParseAzureErrorFromXmlContentTest.java b/azure/src/test/java/org/jclouds/azure/storage/handlers/ParseAzureErrorFromXmlContentTest.java index 5f19192af7..8600120f44 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/handlers/ParseAzureErrorFromXmlContentTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/handlers/ParseAzureErrorFromXmlContentTest.java @@ -28,6 +28,7 @@ import static org.easymock.classextension.EasyMock.verify; import java.net.URI; import org.easymock.IArgumentMatcher; +import org.jclouds.azure.storage.AzureStorageResponseException; import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; @@ -54,6 +55,14 @@ public class ParseAzureErrorFromXmlContentTest { "Length Required", "text/html; charset=us-ascii", "Length Required\r\n", IllegalArgumentException.class); } + + @Test + public void test412WithTextHtmlHttpResponseException() { + assertCodeMakes("GET", URI + .create("https://jclouds.blob.core.windows.net/adriancole-blobstore2?restype=container&comp=list&prefix=apps/apps/apps/&include=metadata"), 412, + "HTTP/1.1 412 The condition specified using HTTP conditional header(s) is not met.", "application/xml", "ConditionNotMetThe condition specified using HTTP conditional header(s) is not met.\nRequestId:921efcad-84bc-4e0a-863d-24810d1096e1\nTime:2010-11-04T15:03:07.8694513Z", + AzureStorageResponseException.class); + } private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, String content, Class expected) { diff --git a/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java b/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java index fa5e52477e..9594a7ecff 100644 --- a/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java +++ b/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java @@ -35,6 +35,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.jclouds.concurrent.Timeout; +import org.jclouds.http.HttpResponseException; import org.jclouds.internal.ClassMethodArgs; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ResourceNotFoundException; @@ -57,7 +58,7 @@ public class SyncProxy implements InvocationHandler { @SuppressWarnings("unchecked") public static T proxy(Class clazz, SyncProxy proxy) throws IllegalArgumentException, SecurityException, - NoSuchMethodException { + NoSuchMethodException { return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, proxy); } @@ -72,8 +73,8 @@ public class SyncProxy implements InvocationHandler { @Inject public SyncProxy(Class declaring, Object async, - @Named("sync") ConcurrentMap delegateMap, Map, Class> sync2Async) - throws SecurityException, NoSuchMethodException { + @Named("sync") ConcurrentMap delegateMap, Map, Class> sync2Async) + throws SecurityException, NoSuchMethodException { this.delegateMap = delegateMap; this.delegate = async; this.declaring = declaring; @@ -92,7 +93,7 @@ public class SyncProxy implements InvocationHandler { Method delegatedMethod = delegate.getClass().getMethod(method.getName(), method.getParameterTypes()); if (!Arrays.equals(delegatedMethod.getExceptionTypes(), method.getExceptionTypes())) throw new IllegalArgumentException(String.format( - "method %s has different typed exceptions than delegated method %s", method, delegatedMethod)); + "method %s has different typed exceptions than delegated method %s", method, delegatedMethod)); if (delegatedMethod.getReturnType().isAssignableFrom(ListenableFuture.class)) { if (method.isAnnotationPresent(Timeout.class)) { Timeout methodTimeout = method.getAnnotation(Timeout.class); @@ -124,7 +125,7 @@ public class SyncProxy implements InvocationHandler { } else if (method.isAnnotationPresent(Delegate.class)) { Class asyncClass = sync2Async.get(method.getReturnType()); checkState(asyncClass != null, "please configure corresponding async class for " + method.getReturnType() - + " in your RestClientModule"); + + " in your RestClientModule"); Object returnVal = delegateMap.get(new ClassMethodArgs(asyncClass, method, args)); return returnVal; } else if (syncMethodMap.containsKey(method)) { @@ -132,7 +133,7 @@ public class SyncProxy implements InvocationHandler { } else { try { return ((ListenableFuture) methodMap.get(method).invoke(delegate, args)).get(timeoutMap.get(method), - TimeUnit.NANOSECONDS); + TimeUnit.NANOSECONDS); } catch (ProvisionException e) { throw throwTypedExceptionOrCause(method.getExceptionTypes(), e); } catch (ExecutionException e) { @@ -143,6 +144,7 @@ public class SyncProxy implements InvocationHandler { } } + // Note this needs to be kept up-to-date with all top-level exceptions jclouds works against @SuppressWarnings("unchecked") public static Exception throwTypedExceptionOrCause(Class[] exceptionTypes, Exception exception) throws Exception { for (Class type : exceptionTypes) { @@ -154,6 +156,7 @@ public class SyncProxy implements InvocationHandler { Throwables.propagateIfInstanceOf(exception, IllegalStateException.class); Throwables.propagateIfInstanceOf(exception, AuthorizationException.class); Throwables.propagateIfInstanceOf(exception, ResourceNotFoundException.class); + Throwables.propagateIfInstanceOf(exception, HttpResponseException.class); Throwables.throwCause(exception, true); return exception; } 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 cb2045e2c1..d313e468ca 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseSax.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseSax.java @@ -26,12 +26,10 @@ import static com.google.common.io.Closeables.closeQuietly; import java.io.InputStream; import java.io.StringReader; -import javax.annotation.Resource; import javax.inject.Inject; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.logging.Logger; import org.jclouds.rest.InvocationContext; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Utils; @@ -41,6 +39,7 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import com.google.common.base.Function; +import com.google.common.base.Throwables; /** * This object will parse the body of an HttpResponse and return the result of type back to the @@ -52,8 +51,6 @@ public class ParseSax implements Function, InvocationContext private final XMLReader parser; private final HandlerWithResult handler; - @Resource - protected Logger logger = Logger.NULL; private HttpRequest request; public static interface Factory { @@ -71,7 +68,7 @@ public class ParseSax implements Function, InvocationContext checkNotNull(from, "http response"); checkNotNull(from.getPayload(), "payload in " + from); } catch (NullPointerException e) { - return addRequestDetailsToException(e); + return addDetailsAndPropagate(from, e); } if (from.getStatusCode() >= 300) return convertStreamToStringAndParse(from); @@ -82,7 +79,7 @@ public class ParseSax implements Function, InvocationContext try { return parse(Utils.toStringAndClose(from.getPayload().getInput())); } catch (Exception e) { - return addRequestDetailsToException(e); + return addDetailsAndPropagate(from, e); } } @@ -91,7 +88,7 @@ public class ParseSax implements Function, InvocationContext checkNotNull(from, "xml string"); checkArgument(from.indexOf('<') >= 0, String.format("not an xml document [%s] ", from)); } catch (RuntimeException e) { - return addRequestDetailsToException(e); + return addDetailsAndPropagate(null, e); } return parse(new InputSource(new StringReader(from))); } @@ -113,31 +110,39 @@ public class ParseSax implements Function, InvocationContext parser.parse(from); return getHandler().getResult(); } catch (Exception e) { - return addRequestDetailsToException(e); + return addDetailsAndPropagate(null, e); } } - private T addRequestDetailsToException(Exception e) { - String exceptionMessage = e.getMessage(); + public T addDetailsAndPropagate(HttpResponse response, Exception e) { + StringBuilder message = new StringBuilder(); + if (request != null) { + message.append("request: ").append(request.getRequestLine()); + } + if (response != null) { + if (message.length() != 0) + message.append("; "); + message.append("response: ").append(response.getStatusLine()); + } if (e instanceof SAXParseException) { SAXParseException parseException = (SAXParseException) e; String systemId = parseException.getSystemId(); if (systemId == null) { systemId = ""; } - exceptionMessage = String.format("Error on line %d of document %s: %s", systemId, parseException - .getLineNumber(), parseException.getMessage()); + if (message.length() != 0) + message.append("; "); + message.append(String.format("error at %d:%d in document %s", parseException.getColumnNumber(), + parseException.getLineNumber(), systemId)); } - if (request != null) { - StringBuilder message = new StringBuilder(); - message.append("Error parsing input for ").append(request.getRequestLine()).append(": "); - message.append(exceptionMessage); - logger.error(e, message.toString()); + if (message.length() != 0) { + message.append("; cause: ").append(e.toString()); throw new RuntimeException(message.toString(), e); } else { - logger.error(e, exceptionMessage.toString()); - throw new RuntimeException(exceptionMessage.toString(), e); + Throwables.propagate(e); + return null; } + } public HandlerWithResult getHandler() {