Example usage for javax.xml.bind DatatypeConverter parseDateTime

List of usage examples for javax.xml.bind DatatypeConverter parseDateTime

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter parseDateTime.

Prototype

public static java.util.Calendar parseDateTime(String lexicalXSDDateTime) 

Source Link

Document

Converts the string argument into a Calendar value.

Usage

From source file:com.microsoft.azure.management.compute.VirtualMachineExtensionOperationsImpl.java

/**
* The operation to get the extension.//from ww w .  j a va2s . co  m
*
* @param resourceGroupName Required. The name of the resource group.
* @param vmName Required. The name of the virtual machine containing the
* extension.
* @param vmExtensionName Required. The name of the virtual machine
* extension.
* @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 Get VM-Extension operation response.
*/
@Override
public VirtualMachineExtensionGetResponse get(String resourceGroupName, String vmName, String vmExtensionName)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (vmName == null) {
        throw new NullPointerException("vmName");
    }
    if (vmExtensionName == null) {
        throw new NullPointerException("vmExtensionName");
    }

    // 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("vmName", vmName);
        tracingParameters.put("vmExtensionName", vmExtensionName);
        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.Compute";
    url = url + "/";
    url = url + "virtualMachines";
    url = url + "/";
    url = url + URLEncoder.encode(vmName, "UTF-8");
    url = url + "/extensions/";
    url = url + URLEncoder.encode(vmExtensionName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2015-06-15");
    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
        VirtualMachineExtensionGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new VirtualMachineExtensionGetResponse();
            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) {
                VirtualMachineExtension virtualMachineExtensionInstance = new VirtualMachineExtension();
                result.setVirtualMachineExtension(virtualMachineExtensionInstance);

                JsonNode propertiesValue = responseDoc.get("properties");
                if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                    JsonNode publisherValue = propertiesValue.get("publisher");
                    if (publisherValue != null && publisherValue instanceof NullNode == false) {
                        String publisherInstance;
                        publisherInstance = publisherValue.getTextValue();
                        virtualMachineExtensionInstance.setPublisher(publisherInstance);
                    }

                    JsonNode typeValue = propertiesValue.get("type");
                    if (typeValue != null && typeValue instanceof NullNode == false) {
                        String typeInstance;
                        typeInstance = typeValue.getTextValue();
                        virtualMachineExtensionInstance.setExtensionType(typeInstance);
                    }

                    JsonNode typeHandlerVersionValue = propertiesValue.get("typeHandlerVersion");
                    if (typeHandlerVersionValue != null
                            && typeHandlerVersionValue instanceof NullNode == false) {
                        String typeHandlerVersionInstance;
                        typeHandlerVersionInstance = typeHandlerVersionValue.getTextValue();
                        virtualMachineExtensionInstance.setTypeHandlerVersion(typeHandlerVersionInstance);
                    }

                    JsonNode autoUpgradeMinorVersionValue = propertiesValue.get("autoUpgradeMinorVersion");
                    if (autoUpgradeMinorVersionValue != null
                            && autoUpgradeMinorVersionValue instanceof NullNode == false) {
                        boolean autoUpgradeMinorVersionInstance;
                        autoUpgradeMinorVersionInstance = autoUpgradeMinorVersionValue.getBooleanValue();
                        virtualMachineExtensionInstance
                                .setAutoUpgradeMinorVersion(autoUpgradeMinorVersionInstance);
                    }

                    JsonNode settingsValue = propertiesValue.get("settings");
                    if (settingsValue != null && settingsValue instanceof NullNode == false) {
                        String settingsInstance;
                        settingsInstance = settingsValue.getTextValue();
                        virtualMachineExtensionInstance.setSettings(settingsInstance);
                    }

                    JsonNode protectedSettingsValue = propertiesValue.get("protectedSettings");
                    if (protectedSettingsValue != null && protectedSettingsValue instanceof NullNode == false) {
                        String protectedSettingsInstance;
                        protectedSettingsInstance = protectedSettingsValue.getTextValue();
                        virtualMachineExtensionInstance.setProtectedSettings(protectedSettingsInstance);
                    }

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

                    JsonNode instanceViewValue = propertiesValue.get("instanceView");
                    if (instanceViewValue != null && instanceViewValue instanceof NullNode == false) {
                        VirtualMachineExtensionInstanceView instanceViewInstance = new VirtualMachineExtensionInstanceView();
                        virtualMachineExtensionInstance.setInstanceView(instanceViewInstance);

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

                        JsonNode typeValue2 = instanceViewValue.get("type");
                        if (typeValue2 != null && typeValue2 instanceof NullNode == false) {
                            String typeInstance2;
                            typeInstance2 = typeValue2.getTextValue();
                            instanceViewInstance.setExtensionType(typeInstance2);
                        }

                        JsonNode typeHandlerVersionValue2 = instanceViewValue.get("typeHandlerVersion");
                        if (typeHandlerVersionValue2 != null
                                && typeHandlerVersionValue2 instanceof NullNode == false) {
                            String typeHandlerVersionInstance2;
                            typeHandlerVersionInstance2 = typeHandlerVersionValue2.getTextValue();
                            instanceViewInstance.setTypeHandlerVersion(typeHandlerVersionInstance2);
                        }

                        JsonNode substatusesArray = instanceViewValue.get("substatuses");
                        if (substatusesArray != null && substatusesArray instanceof NullNode == false) {
                            for (JsonNode substatusesValue : ((ArrayNode) substatusesArray)) {
                                InstanceViewStatus instanceViewStatusInstance = new InstanceViewStatus();
                                instanceViewInstance.getSubStatuses().add(instanceViewStatusInstance);

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

                                JsonNode levelValue = substatusesValue.get("level");
                                if (levelValue != null && levelValue instanceof NullNode == false) {
                                    String levelInstance;
                                    levelInstance = levelValue.getTextValue();
                                    instanceViewStatusInstance.setLevel(levelInstance);
                                }

                                JsonNode displayStatusValue = substatusesValue.get("displayStatus");
                                if (displayStatusValue != null
                                        && displayStatusValue instanceof NullNode == false) {
                                    String displayStatusInstance;
                                    displayStatusInstance = displayStatusValue.getTextValue();
                                    instanceViewStatusInstance.setDisplayStatus(displayStatusInstance);
                                }

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

                                JsonNode timeValue = substatusesValue.get("time");
                                if (timeValue != null && timeValue instanceof NullNode == false) {
                                    Calendar timeInstance;
                                    timeInstance = DatatypeConverter.parseDateTime(timeValue.getTextValue());
                                    instanceViewStatusInstance.setTime(timeInstance);
                                }
                            }
                        }

                        JsonNode statusesArray = instanceViewValue.get("statuses");
                        if (statusesArray != null && statusesArray instanceof NullNode == false) {
                            for (JsonNode statusesValue : ((ArrayNode) statusesArray)) {
                                InstanceViewStatus instanceViewStatusInstance2 = new InstanceViewStatus();
                                instanceViewInstance.getStatuses().add(instanceViewStatusInstance2);

                                JsonNode codeValue2 = statusesValue.get("code");
                                if (codeValue2 != null && codeValue2 instanceof NullNode == false) {
                                    String codeInstance2;
                                    codeInstance2 = codeValue2.getTextValue();
                                    instanceViewStatusInstance2.setCode(codeInstance2);
                                }

                                JsonNode levelValue2 = statusesValue.get("level");
                                if (levelValue2 != null && levelValue2 instanceof NullNode == false) {
                                    String levelInstance2;
                                    levelInstance2 = levelValue2.getTextValue();
                                    instanceViewStatusInstance2.setLevel(levelInstance2);
                                }

                                JsonNode displayStatusValue2 = statusesValue.get("displayStatus");
                                if (displayStatusValue2 != null
                                        && displayStatusValue2 instanceof NullNode == false) {
                                    String displayStatusInstance2;
                                    displayStatusInstance2 = displayStatusValue2.getTextValue();
                                    instanceViewStatusInstance2.setDisplayStatus(displayStatusInstance2);
                                }

                                JsonNode messageValue2 = statusesValue.get("message");
                                if (messageValue2 != null && messageValue2 instanceof NullNode == false) {
                                    String messageInstance2;
                                    messageInstance2 = messageValue2.getTextValue();
                                    instanceViewStatusInstance2.setMessage(messageInstance2);
                                }

                                JsonNode timeValue2 = statusesValue.get("time");
                                if (timeValue2 != null && timeValue2 instanceof NullNode == false) {
                                    Calendar timeInstance2;
                                    timeInstance2 = DatatypeConverter.parseDateTime(timeValue2.getTextValue());
                                    instanceViewStatusInstance2.setTime(timeInstance2);
                                }
                            }
                        }
                    }
                }

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

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

                JsonNode typeValue3 = responseDoc.get("type");
                if (typeValue3 != null && typeValue3 instanceof NullNode == false) {
                    String typeInstance3;
                    typeInstance3 = typeValue3.getTextValue();
                    virtualMachineExtensionInstance.setType(typeInstance3);
                }

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

                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();
                        virtualMachineExtensionInstance.getTags().put(tagsKey, tagsValue);
                    }
                }
            }

        }
        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.windowsazure.management.compute.VirtualMachineVMImageOperationsImpl.java

