1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.azure.storage.util;
20
21 import java.io.InputStream;
22
23 import javax.inject.Inject;
24 import javax.inject.Provider;
25
26 import org.jclouds.azure.storage.domain.AzureStorageError;
27 import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
28 import org.jclouds.azure.storage.reference.AzureStorageHeaders;
29 import org.jclouds.azure.storage.xml.ErrorHandler;
30 import org.jclouds.http.HttpCommand;
31 import org.jclouds.http.HttpException;
32 import org.jclouds.http.HttpResponse;
33 import org.jclouds.http.functions.ParseSax;
34
35
36
37
38
39
40
41 public class AzureStorageUtils {
42
43 @Inject
44 SharedKeyLiteAuthentication signer;
45
46 @Inject
47 ParseSax.Factory factory;
48
49 @Inject
50 Provider<ErrorHandler> errorHandlerProvider;
51
52 public AzureStorageError parseAzureStorageErrorFromContent(HttpCommand command,
53 HttpResponse response, InputStream content) throws HttpException {
54 AzureStorageError error = factory.create(errorHandlerProvider.get()).parse(content);
55 error.setRequestId(response.getFirstHeaderOrNull(AzureStorageHeaders.REQUEST_ID));
56 if ("AuthenticationFailed".equals(error.getCode())) {
57 error.setStringSigned(signer.createStringToSign(command.getCurrentRequest()));
58 error.setSignature(signer.signString(error.getStringSigned()));
59 }
60 return error;
61 }
62
63 }