Buscar datos del almacenamiento de Azure
Este artículo muestra cómo rellenar un formulario adaptable con los datos almacenados en Azure Storage.
Se da por hecho que ha almacenado los datos del formulario adaptable en Azure Storage y ahora desea rellenar previamente el formulario adaptable con esos datos.
Crear solicitud de GET
El siguiente paso es escribir el código para recuperar los datos del almacenamiento de Azure con el blobID. El siguiente código se escribió para recuperar los datos. La URL se construyó utilizando los valores sasToken y storageURI de la configuración OSGi y el blobID pasado a la función getBlobData
@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;
}
Cuando se procesa un formulario adaptable con un parámetro guid en la dirección URL, el componente de página personalizada asociado a la plantilla recupera y rellena el formulario adaptable con los datos del almacenamiento de Azure.
El siguiente es el código en el jsp del componente de página asociado a la plantilla
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);
}
Prueba de la solución
-
Compruebe que los datos están almacenados en el contenedor de almacenamiento de Azure que elija. Copie el ID de blob.
-
Obtenga una vista previa del formulario de BankAccount y especifique el ID del blob como parámetro de GUID en la dirección URL para que el formulario se rellene previamente con los datos del almacenamiento de Azure