/**
* Gets VMImage's properties and its replication details. This operation is
* only for publishers. You have to be registered as image publisher with
* Windows Azure to be able to call this.
*
* @param vmImageName Required. The name of the virtual machine image to
* replicate./*from  w  ww.  j  a  v  a2  s .  com*/
* @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 ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Get Details VM Images operation response.
*/
@Override
public VirtualMachineVMImageGetDetailsResponse getDetails(String vmImageName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (vmImageName == null) {
        throw new NullPointerException("vmImageName");
    }

    // 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("vmImageName", vmImageName);
        CloudTracing.enter(invocationId, this, "getDetailsAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/vmimages/";
    url = url + URLEncoder.encode(vmImageName, "UTF-8");
    url = url + "/details";
    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("x-ms-version", "2015-04-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) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        VirtualMachineVMImageGetDetailsResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new VirtualMachineVMImageGetDetailsResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element vMImageDetailsElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "VMImageDetails");
            if (vMImageDetailsElement != null) {
                Element nameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement != null) {
                    String nameInstance;
                    nameInstance = nameElement.getTextContent();
                    result.setName(nameInstance);
                }

                Element labelElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Label");
                if (labelElement != null) {
                    String labelInstance;
                    labelInstance = labelElement.getTextContent();
                    result.setLabel(labelInstance);
                }

                Element categoryElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Category");
                if (categoryElement != null) {
                    String categoryInstance;
                    categoryInstance = categoryElement.getTextContent();
                    result.setCategory(categoryInstance);
                }

                Element descriptionElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Description");
                if (descriptionElement != null) {
                    String descriptionInstance;
                    descriptionInstance = descriptionElement.getTextContent();
                    result.setDescription(descriptionInstance);
                }

                Element oSDiskConfigurationElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "OSDiskConfiguration");
                if (oSDiskConfigurationElement != null) {
                    VirtualMachineVMImageListResponse.OSDiskConfiguration oSDiskConfigurationInstance = new VirtualMachineVMImageListResponse.OSDiskConfiguration();
                    result.setOSDiskConfiguration(oSDiskConfigurationInstance);

                    Element nameElement2 = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement,
                            "http://schemas.microsoft.com/windowsazure", "Name");
                    if (nameElement2 != null) {
                        String nameInstance2;
                        nameInstance2 = nameElement2.getTextContent();
                        oSDiskConfigurationInstance.setName(nameInstance2);
                    }

                    Element hostCachingElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement,
                            "http://schemas.microsoft.com/windowsazure", "HostCaching");
                    if (hostCachingElement != null) {
                        String hostCachingInstance;
                        hostCachingInstance = hostCachingElement.getTextContent();
                        oSDiskConfigurationInstance.setHostCaching(hostCachingInstance);
                    }

                    Element oSStateElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement,
                            "http://schemas.microsoft.com/windowsazure", "OSState");
                    if (oSStateElement != null) {
                        String oSStateInstance;
                        oSStateInstance = oSStateElement.getTextContent();
                        oSDiskConfigurationInstance.setOSState(oSStateInstance);
                    }

                    Element osElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement,
                            "http://schemas.microsoft.com/windowsazure", "OS");
                    if (osElement != null) {
                        String osInstance;
                        osInstance = osElement.getTextContent();
                        oSDiskConfigurationInstance.setOperatingSystem(osInstance);
                    }

                    Element mediaLinkElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement,
                            "http://schemas.microsoft.com/windowsazure", "MediaLink");
                    if (mediaLinkElement != null) {
                        URI mediaLinkInstance;
                        mediaLinkInstance = new URI(mediaLinkElement.getTextContent());
                        oSDiskConfigurationInstance.setMediaLink(mediaLinkInstance);
                    }

                    Element logicalDiskSizeInGBElement = XmlUtility.getElementByTagNameNS(
                            oSDiskConfigurationElement, "http://schemas.microsoft.com/windowsazure",
                            "LogicalDiskSizeInGB");
                    if (logicalDiskSizeInGBElement != null) {
                        int logicalDiskSizeInGBInstance;
                        logicalDiskSizeInGBInstance = DatatypeConverter
                                .parseInt(logicalDiskSizeInGBElement.getTextContent());
                        oSDiskConfigurationInstance.setLogicalDiskSizeInGB(logicalDiskSizeInGBInstance);
                    }

                    Element iOTypeElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement,
                            "http://schemas.microsoft.com/windowsazure", "IOType");
                    if (iOTypeElement != null) {
                        String iOTypeInstance;
                        iOTypeInstance = iOTypeElement.getTextContent();
                        oSDiskConfigurationInstance.setIOType(iOTypeInstance);
                    }
                }

                Element dataDiskConfigurationsSequenceElement = XmlUtility.getElementByTagNameNS(
                        vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure",
                        "DataDiskConfigurations");
                if (dataDiskConfigurationsSequenceElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(dataDiskConfigurationsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "DataDiskConfiguration")
                            .size(); i1 = i1 + 1) {
                        org.w3c.dom.Element dataDiskConfigurationsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(dataDiskConfigurationsSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "DataDiskConfiguration")
                                .get(i1));
                        VirtualMachineVMImageListResponse.DataDiskConfiguration dataDiskConfigurationInstance = new VirtualMachineVMImageListResponse.DataDiskConfiguration();
                        result.getDataDiskConfigurations().add(dataDiskConfigurationInstance);

                        Element nameElement3 = XmlUtility.getElementByTagNameNS(dataDiskConfigurationsElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement3 != null) {
                            String nameInstance3;
                            nameInstance3 = nameElement3.getTextContent();
                            dataDiskConfigurationInstance.setName(nameInstance3);
                        }

                        Element hostCachingElement2 = XmlUtility.getElementByTagNameNS(
                                dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure",
                                "HostCaching");
                        if (hostCachingElement2 != null) {
                            String hostCachingInstance2;
                            hostCachingInstance2 = hostCachingElement2.getTextContent();
                            dataDiskConfigurationInstance.setHostCaching(hostCachingInstance2);
                        }

                        Element lunElement = XmlUtility.getElementByTagNameNS(dataDiskConfigurationsElement,
                                "http://schemas.microsoft.com/windowsazure", "Lun");
                        if (lunElement != null && lunElement.getTextContent() != null
                                && !lunElement.getTextContent().isEmpty()) {
                            int lunInstance;
                            lunInstance = DatatypeConverter.parseInt(lunElement.getTextContent());
                            dataDiskConfigurationInstance.setLogicalUnitNumber(lunInstance);
                        }

                        Element mediaLinkElement2 = XmlUtility.getElementByTagNameNS(
                                dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure",
                                "MediaLink");
                        if (mediaLinkElement2 != null) {
                            URI mediaLinkInstance2;
                            mediaLinkInstance2 = new URI(mediaLinkElement2.getTextContent());
                            dataDiskConfigurationInstance.setMediaLink(mediaLinkInstance2);
                        }

                        Element logicalDiskSizeInGBElement2 = XmlUtility.getElementByTagNameNS(
                                dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure",
                                "LogicalDiskSizeInGB");
                        if (logicalDiskSizeInGBElement2 != null) {
                            int logicalDiskSizeInGBInstance2;
                            logicalDiskSizeInGBInstance2 = DatatypeConverter
                                    .parseInt(logicalDiskSizeInGBElement2.getTextContent());
                            dataDiskConfigurationInstance.setLogicalDiskSizeInGB(logicalDiskSizeInGBInstance2);
                        }

                        Element iOTypeElement2 = XmlUtility.getElementByTagNameNS(dataDiskConfigurationsElement,
                                "http://schemas.microsoft.com/windowsazure", "IOType");
                        if (iOTypeElement2 != null) {
                            String iOTypeInstance2;
                            iOTypeInstance2 = iOTypeElement2.getTextContent();
                            dataDiskConfigurationInstance.setIOType(iOTypeInstance2);
                        }
                    }
                }

                Element serviceNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "ServiceName");
                if (serviceNameElement != null) {
                    String serviceNameInstance;
                    serviceNameInstance = serviceNameElement.getTextContent();
                    result.setServiceName(serviceNameInstance);
                }

                Element deploymentNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "DeploymentName");
                if (deploymentNameElement != null) {
                    String deploymentNameInstance;
                    deploymentNameInstance = deploymentNameElement.getTextContent();
                    result.setDeploymentName(deploymentNameInstance);
                }

                Element roleNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "RoleName");
                if (roleNameElement != null) {
                    String roleNameInstance;
                    roleNameInstance = roleNameElement.getTextContent();
                    result.setRoleName(roleNameInstance);
                }

                Element affinityGroupElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "AffinityGroup");
                if (affinityGroupElement != null) {
                    String affinityGroupInstance;
                    affinityGroupInstance = affinityGroupElement.getTextContent();
                    result.setAffinityGroup(affinityGroupInstance);
                }

                Element locationElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Location");
                if (locationElement != null) {
                    String locationInstance;
                    locationInstance = locationElement.getTextContent();
                    result.setLocation(locationInstance);
                }

                Element createdTimeElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "CreatedTime");
                if (createdTimeElement != null && createdTimeElement.getTextContent() != null
                        && !createdTimeElement.getTextContent().isEmpty()) {
                    Calendar createdTimeInstance;
                    createdTimeInstance = DatatypeConverter.parseDateTime(createdTimeElement.getTextContent());
                    result.setCreatedTime(createdTimeInstance);
                }

                Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "ModifiedTime");
                if (modifiedTimeElement != null && modifiedTimeElement.getTextContent() != null
                        && !modifiedTimeElement.getTextContent().isEmpty()) {
                    Calendar modifiedTimeInstance;
                    modifiedTimeInstance = DatatypeConverter
                            .parseDateTime(modifiedTimeElement.getTextContent());
                    result.setModifiedTime(modifiedTimeInstance);
                }

                Element languageElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Language");
                if (languageElement != null) {
                    String languageInstance;
                    languageInstance = languageElement.getTextContent();
                    result.setLanguage(languageInstance);
                }

                Element imageFamilyElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "ImageFamily");
                if (imageFamilyElement != null) {
                    String imageFamilyInstance;
                    imageFamilyInstance = imageFamilyElement.getTextContent();
                    result.setImageFamily(imageFamilyInstance);
                }

                Element recommendedVMSizeElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "RecommendedVMSize");
                if (recommendedVMSizeElement != null) {
                    String recommendedVMSizeInstance;
                    recommendedVMSizeInstance = recommendedVMSizeElement.getTextContent();
                    result.setRecommendedVMSize(recommendedVMSizeInstance);
                }

                Element isPremiumElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "IsPremium");
                if (isPremiumElement != null && isPremiumElement.getTextContent() != null
                        && !isPremiumElement.getTextContent().isEmpty()) {
                    boolean isPremiumInstance;
                    isPremiumInstance = DatatypeConverter
                            .parseBoolean(isPremiumElement.getTextContent().toLowerCase());
                    result.setIsPremium(isPremiumInstance);
                }

                Element eulaElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Eula");
                if (eulaElement != null) {
                    String eulaInstance;
                    eulaInstance = eulaElement.getTextContent();
                    result.setEula(eulaInstance);
                }

                Element iconUriElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "IconUri");
                if (iconUriElement != null) {
                    String iconUriInstance;
                    iconUriInstance = iconUriElement.getTextContent();
                    result.setIconUri(iconUriInstance);
                }

                Element smallIconUriElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "SmallIconUri");
                if (smallIconUriElement != null) {
                    String smallIconUriInstance;
                    smallIconUriInstance = smallIconUriElement.getTextContent();
                    result.setSmallIconUri(smallIconUriInstance);
                }

                Element privacyUriElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PrivacyUri");
                if (privacyUriElement != null) {
                    URI privacyUriInstance;
                    privacyUriInstance = new URI(privacyUriElement.getTextContent());
                    result.setPrivacyUri(privacyUriInstance);
                }

                Element publisherNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PublisherName");
                if (publisherNameElement != null) {
                    String publisherNameInstance;
                    publisherNameInstance = publisherNameElement.getTextContent();
                    result.setPublisherName(publisherNameInstance);
                }

                Element publishedDateElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PublishedDate");
                if (publishedDateElement != null && publishedDateElement.getTextContent() != null
                        && !publishedDateElement.getTextContent().isEmpty()) {
                    Calendar publishedDateInstance;
                    publishedDateInstance = DatatypeConverter
                            .parseDateTime(publishedDateElement.getTextContent());
                    result.setPublishedDate(publishedDateInstance);
                }

                Element showInGuiElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "ShowInGui");
                if (showInGuiElement != null && showInGuiElement.getTextContent() != null
                        && !showInGuiElement.getTextContent().isEmpty()) {
                    boolean showInGuiInstance;
                    showInGuiInstance = DatatypeConverter
                            .parseBoolean(showInGuiElement.getTextContent().toLowerCase());
                    result.setShowInGui(showInGuiInstance);
                }

                Element pricingDetailLinkElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PricingDetailLink");
                if (pricingDetailLinkElement != null) {
                    URI pricingDetailLinkInstance;
                    pricingDetailLinkInstance = new URI(pricingDetailLinkElement.getTextContent());
                    result.setPricingDetailLink(pricingDetailLinkInstance);
                }

                Element isCorruptedElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "IsCorrupted");
                if (isCorruptedElement != null && isCorruptedElement.getTextContent() != null
                        && !isCorruptedElement.getTextContent().isEmpty()) {
                    boolean isCorruptedInstance;
                    isCorruptedInstance = DatatypeConverter
                            .parseBoolean(isCorruptedElement.getTextContent().toLowerCase());
                    result.setIsCorrupted(isCorruptedInstance);
                }

                Element publishedNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PublishedName");
                if (publishedNameElement != null) {
                    String publishedNameInstance;
                    publishedNameInstance = publishedNameElement.getTextContent();
                    result.setPublishedName(publishedNameInstance);
                }

                Element sharingStatusElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "SharingStatus");
                if (sharingStatusElement != null) {
                    String sharingStatusInstance;
                    sharingStatusInstance = sharingStatusElement.getTextContent();
                    result.setSharingStatus(sharingStatusInstance);
                }

                Element replicationProgressSequenceElement = XmlUtility.getElementByTagNameNS(
                        vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure",
                        "ReplicationProgress");
                if (replicationProgressSequenceElement != null) {
                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(replicationProgressSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "ReplicationProgressElement")
                            .size(); i2 = i2 + 1) {
                        org.w3c.dom.Element replicationProgressElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(replicationProgressSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure",
                                        "ReplicationProgressElement")
                                .get(i2));
                        VirtualMachineVMImageGetDetailsResponse.ReplicationProgressElement replicationProgressElementInstance = new VirtualMachineVMImageGetDetailsResponse.ReplicationProgressElement();
                        result.getReplicationProgress().add(replicationProgressElementInstance);

                        Element locationElement2 = XmlUtility.getElementByTagNameNS(replicationProgressElement,
                                "http://schemas.microsoft.com/windowsazure", "Location");
                        if (locationElement2 != null) {
                            String locationInstance2;
                            locationInstance2 = locationElement2.getTextContent();
                            replicationProgressElementInstance.setLocation(locationInstance2);
                        }

                        Element progressElement = XmlUtility.getElementByTagNameNS(replicationProgressElement,
                                "http://schemas.microsoft.com/windowsazure", "Progress");
                        if (progressElement != null) {
                            String progressInstance;
                            progressInstance = progressElement.getTextContent();
                            replicationProgressElementInstance.setProgress(progressInstance);
                        }
                    }
                }

                Element computeImageAttributesElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "ComputeImageAttributes");
                if (computeImageAttributesElement != null) {
                    ComputeImageAttributes computeImageAttributesInstance = new ComputeImageAttributes();
                    result.setComputeImageAttributes(computeImageAttributesInstance);

                    Element offerElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement,
                            "http://schemas.microsoft.com/windowsazure", "Offer");
                    if (offerElement != null) {
                        String offerInstance;
                        offerInstance = offerElement.getTextContent();
                        computeImageAttributesInstance.setOffer(offerInstance);
                    }

                    Element skuElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement,
                            "http://schemas.microsoft.com/windowsazure", "Sku");
                    if (skuElement != null) {
                        String skuInstance;
                        skuInstance = skuElement.getTextContent();
                        computeImageAttributesInstance.setSku(skuInstance);
                    }

                    Element versionElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement,
                            "http://schemas.microsoft.com/windowsazure", "Version");
                    if (versionElement != null) {
                        String versionInstance;
                        versionInstance = versionElement.getTextContent();
                        computeImageAttributesInstance.setVersion(versionInstance);
                    }
                }

                Element marketplaceImageAttributesElement = XmlUtility.getElementByTagNameNS(
                        vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure",
                        "MarketplaceImageAttributes");
                if (marketplaceImageAttributesElement != null) {
                    MarketplaceImageAttributes marketplaceImageAttributesInstance = new MarketplaceImageAttributes();
                    result.setMarketplaceImageAttributes(marketplaceImageAttributesInstance);

                    Element publisherIdElement = XmlUtility.getElementByTagNameNS(
                            marketplaceImageAttributesElement, "http://schemas.microsoft.com/windowsazure",
                            "PublisherId");
                    if (publisherIdElement != null) {
                        String publisherIdInstance;
                        publisherIdInstance = publisherIdElement.getTextContent();
                        marketplaceImageAttributesInstance.setPublisherId(publisherIdInstance);
                    }

                    Element planElement = XmlUtility.getElementByTagNameNS(marketplaceImageAttributesElement,
                            "http://schemas.microsoft.com/windowsazure", "Plan");
                    if (planElement != null) {
                        Plan planInstance = new Plan();
                        marketplaceImageAttributesInstance.setPlan(planInstance);

                        Element nameElement4 = XmlUtility.getElementByTagNameNS(planElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement4 != null) {
                            String nameInstance4;
                            nameInstance4 = nameElement4.getTextContent();
                            planInstance.setName(nameInstance4);
                        }

                        Element publisherElement = XmlUtility.getElementByTagNameNS(planElement,
                                "http://schemas.microsoft.com/windowsazure", "Publisher");
                        if (publisherElement != null) {
                            String publisherInstance;
                            publisherInstance = publisherElement.getTextContent();
                            planInstance.setPublisher(publisherInstance);
                        }

                        Element productElement = XmlUtility.getElementByTagNameNS(planElement,
                                "http://schemas.microsoft.com/windowsazure", "Product");
                        if (productElement != null) {
                            String productInstance;
                            productInstance = productElement.getTextContent();
                            planInstance.setProduct(productInstance);
                        }
                    }
                }
            }

        }
        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.websites.WebSiteOperationsImpl.java

