| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.azureblob.handlers; |
| 20 | |
| 21 | import java.util.List; |
| 22 | |
| 23 | import javax.inject.Inject; |
| 24 | import javax.inject.Singleton; |
| 25 | |
| 26 | import org.jclouds.azure.storage.domain.AzureStorageError; |
| 27 | import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent; |
| 28 | import org.jclouds.azure.storage.util.AzureStorageUtils; |
| 29 | import org.jclouds.blobstore.ContainerNotFoundException; |
| 30 | import org.jclouds.blobstore.KeyNotFoundException; |
| 31 | import org.jclouds.http.HttpCommand; |
| 32 | import org.jclouds.http.HttpResponse; |
| 33 | import org.jclouds.rest.ResourceNotFoundException; |
| 34 | |
| 35 | import com.google.common.base.Joiner; |
| 36 | import com.google.common.base.Splitter; |
| 37 | import com.google.common.collect.Lists; |
| 38 | |
| 39 | /** |
| 40 | * @author Adrian Cole |
| 41 | * |
| 42 | */ |
| 43 | @Singleton |
| 44 | public class ParseAzureBlobErrorFromXmlContent extends ParseAzureStorageErrorFromXmlContent { |
| 45 | |
| 46 | @Inject |
| 47 | ParseAzureBlobErrorFromXmlContent(AzureStorageUtils utils) { |
| 48 | super(utils); |
| 49 | } |
| 50 | |
| 51 | protected Exception refineException(HttpCommand command, HttpResponse response, Exception exception, |
| 52 | AzureStorageError error, String message) { |
| 53 | switch (response.getStatusCode()) { |
| 54 | case 404: |
| 55 | if (!command.getCurrentRequest().getMethod().equals("DELETE")) { |
| 56 | exception = new ResourceNotFoundException(message, exception); |
| 57 | List<String> parts = Lists.newArrayList(Splitter.on('/').split( |
| 58 | command.getCurrentRequest().getEndpoint().getPath())); |
| 59 | parts.remove(""); |
| 60 | if (parts.size() > 0) { |
| 61 | String container = parts.remove(0); |
| 62 | String query = command.getCurrentRequest().getEndpoint().getQuery(); |
| 63 | if (query != null && query.indexOf("container") != -1) { |
| 64 | exception = new ContainerNotFoundException(container, message); |
| 65 | } else { |
| 66 | exception = new KeyNotFoundException(container, Joiner.on('/').join(parts), message); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | return exception; |
| 71 | default: |
| 72 | return super.refineException(command, response, exception, error, message); |
| 73 | } |
| 74 | } |
| 75 | } |