2017-11-15 15 views
2

Azureの政府機関のエンドポイントでAzure Storage Javaライブラリを使用しようとしています。私のコードは以下の通りです。Azure Storage JavaライブラリでAzure Governmentエンドポイントを使用しようとするとエラーが発生する

CloudStorageAccount account = CloudStorageAccount.parse(connectionString); 

connectionStringアズール知事雲の接尾辞を持っています。何らかの理由でblob.storage URIの値がまだblob.core.windows.netとマークされていて、次のエラーが表示されます。私はBLOB操作を実行することができません。

com.microsoft.azure.storage.StorageException: The server encountered an unknown failure: at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:178) 
at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:214) 
at com.microsoft.azure.storage.blob.CloudBlobContainer.exists(CloudBlobContainer.java:749) 
at com.microsoft.azure.storage.blob.CloudBlobContainer.exists(CloudBlobContainer.java:736) 
at com.microsoft.azure.storage.blob.CloudBlobContainer.exists(CloudBlobContainer.java:710) 
at com.scalegrid.cloudconnector.azure.AzureStorageClient.createContainerIfItDoesntExist(AzureStorageClient.java:369) 

java.net.UnknownHostException: XXXX.core.usgovcloudapi.net 
ERROR ~ s failed. 
Code:12207 

これを動作させる方法はありますか?

更新

私はAzureのストレージのJavaの以前のバージョンを使用していました。ストレージエンドポイントはこの時点で追加されていません。新しいバージョンに更新すると修正されました。

+0

は、ここで修正されたサンプルのJavaコードですか?共有する前に、アカウント名/キーをランダムな値に置き換えてください。 –

+0

今すぐ進歩がありますか? –

+0

はい、私はこのチケットを更新するのを忘れていました。 AzureストレージSDKの以前のバージョンを使用していましたが、その時点でgovクラウドエンドポイントを追加しませんでした。それを新しいバージョンに更新してそれを修正しました。 – nwarriorch

答えて

0

official pageからC#​​コードのスニペットが見つかりました。

var credentials = new StorageCredentials(storageAccountName, storageAccountKey); 

var storageAccount = new CloudStorageAccount(credentials, "core.usgovcloudapi.net", useHttps: true); 

したがって、クライアントを初期化する方法を変更する必要があると思います。

上記の方法はJava official sdkにあります。

CloudStorageAccount(StorageCredentials storageCredentials, boolean useHttps, String endpointSuffix) 
Creates an instance of the CloudStorageAccount class using the specified account credentials. 

コードを変更するには、以下のサンプルコードを参照してください。

StorageCredentialsAccountAndKey storageCredentials = new StorageCredentialsAccountAndKey(<your account name>, <your account key>); 

CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true, "core.windows.net"); 

// Create the Azure Files client. 
CloudFileClient fileClient = storageAccount.createCloudFileClient(); 

ポータルに接続文字の最後に、あなた自身のGOV Endpointsuffixパラメータを見つけることができることに注意してください。

お手伝いします。

1

azure-storage-java README.mdのコードサンプルから必要な変更は、Azure Governmentエンドポイントの接続文字列にEndpointSuffixを追加してください。です。あなたの質問を編集し、使用している接続文字列を含めてください

import java.io.*; 

import com.microsoft.azure.storage.*; 
import com.microsoft.azure.storage.blob.*; 

public class BlobSample { 
    public static final String storageConnectionString = 
     "DefaultEndpointsProtocol=http;" 
     + "AccountName=your_account_name;" 
     + "AccountKey=your_account_key" 
     + "EndpointSuffix=core.usgovcloudapi.net"; 

    public static void main(String[] args) { 
     try { 
      CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString); 
      CloudBlobClient serviceClient = account.createCloudBlobClient(); 

      // Container name must be lower case. 
      CloudBlobContainer container = serviceClient.getContainerReference("myimages"); 
      container.createIfNotExists(); 

      // Upload an image file. 
      CloudBlockBlob blob = container.getBlockBlobReference("image1.jpg"); 
      File sourceFile = new File("c:\\myimages\\image1.jpg"); 
      blob.upload(new FileInputStream(sourceFile), sourceFile.length()); 

      // Download the image file. 
      File destinationFile = new File(sourceFile.getParentFile(), "image1Download.tmp"); 
      blob.downloadToFile(destinationFile.getAbsolutePath()); 
     } 
     catch (FileNotFoundException fileNotFoundException) { 
      System.out.print("FileNotFoundException encountered: "); 
      System.out.println(fileNotFoundException.getMessage()); 
      System.exit(-1); 
     } 
     catch (StorageException storageException) { 
      System.out.print("StorageException encountered: "); 
      System.out.println(storageException.getMessage()); 
      System.exit(-1); 
     } 
     catch (Exception e) { 
      System.out.print("Exception encountered: "); 
      System.out.println(e.getMessage()); 
      System.exit(-1); 
     } 
    } 
} 
関連する問題