/**
* You can create a web site by using a POST request that includes the name
* of the web site and other information in the request body.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx for
* more information)/*from ww w .j av a2 s .co  m*/
*
* @param resourceGroupName Required. The name of the resource group.
* @param webSiteName Required. The name of the web site.
* @param slotName Optional. The name of the slot.
* @param parameters Required. Parameters supplied to the Create Web Site
* 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 Create Web Space operation response.
*/
@Override
public WebSiteCreateResponse createOrUpdate(String resourceGroupName, String webSiteName, String slotName,
        WebSiteCreateOrUpdateParameters parameters) throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (webSiteName == null) {
        throw new NullPointerException("webSiteName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getWebSite() == null) {
        throw new NullPointerException("parameters.WebSite");
    }
    if (parameters.getWebSite().getLocation() == null) {
        throw new NullPointerException("parameters.WebSite.Location");
    }
    if (parameters.getWebSite().getProperties() != null) {
        if (parameters.getWebSite().getProperties().getServerFarm() == null) {
            throw new NullPointerException("parameters.WebSite.Properties.ServerFarm");
        }
    }

    // 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("webSiteName", webSiteName);
        tracingParameters.put("slotName", slotName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "createOrUpdateAsync", 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.Web";
    url = url + "/";
    url = url + "sites";
    url = url + "/";
    url = url + URLEncoder.encode(webSiteName, "UTF-8");
    if (slotName != null) {
        url = url + "/slots/" + URLEncoder.encode(slotName, "UTF-8");
    }
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-06-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
    HttpPut httpRequest = new HttpPut(url);

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

    // Serialize Request
    String requestContent = null;
    JsonNode requestDoc = null;

    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode webSiteCreateOrUpdateParametersValue = objectMapper.createObjectNode();
    requestDoc = webSiteCreateOrUpdateParametersValue;

    if (parameters.getWebSite().getProperties() != null) {
        ObjectNode propertiesValue = objectMapper.createObjectNode();
        ((ObjectNode) webSiteCreateOrUpdateParametersValue).put("properties", propertiesValue);

        ((ObjectNode) propertiesValue).put("ServerFarm",
                parameters.getWebSite().getProperties().getServerFarm());
    }

    if (parameters.getWebSite().getId() != null) {
        ((ObjectNode) webSiteCreateOrUpdateParametersValue).put("id", parameters.getWebSite().getId());
    }

    if (parameters.getWebSite().getName() != null) {
        ((ObjectNode) webSiteCreateOrUpdateParametersValue).put("name", parameters.getWebSite().getName());
    }

    ((ObjectNode) webSiteCreateOrUpdateParametersValue).put("location", parameters.getWebSite().getLocation());

    if (parameters.getWebSite().getTags() != null) {
        ObjectNode tagsDictionary = objectMapper.createObjectNode();
        for (Map.Entry<String, String> entry : parameters.getWebSite().getTags().entrySet()) {
            String tagsKey = entry.getKey();
            String tagsValue = entry.getValue();
            ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue);
        }
        ((ObjectNode) webSiteCreateOrUpdateParametersValue).put("tags", tagsDictionary);
    }

    if (parameters.getWebSite().getType() != null) {
        ((ObjectNode) webSiteCreateOrUpdateParametersValue).put("type", parameters.getWebSite().getType());
    }

    StringWriter stringWriter = new StringWriter();
    objectMapper.writeValue(stringWriter, requestDoc);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    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, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        WebSiteCreateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new WebSiteCreateResponse();
            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) {
                WebSite webSiteInstance = new WebSite();
                result.setWebSite(webSiteInstance);

                JsonNode propertiesValue2 = responseDoc.get("properties");
                if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                    WebSiteProperties propertiesInstance = new WebSiteProperties();
                    webSiteInstance.setProperties(propertiesInstance);

                    JsonNode adminEnabledValue = propertiesValue2.get("adminEnabled");
                    if (adminEnabledValue != null && adminEnabledValue instanceof NullNode == false) {
                        boolean adminEnabledInstance;
                        adminEnabledInstance = adminEnabledValue.getBooleanValue();
                        propertiesInstance.setAdminEnabled(adminEnabledInstance);
                    }

                    JsonNode availabilityStateValue = propertiesValue2.get("availabilityState");
                    if (availabilityStateValue != null && availabilityStateValue instanceof NullNode == false) {
                        WebSpaceAvailabilityState availabilityStateInstance;
                        availabilityStateInstance = Enum.valueOf(WebSpaceAvailabilityState.class,
                                availabilityStateValue.getTextValue());
                        propertiesInstance.setAvailabilityState(availabilityStateInstance);
                    }

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

                    JsonNode enabledHostNamesArray = propertiesValue2.get("enabledHostNames");
                    if (enabledHostNamesArray != null && enabledHostNamesArray instanceof NullNode == false) {
                        for (JsonNode enabledHostNamesValue : ((ArrayNode) enabledHostNamesArray)) {
                            propertiesInstance.getEnabledHostNames().add(enabledHostNamesValue.getTextValue());
                        }
                    }

                    JsonNode hostNameSslStatesArray = propertiesValue2.get("hostNameSslStates");
                    if (hostNameSslStatesArray != null && hostNameSslStatesArray instanceof NullNode == false) {
                        for (JsonNode hostNameSslStatesValue : ((ArrayNode) hostNameSslStatesArray)) {
                            WebSiteProperties.WebSiteHostNameSslState webSiteHostNameSslStateInstance = new WebSiteProperties.WebSiteHostNameSslState();
                            propertiesInstance.getHostNameSslStates().add(webSiteHostNameSslStateInstance);

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

                            JsonNode sslStateValue = hostNameSslStatesValue.get("sslState");
                            if (sslStateValue != null && sslStateValue instanceof NullNode == false) {
                                WebSiteSslState sslStateInstance;
                                sslStateInstance = Enum.valueOf(WebSiteSslState.class,
                                        sslStateValue.getTextValue());
                                webSiteHostNameSslStateInstance.setSslState(sslStateInstance);
                            }

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

                            JsonNode virtualIPValue = hostNameSslStatesValue.get("virtualIP");
                            if (virtualIPValue != null && virtualIPValue instanceof NullNode == false) {
                                InetAddress virtualIPInstance;
                                virtualIPInstance = InetAddress.getByName(virtualIPValue.getTextValue());
                                webSiteHostNameSslStateInstance.setVirtualIP(virtualIPInstance);
                            }

                            JsonNode ipBasedSslResultValue = hostNameSslStatesValue.get("ipBasedSslResult");
                            if (ipBasedSslResultValue != null
                                    && ipBasedSslResultValue instanceof NullNode == false) {
                                String ipBasedSslResultInstance;
                                ipBasedSslResultInstance = ipBasedSslResultValue.getTextValue();
                                webSiteHostNameSslStateInstance.setIpBasedSslResult(ipBasedSslResultInstance);
                            }

                            JsonNode toUpdateValue = hostNameSslStatesValue.get("toUpdate");
                            if (toUpdateValue != null && toUpdateValue instanceof NullNode == false) {
                                boolean toUpdateInstance;
                                toUpdateInstance = toUpdateValue.getBooleanValue();
                                webSiteHostNameSslStateInstance.setToUpdate(toUpdateInstance);
                            }

                            JsonNode toUpdateIpBasedSslValue = hostNameSslStatesValue.get("toUpdateIpBasedSsl");
                            if (toUpdateIpBasedSslValue != null
                                    && toUpdateIpBasedSslValue instanceof NullNode == false) {
                                boolean toUpdateIpBasedSslInstance;
                                toUpdateIpBasedSslInstance = toUpdateIpBasedSslValue.getBooleanValue();
                                webSiteHostNameSslStateInstance
                                        .setToUpdateIpBasedSsl(toUpdateIpBasedSslInstance);
                            }

                            JsonNode hostTypeValue = hostNameSslStatesValue.get("hostType");
                            if (hostTypeValue != null && hostTypeValue instanceof NullNode == false) {
                                HostType hostTypeInstance;
                                hostTypeInstance = Enum.valueOf(HostType.class, hostTypeValue.getTextValue());
                                webSiteHostNameSslStateInstance.setHostType(hostTypeInstance);
                            }
                        }
                    }

                    JsonNode hostNamesArray = propertiesValue2.get("hostNames");
                    if (hostNamesArray != null && hostNamesArray instanceof NullNode == false) {
                        for (JsonNode hostNamesValue : ((ArrayNode) hostNamesArray)) {
                            propertiesInstance.getHostNames().add(hostNamesValue.getTextValue());
                        }
                    }

                    JsonNode lastModifiedTimeUtcValue = propertiesValue2.get("lastModifiedTimeUtc");
                    if (lastModifiedTimeUtcValue != null
                            && lastModifiedTimeUtcValue instanceof NullNode == false) {
                        Calendar lastModifiedTimeUtcInstance;
                        lastModifiedTimeUtcInstance = DatatypeConverter
                                .parseDateTime(lastModifiedTimeUtcValue.getTextValue());
                        propertiesInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance);
                    }

                    JsonNode repositorySiteNameValue = propertiesValue2.get("repositorySiteName");
                    if (repositorySiteNameValue != null
                            && repositorySiteNameValue instanceof NullNode == false) {
                        String repositorySiteNameInstance;
                        repositorySiteNameInstance = repositorySiteNameValue.getTextValue();
                        propertiesInstance.setRepositorySiteName(repositorySiteNameInstance);
                    }

                    JsonNode runtimeAvailabilityStateValue = propertiesValue2.get("runtimeAvailabilityState");
                    if (runtimeAvailabilityStateValue != null
                            && runtimeAvailabilityStateValue instanceof NullNode == false) {
                        WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance;
                        runtimeAvailabilityStateInstance = Enum.valueOf(WebSiteRuntimeAvailabilityState.class,
                                runtimeAvailabilityStateValue.getTextValue());
                        propertiesInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance);
                    }

                    JsonNode trafficManagerHostNamesArray = propertiesValue2.get("trafficManagerHostNames");
                    if (trafficManagerHostNamesArray != null
                            && trafficManagerHostNamesArray instanceof NullNode == false) {
                        for (JsonNode trafficManagerHostNamesValue : ((ArrayNode) trafficManagerHostNamesArray)) {
                            propertiesInstance.getTrafficManagerHostNames()
                                    .add(trafficManagerHostNamesValue.getTextValue());
                        }
                    }

                    JsonNode selfLinkValue = propertiesValue2.get("selfLink");
                    if (selfLinkValue != null && selfLinkValue instanceof NullNode == false) {
                        URI selfLinkInstance;
                        selfLinkInstance = new URI(selfLinkValue.getTextValue());
                        propertiesInstance.setUri(selfLinkInstance);
                    }

                    JsonNode serverFarmValue = propertiesValue2.get("serverFarm");
                    if (serverFarmValue != null && serverFarmValue instanceof NullNode == false) {
                        String serverFarmInstance;
                        serverFarmInstance = serverFarmValue.getTextValue();
                        propertiesInstance.setServerFarm(serverFarmInstance);
                    }

                    JsonNode serverFarmIdValue = propertiesValue2.get("serverFarmId");
                    if (serverFarmIdValue != null && serverFarmIdValue instanceof NullNode == false) {
                        String serverFarmIdInstance;
                        serverFarmIdInstance = serverFarmIdValue.getTextValue();
                        propertiesInstance.setServerFarmId(serverFarmIdInstance);
                    }

                    JsonNode skuValue = propertiesValue2.get("sku");
                    if (skuValue != null && skuValue instanceof NullNode == false) {
                        SkuOptions skuInstance;
                        skuInstance = Enum.valueOf(SkuOptions.class, skuValue.getTextValue());
                        propertiesInstance.setSku(skuInstance);
                    }

                    JsonNode sitePropertiesValue = propertiesValue2.get("siteProperties");
                    if (sitePropertiesValue != null && sitePropertiesValue instanceof NullNode == false) {
                        WebSiteProperties.SiteProperties sitePropertiesInstance = new WebSiteProperties.SiteProperties();
                        propertiesInstance.setProperties(sitePropertiesInstance);

                        JsonNode appSettingsSequenceElement = ((JsonNode) sitePropertiesValue
                                .get("appSettings"));
                        if (appSettingsSequenceElement != null
                                && appSettingsSequenceElement instanceof NullNode == false) {
                            Iterator<Map.Entry<String, JsonNode>> itr = appSettingsSequenceElement.getFields();
                            while (itr.hasNext()) {
                                Map.Entry<String, JsonNode> property = itr.next();
                                String appSettingsKey = property.getKey();
                                String appSettingsValue = property.getValue().getTextValue();
                                sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue);
                            }
                        }

                        JsonNode metadataSequenceElement = ((JsonNode) sitePropertiesValue.get("metadata"));
                        if (metadataSequenceElement != null
                                && metadataSequenceElement instanceof NullNode == false) {
                            Iterator<Map.Entry<String, JsonNode>> itr2 = metadataSequenceElement.getFields();
                            while (itr2.hasNext()) {
                                Map.Entry<String, JsonNode> property2 = itr2.next();
                                String metadataKey = property2.getKey();
                                String metadataValue = property2.getValue().getTextValue();
                                sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue);
                            }
                        }

                        JsonNode propertiesSequenceElement = ((JsonNode) sitePropertiesValue.get("properties"));
                        if (propertiesSequenceElement != null
                                && propertiesSequenceElement instanceof NullNode == false) {
                            Iterator<Map.Entry<String, JsonNode>> itr3 = propertiesSequenceElement.getFields();
                            while (itr3.hasNext()) {
                                Map.Entry<String, JsonNode> property3 = itr3.next();
                                String propertiesKey = property3.getKey();
                                String propertiesValue3 = property3.getValue().getTextValue();
                                sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue3);
                            }
                        }
                    }

                    JsonNode siteConfigValue = propertiesValue2.get("siteConfig");
                    if (siteConfigValue != null && siteConfigValue instanceof NullNode == false) {
                        WebSiteConfiguration siteConfigInstance = new WebSiteConfiguration();
                        propertiesInstance.setSiteConfig(siteConfigInstance);

                        JsonNode appSettingsSequenceElement2 = ((JsonNode) siteConfigValue.get("appSettings"));
                        if (appSettingsSequenceElement2 != null
                                && appSettingsSequenceElement2 instanceof NullNode == false) {
                            Iterator<Map.Entry<String, JsonNode>> itr4 = appSettingsSequenceElement2
                                    .getFields();
                            while (itr4.hasNext()) {
                                Map.Entry<String, JsonNode> property4 = itr4.next();
                                String appSettingsKey2 = property4.getKey();
                                String appSettingsValue2 = property4.getValue().getTextValue();
                                siteConfigInstance.getAppSettings().put(appSettingsKey2, appSettingsValue2);
                            }
                        }

                        JsonNode connectionStringsArray = siteConfigValue.get("connectionStrings");
                        if (connectionStringsArray != null
                                && connectionStringsArray instanceof NullNode == false) {
                            for (JsonNode connectionStringsValue : ((ArrayNode) connectionStringsArray)) {
                                ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
                                siteConfigInstance.getConnectionStrings().add(connStringInfoInstance);

                                JsonNode connectionStringValue = connectionStringsValue.get("connectionString");
                                if (connectionStringValue != null
                                        && connectionStringValue instanceof NullNode == false) {
                                    String connectionStringInstance;
                                    connectionStringInstance = connectionStringValue.getTextValue();
                                    connStringInfoInstance.setConnectionString(connectionStringInstance);
                                }

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

                                JsonNode typeValue = connectionStringsValue.get("type");
                                if (typeValue != null && typeValue instanceof NullNode == false) {
                                    DatabaseServerType typeInstance;
                                    typeInstance = Enum.valueOf(DatabaseServerType.class,
                                            typeValue.getTextValue());
                                    connStringInfoInstance.setType(typeInstance);
                                }
                            }
                        }

                        JsonNode defaultDocumentsArray = siteConfigValue.get("defaultDocuments");
                        if (defaultDocumentsArray != null
                                && defaultDocumentsArray instanceof NullNode == false) {
                            for (JsonNode defaultDocumentsValue : ((ArrayNode) defaultDocumentsArray)) {
                                siteConfigInstance.getDefaultDocuments()
                                        .add(defaultDocumentsValue.getTextValue());
                            }
                        }

                        JsonNode detailedErrorLoggingEnabledValue = siteConfigValue
                                .get("detailedErrorLoggingEnabled");
                        if (detailedErrorLoggingEnabledValue != null
                                && detailedErrorLoggingEnabledValue instanceof NullNode == false) {
                            boolean detailedErrorLoggingEnabledInstance;
                            detailedErrorLoggingEnabledInstance = detailedErrorLoggingEnabledValue
                                    .getBooleanValue();
                            siteConfigInstance
                                    .setDetailedErrorLoggingEnabled(detailedErrorLoggingEnabledInstance);
                        }

                        JsonNode documentRootValue = siteConfigValue.get("documentRoot");
                        if (documentRootValue != null && documentRootValue instanceof NullNode == false) {
                            String documentRootInstance;
                            documentRootInstance = documentRootValue.getTextValue();
                            siteConfigInstance.setDocumentRoot(documentRootInstance);
                        }

                        JsonNode handlerMappingsArray = siteConfigValue.get("handlerMappings");
                        if (handlerMappingsArray != null && handlerMappingsArray instanceof NullNode == false) {
                            for (JsonNode handlerMappingsValue : ((ArrayNode) handlerMappingsArray)) {
                                WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
                                siteConfigInstance.getHandlerMappings().add(handlerMappingInstance);

                                JsonNode argumentsValue = handlerMappingsValue.get("arguments");
                                if (argumentsValue != null && argumentsValue instanceof NullNode == false) {
                                    String argumentsInstance;
                                    argumentsInstance = argumentsValue.getTextValue();
                                    handlerMappingInstance.setArguments(argumentsInstance);
                                }

                                JsonNode extensionValue = handlerMappingsValue.get("extension");
                                if (extensionValue != null && extensionValue instanceof NullNode == false) {
                                    String extensionInstance;
                                    extensionInstance = extensionValue.getTextValue();
                                    handlerMappingInstance.setExtension(extensionInstance);
                                }

                                JsonNode scriptProcessorValue = handlerMappingsValue.get("scriptProcessor");
                                if (scriptProcessorValue != null
                                        && scriptProcessorValue instanceof NullNode == false) {
                                    String scriptProcessorInstance;
                                    scriptProcessorInstance = scriptProcessorValue.getTextValue();
                                    handlerMappingInstance.setScriptProcessor(scriptProcessorInstance);
                                }
                            }
                        }

                        JsonNode httpLoggingEnabledValue = siteConfigValue.get("httpLoggingEnabled");
                        if (httpLoggingEnabledValue != null
                                && httpLoggingEnabledValue instanceof NullNode == false) {
                            boolean httpLoggingEnabledInstance;
                            httpLoggingEnabledInstance = httpLoggingEnabledValue.getBooleanValue();
                            siteConfigInstance.setHttpLoggingEnabled(httpLoggingEnabledInstance);
                        }

                        JsonNode logsDirectorySizeLimitValue = siteConfigValue.get("logsDirectorySizeLimit");
                        if (logsDirectorySizeLimitValue != null
                                && logsDirectorySizeLimitValue instanceof NullNode == false) {
                            int logsDirectorySizeLimitInstance;
                            logsDirectorySizeLimitInstance = logsDirectorySizeLimitValue.getIntValue();
                            siteConfigInstance.setLogsDirectorySizeLimit(logsDirectorySizeLimitInstance);
                        }

                        JsonNode managedPipelineModeValue = siteConfigValue.get("managedPipelineMode");
                        if (managedPipelineModeValue != null
                                && managedPipelineModeValue instanceof NullNode == false) {
                            ManagedPipelineMode managedPipelineModeInstance;
                            managedPipelineModeInstance = Enum.valueOf(ManagedPipelineMode.class,
                                    managedPipelineModeValue.getTextValue());
                            siteConfigInstance.setManagedPipelineMode(managedPipelineModeInstance);
                        }

                        JsonNode metadataSequenceElement2 = ((JsonNode) siteConfigValue.get("metadata"));
                        if (metadataSequenceElement2 != null
                                && metadataSequenceElement2 instanceof NullNode == false) {
                            Iterator<Map.Entry<String, JsonNode>> itr5 = metadataSequenceElement2.getFields();
                            while (itr5.hasNext()) {
                                Map.Entry<String, JsonNode> property5 = itr5.next();
                                String metadataKey2 = property5.getKey();
                                String metadataValue2 = property5.getValue().getTextValue();
                                siteConfigInstance.getMetadata().put(metadataKey2, metadataValue2);
                            }
                        }

                        JsonNode netFrameworkVersionValue = siteConfigValue.get("netFrameworkVersion");
                        if (netFrameworkVersionValue != null
                                && netFrameworkVersionValue instanceof NullNode == false) {
                            String netFrameworkVersionInstance;
                            netFrameworkVersionInstance = netFrameworkVersionValue.getTextValue();
                            siteConfigInstance.setNetFrameworkVersion(netFrameworkVersionInstance);
                        }

                        JsonNode numberOfWorkersValue = siteConfigValue.get("numberOfWorkers");
                        if (numberOfWorkersValue != null && numberOfWorkersValue instanceof NullNode == false) {
                            int numberOfWorkersInstance;
                            numberOfWorkersInstance = numberOfWorkersValue.getIntValue();
                            siteConfigInstance.setNumberOfWorkers(numberOfWorkersInstance);
                        }

                        JsonNode phpVersionValue = siteConfigValue.get("phpVersion");
                        if (phpVersionValue != null && phpVersionValue instanceof NullNode == false) {
                            String phpVersionInstance;
                            phpVersionInstance = phpVersionValue.getTextValue();
                            siteConfigInstance.setPhpVersion(phpVersionInstance);
                        }

                        JsonNode pythonVersionValue = siteConfigValue.get("pythonVersion");
                        if (pythonVersionValue != null && pythonVersionValue instanceof NullNode == false) {
                            String pythonVersionInstance;
                            pythonVersionInstance = pythonVersionValue.getTextValue();
                            siteConfigInstance.setPythonVersion(pythonVersionInstance);
                        }

                        JsonNode publishingPasswordValue = siteConfigValue.get("publishingPassword");
                        if (publishingPasswordValue != null
                                && publishingPasswordValue instanceof NullNode == false) {
                            String publishingPasswordInstance;
                            publishingPasswordInstance = publishingPasswordValue.getTextValue();
                            siteConfigInstance.setPublishingPassword(publishingPasswordInstance);
                        }

                        JsonNode publishingUsernameValue = siteConfigValue.get("publishingUsername");
                        if (publishingUsernameValue != null
                                && publishingUsernameValue instanceof NullNode == false) {
                            String publishingUsernameInstance;
                            publishingUsernameInstance = publishingUsernameValue.getTextValue();
                            siteConfigInstance.setPublishingUserName(publishingUsernameInstance);
                        }

                        JsonNode remoteDebuggingEnabledValue = siteConfigValue.get("RemoteDebuggingEnabled");
                        if (remoteDebuggingEnabledValue != null
                                && remoteDebuggingEnabledValue instanceof NullNode == false) {
                            boolean remoteDebuggingEnabledInstance;
                            remoteDebuggingEnabledInstance = remoteDebuggingEnabledValue.getBooleanValue();
                            siteConfigInstance.setRemoteDebuggingEnabled(remoteDebuggingEnabledInstance);
                        }

                        JsonNode remoteDebuggingVersionValue = siteConfigValue.get("remoteDebuggingVersion");
                        if (remoteDebuggingVersionValue != null
                                && remoteDebuggingVersionValue instanceof NullNode == false) {
                            RemoteDebuggingVersion remoteDebuggingVersionInstance;
                            remoteDebuggingVersionInstance = Enum.valueOf(RemoteDebuggingVersion.class,
                                    remoteDebuggingVersionValue.getTextValue());
                            siteConfigInstance.setRemoteDebuggingVersion(remoteDebuggingVersionInstance);
                        }

                        JsonNode requestTracingEnabledValue = siteConfigValue.get("requestTracingEnabled");
                        if (requestTracingEnabledValue != null
                                && requestTracingEnabledValue instanceof NullNode == false) {
                            boolean requestTracingEnabledInstance;
                            requestTracingEnabledInstance = requestTracingEnabledValue.getBooleanValue();
                            siteConfigInstance.setRequestTracingEnabled(requestTracingEnabledInstance);
                        }

                        JsonNode requestTracingExpirationTimeValue = siteConfigValue
                                .get("requestTracingExpirationTime");
                        if (requestTracingExpirationTimeValue != null
                                && requestTracingExpirationTimeValue instanceof NullNode == false) {
                            Calendar requestTracingExpirationTimeInstance;
                            requestTracingExpirationTimeInstance = DatatypeConverter
                                    .parseDateTime(requestTracingExpirationTimeValue.getTextValue());
                            siteConfigInstance
                                    .setRequestTracingExpirationTime(requestTracingExpirationTimeInstance);
                        }

                        JsonNode scmTypeValue = siteConfigValue.get("scmType");
                        if (scmTypeValue != null && scmTypeValue instanceof NullNode == false) {
                            String scmTypeInstance;
                            scmTypeInstance = scmTypeValue.getTextValue();
                            siteConfigInstance.setScmType(scmTypeInstance);
                        }

                        JsonNode autoSwapSlotNameValue = siteConfigValue.get("autoSwapSlotName");
                        if (autoSwapSlotNameValue != null
                                && autoSwapSlotNameValue instanceof NullNode == false) {
                            String autoSwapSlotNameInstance;
                            autoSwapSlotNameInstance = autoSwapSlotNameValue.getTextValue();
                            siteConfigInstance.setAutoSwapSlotName(autoSwapSlotNameInstance);
                        }

                        JsonNode use32BitWorkerProcessValue = siteConfigValue.get("use32BitWorkerProcess");
                        if (use32BitWorkerProcessValue != null
                                && use32BitWorkerProcessValue instanceof NullNode == false) {
                            boolean use32BitWorkerProcessInstance;
                            use32BitWorkerProcessInstance = use32BitWorkerProcessValue.getBooleanValue();
                            siteConfigInstance.setUse32BitWorkerProcess(use32BitWorkerProcessInstance);
                        }

                        JsonNode webSocketsEnabledValue = siteConfigValue.get("webSocketsEnabled");
                        if (webSocketsEnabledValue != null
                                && webSocketsEnabledValue instanceof NullNode == false) {
                            boolean webSocketsEnabledInstance;
                            webSocketsEnabledInstance = webSocketsEnabledValue.getBooleanValue();
                            siteConfigInstance.setWebSocketsEnabled(webSocketsEnabledInstance);
                        }

                        JsonNode limitsValue = siteConfigValue.get("limits");
                        if (limitsValue != null && limitsValue instanceof NullNode == false) {
                            SiteLimits limitsInstance = new SiteLimits();
                            siteConfigInstance.setLimits(limitsInstance);

                            JsonNode maxPercentageCpuValue = limitsValue.get("maxPercentageCpu");
                            if (maxPercentageCpuValue != null
                                    && maxPercentageCpuValue instanceof NullNode == false) {
                                double maxPercentageCpuInstance;
                                maxPercentageCpuInstance = maxPercentageCpuValue.getDoubleValue();
                                limitsInstance.setMaxPercentageCpu(maxPercentageCpuInstance);
                            }

                            JsonNode maxMemoryInMbValue = limitsValue.get("maxMemoryInMb");
                            if (maxMemoryInMbValue != null && maxMemoryInMbValue instanceof NullNode == false) {
                                long maxMemoryInMbInstance;
                                maxMemoryInMbInstance = maxMemoryInMbValue.getLongValue();
                                limitsInstance.setMaxMemoryInMb(maxMemoryInMbInstance);
                            }

                            JsonNode maxDiskSizeInMbValue = limitsValue.get("maxDiskSizeInMb");
                            if (maxDiskSizeInMbValue != null
                                    && maxDiskSizeInMbValue instanceof NullNode == false) {
                                long maxDiskSizeInMbInstance;
                                maxDiskSizeInMbInstance = maxDiskSizeInMbValue.getLongValue();
                                limitsInstance.setMaxDiskSizeInMb(maxDiskSizeInMbInstance);
                            }
                        }
                    }

                    JsonNode stateValue = propertiesValue2.get("state");
                    if (stateValue != null && stateValue instanceof NullNode == false) {
                        WebSiteState stateInstance;
                        stateInstance = Enum.valueOf(WebSiteState.class, stateValue.getTextValue());
                        propertiesInstance.setState(stateInstance);
                    }

                    JsonNode usageStateValue = propertiesValue2.get("usageState");
                    if (usageStateValue != null && usageStateValue instanceof NullNode == false) {
                        WebSiteUsageState usageStateInstance;
                        usageStateInstance = Enum.valueOf(WebSiteUsageState.class,
                                usageStateValue.getTextValue());
                        propertiesInstance.setUsageState(usageStateInstance);
                    }

                    JsonNode webSpaceValue = propertiesValue2.get("webSpace");
                    if (webSpaceValue != null && webSpaceValue instanceof NullNode == false) {
                        String webSpaceInstance;
                        webSpaceInstance = webSpaceValue.getTextValue();
                        propertiesInstance.setWebSpace(webSpaceInstance);
                    }

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

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

                JsonNode nameValue3 = responseDoc.get("name");
                if (nameValue3 != null && nameValue3 instanceof NullNode == false) {
                    String nameInstance3;
                    nameInstance3 = nameValue3.getTextValue();
                    webSiteInstance.setName(nameInstance3);
                }

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

                JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr6 = tagsSequenceElement.getFields();
                    while (itr6.hasNext()) {
                        Map.Entry<String, JsonNode> property6 = itr6.next();
                        String tagsKey2 = property6.getKey();
                        String tagsValue2 = property6.getValue().getTextValue();
                        webSiteInstance.getTags().put(tagsKey2, tagsValue2);
                    }
                }

                JsonNode typeValue2 = responseDoc.get("type");
                if (typeValue2 != null && typeValue2 instanceof NullNode == false) {
                    String typeInstance2;
                    typeInstance2 = typeValue2.getTextValue();
                    webSiteInstance.setType(typeInstance2);
                }
            }

        }
        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.windowsazure.management.sql.DatabaseOperationsImpl.java

