From cee5fcc58bd8f814e8ae65871a62392fddbe8d4c Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Mon, 19 Mar 2012 17:34:11 +0000 Subject: [PATCH] Issue 830: Add non-JAXB response parser for screen image --- .../v1_5/features/VAppAsyncClient.java | 4 +- .../v1_5/functions/ReturnPayloadBytes.java | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ReturnPayloadBytes.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppAsyncClient.java index d0ed213eb9..2f1b7bde84 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppAsyncClient.java @@ -56,6 +56,7 @@ import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.domain.ControlAccessParams; import org.jclouds.vcloud.director.v1_5.domain.DeployVAppParams; @@ -82,6 +83,7 @@ import org.jclouds.vcloud.director.v1_5.domain.ovf.OperatingSystemSection; import org.jclouds.vcloud.director.v1_5.domain.ovf.StartupSection; import org.jclouds.vcloud.director.v1_5.domain.ovf.VirtualHardwareSection; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.ReturnPayloadBytes; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; import com.google.common.util.concurrent.ListenableFuture; @@ -538,8 +540,8 @@ public interface VAppAsyncClient { @GET @Path("/screen") @Consumes(ANY_IMAGE) - @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) + @ResponseParser(ReturnPayloadBytes.class) ListenableFuture getScreenImage(@EndpointParam URI vAppURI); /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ReturnPayloadBytes.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ReturnPayloadBytes.java new file mode 100644 index 0000000000..6cc873db14 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ReturnPayloadBytes.java @@ -0,0 +1,45 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.vcloud.director.v1_5.functions; + +import java.io.IOException; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpResponse; + +import com.google.common.base.Function; +import com.google.common.base.Throwables; +import com.google.common.io.ByteStreams; + +/** + * @author grkvlt@apache.org + */ +@Singleton +public class ReturnPayloadBytes implements Function { + + @Override + public byte[] apply(HttpResponse from) { + try { + return ByteStreams.toByteArray(from.getPayload().getInput()); + } catch (IOException e) { + throw Throwables.propagate(e); + } + } +} \ No newline at end of file