Example usage for java.lang Enum valueOf

List of usage examples for java.lang Enum valueOf

Introduction

In this page you can find the example usage for java.lang Enum valueOf.

Prototype

public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) 

Source Link

Document

Returns the enum constant of the specified enum type with the specified name.

Usage

From source file:org.apache.geode.internal.InternalDataSerializer.java

@SuppressWarnings("unchecked")
private static Enum<?> readGemFireEnum(DataInput in) throws IOException, ClassNotFoundException {
    String className = DataSerializer.readString(in);
    String enumName = DataSerializer.readString(in);
    @SuppressWarnings("rawtypes")
    Class c = getCachedClass(className);
    return Enum.valueOf(c, enumName);
}

From source file:com.microsoft.azure.management.notificationhubs.NamespaceOperationsImpl.java

/**
* The get authorization rule operation gets an authorization rule for a
* namespace by name.//from   w w  w  .j a va2s  . c  o m
*
* @param resourceGroupName Required. The name of the resource group.
* @param namespaceName Required. The namespace to get the authorization
* rule for.
* @param authorizationRuleName Required. The entity name to get the
* authorization rule for.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return The response of the Get Namespace operation.
*/
@Override
public SharedAccessAuthorizationRuleGetResponse getAuthorizationRule(String resourceGroupName,
        String namespaceName, String authorizationRuleName) throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }
    if (authorizationRuleName == null) {
        throw new NullPointerException("authorizationRuleName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("namespaceName", namespaceName);
        tracingParameters.put("authorizationRuleName", authorizationRuleName);
        CloudTracing.enter(invocationId, this, "getAuthorizationRuleAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + "Microsoft.NotificationHubs";
    url = url + "/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    url = url + "/AuthorizationRules/";
    url = url + URLEncoder.encode(authorizationRuleName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-09-01");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPost httpRequest = new HttpPost(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        SharedAccessAuthorizationRuleGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new SharedAccessAuthorizationRuleGetResponse();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                SharedAccessAuthorizationRuleResource valueInstance = new SharedAccessAuthorizationRuleResource();
                result.setValue(valueInstance);

                JsonNode idValue = responseDoc.get("id");
                if (idValue != null && idValue instanceof NullNode == false) {
                    String idInstance;
                    idInstance = idValue.getTextValue();
                    valueInstance.setId(idInstance);
                }

                JsonNode locationValue = responseDoc.get("location");
                if (locationValue != null && locationValue instanceof NullNode == false) {
                    String locationInstance;
                    locationInstance = locationValue.getTextValue();
                    valueInstance.setLocation(locationInstance);
                }

                JsonNode nameValue = responseDoc.get("name");
                if (nameValue != null && nameValue instanceof NullNode == false) {
                    String nameInstance;
                    nameInstance = nameValue.getTextValue();
                    valueInstance.setName(nameInstance);
                }

                JsonNode typeValue = responseDoc.get("type");
                if (typeValue != null && typeValue instanceof NullNode == false) {
                    String typeInstance;
                    typeInstance = typeValue.getTextValue();
                    valueInstance.setType(typeInstance);
                }

                JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields();
                    while (itr.hasNext()) {
                        Map.Entry<String, JsonNode> property = itr.next();
                        String tagsKey = property.getKey();
                        String tagsValue = property.getValue().getTextValue();
                        valueInstance.getTags().put(tagsKey, tagsValue);
                    }
                }

                JsonNode propertiesValue = responseDoc.get("properties");
                if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                    SharedAccessAuthorizationRuleProperties propertiesInstance = new SharedAccessAuthorizationRuleProperties();
                    valueInstance.setProperties(propertiesInstance);

                    JsonNode primaryKeyValue = propertiesValue.get("primaryKey");
                    if (primaryKeyValue != null && primaryKeyValue instanceof NullNode == false) {
                        String primaryKeyInstance;
                        primaryKeyInstance = primaryKeyValue.getTextValue();
                        propertiesInstance.setPrimaryKey(primaryKeyInstance);
                    }

                    JsonNode secondaryKeyValue = propertiesValue.get("secondaryKey");
                    if (secondaryKeyValue != null && secondaryKeyValue instanceof NullNode == false) {
                        String secondaryKeyInstance;
                        secondaryKeyInstance = secondaryKeyValue.getTextValue();
                        propertiesInstance.setSecondaryKey(secondaryKeyInstance);
                    }

                    JsonNode keyNameValue = propertiesValue.get("keyName");
                    if (keyNameValue != null && keyNameValue instanceof NullNode == false) {
                        String keyNameInstance;
                        keyNameInstance = keyNameValue.getTextValue();
                        propertiesInstance.setKeyName(keyNameInstance);
                    }

                    JsonNode claimTypeValue = propertiesValue.get("claimType");
                    if (claimTypeValue != null && claimTypeValue instanceof NullNode == false) {
                        String claimTypeInstance;
                        claimTypeInstance = claimTypeValue.getTextValue();
                        propertiesInstance.setClaimType(claimTypeInstance);
                    }

                    JsonNode claimValueValue = propertiesValue.get("claimValue");
                    if (claimValueValue != null && claimValueValue instanceof NullNode == false) {
                        String claimValueInstance;
                        claimValueInstance = claimValueValue.getTextValue();
                        propertiesInstance.setClaimValue(claimValueInstance);
                    }

                    JsonNode rightsArray = propertiesValue.get("rights");
                    if (rightsArray != null && rightsArray instanceof NullNode == false) {
                        for (JsonNode rightsValue : ((ArrayNode) rightsArray)) {
                            propertiesInstance.getRights()
                                    .add(Enum.valueOf(AccessRights.class, rightsValue.getTextValue()));
                        }
                    }

                    JsonNode createdTimeValue = propertiesValue.get("createdTime");
                    if (createdTimeValue != null && createdTimeValue instanceof NullNode == false) {
                        Calendar createdTimeInstance;
                        createdTimeInstance = DatatypeConverter.parseDateTime(createdTimeValue.getTextValue());
                        propertiesInstance.setCreatedTime(createdTimeInstance);
                    }

                    JsonNode modifiedTimeValue = propertiesValue.get("modifiedTime");
                    if (modifiedTimeValue != null && modifiedTimeValue instanceof NullNode == false) {
                        Calendar modifiedTimeInstance;
                        modifiedTimeInstance = DatatypeConverter
                                .parseDateTime(modifiedTimeValue.getTextValue());
                        propertiesInstance.setModifiedTime(modifiedTimeInstance);
                    }

                    JsonNode revisionValue = propertiesValue.get("revision");
                    if (revisionValue != null && revisionValue instanceof NullNode == false) {
                        int revisionInstance;
                        revisionInstance = revisionValue.getIntValue();
                        propertiesInstance.setRevision(revisionInstance);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.resources.DeploymentOperationsImpl.java

/**
* Get a list of deployments.//from   w w w. jav a2s . co  m
*
* @param resourceGroupName Required. The name of the resource group to
* filter by. The name is case insensitive.
* @param parameters Optional. Query parameters. If null is passed returns
* all deployments.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return List of deployments.
*/
@Override
public DeploymentListResult list(String resourceGroupName, DeploymentListParameters parameters)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "listAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/";
    url = url + "resourcegroups/" + URLEncoder.encode(resourceGroupName, "UTF-8") + "/";
    url = url + "deployments/";
    ArrayList<String> queryParameters = new ArrayList<String>();
    ArrayList<String> odataFilter = new ArrayList<String>();
    if (parameters != null && parameters.getProvisioningState() != null) {
        odataFilter.add(
                "provisioningState eq '" + URLEncoder.encode(parameters.getProvisioningState(), "UTF-8") + "'");
    }
    if (odataFilter.size() > 0) {
        queryParameters.add("$filter=" + CollectionStringBuilder.join(odataFilter, null));
    }
    if (parameters != null && parameters.getTop() != null) {
        queryParameters.add("$top=" + URLEncoder.encode(Integer.toString(parameters.getTop()), "UTF-8"));
    }
    queryParameters.add("api-version=" + "2014-04-01-preview");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        DeploymentListResult result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new DeploymentListResult();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                JsonNode valueArray = responseDoc.get("value");
                if (valueArray != null && valueArray instanceof NullNode == false) {
                    for (JsonNode valueValue : ((ArrayNode) valueArray)) {
                        DeploymentExtended deploymentExtendedInstance = new DeploymentExtended();
                        result.getDeployments().add(deploymentExtendedInstance);

                        JsonNode idValue = valueValue.get("id");
                        if (idValue != null && idValue instanceof NullNode == false) {
                            String idInstance;
                            idInstance = idValue.getTextValue();
                            deploymentExtendedInstance.setId(idInstance);
                        }

                        JsonNode nameValue = valueValue.get("name");
                        if (nameValue != null && nameValue instanceof NullNode == false) {
                            String nameInstance;
                            nameInstance = nameValue.getTextValue();
                            deploymentExtendedInstance.setName(nameInstance);
                        }

                        JsonNode propertiesValue = valueValue.get("properties");
                        if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                            DeploymentPropertiesExtended propertiesInstance = new DeploymentPropertiesExtended();
                            deploymentExtendedInstance.setProperties(propertiesInstance);

                            JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                            if (provisioningStateValue != null
                                    && provisioningStateValue instanceof NullNode == false) {
                                String provisioningStateInstance;
                                provisioningStateInstance = provisioningStateValue.getTextValue();
                                propertiesInstance.setProvisioningState(provisioningStateInstance);
                            }

                            JsonNode correlationIdValue = propertiesValue.get("correlationId");
                            if (correlationIdValue != null && correlationIdValue instanceof NullNode == false) {
                                String correlationIdInstance;
                                correlationIdInstance = correlationIdValue.getTextValue();
                                propertiesInstance.setCorrelationId(correlationIdInstance);
                            }

                            JsonNode timestampValue = propertiesValue.get("timestamp");
                            if (timestampValue != null && timestampValue instanceof NullNode == false) {
                                Calendar timestampInstance;
                                timestampInstance = DatatypeConverter
                                        .parseDateTime(timestampValue.getTextValue());
                                propertiesInstance.setTimestamp(timestampInstance);
                            }

                            JsonNode outputsValue = propertiesValue.get("outputs");
                            if (outputsValue != null && outputsValue instanceof NullNode == false) {
                                String outputsInstance;
                                outputsInstance = outputsValue.getTextValue();
                                propertiesInstance.setOutputs(outputsInstance);
                            }

                            JsonNode providersArray = propertiesValue.get("providers");
                            if (providersArray != null && providersArray instanceof NullNode == false) {
                                for (JsonNode providersValue : ((ArrayNode) providersArray)) {
                                    Provider providerInstance = new Provider();
                                    propertiesInstance.getProviders().add(providerInstance);

                                    JsonNode idValue2 = providersValue.get("id");
                                    if (idValue2 != null && idValue2 instanceof NullNode == false) {
                                        String idInstance2;
                                        idInstance2 = idValue2.getTextValue();
                                        providerInstance.setId(idInstance2);
                                    }

                                    JsonNode namespaceValue = providersValue.get("namespace");
                                    if (namespaceValue != null && namespaceValue instanceof NullNode == false) {
                                        String namespaceInstance;
                                        namespaceInstance = namespaceValue.getTextValue();
                                        providerInstance.setNamespace(namespaceInstance);
                                    }

                                    JsonNode registrationStateValue = providersValue.get("registrationState");
                                    if (registrationStateValue != null
                                            && registrationStateValue instanceof NullNode == false) {
                                        String registrationStateInstance;
                                        registrationStateInstance = registrationStateValue.getTextValue();
                                        providerInstance.setRegistrationState(registrationStateInstance);
                                    }

                                    JsonNode resourceTypesArray = providersValue.get("resourceTypes");
                                    if (resourceTypesArray != null
                                            && resourceTypesArray instanceof NullNode == false) {
                                        for (JsonNode resourceTypesValue : ((ArrayNode) resourceTypesArray)) {
                                            ProviderResourceType providerResourceTypeInstance = new ProviderResourceType();
                                            providerInstance.getResourceTypes()
                                                    .add(providerResourceTypeInstance);

                                            JsonNode resourceTypeValue = resourceTypesValue.get("resourceType");
                                            if (resourceTypeValue != null
                                                    && resourceTypeValue instanceof NullNode == false) {
                                                String resourceTypeInstance;
                                                resourceTypeInstance = resourceTypeValue.getTextValue();
                                                providerResourceTypeInstance.setName(resourceTypeInstance);
                                            }

                                            JsonNode locationsArray = resourceTypesValue.get("locations");
                                            if (locationsArray != null
                                                    && locationsArray instanceof NullNode == false) {
                                                for (JsonNode locationsValue : ((ArrayNode) locationsArray)) {
                                                    providerResourceTypeInstance.getLocations()
                                                            .add(locationsValue.getTextValue());
                                                }
                                            }

                                            JsonNode apiVersionsArray = resourceTypesValue.get("apiVersions");
                                            if (apiVersionsArray != null
                                                    && apiVersionsArray instanceof NullNode == false) {
                                                for (JsonNode apiVersionsValue : ((ArrayNode) apiVersionsArray)) {
                                                    providerResourceTypeInstance.getApiVersions()
                                                            .add(apiVersionsValue.getTextValue());
                                                }
                                            }

                                            JsonNode propertiesSequenceElement = ((JsonNode) resourceTypesValue
                                                    .get("properties"));
                                            if (propertiesSequenceElement != null
                                                    && propertiesSequenceElement instanceof NullNode == false) {
                                                Iterator<Map.Entry<String, JsonNode>> itr = propertiesSequenceElement
                                                        .getFields();
                                                while (itr.hasNext()) {
                                                    Map.Entry<String, JsonNode> property = itr.next();
                                                    String propertiesKey = property.getKey();
                                                    String propertiesValue2 = property.getValue()
                                                            .getTextValue();
                                                    providerResourceTypeInstance.getProperties()
                                                            .put(propertiesKey, propertiesValue2);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            JsonNode dependenciesArray = propertiesValue.get("dependencies");
                            if (dependenciesArray != null && dependenciesArray instanceof NullNode == false) {
                                for (JsonNode dependenciesValue : ((ArrayNode) dependenciesArray)) {
                                    Dependency dependencyInstance = new Dependency();
                                    propertiesInstance.getDependencies().add(dependencyInstance);

                                    JsonNode dependsOnArray = dependenciesValue.get("dependsOn");
                                    if (dependsOnArray != null && dependsOnArray instanceof NullNode == false) {
                                        for (JsonNode dependsOnValue : ((ArrayNode) dependsOnArray)) {
                                            BasicDependency basicDependencyInstance = new BasicDependency();
                                            dependencyInstance.getDependsOn().add(basicDependencyInstance);

                                            JsonNode idValue3 = dependsOnValue.get("id");
                                            if (idValue3 != null && idValue3 instanceof NullNode == false) {
                                                String idInstance3;
                                                idInstance3 = idValue3.getTextValue();
                                                basicDependencyInstance.setId(idInstance3);
                                            }

                                            JsonNode resourceTypeValue2 = dependsOnValue.get("resourceType");
                                            if (resourceTypeValue2 != null
                                                    && resourceTypeValue2 instanceof NullNode == false) {
                                                String resourceTypeInstance2;
                                                resourceTypeInstance2 = resourceTypeValue2.getTextValue();
                                                basicDependencyInstance.setResourceType(resourceTypeInstance2);
                                            }

                                            JsonNode resourceNameValue = dependsOnValue.get("resourceName");
                                            if (resourceNameValue != null
                                                    && resourceNameValue instanceof NullNode == false) {
                                                String resourceNameInstance;
                                                resourceNameInstance = resourceNameValue.getTextValue();
                                                basicDependencyInstance.setResourceName(resourceNameInstance);
                                            }
                                        }
                                    }

                                    JsonNode idValue4 = dependenciesValue.get("id");
                                    if (idValue4 != null && idValue4 instanceof NullNode == false) {
                                        String idInstance4;
                                        idInstance4 = idValue4.getTextValue();
                                        dependencyInstance.setId(idInstance4);
                                    }

                                    JsonNode resourceTypeValue3 = dependenciesValue.get("resourceType");
                                    if (resourceTypeValue3 != null
                                            && resourceTypeValue3 instanceof NullNode == false) {
                                        String resourceTypeInstance3;
                                        resourceTypeInstance3 = resourceTypeValue3.getTextValue();
                                        dependencyInstance.setResourceType(resourceTypeInstance3);
                                    }

                                    JsonNode resourceNameValue2 = dependenciesValue.get("resourceName");
                                    if (resourceNameValue2 != null
                                            && resourceNameValue2 instanceof NullNode == false) {
                                        String resourceNameInstance2;
                                        resourceNameInstance2 = resourceNameValue2.getTextValue();
                                        dependencyInstance.setResourceName(resourceNameInstance2);
                                    }
                                }
                            }

                            JsonNode templateValue = propertiesValue.get("template");
                            if (templateValue != null && templateValue instanceof NullNode == false) {
                                String templateInstance;
                                templateInstance = templateValue.getTextValue();
                                propertiesInstance.setTemplate(templateInstance);
                            }

                            JsonNode templateLinkValue = propertiesValue.get("templateLink");
                            if (templateLinkValue != null && templateLinkValue instanceof NullNode == false) {
                                TemplateLink templateLinkInstance = new TemplateLink();
                                propertiesInstance.setTemplateLink(templateLinkInstance);

                                JsonNode uriValue = templateLinkValue.get("uri");
                                if (uriValue != null && uriValue instanceof NullNode == false) {
                                    URI uriInstance;
                                    uriInstance = new URI(uriValue.getTextValue());
                                    templateLinkInstance.setUri(uriInstance);
                                }

                                JsonNode contentVersionValue = templateLinkValue.get("contentVersion");
                                if (contentVersionValue != null
                                        && contentVersionValue instanceof NullNode == false) {
                                    String contentVersionInstance;
                                    contentVersionInstance = contentVersionValue.getTextValue();
                                    templateLinkInstance.setContentVersion(contentVersionInstance);
                                }
                            }

                            JsonNode parametersValue = propertiesValue.get("parameters");
                            if (parametersValue != null && parametersValue instanceof NullNode == false) {
                                String parametersInstance;
                                parametersInstance = parametersValue.getTextValue();
                                propertiesInstance.setParameters(parametersInstance);
                            }

                            JsonNode parametersLinkValue = propertiesValue.get("parametersLink");
                            if (parametersLinkValue != null
                                    && parametersLinkValue instanceof NullNode == false) {
                                ParametersLink parametersLinkInstance = new ParametersLink();
                                propertiesInstance.setParametersLink(parametersLinkInstance);

                                JsonNode uriValue2 = parametersLinkValue.get("uri");
                                if (uriValue2 != null && uriValue2 instanceof NullNode == false) {
                                    URI uriInstance2;
                                    uriInstance2 = new URI(uriValue2.getTextValue());
                                    parametersLinkInstance.setUri(uriInstance2);
                                }

                                JsonNode contentVersionValue2 = parametersLinkValue.get("contentVersion");
                                if (contentVersionValue2 != null
                                        && contentVersionValue2 instanceof NullNode == false) {
                                    String contentVersionInstance2;
                                    contentVersionInstance2 = contentVersionValue2.getTextValue();
                                    parametersLinkInstance.setContentVersion(contentVersionInstance2);
                                }
                            }

                            JsonNode modeValue = propertiesValue.get("mode");
                            if (modeValue != null && modeValue instanceof NullNode == false) {
                                DeploymentMode modeInstance;
                                modeInstance = Enum.valueOf(DeploymentMode.class, modeValue.getTextValue());
                                propertiesInstance.setMode(modeInstance);
                            }
                        }
                    }
                }

                JsonNode nextLinkValue = responseDoc.get("nextLink");
                if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) {
                    String nextLinkInstance;
                    nextLinkInstance = nextLinkValue.getTextValue();
                    result.setNextLink(nextLinkInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.notificationhubs.NotificationHubOperationsImpl.java

/**
* Lists the notification hubs associated with a namespace.
*
* @param resourceGroupName Required. The name of the resource group.
* @param namespaceName Required. The namespace name.
* @param notificationHubName Required. The notification hub name.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations./*from  w  ww  . j a va 2  s  .com*/
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The response of the Get NotificationHub operation.
*/
@Override
public NotificationHubGetResponse get(String resourceGroupName, String namespaceName,
        String notificationHubName) throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }
    if (notificationHubName == null) {
        throw new NullPointerException("notificationHubName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("namespaceName", namespaceName);
        tracingParameters.put("notificationHubName", notificationHubName);
        CloudTracing.enter(invocationId, this, "getAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + "Microsoft.NotificationHubs";
    url = url + "/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    url = url + "/notificationHubs/";
    url = url + URLEncoder.encode(notificationHubName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-09-01");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        NotificationHubGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new NotificationHubGetResponse();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                NotificationHubResource valueInstance = new NotificationHubResource();
                result.setValue(valueInstance);

                JsonNode idValue = responseDoc.get("id");
                if (idValue != null && idValue instanceof NullNode == false) {
                    String idInstance;
                    idInstance = idValue.getTextValue();
                    valueInstance.setId(idInstance);
                }

                JsonNode locationValue = responseDoc.get("location");
                if (locationValue != null && locationValue instanceof NullNode == false) {
                    String locationInstance;
                    locationInstance = locationValue.getTextValue();
                    valueInstance.setLocation(locationInstance);
                }

                JsonNode nameValue = responseDoc.get("name");
                if (nameValue != null && nameValue instanceof NullNode == false) {
                    String nameInstance;
                    nameInstance = nameValue.getTextValue();
                    valueInstance.setName(nameInstance);
                }

                JsonNode typeValue = responseDoc.get("type");
                if (typeValue != null && typeValue instanceof NullNode == false) {
                    String typeInstance;
                    typeInstance = typeValue.getTextValue();
                    valueInstance.setType(typeInstance);
                }

                JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields();
                    while (itr.hasNext()) {
                        Map.Entry<String, JsonNode> property = itr.next();
                        String tagsKey = property.getKey();
                        String tagsValue = property.getValue().getTextValue();
                        valueInstance.getTags().put(tagsKey, tagsValue);
                    }
                }

                JsonNode propertiesValue = responseDoc.get("properties");
                if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                    NotificationHubProperties propertiesInstance = new NotificationHubProperties();
                    valueInstance.setProperties(propertiesInstance);

                    JsonNode nameValue2 = propertiesValue.get("name");
                    if (nameValue2 != null && nameValue2 instanceof NullNode == false) {
                        String nameInstance2;
                        nameInstance2 = nameValue2.getTextValue();
                        propertiesInstance.setName(nameInstance2);
                    }

                    JsonNode registrationTtlValue = propertiesValue.get("registrationTtl");
                    if (registrationTtlValue != null && registrationTtlValue instanceof NullNode == false) {
                        String registrationTtlInstance;
                        registrationTtlInstance = registrationTtlValue.getTextValue();
                        propertiesInstance.setRegistrationTtl(registrationTtlInstance);
                    }

                    JsonNode authorizationRulesArray = propertiesValue.get("authorizationRules");
                    if (authorizationRulesArray != null
                            && authorizationRulesArray instanceof NullNode == false) {
                        for (JsonNode authorizationRulesValue : ((ArrayNode) authorizationRulesArray)) {
                            SharedAccessAuthorizationRuleProperties sharedAccessAuthorizationRulePropertiesInstance = new SharedAccessAuthorizationRuleProperties();
                            propertiesInstance.getAuthorizationRules()
                                    .add(sharedAccessAuthorizationRulePropertiesInstance);

                            JsonNode primaryKeyValue = authorizationRulesValue.get("primaryKey");
                            if (primaryKeyValue != null && primaryKeyValue instanceof NullNode == false) {
                                String primaryKeyInstance;
                                primaryKeyInstance = primaryKeyValue.getTextValue();
                                sharedAccessAuthorizationRulePropertiesInstance
                                        .setPrimaryKey(primaryKeyInstance);
                            }

                            JsonNode secondaryKeyValue = authorizationRulesValue.get("secondaryKey");
                            if (secondaryKeyValue != null && secondaryKeyValue instanceof NullNode == false) {
                                String secondaryKeyInstance;
                                secondaryKeyInstance = secondaryKeyValue.getTextValue();
                                sharedAccessAuthorizationRulePropertiesInstance
                                        .setSecondaryKey(secondaryKeyInstance);
                            }

                            JsonNode keyNameValue = authorizationRulesValue.get("keyName");
                            if (keyNameValue != null && keyNameValue instanceof NullNode == false) {
                                String keyNameInstance;
                                keyNameInstance = keyNameValue.getTextValue();
                                sharedAccessAuthorizationRulePropertiesInstance.setKeyName(keyNameInstance);
                            }

                            JsonNode claimTypeValue = authorizationRulesValue.get("claimType");
                            if (claimTypeValue != null && claimTypeValue instanceof NullNode == false) {
                                String claimTypeInstance;
                                claimTypeInstance = claimTypeValue.getTextValue();
                                sharedAccessAuthorizationRulePropertiesInstance.setClaimType(claimTypeInstance);
                            }

                            JsonNode claimValueValue = authorizationRulesValue.get("claimValue");
                            if (claimValueValue != null && claimValueValue instanceof NullNode == false) {
                                String claimValueInstance;
                                claimValueInstance = claimValueValue.getTextValue();
                                sharedAccessAuthorizationRulePropertiesInstance
                                        .setClaimValue(claimValueInstance);
                            }

                            JsonNode rightsArray = authorizationRulesValue.get("rights");
                            if (rightsArray != null && rightsArray instanceof NullNode == false) {
                                for (JsonNode rightsValue : ((ArrayNode) rightsArray)) {
                                    sharedAccessAuthorizationRulePropertiesInstance.getRights()
                                            .add(Enum.valueOf(AccessRights.class, rightsValue.getTextValue()));
                                }
                            }

                            JsonNode createdTimeValue = authorizationRulesValue.get("createdTime");
                            if (createdTimeValue != null && createdTimeValue instanceof NullNode == false) {
                                Calendar createdTimeInstance;
                                createdTimeInstance = DatatypeConverter
                                        .parseDateTime(createdTimeValue.getTextValue());
                                sharedAccessAuthorizationRulePropertiesInstance
                                        .setCreatedTime(createdTimeInstance);
                            }

                            JsonNode modifiedTimeValue = authorizationRulesValue.get("modifiedTime");
                            if (modifiedTimeValue != null && modifiedTimeValue instanceof NullNode == false) {
                                Calendar modifiedTimeInstance;
                                modifiedTimeInstance = DatatypeConverter
                                        .parseDateTime(modifiedTimeValue.getTextValue());
                                sharedAccessAuthorizationRulePropertiesInstance
                                        .setModifiedTime(modifiedTimeInstance);
                            }

                            JsonNode revisionValue = authorizationRulesValue.get("revision");
                            if (revisionValue != null && revisionValue instanceof NullNode == false) {
                                int revisionInstance;
                                revisionInstance = revisionValue.getIntValue();
                                sharedAccessAuthorizationRulePropertiesInstance.setRevision(revisionInstance);
                            }
                        }
                    }

                    JsonNode apnsCredentialValue = propertiesValue.get("apnsCredential");
                    if (apnsCredentialValue != null && apnsCredentialValue instanceof NullNode == false) {
                        ApnsCredential apnsCredentialInstance = new ApnsCredential();
                        propertiesInstance.setApnsCredential(apnsCredentialInstance);

                        JsonNode propertiesValue2 = apnsCredentialValue.get("properties");
                        if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                            ApnsCredentialProperties propertiesInstance2 = new ApnsCredentialProperties();
                            apnsCredentialInstance.setProperties(propertiesInstance2);

                            JsonNode apnsCertificateValue = propertiesValue2.get("apnsCertificate");
                            if (apnsCertificateValue != null
                                    && apnsCertificateValue instanceof NullNode == false) {
                                String apnsCertificateInstance;
                                apnsCertificateInstance = apnsCertificateValue.getTextValue();
                                propertiesInstance2.setApnsCertificate(apnsCertificateInstance);
                            }

                            JsonNode certificateKeyValue = propertiesValue2.get("certificateKey");
                            if (certificateKeyValue != null
                                    && certificateKeyValue instanceof NullNode == false) {
                                String certificateKeyInstance;
                                certificateKeyInstance = certificateKeyValue.getTextValue();
                                propertiesInstance2.setCertificateKey(certificateKeyInstance);
                            }

                            JsonNode endpointValue = propertiesValue2.get("endpoint");
                            if (endpointValue != null && endpointValue instanceof NullNode == false) {
                                String endpointInstance;
                                endpointInstance = endpointValue.getTextValue();
                                propertiesInstance2.setEndpoint(endpointInstance);
                            }

                            JsonNode thumbprintValue = propertiesValue2.get("thumbprint");
                            if (thumbprintValue != null && thumbprintValue instanceof NullNode == false) {
                                String thumbprintInstance;
                                thumbprintInstance = thumbprintValue.getTextValue();
                                propertiesInstance2.setThumbprint(thumbprintInstance);
                            }
                        }
                    }

                    JsonNode wnsCredentialValue = propertiesValue.get("wnsCredential");
                    if (wnsCredentialValue != null && wnsCredentialValue instanceof NullNode == false) {
                        WnsCredential wnsCredentialInstance = new WnsCredential();
                        propertiesInstance.setWnsCredential(wnsCredentialInstance);

                        JsonNode propertiesValue3 = wnsCredentialValue.get("properties");
                        if (propertiesValue3 != null && propertiesValue3 instanceof NullNode == false) {
                            WnsCredentialProperties propertiesInstance3 = new WnsCredentialProperties();
                            wnsCredentialInstance.setProperties(propertiesInstance3);

                            JsonNode packageSidValue = propertiesValue3.get("packageSid");
                            if (packageSidValue != null && packageSidValue instanceof NullNode == false) {
                                String packageSidInstance;
                                packageSidInstance = packageSidValue.getTextValue();
                                propertiesInstance3.setPackageSid(packageSidInstance);
                            }

                            JsonNode secretKeyValue = propertiesValue3.get("secretKey");
                            if (secretKeyValue != null && secretKeyValue instanceof NullNode == false) {
                                String secretKeyInstance;
                                secretKeyInstance = secretKeyValue.getTextValue();
                                propertiesInstance3.setSecretKey(secretKeyInstance);
                            }

                            JsonNode windowsLiveEndpointValue = propertiesValue3.get("windowsLiveEndpoint");
                            if (windowsLiveEndpointValue != null
                                    && windowsLiveEndpointValue instanceof NullNode == false) {
                                String windowsLiveEndpointInstance;
                                windowsLiveEndpointInstance = windowsLiveEndpointValue.getTextValue();
                                propertiesInstance3.setWindowsLiveEndpoint(windowsLiveEndpointInstance);
                            }
                        }
                    }

                    JsonNode gcmCredentialValue = propertiesValue.get("gcmCredential");
                    if (gcmCredentialValue != null && gcmCredentialValue instanceof NullNode == false) {
                        GcmCredential gcmCredentialInstance = new GcmCredential();
                        propertiesInstance.setGcmCredential(gcmCredentialInstance);

                        JsonNode propertiesValue4 = gcmCredentialValue.get("properties");
                        if (propertiesValue4 != null && propertiesValue4 instanceof NullNode == false) {
                            GcmCredentialProperties propertiesInstance4 = new GcmCredentialProperties();
                            gcmCredentialInstance.setProperties(propertiesInstance4);

                            JsonNode gcmEndpointValue = propertiesValue4.get("gcmEndpoint");
                            if (gcmEndpointValue != null && gcmEndpointValue instanceof NullNode == false) {
                                String gcmEndpointInstance;
                                gcmEndpointInstance = gcmEndpointValue.getTextValue();
                                propertiesInstance4.setGcmEndpoint(gcmEndpointInstance);
                            }

                            JsonNode googleApiKeyValue = propertiesValue4.get("googleApiKey");
                            if (googleApiKeyValue != null && googleApiKeyValue instanceof NullNode == false) {
                                String googleApiKeyInstance;
                                googleApiKeyInstance = googleApiKeyValue.getTextValue();
                                propertiesInstance4.setGoogleApiKey(googleApiKeyInstance);
                            }
                        }
                    }

                    JsonNode mpnsCredentialValue = propertiesValue.get("mpnsCredential");
                    if (mpnsCredentialValue != null && mpnsCredentialValue instanceof NullNode == false) {
                        MpnsCredential mpnsCredentialInstance = new MpnsCredential();
                        propertiesInstance.setMpnsCredential(mpnsCredentialInstance);

                        JsonNode propertiesValue5 = mpnsCredentialValue.get("properties");
                        if (propertiesValue5 != null && propertiesValue5 instanceof NullNode == false) {
                            MpnsCredentialProperties propertiesInstance5 = new MpnsCredentialProperties();
                            mpnsCredentialInstance.setProperties(propertiesInstance5);

                            JsonNode mpnsCertificateValue = propertiesValue5.get("mpnsCertificate");
                            if (mpnsCertificateValue != null
                                    && mpnsCertificateValue instanceof NullNode == false) {
                                String mpnsCertificateInstance;
                                mpnsCertificateInstance = mpnsCertificateValue.getTextValue();
                                propertiesInstance5.setMpnsCertificate(mpnsCertificateInstance);
                            }

                            JsonNode certificateKeyValue2 = propertiesValue5.get("certificateKey");
                            if (certificateKeyValue2 != null
                                    && certificateKeyValue2 instanceof NullNode == false) {
                                String certificateKeyInstance2;
                                certificateKeyInstance2 = certificateKeyValue2.getTextValue();
                                propertiesInstance5.setCertificateKey(certificateKeyInstance2);
                            }

                            JsonNode thumbprintValue2 = propertiesValue5.get("thumbprint");
                            if (thumbprintValue2 != null && thumbprintValue2 instanceof NullNode == false) {
                                String thumbprintInstance2;
                                thumbprintInstance2 = thumbprintValue2.getTextValue();
                                propertiesInstance5.setThumbprint(thumbprintInstance2);
                            }
                        }
                    }

                    JsonNode admCredentialValue = propertiesValue.get("admCredential");
                    if (admCredentialValue != null && admCredentialValue instanceof NullNode == false) {
                        AdmCredential admCredentialInstance = new AdmCredential();
                        propertiesInstance.setAdmCredential(admCredentialInstance);

                        JsonNode propertiesValue6 = admCredentialValue.get("properties");
                        if (propertiesValue6 != null && propertiesValue6 instanceof NullNode == false) {
                            AdmCredentialProperties propertiesInstance6 = new AdmCredentialProperties();
                            admCredentialInstance.setProperties(propertiesInstance6);

                            JsonNode clientIdValue = propertiesValue6.get("clientId");
                            if (clientIdValue != null && clientIdValue instanceof NullNode == false) {
                                String clientIdInstance;
                                clientIdInstance = clientIdValue.getTextValue();
                                propertiesInstance6.setClientId(clientIdInstance);
                            }

                            JsonNode clientSecretValue = propertiesValue6.get("clientSecret");
                            if (clientSecretValue != null && clientSecretValue instanceof NullNode == false) {
                                String clientSecretInstance;
                                clientSecretInstance = clientSecretValue.getTextValue();
                                propertiesInstance6.setClientSecret(clientSecretInstance);
                            }

                            JsonNode authTokenUrlValue = propertiesValue6.get("authTokenUrl");
                            if (authTokenUrlValue != null && authTokenUrlValue instanceof NullNode == false) {
                                String authTokenUrlInstance;
                                authTokenUrlInstance = authTokenUrlValue.getTextValue();
                                propertiesInstance6.setAuthTokenUrl(authTokenUrlInstance);
                            }
                        }
                    }

                    JsonNode baiduCredentialValue = propertiesValue.get("baiduCredential");
                    if (baiduCredentialValue != null && baiduCredentialValue instanceof NullNode == false) {
                        BaiduCredential baiduCredentialInstance = new BaiduCredential();
                        propertiesInstance.setBaiduCredential(baiduCredentialInstance);

                        JsonNode propertiesValue7 = baiduCredentialValue.get("properties");
                        if (propertiesValue7 != null && propertiesValue7 instanceof NullNode == false) {
                            BaiduCredentialProperties propertiesInstance7 = new BaiduCredentialProperties();
                            baiduCredentialInstance.setProperties(propertiesInstance7);

                            JsonNode baiduApiKeyValue = propertiesValue7.get("baiduApiKey");
                            if (baiduApiKeyValue != null && baiduApiKeyValue instanceof NullNode == false) {
                                String baiduApiKeyInstance;
                                baiduApiKeyInstance = baiduApiKeyValue.getTextValue();
                                propertiesInstance7.setBaiduApiKey(baiduApiKeyInstance);
                            }

                            JsonNode baiduEndPointValue = propertiesValue7.get("baiduEndPoint");
                            if (baiduEndPointValue != null && baiduEndPointValue instanceof NullNode == false) {
                                String baiduEndPointInstance;
                                baiduEndPointInstance = baiduEndPointValue.getTextValue();
                                propertiesInstance7.setBaiduEndPoint(baiduEndPointInstance);
                            }

                            JsonNode baiduSecretKeyValue = propertiesValue7.get("baiduSecretKey");
                            if (baiduSecretKeyValue != null
                                    && baiduSecretKeyValue instanceof NullNode == false) {
                                String baiduSecretKeyInstance;
                                baiduSecretKeyInstance = baiduSecretKeyValue.getTextValue();
                                propertiesInstance7.setBaiduSecretKey(baiduSecretKeyInstance);
                            }
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.notificationhubs.NamespaceOperationsImpl.java

/**
* The Get namespace Delete Operation Status operation returns the status of
* the delete operation. After calling the operation, you can call Get
* namespace Delete Operation Status to determine whether the operation has
* succeeded, failed, or is still in progress. This method differs from
* GetLongRunningOperationStatus in providing NotificationHub service
* resource description.// w w w .j  av  a  2s.c om
*
* @param operationStatusLink Required. Location value returned by the Begin
* operation.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The response of the CreateOrUpdate Api Management service long
* running operation.
*/
@Override
public NamespaceLongRunningResponse getDeleteNamespaceOperationStatus(String operationStatusLink)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (operationStatusLink == null) {
        throw new NullPointerException("operationStatusLink");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("operationStatusLink", operationStatusLink);
        CloudTracing.enter(invocationId, this, "getDeleteNamespaceOperationStatusAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + operationStatusLink;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2014-09-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_ACCEPTED
                && statusCode != HttpStatus.SC_NOT_FOUND) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        NamespaceLongRunningResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED
                || statusCode == HttpStatus.SC_NOT_FOUND) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new NamespaceLongRunningResponse();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                NamespaceResource valueInstance = new NamespaceResource();
                result.setValue(valueInstance);

                JsonNode idValue = responseDoc.get("id");
                if (idValue != null && idValue instanceof NullNode == false) {
                    String idInstance;
                    idInstance = idValue.getTextValue();
                    valueInstance.setId(idInstance);
                }

                JsonNode locationValue = responseDoc.get("location");
                if (locationValue != null && locationValue instanceof NullNode == false) {
                    String locationInstance;
                    locationInstance = locationValue.getTextValue();
                    valueInstance.setLocation(locationInstance);
                }

                JsonNode nameValue = responseDoc.get("name");
                if (nameValue != null && nameValue instanceof NullNode == false) {
                    String nameInstance;
                    nameInstance = nameValue.getTextValue();
                    valueInstance.setName(nameInstance);
                }

                JsonNode typeValue = responseDoc.get("type");
                if (typeValue != null && typeValue instanceof NullNode == false) {
                    String typeInstance;
                    typeInstance = typeValue.getTextValue();
                    valueInstance.setType(typeInstance);
                }

                JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields();
                    while (itr.hasNext()) {
                        Map.Entry<String, JsonNode> property = itr.next();
                        String tagsKey = property.getKey();
                        String tagsValue = property.getValue().getTextValue();
                        valueInstance.getTags().put(tagsKey, tagsValue);
                    }
                }

                JsonNode propertiesValue = responseDoc.get("properties");
                if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                    NamespaceProperties propertiesInstance = new NamespaceProperties();
                    valueInstance.setProperties(propertiesInstance);

                    JsonNode nameValue2 = propertiesValue.get("name");
                    if (nameValue2 != null && nameValue2 instanceof NullNode == false) {
                        String nameInstance2;
                        nameInstance2 = nameValue2.getTextValue();
                        propertiesInstance.setName(nameInstance2);
                    }

                    JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                    if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) {
                        String provisioningStateInstance;
                        provisioningStateInstance = provisioningStateValue.getTextValue();
                        propertiesInstance.setProvisioningState(provisioningStateInstance);
                    }

                    JsonNode regionValue = propertiesValue.get("region");
                    if (regionValue != null && regionValue instanceof NullNode == false) {
                        String regionInstance;
                        regionInstance = regionValue.getTextValue();
                        propertiesInstance.setRegion(regionInstance);
                    }

                    JsonNode statusValue = propertiesValue.get("status");
                    if (statusValue != null && statusValue instanceof NullNode == false) {
                        String statusInstance;
                        statusInstance = statusValue.getTextValue();
                        propertiesInstance.setStatus(statusInstance);
                    }

                    JsonNode createdAtValue = propertiesValue.get("createdAt");
                    if (createdAtValue != null && createdAtValue instanceof NullNode == false) {
                        Calendar createdAtInstance;
                        createdAtInstance = DatatypeConverter.parseDateTime(createdAtValue.getTextValue());
                        propertiesInstance.setCreatedAt(createdAtInstance);
                    }

                    JsonNode serviceBusEndpointValue = propertiesValue.get("serviceBusEndpoint");
                    if (serviceBusEndpointValue != null
                            && serviceBusEndpointValue instanceof NullNode == false) {
                        URI serviceBusEndpointInstance;
                        serviceBusEndpointInstance = new URI(serviceBusEndpointValue.getTextValue());
                        propertiesInstance.setServiceBusEndpoint(serviceBusEndpointInstance);
                    }

                    JsonNode subscriptionIdValue = propertiesValue.get("subscriptionId");
                    if (subscriptionIdValue != null && subscriptionIdValue instanceof NullNode == false) {
                        String subscriptionIdInstance;
                        subscriptionIdInstance = subscriptionIdValue.getTextValue();
                        propertiesInstance.setSubscriptionId(subscriptionIdInstance);
                    }

                    JsonNode scaleUnitValue = propertiesValue.get("scaleUnit");
                    if (scaleUnitValue != null && scaleUnitValue instanceof NullNode == false) {
                        String scaleUnitInstance;
                        scaleUnitInstance = scaleUnitValue.getTextValue();
                        propertiesInstance.setScaleUnit(scaleUnitInstance);
                    }

                    JsonNode enabledValue = propertiesValue.get("enabled");
                    if (enabledValue != null && enabledValue instanceof NullNode == false) {
                        boolean enabledInstance;
                        enabledInstance = enabledValue.getBooleanValue();
                        propertiesInstance.setEnabled(enabledInstance);
                    }

                    JsonNode criticalValue = propertiesValue.get("critical");
                    if (criticalValue != null && criticalValue instanceof NullNode == false) {
                        boolean criticalInstance;
                        criticalInstance = criticalValue.getBooleanValue();
                        propertiesInstance.setCritical(criticalInstance);
                    }

                    JsonNode namespaceTypeValue = propertiesValue.get("namespaceType");
                    if (namespaceTypeValue != null && namespaceTypeValue instanceof NullNode == false) {
                        NamespaceType namespaceTypeInstance;
                        namespaceTypeInstance = Enum.valueOf(NamespaceType.class,
                                namespaceTypeValue.getTextValue());
                        propertiesInstance.setNamespaceType(namespaceTypeInstance);
                    }
                }

                ResourceError errorInstance = new ResourceError();
                result.setError(errorInstance);

                JsonNode codeValue = responseDoc.get("code");
                if (codeValue != null && codeValue instanceof NullNode == false) {
                    String codeInstance;
                    codeInstance = codeValue.getTextValue();
                    errorInstance.setCode(codeInstance);
                }

                JsonNode messageValue = responseDoc.get("message");
                if (messageValue != null && messageValue instanceof NullNode == false) {
                    String messageInstance;
                    messageInstance = messageValue.getTextValue();
                    errorInstance.setMessage(messageInstance);
                }

                JsonNode detailsSequenceElement = ((JsonNode) responseDoc.get("details"));
                if (detailsSequenceElement != null && detailsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr2 = detailsSequenceElement.getFields();
                    while (itr2.hasNext()) {
                        Map.Entry<String, JsonNode> property2 = itr2.next();
                        String detailsKey = property2.getKey();
                        String detailsValue = property2.getValue().getTextValue();
                        errorInstance.getDetails().put(detailsKey, detailsValue);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_BAD_REQUEST) {
            result.setStatus(OperationStatus.Failed);
        }
        if (statusCode == HttpStatus.SC_OK) {
            result.setStatus(OperationStatus.Succeeded);
        }
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            result.setStatus(OperationStatus.Succeeded);
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.cloud.storage.StorageManagerImpl.java

@Override
public ImageStore createSecondaryStagingStore(CreateSecondaryStagingStoreCmd cmd) {
    String providerName = cmd.getProviderName();
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);

    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultCacheDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find cache store provider: " + providerName);
        }//from w  ww.j  av  a2s. c  o  m
    }

    Long dcId = cmd.getZoneId();

    ScopeType scopeType = null;
    String scope = cmd.getScope();
    if (scope != null) {
        try {
            scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());

        } catch (Exception e) {
            throw new InvalidParameterValueException("invalid scope for cache store " + scope);
        }

        if (scopeType != ScopeType.ZONE) {
            throw new InvalidParameterValueException("Only zone wide cache storage is supported");
        }
    }

    if (scopeType == ScopeType.ZONE && dcId == null) {
        throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
    }

    // Check if the zone exists in the system
    DataCenterVO zone = _dcDao.findById(dcId);
    if (zone == null) {
        throw new InvalidParameterValueException("Can't find zone by id " + dcId);
    }

    Account account = CallContext.current().getCallingAccount();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState()
            && !_accountMgr.isRootAdmin(account.getId())) {
        PermissionDeniedException ex = new PermissionDeniedException(
                "Cannot perform this operation, Zone with specified id is currently disabled");
        ex.addProxyObject(zone.getUuid(), "dcId");
        throw ex;
    }

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("zoneId", dcId);
    params.put("url", cmd.getUrl());
    params.put("name", cmd.getUrl());
    params.put("details", cmd.getDetails());
    params.put("scope", scopeType);
    params.put("providerName", storeProvider.getName());
    params.put("role", DataStoreRole.ImageCache);

    DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    DataStore store = null;
    try {
        store = lifeCycle.initialize(params);
    } catch (Exception e) {
        s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }

    return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.ImageCache);
}

From source file:mondrian.olap.Util.java

/**
 * Looks up an enumeration by name, returning a given default value if null
 * or not valid.//from  w ww.ja v a  2 s . co  m
 *
 * @param clazz Enumerated type
 * @param name Name of constant
 * @param defaultValue Default value if constant is not found
 * @return Value, or null if name is null or value does not exist
 */
public static <E extends Enum<E>> E lookup(Class<E> clazz, String name, E defaultValue) {
    if (name == null) {
        return defaultValue;
    }
    try {
        return Enum.valueOf(clazz, name);
    } catch (IllegalArgumentException e) {
        return defaultValue;
    }
}

From source file:com.microsoft.azure.management.resources.DeploymentOperationsImpl.java

/**
* Get a list of deployments./*from ww  w.  j  a  v  a  2s. co m*/
*
* @param nextLink Required. NextLink from the previous successful call to
* List operation.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return List of deployments.
*/
@Override
public DeploymentListResult listNext(String nextLink) throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (nextLink == null) {
        throw new NullPointerException("nextLink");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("nextLink", nextLink);
        CloudTracing.enter(invocationId, this, "listNextAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + nextLink;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        DeploymentListResult result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new DeploymentListResult();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                JsonNode valueArray = responseDoc.get("value");
                if (valueArray != null && valueArray instanceof NullNode == false) {
                    for (JsonNode valueValue : ((ArrayNode) valueArray)) {
                        DeploymentExtended deploymentExtendedInstance = new DeploymentExtended();
                        result.getDeployments().add(deploymentExtendedInstance);

                        JsonNode idValue = valueValue.get("id");
                        if (idValue != null && idValue instanceof NullNode == false) {
                            String idInstance;
                            idInstance = idValue.getTextValue();
                            deploymentExtendedInstance.setId(idInstance);
                        }

                        JsonNode nameValue = valueValue.get("name");
                        if (nameValue != null && nameValue instanceof NullNode == false) {
                            String nameInstance;
                            nameInstance = nameValue.getTextValue();
                            deploymentExtendedInstance.setName(nameInstance);
                        }

                        JsonNode propertiesValue = valueValue.get("properties");
                        if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                            DeploymentPropertiesExtended propertiesInstance = new DeploymentPropertiesExtended();
                            deploymentExtendedInstance.setProperties(propertiesInstance);

                            JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                            if (provisioningStateValue != null
                                    && provisioningStateValue instanceof NullNode == false) {
                                String provisioningStateInstance;
                                provisioningStateInstance = provisioningStateValue.getTextValue();
                                propertiesInstance.setProvisioningState(provisioningStateInstance);
                            }

                            JsonNode correlationIdValue = propertiesValue.get("correlationId");
                            if (correlationIdValue != null && correlationIdValue instanceof NullNode == false) {
                                String correlationIdInstance;
                                correlationIdInstance = correlationIdValue.getTextValue();
                                propertiesInstance.setCorrelationId(correlationIdInstance);
                            }

                            JsonNode timestampValue = propertiesValue.get("timestamp");
                            if (timestampValue != null && timestampValue instanceof NullNode == false) {
                                Calendar timestampInstance;
                                timestampInstance = DatatypeConverter
                                        .parseDateTime(timestampValue.getTextValue());
                                propertiesInstance.setTimestamp(timestampInstance);
                            }

                            JsonNode outputsValue = propertiesValue.get("outputs");
                            if (outputsValue != null && outputsValue instanceof NullNode == false) {
                                String outputsInstance;
                                outputsInstance = outputsValue.getTextValue();
                                propertiesInstance.setOutputs(outputsInstance);
                            }

                            JsonNode providersArray = propertiesValue.get("providers");
                            if (providersArray != null && providersArray instanceof NullNode == false) {
                                for (JsonNode providersValue : ((ArrayNode) providersArray)) {
                                    Provider providerInstance = new Provider();
                                    propertiesInstance.getProviders().add(providerInstance);

                                    JsonNode idValue2 = providersValue.get("id");
                                    if (idValue2 != null && idValue2 instanceof NullNode == false) {
                                        String idInstance2;
                                        idInstance2 = idValue2.getTextValue();
                                        providerInstance.setId(idInstance2);
                                    }

                                    JsonNode namespaceValue = providersValue.get("namespace");
                                    if (namespaceValue != null && namespaceValue instanceof NullNode == false) {
                                        String namespaceInstance;
                                        namespaceInstance = namespaceValue.getTextValue();
                                        providerInstance.setNamespace(namespaceInstance);
                                    }

                                    JsonNode registrationStateValue = providersValue.get("registrationState");
                                    if (registrationStateValue != null
                                            && registrationStateValue instanceof NullNode == false) {
                                        String registrationStateInstance;
                                        registrationStateInstance = registrationStateValue.getTextValue();
                                        providerInstance.setRegistrationState(registrationStateInstance);
                                    }

                                    JsonNode resourceTypesArray = providersValue.get("resourceTypes");
                                    if (resourceTypesArray != null
                                            && resourceTypesArray instanceof NullNode == false) {
                                        for (JsonNode resourceTypesValue : ((ArrayNode) resourceTypesArray)) {
                                            ProviderResourceType providerResourceTypeInstance = new ProviderResourceType();
                                            providerInstance.getResourceTypes()
                                                    .add(providerResourceTypeInstance);

                                            JsonNode resourceTypeValue = resourceTypesValue.get("resourceType");
                                            if (resourceTypeValue != null
                                                    && resourceTypeValue instanceof NullNode == false) {
                                                String resourceTypeInstance;
                                                resourceTypeInstance = resourceTypeValue.getTextValue();
                                                providerResourceTypeInstance.setName(resourceTypeInstance);
                                            }

                                            JsonNode locationsArray = resourceTypesValue.get("locations");
                                            if (locationsArray != null
                                                    && locationsArray instanceof NullNode == false) {
                                                for (JsonNode locationsValue : ((ArrayNode) locationsArray)) {
                                                    providerResourceTypeInstance.getLocations()
                                                            .add(locationsValue.getTextValue());
                                                }
                                            }

                                            JsonNode apiVersionsArray = resourceTypesValue.get("apiVersions");
                                            if (apiVersionsArray != null
                                                    && apiVersionsArray instanceof NullNode == false) {
                                                for (JsonNode apiVersionsValue : ((ArrayNode) apiVersionsArray)) {
                                                    providerResourceTypeInstance.getApiVersions()
                                                            .add(apiVersionsValue.getTextValue());
                                                }
                                            }

                                            JsonNode propertiesSequenceElement = ((JsonNode) resourceTypesValue
                                                    .get("properties"));
                                            if (propertiesSequenceElement != null
                                                    && propertiesSequenceElement instanceof NullNode == false) {
                                                Iterator<Map.Entry<String, JsonNode>> itr = propertiesSequenceElement
                                                        .getFields();
                                                while (itr.hasNext()) {
                                                    Map.Entry<String, JsonNode> property = itr.next();
                                                    String propertiesKey = property.getKey();
                                                    String propertiesValue2 = property.getValue()
                                                            .getTextValue();
                                                    providerResourceTypeInstance.getProperties()
                                                            .put(propertiesKey, propertiesValue2);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            JsonNode dependenciesArray = propertiesValue.get("dependencies");
                            if (dependenciesArray != null && dependenciesArray instanceof NullNode == false) {
                                for (JsonNode dependenciesValue : ((ArrayNode) dependenciesArray)) {
                                    Dependency dependencyInstance = new Dependency();
                                    propertiesInstance.getDependencies().add(dependencyInstance);

                                    JsonNode dependsOnArray = dependenciesValue.get("dependsOn");
                                    if (dependsOnArray != null && dependsOnArray instanceof NullNode == false) {
                                        for (JsonNode dependsOnValue : ((ArrayNode) dependsOnArray)) {
                                            BasicDependency basicDependencyInstance = new BasicDependency();
                                            dependencyInstance.getDependsOn().add(basicDependencyInstance);

                                            JsonNode idValue3 = dependsOnValue.get("id");
                                            if (idValue3 != null && idValue3 instanceof NullNode == false) {
                                                String idInstance3;
                                                idInstance3 = idValue3.getTextValue();
                                                basicDependencyInstance.setId(idInstance3);
                                            }

                                            JsonNode resourceTypeValue2 = dependsOnValue.get("resourceType");
                                            if (resourceTypeValue2 != null
                                                    && resourceTypeValue2 instanceof NullNode == false) {
                                                String resourceTypeInstance2;
                                                resourceTypeInstance2 = resourceTypeValue2.getTextValue();
                                                basicDependencyInstance.setResourceType(resourceTypeInstance2);
                                            }

                                            JsonNode resourceNameValue = dependsOnValue.get("resourceName");
                                            if (resourceNameValue != null
                                                    && resourceNameValue instanceof NullNode == false) {
                                                String resourceNameInstance;
                                                resourceNameInstance = resourceNameValue.getTextValue();
                                                basicDependencyInstance.setResourceName(resourceNameInstance);
                                            }
                                        }
                                    }

                                    JsonNode idValue4 = dependenciesValue.get("id");
                                    if (idValue4 != null && idValue4 instanceof NullNode == false) {
                                        String idInstance4;
                                        idInstance4 = idValue4.getTextValue();
                                        dependencyInstance.setId(idInstance4);
                                    }

                                    JsonNode resourceTypeValue3 = dependenciesValue.get("resourceType");
                                    if (resourceTypeValue3 != null
                                            && resourceTypeValue3 instanceof NullNode == false) {
                                        String resourceTypeInstance3;
                                        resourceTypeInstance3 = resourceTypeValue3.getTextValue();
                                        dependencyInstance.setResourceType(resourceTypeInstance3);
                                    }

                                    JsonNode resourceNameValue2 = dependenciesValue.get("resourceName");
                                    if (resourceNameValue2 != null
                                            && resourceNameValue2 instanceof NullNode == false) {
                                        String resourceNameInstance2;
                                        resourceNameInstance2 = resourceNameValue2.getTextValue();
                                        dependencyInstance.setResourceName(resourceNameInstance2);
                                    }
                                }
                            }

                            JsonNode templateValue = propertiesValue.get("template");
                            if (templateValue != null && templateValue instanceof NullNode == false) {
                                String templateInstance;
                                templateInstance = templateValue.getTextValue();
                                propertiesInstance.setTemplate(templateInstance);
                            }

                            JsonNode templateLinkValue = propertiesValue.get("templateLink");
                            if (templateLinkValue != null && templateLinkValue instanceof NullNode == false) {
                                TemplateLink templateLinkInstance = new TemplateLink();
                                propertiesInstance.setTemplateLink(templateLinkInstance);

                                JsonNode uriValue = templateLinkValue.get("uri");
                                if (uriValue != null && uriValue instanceof NullNode == false) {
                                    URI uriInstance;
                                    uriInstance = new URI(uriValue.getTextValue());
                                    templateLinkInstance.setUri(uriInstance);
                                }

                                JsonNode contentVersionValue = templateLinkValue.get("contentVersion");
                                if (contentVersionValue != null
                                        && contentVersionValue instanceof NullNode == false) {
                                    String contentVersionInstance;
                                    contentVersionInstance = contentVersionValue.getTextValue();
                                    templateLinkInstance.setContentVersion(contentVersionInstance);
                                }
                            }

                            JsonNode parametersValue = propertiesValue.get("parameters");
                            if (parametersValue != null && parametersValue instanceof NullNode == false) {
                                String parametersInstance;
                                parametersInstance = parametersValue.getTextValue();
                                propertiesInstance.setParameters(parametersInstance);
                            }

                            JsonNode parametersLinkValue = propertiesValue.get("parametersLink");
                            if (parametersLinkValue != null
                                    && parametersLinkValue instanceof NullNode == false) {
                                ParametersLink parametersLinkInstance = new ParametersLink();
                                propertiesInstance.setParametersLink(parametersLinkInstance);

                                JsonNode uriValue2 = parametersLinkValue.get("uri");
                                if (uriValue2 != null && uriValue2 instanceof NullNode == false) {
                                    URI uriInstance2;
                                    uriInstance2 = new URI(uriValue2.getTextValue());
                                    parametersLinkInstance.setUri(uriInstance2);
                                }

                                JsonNode contentVersionValue2 = parametersLinkValue.get("contentVersion");
                                if (contentVersionValue2 != null
                                        && contentVersionValue2 instanceof NullNode == false) {
                                    String contentVersionInstance2;
                                    contentVersionInstance2 = contentVersionValue2.getTextValue();
                                    parametersLinkInstance.setContentVersion(contentVersionInstance2);
                                }
                            }

                            JsonNode modeValue = propertiesValue.get("mode");
                            if (modeValue != null && modeValue instanceof NullNode == false) {
                                DeploymentMode modeInstance;
                                modeInstance = Enum.valueOf(DeploymentMode.class, modeValue.getTextValue());
                                propertiesInstance.setMode(modeInstance);
                            }
                        }
                    }
                }

                JsonNode nextLinkValue = responseDoc.get("nextLink");
                if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) {
                    String nextLinkInstance;
                    nextLinkInstance = nextLinkValue.getTextValue();
                    result.setNextLink(nextLinkInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.notificationhubs.NamespaceOperationsImpl.java

/**
* Lists the available namespaces within a resourceGroup.  (see
* http://msdn.microsoft.com/en-us/library/azure/hh780759.aspx for more
* information)/*  w w  w.ja v  a 2 s.c o m*/
*
* @param resourceGroupName Required. The name of the resource group. If
* resourceGroupName value is null the method lists all the namespaces
* within subscription
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The response of the List Namespace operation.
*/
@Override
public NamespaceListResponse list(String resourceGroupName)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        CloudTracing.enter(invocationId, this, "listAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + "Microsoft.NotificationHubs";
    url = url + "/namespaces";
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-09-01");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        NamespaceListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new NamespaceListResponse();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                JsonNode valueArray = responseDoc.get("value");
                if (valueArray != null && valueArray instanceof NullNode == false) {
                    for (JsonNode valueValue : ((ArrayNode) valueArray)) {
                        NamespaceResource namespaceResourceInstance = new NamespaceResource();
                        result.getValue().add(namespaceResourceInstance);

                        JsonNode idValue = valueValue.get("id");
                        if (idValue != null && idValue instanceof NullNode == false) {
                            String idInstance;
                            idInstance = idValue.getTextValue();
                            namespaceResourceInstance.setId(idInstance);
                        }

                        JsonNode locationValue = valueValue.get("location");
                        if (locationValue != null && locationValue instanceof NullNode == false) {
                            String locationInstance;
                            locationInstance = locationValue.getTextValue();
                            namespaceResourceInstance.setLocation(locationInstance);
                        }

                        JsonNode nameValue = valueValue.get("name");
                        if (nameValue != null && nameValue instanceof NullNode == false) {
                            String nameInstance;
                            nameInstance = nameValue.getTextValue();
                            namespaceResourceInstance.setName(nameInstance);
                        }

                        JsonNode typeValue = valueValue.get("type");
                        if (typeValue != null && typeValue instanceof NullNode == false) {
                            String typeInstance;
                            typeInstance = typeValue.getTextValue();
                            namespaceResourceInstance.setType(typeInstance);
                        }

                        JsonNode tagsSequenceElement = ((JsonNode) valueValue.get("tags"));
                        if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                            Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields();
                            while (itr.hasNext()) {
                                Map.Entry<String, JsonNode> property = itr.next();
                                String tagsKey = property.getKey();
                                String tagsValue = property.getValue().getTextValue();
                                namespaceResourceInstance.getTags().put(tagsKey, tagsValue);
                            }
                        }

                        JsonNode propertiesValue = valueValue.get("properties");
                        if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                            NamespaceProperties propertiesInstance = new NamespaceProperties();
                            namespaceResourceInstance.setProperties(propertiesInstance);

                            JsonNode nameValue2 = propertiesValue.get("name");
                            if (nameValue2 != null && nameValue2 instanceof NullNode == false) {
                                String nameInstance2;
                                nameInstance2 = nameValue2.getTextValue();
                                propertiesInstance.setName(nameInstance2);
                            }

                            JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                            if (provisioningStateValue != null
                                    && provisioningStateValue instanceof NullNode == false) {
                                String provisioningStateInstance;
                                provisioningStateInstance = provisioningStateValue.getTextValue();
                                propertiesInstance.setProvisioningState(provisioningStateInstance);
                            }

                            JsonNode regionValue = propertiesValue.get("region");
                            if (regionValue != null && regionValue instanceof NullNode == false) {
                                String regionInstance;
                                regionInstance = regionValue.getTextValue();
                                propertiesInstance.setRegion(regionInstance);
                            }

                            JsonNode statusValue = propertiesValue.get("status");
                            if (statusValue != null && statusValue instanceof NullNode == false) {
                                String statusInstance;
                                statusInstance = statusValue.getTextValue();
                                propertiesInstance.setStatus(statusInstance);
                            }

                            JsonNode createdAtValue = propertiesValue.get("createdAt");
                            if (createdAtValue != null && createdAtValue instanceof NullNode == false) {
                                Calendar createdAtInstance;
                                createdAtInstance = DatatypeConverter
                                        .parseDateTime(createdAtValue.getTextValue());
                                propertiesInstance.setCreatedAt(createdAtInstance);
                            }

                            JsonNode serviceBusEndpointValue = propertiesValue.get("serviceBusEndpoint");
                            if (serviceBusEndpointValue != null
                                    && serviceBusEndpointValue instanceof NullNode == false) {
                                URI serviceBusEndpointInstance;
                                serviceBusEndpointInstance = new URI(serviceBusEndpointValue.getTextValue());
                                propertiesInstance.setServiceBusEndpoint(serviceBusEndpointInstance);
                            }

                            JsonNode subscriptionIdValue = propertiesValue.get("subscriptionId");
                            if (subscriptionIdValue != null
                                    && subscriptionIdValue instanceof NullNode == false) {
                                String subscriptionIdInstance;
                                subscriptionIdInstance = subscriptionIdValue.getTextValue();
                                propertiesInstance.setSubscriptionId(subscriptionIdInstance);
                            }

                            JsonNode scaleUnitValue = propertiesValue.get("scaleUnit");
                            if (scaleUnitValue != null && scaleUnitValue instanceof NullNode == false) {
                                String scaleUnitInstance;
                                scaleUnitInstance = scaleUnitValue.getTextValue();
                                propertiesInstance.setScaleUnit(scaleUnitInstance);
                            }

                            JsonNode enabledValue = propertiesValue.get("enabled");
                            if (enabledValue != null && enabledValue instanceof NullNode == false) {
                                boolean enabledInstance;
                                enabledInstance = enabledValue.getBooleanValue();
                                propertiesInstance.setEnabled(enabledInstance);
                            }

                            JsonNode criticalValue = propertiesValue.get("critical");
                            if (criticalValue != null && criticalValue instanceof NullNode == false) {
                                boolean criticalInstance;
                                criticalInstance = criticalValue.getBooleanValue();
                                propertiesInstance.setCritical(criticalInstance);
                            }

                            JsonNode namespaceTypeValue = propertiesValue.get("namespaceType");
                            if (namespaceTypeValue != null && namespaceTypeValue instanceof NullNode == false) {
                                NamespaceType namespaceTypeInstance;
                                namespaceTypeInstance = Enum.valueOf(NamespaceType.class,
                                        namespaceTypeValue.getTextValue());
                                propertiesInstance.setNamespaceType(namespaceTypeInstance);
                            }
                        }
                    }
                }

                JsonNode nextLinkValue = responseDoc.get("nextLink");
                if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) {
                    String nextLinkInstance;
                    nextLinkInstance = nextLinkValue.getTextValue();
                    result.setNextLink(nextLinkInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.notificationhubs.NotificationHubOperationsImpl.java

/**
* The get authorization rule operation gets an authorization rule for a
* NotificationHub by name.//from w w w.j a va 2 s.  co m
*
* @param resourceGroupName Required. The name of the resource group.
* @param namespaceName Required. The namespace to get the authorization
* rule for.
* @param notificationHubName Required. The notification hub name.
* @param authorizationRuleName Required. The entity name to get the
* authorization rule for.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return The response of the Get Namespace operation.
*/
@Override
public SharedAccessAuthorizationRuleGetResponse getAuthorizationRule(String resourceGroupName,
        String namespaceName, String notificationHubName, String authorizationRuleName)
        throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }
    if (notificationHubName == null) {
        throw new NullPointerException("notificationHubName");
    }
    if (authorizationRuleName == null) {
        throw new NullPointerException("authorizationRuleName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("namespaceName", namespaceName);
        tracingParameters.put("notificationHubName", notificationHubName);
        tracingParameters.put("authorizationRuleName", authorizationRuleName);
        CloudTracing.enter(invocationId, this, "getAuthorizationRuleAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + "Microsoft.NotificationHubs";
    url = url + "/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    url = url + "/notificationHubs/";
    url = url + URLEncoder.encode(notificationHubName, "UTF-8");
    url = url + "/AuthorizationRules/";
    url = url + URLEncoder.encode(authorizationRuleName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-09-01");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPost httpRequest = new HttpPost(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        SharedAccessAuthorizationRuleGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new SharedAccessAuthorizationRuleGetResponse();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                SharedAccessAuthorizationRuleResource valueInstance = new SharedAccessAuthorizationRuleResource();
                result.setValue(valueInstance);

                JsonNode idValue = responseDoc.get("id");
                if (idValue != null && idValue instanceof NullNode == false) {
                    String idInstance;
                    idInstance = idValue.getTextValue();
                    valueInstance.setId(idInstance);
                }

                JsonNode locationValue = responseDoc.get("location");
                if (locationValue != null && locationValue instanceof NullNode == false) {
                    String locationInstance;
                    locationInstance = locationValue.getTextValue();
                    valueInstance.setLocation(locationInstance);
                }

                JsonNode nameValue = responseDoc.get("name");
                if (nameValue != null && nameValue instanceof NullNode == false) {
                    String nameInstance;
                    nameInstance = nameValue.getTextValue();
                    valueInstance.setName(nameInstance);
                }

                JsonNode typeValue = responseDoc.get("type");
                if (typeValue != null && typeValue instanceof NullNode == false) {
                    String typeInstance;
                    typeInstance = typeValue.getTextValue();
                    valueInstance.setType(typeInstance);
                }

                JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields();
                    while (itr.hasNext()) {
                        Map.Entry<String, JsonNode> property = itr.next();
                        String tagsKey = property.getKey();
                        String tagsValue = property.getValue().getTextValue();
                        valueInstance.getTags().put(tagsKey, tagsValue);
                    }
                }

                JsonNode propertiesValue = responseDoc.get("properties");
                if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                    SharedAccessAuthorizationRuleProperties propertiesInstance = new SharedAccessAuthorizationRuleProperties();
                    valueInstance.setProperties(propertiesInstance);

                    JsonNode primaryKeyValue = propertiesValue.get("primaryKey");
                    if (primaryKeyValue != null && primaryKeyValue instanceof NullNode == false) {
                        String primaryKeyInstance;
                        primaryKeyInstance = primaryKeyValue.getTextValue();
                        propertiesInstance.setPrimaryKey(primaryKeyInstance);
                    }

                    JsonNode secondaryKeyValue = propertiesValue.get("secondaryKey");
                    if (secondaryKeyValue != null && secondaryKeyValue instanceof NullNode == false) {
                        String secondaryKeyInstance;
                        secondaryKeyInstance = secondaryKeyValue.getTextValue();
                        propertiesInstance.setSecondaryKey(secondaryKeyInstance);
                    }

                    JsonNode keyNameValue = propertiesValue.get("keyName");
                    if (keyNameValue != null && keyNameValue instanceof NullNode == false) {
                        String keyNameInstance;
                        keyNameInstance = keyNameValue.getTextValue();
                        propertiesInstance.setKeyName(keyNameInstance);
                    }

                    JsonNode claimTypeValue = propertiesValue.get("claimType");
                    if (claimTypeValue != null && claimTypeValue instanceof NullNode == false) {
                        String claimTypeInstance;
                        claimTypeInstance = claimTypeValue.getTextValue();
                        propertiesInstance.setClaimType(claimTypeInstance);
                    }

                    JsonNode claimValueValue = propertiesValue.get("claimValue");
                    if (claimValueValue != null && claimValueValue instanceof NullNode == false) {
                        String claimValueInstance;
                        claimValueInstance = claimValueValue.getTextValue();
                        propertiesInstance.setClaimValue(claimValueInstance);
                    }

                    JsonNode rightsArray = propertiesValue.get("rights");
                    if (rightsArray != null && rightsArray instanceof NullNode == false) {
                        for (JsonNode rightsValue : ((ArrayNode) rightsArray)) {
                            propertiesInstance.getRights()
                                    .add(Enum.valueOf(AccessRights.class, rightsValue.getTextValue()));
                        }
                    }

                    JsonNode createdTimeValue = propertiesValue.get("createdTime");
                    if (createdTimeValue != null && createdTimeValue instanceof NullNode == false) {
                        Calendar createdTimeInstance;
                        createdTimeInstance = DatatypeConverter.parseDateTime(createdTimeValue.getTextValue());
                        propertiesInstance.setCreatedTime(createdTimeInstance);
                    }

                    JsonNode modifiedTimeValue = propertiesValue.get("modifiedTime");
                    if (modifiedTimeValue != null && modifiedTimeValue instanceof NullNode == false) {
                        Calendar modifiedTimeInstance;
                        modifiedTimeInstance = DatatypeConverter
                                .parseDateTime(modifiedTimeValue.getTextValue());
                        propertiesInstance.setModifiedTime(modifiedTimeInstance);
                    }

                    JsonNode revisionValue = propertiesValue.get("revision");
                    if (revisionValue != null && revisionValue instanceof NullNode == false) {
                        int revisionInstance;
                        revisionInstance = revisionValue.getIntValue();
                        propertiesInstance.setRevision(revisionInstance);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}