/**
* Returns the usage information for an Azure SQL Database.
*
* @param serverName Required. The name of the Azure SQL Database Server on
* which the database is hosted./* ww w.  ja  v a 2s.com*/
* @param databaseName Required. The name of the Azure SQL Database.
* @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 ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return Contains the response to a Get Database Usages request.
*/
@Override
public DatabaseUsagesListResponse getUsages(String serverName, String databaseName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }
    if (databaseName == null) {
        throw new NullPointerException("databaseName");
    }

    // 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("serverName", serverName);
        tracingParameters.put("databaseName", databaseName);
        CloudTracing.enter(invocationId, this, "getUsagesAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/sqlservers/servers/";
    url = url + URLEncoder.encode(serverName, "UTF-8");
    url = url + "/databases/";
    url = url + URLEncoder.encode(databaseName, "UTF-8");
    url = url + "/usages";
    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("x-ms-version", "2012-03-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) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        DatabaseUsagesListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new DatabaseUsagesListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element usagesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Usages");
            if (usagesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(usagesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "Usage")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element usagesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(usagesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "Usage")
                            .get(i1));
                    DatabaseUsageMetric usageInstance = new DatabaseUsageMetric();
                    result.getUsages().add(usageInstance);

                    Element nameElement = XmlUtility.getElementByTagNameNS(usagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Name");
                    if (nameElement != null) {
                        String nameInstance;
                        nameInstance = nameElement.getTextContent();
                        usageInstance.setName(nameInstance);
                    }

                    Element resourceNameElement = XmlUtility.getElementByTagNameNS(usagesElement,
                            "http://schemas.microsoft.com/windowsazure", "ResourceName");
                    if (resourceNameElement != null) {
                        String resourceNameInstance;
                        resourceNameInstance = resourceNameElement.getTextContent();
                        usageInstance.setResourceName(resourceNameInstance);
                    }

                    Element currentValueElement = XmlUtility.getElementByTagNameNS(usagesElement,
                            "http://schemas.microsoft.com/windowsazure", "CurrentValue");
                    if (currentValueElement != null) {
                        String currentValueInstance;
                        currentValueInstance = currentValueElement.getTextContent();
                        usageInstance.setCurrentValue(currentValueInstance);
                    }

                    Element limitElement = XmlUtility.getElementByTagNameNS(usagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Limit");
                    if (limitElement != null) {
                        String limitInstance;
                        limitInstance = limitElement.getTextContent();
                        usageInstance.setLimit(limitInstance);
                    }

                    Element unitElement = XmlUtility.getElementByTagNameNS(usagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Unit");
                    if (unitElement != null) {
                        String unitInstance;
                        unitInstance = unitElement.getTextContent();
                        usageInstance.setUnit(unitInstance);
                    }

                    Element nextResetTimeElement = XmlUtility.getElementByTagNameNS(usagesElement,
                            "http://schemas.microsoft.com/windowsazure", "NextResetTime");
                    if (nextResetTimeElement != null && nextResetTimeElement.getTextContent() != null
                            && !nextResetTimeElement.getTextContent().isEmpty()) {
                        Calendar nextResetTimeInstance;
                        nextResetTimeInstance = DatatypeConverter
                                .parseDateTime(nextResetTimeElement.getTextContent());
                        usageInstance.setNextResetTime(nextResetTimeInstance);
                    }
                }
            }

        }
        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.windowsazure.management.storage.StorageAccountOperationsImpl.java

/**
* The List Storage Accounts operation lists the storage accounts available
* under the current subscription.  (see//from   w ww.  j av a2s  . c o m
* http://msdn.microsoft.com/en-us/library/windowsazure/ee460787.aspx for
* more information)
*
* @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 ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The List Storage Accounts operation response.
*/
@Override
public StorageAccountListResponse list()
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate

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

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/storageservices";
    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("x-ms-version", "2014-10-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) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        StorageAccountListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new StorageAccountListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element storageServicesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "StorageServices");
            if (storageServicesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(storageServicesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "StorageService")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element storageServicesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(storageServicesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "StorageService")
                            .get(i1));
                    StorageAccount storageServiceInstance = new StorageAccount();
                    result.getStorageAccounts().add(storageServiceInstance);

                    Element urlElement = XmlUtility.getElementByTagNameNS(storageServicesElement,
                            "http://schemas.microsoft.com/windowsazure", "Url");
                    if (urlElement != null) {
                        URI urlInstance;
                        urlInstance = new URI(urlElement.getTextContent());
                        storageServiceInstance.setUri(urlInstance);
                    }

                    Element serviceNameElement = XmlUtility.getElementByTagNameNS(storageServicesElement,
                            "http://schemas.microsoft.com/windowsazure", "ServiceName");
                    if (serviceNameElement != null) {
                        String serviceNameInstance;
                        serviceNameInstance = serviceNameElement.getTextContent();
                        storageServiceInstance.setName(serviceNameInstance);
                    }

                    Element storageServicePropertiesElement = XmlUtility.getElementByTagNameNS(
                            storageServicesElement, "http://schemas.microsoft.com/windowsazure",
                            "StorageServiceProperties");
                    if (storageServicePropertiesElement != null) {
                        StorageAccountProperties storageServicePropertiesInstance = new StorageAccountProperties();
                        storageServiceInstance.setProperties(storageServicePropertiesInstance);

                        Element descriptionElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "Description");
                        if (descriptionElement != null) {
                            boolean isNil = false;
                            Attr nilAttribute = descriptionElement
                                    .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                            if (nilAttribute != null) {
                                isNil = "true".equals(nilAttribute.getValue());
                            }
                            if (isNil == false) {
                                String descriptionInstance;
                                descriptionInstance = descriptionElement.getTextContent();
                                storageServicePropertiesInstance.setDescription(descriptionInstance);
                            }
                        }

                        Element affinityGroupElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "AffinityGroup");
                        if (affinityGroupElement != null) {
                            String affinityGroupInstance;
                            affinityGroupInstance = affinityGroupElement.getTextContent();
                            storageServicePropertiesInstance.setAffinityGroup(affinityGroupInstance);
                        }

                        Element locationElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "Location");
                        if (locationElement != null) {
                            String locationInstance;
                            locationInstance = locationElement.getTextContent();
                            storageServicePropertiesInstance.setLocation(locationInstance);
                        }

                        Element labelElement = XmlUtility.getElementByTagNameNS(storageServicePropertiesElement,
                                "http://schemas.microsoft.com/windowsazure", "Label");
                        if (labelElement != null) {
                            String labelInstance;
                            labelInstance = labelElement.getTextContent() != null
                                    ? new String(Base64.decode(labelElement.getTextContent()))
                                    : null;
                            storageServicePropertiesInstance.setLabel(labelInstance);
                        }

                        Element statusElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "Status");
                        if (statusElement != null && statusElement.getTextContent() != null
                                && !statusElement.getTextContent().isEmpty()) {
                            StorageAccountStatus statusInstance;
                            statusInstance = StorageAccountStatus.valueOf(statusElement.getTextContent());
                            storageServicePropertiesInstance.setStatus(statusInstance);
                        }

                        Element endpointsSequenceElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "Endpoints");
                        if (endpointsSequenceElement != null) {
                            for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(endpointsSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "Endpoint")
                                    .size(); i2 = i2 + 1) {
                                org.w3c.dom.Element endpointsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(endpointsSequenceElement,
                                                "http://schemas.microsoft.com/windowsazure", "Endpoint")
                                        .get(i2));
                                storageServicePropertiesInstance.getEndpoints()
                                        .add(new URI(endpointsElement.getTextContent()));
                            }
                        }

                        Element geoPrimaryRegionElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "GeoPrimaryRegion");
                        if (geoPrimaryRegionElement != null) {
                            String geoPrimaryRegionInstance;
                            geoPrimaryRegionInstance = geoPrimaryRegionElement.getTextContent();
                            storageServicePropertiesInstance.setGeoPrimaryRegion(geoPrimaryRegionInstance);
                        }

                        Element statusOfPrimaryElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "StatusOfPrimary");
                        if (statusOfPrimaryElement != null && statusOfPrimaryElement.getTextContent() != null
                                && !statusOfPrimaryElement.getTextContent().isEmpty()) {
                            GeoRegionStatus statusOfPrimaryInstance;
                            statusOfPrimaryInstance = GeoRegionStatus
                                    .valueOf(statusOfPrimaryElement.getTextContent());
                            storageServicePropertiesInstance
                                    .setStatusOfGeoPrimaryRegion(statusOfPrimaryInstance);
                        }

                        Element lastGeoFailoverTimeElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "LastGeoFailoverTime");
                        if (lastGeoFailoverTimeElement != null
                                && lastGeoFailoverTimeElement.getTextContent() != null
                                && !lastGeoFailoverTimeElement.getTextContent().isEmpty()) {
                            Calendar lastGeoFailoverTimeInstance;
                            lastGeoFailoverTimeInstance = DatatypeConverter
                                    .parseDateTime(lastGeoFailoverTimeElement.getTextContent());
                            storageServicePropertiesInstance
                                    .setLastGeoFailoverTime(lastGeoFailoverTimeInstance);
                        }

                        Element geoSecondaryRegionElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "GeoSecondaryRegion");
                        if (geoSecondaryRegionElement != null) {
                            String geoSecondaryRegionInstance;
                            geoSecondaryRegionInstance = geoSecondaryRegionElement.getTextContent();
                            storageServicePropertiesInstance.setGeoSecondaryRegion(geoSecondaryRegionInstance);
                        }

                        Element statusOfSecondaryElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "StatusOfSecondary");
                        if (statusOfSecondaryElement != null
                                && statusOfSecondaryElement.getTextContent() != null
                                && !statusOfSecondaryElement.getTextContent().isEmpty()) {
                            GeoRegionStatus statusOfSecondaryInstance;
                            statusOfSecondaryInstance = GeoRegionStatus
                                    .valueOf(statusOfSecondaryElement.getTextContent());
                            storageServicePropertiesInstance
                                    .setStatusOfGeoSecondaryRegion(statusOfSecondaryInstance);
                        }

                        Element accountTypeElement = XmlUtility.getElementByTagNameNS(
                                storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "AccountType");
                        if (accountTypeElement != null) {
                            String accountTypeInstance;
                            accountTypeInstance = accountTypeElement.getTextContent();
                            storageServicePropertiesInstance.setAccountType(accountTypeInstance);
                        }
                    }

                    Element extendedPropertiesSequenceElement = XmlUtility.getElementByTagNameNS(
                            storageServicesElement, "http://schemas.microsoft.com/windowsazure",
                            "ExtendedProperties");
                    if (extendedPropertiesSequenceElement != null) {
                        for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(extendedPropertiesSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "ExtendedProperty")
                                .size(); i3 = i3 + 1) {
                            org.w3c.dom.Element extendedPropertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(extendedPropertiesSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "ExtendedProperty")
                                    .get(i3));
                            String extendedPropertiesKey = XmlUtility
                                    .getElementByTagNameNS(extendedPropertiesElement,
                                            "http://schemas.microsoft.com/windowsazure", "Name")
                                    .getTextContent();
                            String extendedPropertiesValue = XmlUtility
                                    .getElementByTagNameNS(extendedPropertiesElement,
                                            "http://schemas.microsoft.com/windowsazure", "Value")
                                    .getTextContent();
                            storageServiceInstance.getExtendedProperties().put(extendedPropertiesKey,
                                    extendedPropertiesValue);
                        }
                    }
                }
            }

        }
        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.windowsazure.management.servicebus.TopicOperationsImpl.java

