Azure ストレージからデータを取得

この記事では、Azure ストレージに保存されているデータをアダプティブフォームに入力する方法について説明します。
ここでは、アダプティブフォームのデータが Azure ストレージに保存されており、アダプティブフォームにそのデータを事前入力する必要があると想定しています。

NOTE
この記事のコードは、コアコンポーネントベースのアダプティブフォームでは機能しません。コアコンポーネントベースのアダプティブフォームに関する同様の記事は、こちらから参照できます

GET リクエストを作成

次の手順では、blobID を使用して Azure ストレージからデータを取得するコードを記述します。データを取得するには、次のコードを書き込みます。URL は、OSGi 設定の sasToken 値と storageURI 値、および getBlobData 関数に渡された blobID を使用して構築されました

 @Override
public String getBlobData(String blobID) {
    String sasToken = azurePortalConfigurationService.getSASToken();
    String storageURI = azurePortalConfigurationService.getStorageURI();
    log.debug("The SAS Token is " + sasToken);
    log.debug("The Storage URL is " + storageURI);
    String httpGetURL = storageURI + blobID;
    httpGetURL = httpGetURL + sasToken;
    HttpGet httpGet = new HttpGet(httpGetURL);

    org.apache.http.impl.client.CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    CloseableHttpResponse httpResponse = null;
    try {
        httpResponse = httpClient.execute(httpGet);
        HttpEntity httpEntity = httpResponse.getEntity();
        String blobData = EntityUtils.toString(httpEntity);
        log.debug("The blob data I got was " + blobData);
        return blobData;

    } catch (ClientProtocolException e) {

        log.debug("Got Client Protocol Exception " + e.getMessage());
    } catch (IOException e) {

        log.debug("Got IOEXception " + e.getMessage());
    }

    return null;
}

アダプティブフォームが URL 内の guid パラメーターを使用してレンダリングされると、テンプレートに関連付けられているカスタムページコンポーネントが Azure ストレージからデータを取得し、アダプティブフォームにデータを入力します。
以下は、テンプレートに関連付けられたページコンポーネントの jsp 内のコードです。

com.aemforms.saveandfetchfromazure.StoreAndFetchDataFromAzureStorage azureStorage = sling.getService(com.aemforms.saveandfetchfromazure.StoreAndFetchDataFromAzureStorage.class);


String guid = request.getParameter("guid");

if(guid!=null&&!guid.isEmpty())
{
    String dataXml = azureStorage.getBlobData(guid);
    slingRequest.setAttribute("data",dataXml);

}

ソリューションのテスト

recommendation-more-help
8de24117-1378-413c-a581-01e660b7163e