use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class UIHelperImpl method getDetails.
@NotNull
private static String getDetails(@Nullable Throwable ex) {
String details = "";
if (ex != null) {
StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
details = sw.toString();
if (ex instanceof AzureCmdException) {
String errorLog = ((AzureCmdException) ex).getErrorLog();
if (errorLog != null && !errorLog.isEmpty()) {
details = errorLog;
}
}
}
return details;
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class AzureAADHelper method getHttpsURLConnectionProvider.
@NotNull
private static HttpsURLConnectionProvider getHttpsURLConnectionProvider(@NotNull final String accessToken, @NotNull final RestServiceManager manager) {
return new HttpsURLConnectionProvider() {
@Override
@NotNull
public HttpsURLConnection getSSLConnection(@NotNull String managementUrl, @NotNull String path, @NotNull ContentType contentType) throws AzureCmdException {
HttpsURLConnection sslConnection = manager.getSSLConnection(managementUrl, path, contentType);
sslConnection.addRequestProperty(AUTHORIZATION_HEADER, "Bearer " + accessToken);
return sslConnection;
}
};
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class RestServiceManagerBaseImpl method executeRequest.
@NotNull
public String executeRequest(@NotNull String managementUrl, @NotNull String path, @NotNull ContentType contentType, @NotNull String method, @Nullable String postData, @NotNull HttpsURLConnectionProvider sslConnectionProvider) throws AzureCmdException {
try {
HttpsURLConnection sslConnection = sslConnectionProvider.getSSLConnection(managementUrl, path, contentType);
HttpResponse response = getResponse(method, postData, sslConnection);
int code = response.getCode();
if (code < 200 || code >= 300) {
throw new AzureCmdException(String.format("Error status code %s: %s", code, response.getMessage()), response.getContent());
}
return response.getContent();
} catch (IOException e) {
throw new AzureCmdException(e.getMessage(), e);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getBlobContainers.
@NotNull
public List<BlobContainer> getBlobContainers(@NotNull String connectionString) throws AzureCmdException {
List<BlobContainer> bcList = new ArrayList<BlobContainer>();
try {
CloudBlobClient client = getCloudBlobClient(connectionString);
for (CloudBlobContainer container : client.listContainers(null, ContainerListingDetails.ALL, null, null)) {
String uri = container.getUri() != null ? container.getUri().toString() : "";
String eTag = "";
Calendar lastModified = new GregorianCalendar();
BlobContainerProperties properties = container.getProperties();
if (properties != null) {
eTag = Strings.nullToEmpty(properties.getEtag());
if (properties.getLastModified() != null) {
lastModified.setTime(properties.getLastModified());
}
}
String publicReadAccessType = "";
BlobContainerPermissions blobContainerPermissions = container.downloadPermissions();
if (blobContainerPermissions != null && blobContainerPermissions.getPublicAccess() != null) {
publicReadAccessType = blobContainerPermissions.getPublicAccess().toString();
}
bcList.add(new BlobContainer(Strings.nullToEmpty(container.getName()), uri, eTag, lastModified, publicReadAccessType));
}
return bcList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Blob Container list", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method dequeueFirstQueueMessage.
@NotNull
public QueueMessage dequeueFirstQueueMessage(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
String queueName = queue.getName();
CloudQueue cloudQueue = client.getQueueReference(queueName);
CloudQueueMessage cqm = cloudQueue.retrieveMessage();
String id = "";
String content = "";
Calendar insertionTime = new GregorianCalendar();
Calendar expirationTime = new GregorianCalendar();
int dequeueCount = 0;
if (cqm != null) {
id = Strings.nullToEmpty(cqm.getId());
content = Strings.nullToEmpty(cqm.getMessageContentAsString());
if (cqm.getInsertionTime() != null) {
insertionTime.setTime(cqm.getInsertionTime());
}
if (cqm.getExpirationTime() != null) {
expirationTime.setTime(cqm.getExpirationTime());
}
dequeueCount = cqm.getDequeueCount();
}
QueueMessage queueMessage = new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount);
if (cqm != null) {
cloudQueue.deleteMessage(cqm);
}
return queueMessage;
} catch (Throwable t) {
throw new AzureCmdException("Error dequeuing the first Queue Message", t);
}
}
Aggregations