/**
* The topic description is an XML AtomPub document that defines the desired
* semantics for a topic. The topic description contains the following
* properties. For more information, see the TopicDescription Properties
* topic.  (see/*w w w. j  av  a 2 s  .c o  m*/
* http://msdn.microsoft.com/en-us/library/windowsazure/hh780749.aspx for
* more information)
*
* @param namespaceName Required. The namespace name.
* @param topicName Required. The topic.
* @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 ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return A response to a request for a particular topic.
*/
@Override
public ServiceBusTopicResponse get(String namespaceName, String topicName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }
    if (topicName == null) {
        throw new NullPointerException("topicName");
    }

    // 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("namespaceName", namespaceName);
        tracingParameters.put("topicName", topicName);
        CloudTracing.enter(invocationId, this, "getAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/servicebus/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    url = url + "/topics/";
    url = url + URLEncoder.encode(topicName, "UTF-8");
    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/xml; charset=utf-8");
    httpRequest.setHeader("x-ms-version", "2013-08-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) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ServiceBusTopicResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServiceBusTopicResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element entryElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom",
                    "entry");
            if (entryElement != null) {
                Element titleElement = XmlUtility.getElementByTagNameNS(entryElement,
                        "http://www.w3.org/2005/Atom", "title");
                if (titleElement != null) {
                }

                Element contentElement = XmlUtility.getElementByTagNameNS(entryElement,
                        "http://www.w3.org/2005/Atom", "content");
                if (contentElement != null) {
                    Element topicDescriptionElement = XmlUtility.getElementByTagNameNS(contentElement,
                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                            "TopicDescription");
                    if (topicDescriptionElement != null) {
                        ServiceBusTopic topicDescriptionInstance = new ServiceBusTopic();
                        result.setTopic(topicDescriptionInstance);

                        Element defaultMessageTimeToLiveElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "DefaultMessageTimeToLive");
                        if (defaultMessageTimeToLiveElement != null) {
                            String defaultMessageTimeToLiveInstance;
                            defaultMessageTimeToLiveInstance = defaultMessageTimeToLiveElement.getTextContent();
                            topicDescriptionInstance
                                    .setDefaultMessageTimeToLive(defaultMessageTimeToLiveInstance);
                        }

                        Element maxSizeInMegabytesElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "MaxSizeInMegabytes");
                        if (maxSizeInMegabytesElement != null) {
                            int maxSizeInMegabytesInstance;
                            maxSizeInMegabytesInstance = DatatypeConverter
                                    .parseInt(maxSizeInMegabytesElement.getTextContent());
                            topicDescriptionInstance.setMaxSizeInMegabytes(maxSizeInMegabytesInstance);
                        }

                        Element requiresDuplicateDetectionElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "RequiresDuplicateDetection");
                        if (requiresDuplicateDetectionElement != null) {
                            boolean requiresDuplicateDetectionInstance;
                            requiresDuplicateDetectionInstance = DatatypeConverter.parseBoolean(
                                    requiresDuplicateDetectionElement.getTextContent().toLowerCase());
                            topicDescriptionInstance
                                    .setRequiresDuplicateDetection(requiresDuplicateDetectionInstance);
                        }

                        Element duplicateDetectionHistoryTimeWindowElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "DuplicateDetectionHistoryTimeWindow");
                        if (duplicateDetectionHistoryTimeWindowElement != null) {
                            String duplicateDetectionHistoryTimeWindowInstance;
                            duplicateDetectionHistoryTimeWindowInstance = duplicateDetectionHistoryTimeWindowElement
                                    .getTextContent();
                            topicDescriptionInstance.setDuplicateDetectionHistoryTimeWindow(
                                    duplicateDetectionHistoryTimeWindowInstance);
                        }

                        Element enableBatchedOperationsElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "EnableBatchedOperations");
                        if (enableBatchedOperationsElement != null) {
                            boolean enableBatchedOperationsInstance;
                            enableBatchedOperationsInstance = DatatypeConverter.parseBoolean(
                                    enableBatchedOperationsElement.getTextContent().toLowerCase());
                            topicDescriptionInstance
                                    .setEnableBatchedOperations(enableBatchedOperationsInstance);
                        }

                        Element sizeInBytesElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "SizeInBytes");
                        if (sizeInBytesElement != null) {
                            int sizeInBytesInstance;
                            sizeInBytesInstance = DatatypeConverter
                                    .parseInt(sizeInBytesElement.getTextContent());
                            topicDescriptionInstance.setSizeInBytes(sizeInBytesInstance);
                        }

                        Element filteringMessagesBeforePublishingElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "FilteringMessagesBeforePublishing");
                        if (filteringMessagesBeforePublishingElement != null) {
                            boolean filteringMessagesBeforePublishingInstance;
                            filteringMessagesBeforePublishingInstance = DatatypeConverter.parseBoolean(
                                    filteringMessagesBeforePublishingElement.getTextContent().toLowerCase());
                            topicDescriptionInstance.setFilteringMessagesBeforePublishing(
                                    filteringMessagesBeforePublishingInstance);
                        }

                        Element isAnonymousAccessibleElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "IsAnonymousAccessible");
                        if (isAnonymousAccessibleElement != null) {
                            boolean isAnonymousAccessibleInstance;
                            isAnonymousAccessibleInstance = DatatypeConverter
                                    .parseBoolean(isAnonymousAccessibleElement.getTextContent().toLowerCase());
                            topicDescriptionInstance.setIsAnonymousAccessible(isAnonymousAccessibleInstance);
                        }

                        Element authorizationRulesSequenceElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "AuthorizationRules");
                        if (authorizationRulesSequenceElement != null) {
                            for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(authorizationRulesSequenceElement,
                                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                            "AuthorizationRule")
                                    .size(); i1 = i1 + 1) {
                                org.w3c.dom.Element authorizationRulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(authorizationRulesSequenceElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "AuthorizationRule")
                                        .get(i1));
                                ServiceBusSharedAccessAuthorizationRule authorizationRuleInstance = new ServiceBusSharedAccessAuthorizationRule();
                                topicDescriptionInstance.getAuthorizationRules().add(authorizationRuleInstance);

                                Element claimTypeElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ClaimType");
                                if (claimTypeElement != null) {
                                    String claimTypeInstance;
                                    claimTypeInstance = claimTypeElement.getTextContent();
                                    authorizationRuleInstance.setClaimType(claimTypeInstance);
                                }

                                Element claimValueElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ClaimValue");
                                if (claimValueElement != null) {
                                    String claimValueInstance;
                                    claimValueInstance = claimValueElement.getTextContent();
                                    authorizationRuleInstance.setClaimValue(claimValueInstance);
                                }

                                Element rightsSequenceElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "Rights");
                                if (rightsSequenceElement != null) {
                                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                            .getElementsByTagNameNS(rightsSequenceElement,
                                                    "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                    "AccessRights")
                                            .size(); i2 = i2 + 1) {
                                        org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                .getElementsByTagNameNS(rightsSequenceElement,
                                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                        "AccessRights")
                                                .get(i2));
                                        authorizationRuleInstance.getRights()
                                                .add(AccessRight.valueOf(rightsElement.getTextContent()));
                                    }
                                }

                                Element createdTimeElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "CreatedTime");
                                if (createdTimeElement != null) {
                                    Calendar createdTimeInstance;
                                    createdTimeInstance = DatatypeConverter
                                            .parseDateTime(createdTimeElement.getTextContent());
                                    authorizationRuleInstance.setCreatedTime(createdTimeInstance);
                                }

                                Element keyNameElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "KeyName");
                                if (keyNameElement != null) {
                                    String keyNameInstance;
                                    keyNameInstance = keyNameElement.getTextContent();
                                    authorizationRuleInstance.setKeyName(keyNameInstance);
                                }

                                Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ModifiedTime");
                                if (modifiedTimeElement != null) {
                                    Calendar modifiedTimeInstance;
                                    modifiedTimeInstance = DatatypeConverter
                                            .parseDateTime(modifiedTimeElement.getTextContent());
                                    authorizationRuleInstance.setModifiedTime(modifiedTimeInstance);
                                }

                                Element primaryKeyElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "PrimaryKey");
                                if (primaryKeyElement != null) {
                                    String primaryKeyInstance;
                                    primaryKeyInstance = primaryKeyElement.getTextContent();
                                    authorizationRuleInstance.setPrimaryKey(primaryKeyInstance);
                                }

                                Element secondaryKeyElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "SecondaryKey");
                                if (secondaryKeyElement != null) {
                                    String secondaryKeyInstance;
                                    secondaryKeyInstance = secondaryKeyElement.getTextContent();
                                    authorizationRuleInstance.setSecondaryKey(secondaryKeyInstance);
                                }
                            }
                        }

                        Element statusElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "Status");
                        if (statusElement != null) {
                            String statusInstance;
                            statusInstance = statusElement.getTextContent();
                            topicDescriptionInstance.setStatus(statusInstance);
                        }

                        Element createdAtElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "CreatedAt");
                        if (createdAtElement != null) {
                            Calendar createdAtInstance;
                            createdAtInstance = DatatypeConverter
                                    .parseDateTime(createdAtElement.getTextContent());
                            topicDescriptionInstance.setCreatedAt(createdAtInstance);
                        }

                        Element updatedAtElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "UpdatedAt");
                        if (updatedAtElement != null) {
                            Calendar updatedAtInstance;
                            updatedAtInstance = DatatypeConverter
                                    .parseDateTime(updatedAtElement.getTextContent());
                            topicDescriptionInstance.setUpdatedAt(updatedAtInstance);
                        }

                        Element accessedAtElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "AccessedAt");
                        if (accessedAtElement != null) {
                            Calendar accessedAtInstance;
                            accessedAtInstance = DatatypeConverter
                                    .parseDateTime(accessedAtElement.getTextContent());
                            topicDescriptionInstance.setAccessedAt(accessedAtInstance);
                        }

                        Element supportOrderingElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "SupportOrdering");
                        if (supportOrderingElement != null) {
                            boolean supportOrderingInstance;
                            supportOrderingInstance = DatatypeConverter
                                    .parseBoolean(supportOrderingElement.getTextContent().toLowerCase());
                            topicDescriptionInstance.setSupportOrdering(supportOrderingInstance);
                        }

                        Element countDetailsElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "CountDetails");
                        if (countDetailsElement != null) {
                            CountDetails countDetailsInstance = new CountDetails();
                            topicDescriptionInstance.setCountDetails(countDetailsInstance);
                        }

                        Element subscriptionCountElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "SubscriptionCount");
                        if (subscriptionCountElement != null) {
                            int subscriptionCountInstance;
                            subscriptionCountInstance = DatatypeConverter
                                    .parseInt(subscriptionCountElement.getTextContent());
                            topicDescriptionInstance.setSubscriptionCount(subscriptionCountInstance);
                        }

                        Element autoDeleteOnIdleElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "AutoDeleteOnIdle");
                        if (autoDeleteOnIdleElement != null) {
                            String autoDeleteOnIdleInstance;
                            autoDeleteOnIdleInstance = autoDeleteOnIdleElement.getTextContent();
                            topicDescriptionInstance.setAutoDeleteOnIdle(autoDeleteOnIdleInstance);
                        }

                        Element entityAvailabilityStatusElement = XmlUtility.getElementByTagNameNS(
                                topicDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "EntityAvailabilityStatus");
                        if (entityAvailabilityStatusElement != null) {
                            String entityAvailabilityStatusInstance;
                            entityAvailabilityStatusInstance = entityAvailabilityStatusElement.getTextContent();
                            topicDescriptionInstance
                                    .setEntityAvailabilityStatus(entityAvailabilityStatusInstance);
                        }
                    }
                }
            }

        }
        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.windowsazure.management.websites.WebSpaceOperationsImpl.java

/**
* You can retrieve a list of all web sites in a web space by issuing an
* HTTP GET request.  (see/*from w  ww.j  a va 2 s  .c om*/
* http://msdn.microsoft.com/en-us/library/windowsazure/dn236429.aspx for
* more information)
*
* @param webSpaceName Required. The name of the web space.
* @param parameters Optional. Additional parameters.
* @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 ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The List Web Sites operation response.
*/
@Override
public WebSpacesListWebSitesResponse listWebSites(String webSpaceName, WebSiteListParameters parameters)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (webSpaceName == null) {
        throw new NullPointerException("webSpaceName");
    }

    // 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("webSpaceName", webSpaceName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "listWebSitesAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/WebSpaces/";
    url = url + URLEncoder.encode(webSpaceName, "UTF-8");
    url = url + "/sites";
    ArrayList<String> queryParameters = new ArrayList<String>();
    if (parameters != null && parameters.getPropertiesToInclude() != null
            && parameters.getPropertiesToInclude().size() > 0) {
        queryParameters.add("propertiesToInclude=" + URLEncoder
                .encode(CollectionStringBuilder.join(parameters.getPropertiesToInclude(), ","), "UTF-8"));
    }
    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("x-ms-version", "2014-04-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) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        WebSpacesListWebSitesResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new WebSpacesListWebSitesResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element sitesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Sites");
            if (sitesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(sitesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "Site")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element sitesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(sitesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "Site")
                            .get(i1));
                    WebSite siteInstance = new WebSite();
                    result.getWebSites().add(siteInstance);

                    Element adminEnabledElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "AdminEnabled");
                    if (adminEnabledElement != null && adminEnabledElement.getTextContent() != null
                            && !adminEnabledElement.getTextContent().isEmpty()) {
                        boolean adminEnabledInstance;
                        adminEnabledInstance = DatatypeConverter
                                .parseBoolean(adminEnabledElement.getTextContent().toLowerCase());
                        siteInstance.setAdminEnabled(adminEnabledInstance);
                    }

                    Element availabilityStateElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "AvailabilityState");
                    if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null
                            && !availabilityStateElement.getTextContent().isEmpty()) {
                        WebSpaceAvailabilityState availabilityStateInstance;
                        availabilityStateInstance = WebSpaceAvailabilityState
                                .valueOf(availabilityStateElement.getTextContent());
                        siteInstance.setAvailabilityState(availabilityStateInstance);
                    }

                    Element sKUElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "SKU");
                    if (sKUElement != null && sKUElement.getTextContent() != null
                            && !sKUElement.getTextContent().isEmpty()) {
                        SkuOptions sKUInstance;
                        sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent());
                        siteInstance.setSku(sKUInstance);
                    }

                    Element enabledElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "Enabled");
                    if (enabledElement != null && enabledElement.getTextContent() != null
                            && !enabledElement.getTextContent().isEmpty()) {
                        boolean enabledInstance;
                        enabledInstance = DatatypeConverter
                                .parseBoolean(enabledElement.getTextContent().toLowerCase());
                        siteInstance.setEnabled(enabledInstance);
                    }

                    Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "EnabledHostNames");
                    if (enabledHostNamesSequenceElement != null) {
                        for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(enabledHostNamesSequenceElement,
                                        "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string")
                                .size(); i2 = i2 + 1) {
                            org.w3c.dom.Element enabledHostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(enabledHostNamesSequenceElement,
                                            "http://schemas.microsoft.com/2003/10/Serialization/Arrays",
                                            "string")
                                    .get(i2));
                            siteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent());
                        }
                    }

                    Element hostNameSslStatesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "HostNameSslStates");
                    if (hostNameSslStatesSequenceElement != null) {
                        for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(hostNameSslStatesSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "HostNameSslState")
                                .size(); i3 = i3 + 1) {
                            org.w3c.dom.Element hostNameSslStatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(hostNameSslStatesSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "HostNameSslState")
                                    .get(i3));
                            WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState();
                            siteInstance.getHostNameSslStates().add(hostNameSslStateInstance);

                            Element nameElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement,
                                    "http://schemas.microsoft.com/windowsazure", "Name");
                            if (nameElement != null) {
                                String nameInstance;
                                nameInstance = nameElement.getTextContent();
                                hostNameSslStateInstance.setName(nameInstance);
                            }

                            Element sslStateElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement,
                                    "http://schemas.microsoft.com/windowsazure", "SslState");
                            if (sslStateElement != null && sslStateElement.getTextContent() != null
                                    && !sslStateElement.getTextContent().isEmpty()) {
                                WebSiteSslState sslStateInstance;
                                sslStateInstance = WebSiteSslState.valueOf(sslStateElement.getTextContent());
                                hostNameSslStateInstance.setSslState(sslStateInstance);
                            }

                            Element thumbprintElement = XmlUtility.getElementByTagNameNS(
                                    hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure",
                                    "Thumbprint");
                            if (thumbprintElement != null) {
                                boolean isNil = false;
                                Attr nilAttribute = thumbprintElement
                                        .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                                if (nilAttribute != null) {
                                    isNil = "true".equals(nilAttribute.getValue());
                                }
                                if (isNil == false) {
                                    String thumbprintInstance;
                                    thumbprintInstance = thumbprintElement.getTextContent();
                                    hostNameSslStateInstance.setThumbprint(thumbprintInstance);
                                }
                            }

                            Element virtualIPElement = XmlUtility.getElementByTagNameNS(
                                    hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure",
                                    "VirtualIP");
                            if (virtualIPElement != null) {
                                boolean isNil2 = false;
                                Attr nilAttribute2 = virtualIPElement
                                        .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                                if (nilAttribute2 != null) {
                                    isNil2 = "true".equals(nilAttribute2.getValue());
                                }
                                if (isNil2 == false) {
                                    InetAddress virtualIPInstance;
                                    virtualIPInstance = InetAddress
                                            .getByName(virtualIPElement.getTextContent());
                                    hostNameSslStateInstance.setVirtualIP(virtualIPInstance);
                                }
                            }
                        }
                    }

                    Element hostNamesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "HostNames");
                    if (hostNamesSequenceElement != null) {
                        for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(hostNamesSequenceElement,
                                        "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string")
                                .size(); i4 = i4 + 1) {
                            org.w3c.dom.Element hostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(hostNamesSequenceElement,
                                            "http://schemas.microsoft.com/2003/10/Serialization/Arrays",
                                            "string")
                                    .get(i4));
                            siteInstance.getHostNames().add(hostNamesElement.getTextContent());
                        }
                    }

                    Element lastModifiedTimeUtcElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "LastModifiedTimeUtc");
                    if (lastModifiedTimeUtcElement != null
                            && lastModifiedTimeUtcElement.getTextContent() != null
                            && !lastModifiedTimeUtcElement.getTextContent().isEmpty()) {
                        Calendar lastModifiedTimeUtcInstance;
                        lastModifiedTimeUtcInstance = DatatypeConverter
                                .parseDateTime(lastModifiedTimeUtcElement.getTextContent());
                        siteInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance);
                    }

                    Element nameElement2 = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "Name");
                    if (nameElement2 != null) {
                        String nameInstance2;
                        nameInstance2 = nameElement2.getTextContent();
                        siteInstance.setName(nameInstance2);
                    }

                    Element repositorySiteNameElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "RepositorySiteName");
                    if (repositorySiteNameElement != null) {
                        String repositorySiteNameInstance;
                        repositorySiteNameInstance = repositorySiteNameElement.getTextContent();
                        siteInstance.setRepositorySiteName(repositorySiteNameInstance);
                    }

                    Element runtimeAvailabilityStateElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "RuntimeAvailabilityState");
                    if (runtimeAvailabilityStateElement != null
                            && runtimeAvailabilityStateElement.getTextContent() != null
                            && !runtimeAvailabilityStateElement.getTextContent().isEmpty()) {
                        WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance;
                        runtimeAvailabilityStateInstance = WebSiteRuntimeAvailabilityState
                                .valueOf(runtimeAvailabilityStateElement.getTextContent());
                        siteInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance);
                    }

                    Element selfLinkElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "SelfLink");
                    if (selfLinkElement != null) {
                        URI selfLinkInstance;
                        selfLinkInstance = new URI(selfLinkElement.getTextContent());
                        siteInstance.setUri(selfLinkInstance);
                    }

                    Element serverFarmElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "ServerFarm");
                    if (serverFarmElement != null) {
                        String serverFarmInstance;
                        serverFarmInstance = serverFarmElement.getTextContent();
                        siteInstance.setServerFarm(serverFarmInstance);
                    }

                    Element sitePropertiesElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "SiteProperties");
                    if (sitePropertiesElement != null) {
                        WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties();
                        siteInstance.setSiteProperties(sitePropertiesInstance);

                        Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS(
                                sitePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "AppSettings");
                        if (appSettingsSequenceElement != null) {
                            for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(appSettingsSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                    .size(); i5 = i5 + 1) {
                                org.w3c.dom.Element appSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(appSettingsSequenceElement,
                                                "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                        .get(i5));
                                String appSettingsKey = XmlUtility
                                        .getElementByTagNameNS(appSettingsElement,
                                                "http://schemas.microsoft.com/windowsazure", "Name")
                                        .getTextContent();
                                String appSettingsValue = XmlUtility
                                        .getElementByTagNameNS(appSettingsElement,
                                                "http://schemas.microsoft.com/windowsazure", "Value")
                                        .getTextContent();
                                sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue);
                            }
                        }

                        Element metadataSequenceElement = XmlUtility.getElementByTagNameNS(
                                sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Metadata");
                        if (metadataSequenceElement != null) {
                            for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(metadataSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                    .size(); i6 = i6 + 1) {
                                org.w3c.dom.Element metadataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(metadataSequenceElement,
                                                "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                        .get(i6));
                                String metadataKey = XmlUtility
                                        .getElementByTagNameNS(metadataElement,
                                                "http://schemas.microsoft.com/windowsazure", "Name")
                                        .getTextContent();
                                String metadataValue = XmlUtility
                                        .getElementByTagNameNS(metadataElement,
                                                "http://schemas.microsoft.com/windowsazure", "Value")
                                        .getTextContent();
                                sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue);
                            }
                        }

                        Element propertiesSequenceElement = XmlUtility.getElementByTagNameNS(
                                sitePropertiesElement, "http://schemas.microsoft.com/windowsazure",
                                "Properties");
                        if (propertiesSequenceElement != null) {
                            for (int i7 = 0; i7 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(propertiesSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                    .size(); i7 = i7 + 1) {
                                org.w3c.dom.Element propertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(propertiesSequenceElement,
                                                "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                        .get(i7));
                                String propertiesKey = XmlUtility
                                        .getElementByTagNameNS(propertiesElement,
                                                "http://schemas.microsoft.com/windowsazure", "Name")
                                        .getTextContent();
                                String propertiesValue = XmlUtility
                                        .getElementByTagNameNS(propertiesElement,
                                                "http://schemas.microsoft.com/windowsazure", "Value")
                                        .getTextContent();
                                sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue);
                            }
                        }
                    }

                    Element stateElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "State");
                    if (stateElement != null) {
                        String stateInstance;
                        stateInstance = stateElement.getTextContent();
                        siteInstance.setState(stateInstance);
                    }

                    Element usageStateElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "UsageState");
                    if (usageStateElement != null && usageStateElement.getTextContent() != null
                            && !usageStateElement.getTextContent().isEmpty()) {
                        WebSiteUsageState usageStateInstance;
                        usageStateInstance = WebSiteUsageState.valueOf(usageStateElement.getTextContent());
                        siteInstance.setUsageState(usageStateInstance);
                    }

                    Element webSpaceElement = XmlUtility.getElementByTagNameNS(sitesElement,
                            "http://schemas.microsoft.com/windowsazure", "WebSpace");
                    if (webSpaceElement != null) {
                        String webSpaceInstance;
                        webSpaceInstance = webSpaceElement.getTextContent();
                        siteInstance.setWebSpace(webSpaceInstance);
                    }
                }
            }

        }
        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

/**
* Returns the description for the specified namespace.  (see
* http://msdn.microsoft.com/library/azure/dn140232.aspx for more
* information)//from w w w .j a v a 2  s  . co m
*
* @param resourceGroupName Required. The name of the resource group.
* @param namespaceName Required. The namespace 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.
* @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 Namespace operation.
*/
@Override
public NamespaceGetResponse get(String resourceGroupName, String namespaceName)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }

    // 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);
        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");
    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
        NamespaceGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new NamespaceGetResponse();
            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);
                    }
                }
            }

        }
        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 create NotificationHub authorization rule operation creates an
* authorization rule for a NotificationHub
*
* @param resourceGroupName Required. The name of the resource group.
* @param namespaceName Required. The namespace name.
* @param notificationHubName Required. The notification hub name.
* @param authorizationRuleName Required. The namespace
* authorizationRuleName name.//from w  w  w .ja  v  a 2s .  co  m
* @param parameters Required. The shared access authorization rule.
* @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 Response of the CreateOrUpdate operation on the AuthorizationRules
*/
@Override
public SharedAccessAuthorizationRuleCreateOrUpdateResponse createOrUpdateAuthorizationRule(
        String resourceGroupName, String namespaceName, String notificationHubName,
        String authorizationRuleName, SharedAccessAuthorizationRuleCreateOrUpdateParameters parameters)
        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");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getProperties() == null) {
        throw new NullPointerException("parameters.Properties");
    }

    // 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);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "createOrUpdateAuthorizationRuleAsync", 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
    HttpPut httpRequest = new HttpPut(url);

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

    // Serialize Request
    String requestContent = null;
    JsonNode requestDoc = null;

    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode sharedAccessAuthorizationRuleCreateOrUpdateParametersValue = objectMapper.createObjectNode();
    requestDoc = sharedAccessAuthorizationRuleCreateOrUpdateParametersValue;

    if (parameters.getLocation() != null) {
        ((ObjectNode) sharedAccessAuthorizationRuleCreateOrUpdateParametersValue).put("location",
                parameters.getLocation());
    }

    if (parameters.getName() != null) {
        ((ObjectNode) sharedAccessAuthorizationRuleCreateOrUpdateParametersValue).put("name",
                parameters.getName());
    }

    ObjectNode propertiesValue = objectMapper.createObjectNode();
    ((ObjectNode) sharedAccessAuthorizationRuleCreateOrUpdateParametersValue).put("properties",
            propertiesValue);

    if (parameters.getProperties().getPrimaryKey() != null) {
        ((ObjectNode) propertiesValue).put("primaryKey", parameters.getProperties().getPrimaryKey());
    }

    if (parameters.getProperties().getSecondaryKey() != null) {
        ((ObjectNode) propertiesValue).put("secondaryKey", parameters.getProperties().getSecondaryKey());
    }

    if (parameters.getProperties().getKeyName() != null) {
        ((ObjectNode) propertiesValue).put("keyName", parameters.getProperties().getKeyName());
    }

    if (parameters.getProperties().getClaimType() != null) {
        ((ObjectNode) propertiesValue).put("claimType", parameters.getProperties().getClaimType());
    }

    if (parameters.getProperties().getClaimValue() != null) {
        ((ObjectNode) propertiesValue).put("claimValue", parameters.getProperties().getClaimValue());
    }

    if (parameters.getProperties().getRights() != null) {
        ArrayNode rightsArray = objectMapper.createArrayNode();
        for (AccessRights rightsItem : parameters.getProperties().getRights()) {
            rightsArray.add(rightsItem.toString());
        }
        ((ObjectNode) propertiesValue).put("rights", rightsArray);
    }

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    ((ObjectNode) propertiesValue).put("createdTime",
            simpleDateFormat.format(parameters.getProperties().getCreatedTime().getTime()));

    SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
    simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC"));
    ((ObjectNode) propertiesValue).put("modifiedTime",
            simpleDateFormat2.format(parameters.getProperties().getModifiedTime().getTime()));

    ((ObjectNode) propertiesValue).put("revision", parameters.getProperties().getRevision());

    StringWriter stringWriter = new StringWriter();
    objectMapper.writeValue(stringWriter, requestDoc);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    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, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        SharedAccessAuthorizationRuleCreateOrUpdateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new SharedAccessAuthorizationRuleCreateOrUpdateResponse();
            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 propertiesValue2 = responseDoc.get("properties");
                if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                    SharedAccessAuthorizationRuleProperties propertiesInstance = new SharedAccessAuthorizationRuleProperties();
                    valueInstance.setProperties(propertiesInstance);

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

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

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

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

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

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

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

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

                    JsonNode revisionValue = propertiesValue2.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.storage.StorageAccountOperationsImpl.java

/**
* Lists all the storage accounts available under the subscription. Note
* that storage keys are not returned; use the ListKeys operation for this.
*
* @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./*w  ww .  ja  v a  2 s  .  c  o m*/
* @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 list storage accounts operation response.
*/
@Override
public StorageAccountListResponse list() throws IOException, ServiceException, URISyntaxException {
    // Validate

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        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 + "/providers/Microsoft.Storage/storageAccounts";
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2015-06-15");
    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("x-ms-client-request-id", UUID.randomUUID().toString());

    // 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
        StorageAccountListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new StorageAccountListResponse();
            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)) {
                        StorageAccount storageAccountJsonInstance = new StorageAccount();
                        result.getStorageAccounts().add(storageAccountJsonInstance);

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

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

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

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

                        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();
                                storageAccountJsonInstance.getTags().put(tagsKey, tagsValue);
                            }
                        }

                        JsonNode propertiesValue = valueValue.get("properties");
                        if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                            JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                            if (provisioningStateValue != null
                                    && provisioningStateValue instanceof NullNode == false) {
                                ProvisioningState provisioningStateInstance;
                                provisioningStateInstance = EnumUtility.fromString(ProvisioningState.class,
                                        provisioningStateValue.getTextValue());
                                storageAccountJsonInstance.setProvisioningState(provisioningStateInstance);
                            }

                            JsonNode accountTypeValue = propertiesValue.get("accountType");
                            if (accountTypeValue != null && accountTypeValue instanceof NullNode == false) {
                                AccountType accountTypeInstance;
                                accountTypeInstance = StorageManagementClientImpl
                                        .parseAccountType(accountTypeValue.getTextValue());
                                storageAccountJsonInstance.setAccountType(accountTypeInstance);
                            }

                            JsonNode primaryEndpointsValue = propertiesValue.get("primaryEndpoints");
                            if (primaryEndpointsValue != null
                                    && primaryEndpointsValue instanceof NullNode == false) {
                                Endpoints primaryEndpointsInstance = new Endpoints();
                                storageAccountJsonInstance.setPrimaryEndpoints(primaryEndpointsInstance);

                                JsonNode blobValue = primaryEndpointsValue.get("blob");
                                if (blobValue != null && blobValue instanceof NullNode == false) {
                                    URI blobInstance;
                                    blobInstance = new URI(blobValue.getTextValue());
                                    primaryEndpointsInstance.setBlob(blobInstance);
                                }

                                JsonNode queueValue = primaryEndpointsValue.get("queue");
                                if (queueValue != null && queueValue instanceof NullNode == false) {
                                    URI queueInstance;
                                    queueInstance = new URI(queueValue.getTextValue());
                                    primaryEndpointsInstance.setQueue(queueInstance);
                                }

                                JsonNode tableValue = primaryEndpointsValue.get("table");
                                if (tableValue != null && tableValue instanceof NullNode == false) {
                                    URI tableInstance;
                                    tableInstance = new URI(tableValue.getTextValue());
                                    primaryEndpointsInstance.setTable(tableInstance);
                                }

                                JsonNode fileValue = primaryEndpointsValue.get("file");
                                if (fileValue != null && fileValue instanceof NullNode == false) {
                                    URI fileInstance;
                                    fileInstance = new URI(fileValue.getTextValue());
                                    primaryEndpointsInstance.setFile(fileInstance);
                                }
                            }

                            JsonNode primaryLocationValue = propertiesValue.get("primaryLocation");
                            if (primaryLocationValue != null
                                    && primaryLocationValue instanceof NullNode == false) {
                                String primaryLocationInstance;
                                primaryLocationInstance = primaryLocationValue.getTextValue();
                                storageAccountJsonInstance.setPrimaryLocation(primaryLocationInstance);
                            }

                            JsonNode statusOfPrimaryValue = propertiesValue.get("statusOfPrimary");
                            if (statusOfPrimaryValue != null
                                    && statusOfPrimaryValue instanceof NullNode == false) {
                                AccountStatus statusOfPrimaryInstance;
                                statusOfPrimaryInstance = EnumUtility.fromString(AccountStatus.class,
                                        statusOfPrimaryValue.getTextValue());
                                storageAccountJsonInstance.setStatusOfPrimary(statusOfPrimaryInstance);
                            }

                            JsonNode lastGeoFailoverTimeValue = propertiesValue.get("lastGeoFailoverTime");
                            if (lastGeoFailoverTimeValue != null
                                    && lastGeoFailoverTimeValue instanceof NullNode == false) {
                                Calendar lastGeoFailoverTimeInstance;
                                lastGeoFailoverTimeInstance = DatatypeConverter
                                        .parseDateTime(lastGeoFailoverTimeValue.getTextValue());
                                storageAccountJsonInstance.setLastGeoFailoverTime(lastGeoFailoverTimeInstance);
                            }

                            JsonNode secondaryLocationValue = propertiesValue.get("secondaryLocation");
                            if (secondaryLocationValue != null
                                    && secondaryLocationValue instanceof NullNode == false) {
                                String secondaryLocationInstance;
                                secondaryLocationInstance = secondaryLocationValue.getTextValue();
                                storageAccountJsonInstance.setSecondaryLocation(secondaryLocationInstance);
                            }

                            JsonNode statusOfSecondaryValue = propertiesValue.get("statusOfSecondary");
                            if (statusOfSecondaryValue != null
                                    && statusOfSecondaryValue instanceof NullNode == false) {
                                AccountStatus statusOfSecondaryInstance;
                                statusOfSecondaryInstance = EnumUtility.fromString(AccountStatus.class,
                                        statusOfSecondaryValue.getTextValue());
                                storageAccountJsonInstance.setStatusOfSecondary(statusOfSecondaryInstance);
                            }

                            JsonNode creationTimeValue = propertiesValue.get("creationTime");
                            if (creationTimeValue != null && creationTimeValue instanceof NullNode == false) {
                                Calendar creationTimeInstance;
                                creationTimeInstance = DatatypeConverter
                                        .parseDateTime(creationTimeValue.getTextValue());
                                storageAccountJsonInstance.setCreationTime(creationTimeInstance);
                            }

                            JsonNode customDomainValue = propertiesValue.get("customDomain");
                            if (customDomainValue != null && customDomainValue instanceof NullNode == false) {
                                CustomDomain customDomainInstance = new CustomDomain();
                                storageAccountJsonInstance.setCustomDomain(customDomainInstance);

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

                                JsonNode useSubDomainValue = customDomainValue.get("useSubDomain");
                                if (useSubDomainValue != null
                                        && useSubDomainValue instanceof NullNode == false) {
                                    boolean useSubDomainInstance;
                                    useSubDomainInstance = useSubDomainValue.getBooleanValue();
                                    customDomainInstance.setUseSubDomain(useSubDomainInstance);
                                }
                            }

                            JsonNode secondaryEndpointsValue = propertiesValue.get("secondaryEndpoints");
                            if (secondaryEndpointsValue != null
                                    && secondaryEndpointsValue instanceof NullNode == false) {
                                Endpoints secondaryEndpointsInstance = new Endpoints();
                                storageAccountJsonInstance.setSecondaryEndpoints(secondaryEndpointsInstance);

                                JsonNode blobValue2 = secondaryEndpointsValue.get("blob");
                                if (blobValue2 != null && blobValue2 instanceof NullNode == false) {
                                    URI blobInstance2;
                                    blobInstance2 = new URI(blobValue2.getTextValue());
                                    secondaryEndpointsInstance.setBlob(blobInstance2);
                                }

                                JsonNode queueValue2 = secondaryEndpointsValue.get("queue");
                                if (queueValue2 != null && queueValue2 instanceof NullNode == false) {
                                    URI queueInstance2;
                                    queueInstance2 = new URI(queueValue2.getTextValue());
                                    secondaryEndpointsInstance.setQueue(queueInstance2);
                                }

                                JsonNode tableValue2 = secondaryEndpointsValue.get("table");
                                if (tableValue2 != null && tableValue2 instanceof NullNode == false) {
                                    URI tableInstance2;
                                    tableInstance2 = new URI(tableValue2.getTextValue());
                                    secondaryEndpointsInstance.setTable(tableInstance2);
                                }

                                JsonNode fileValue2 = secondaryEndpointsValue.get("file");
                                if (fileValue2 != null && fileValue2 instanceof NullNode == false) {
                                    URI fileInstance2;
                                    fileInstance2 = new URI(fileValue2.getTextValue());
                                    secondaryEndpointsInstance.setFile(fileInstance2);
                                }
                            }
                        }
                    }
                }
            }

        }
        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();
        }
    }
}