Example usage for javax.xml.bind DatatypeConverter parseBoolean

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

Introduction

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

Prototype

public static boolean parseBoolean(String lexicalXSDBoolean) 

Source Link

Document

Converts the string argument into a boolean value.

Usage

From source file:com.microsoft.windowsazure.management.network.ReservedIPOperationsImpl.java

/**
* The Get Reserved IP operation retrieves the details for the virtual IP
* reserved for the subscription./*from  www.j  a va  2s.c  o m*/
*
* @param ipName Required. The name of the reserved IP to retrieve.
* @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 A reserved IP associated with your subscription.
*/
@Override
public NetworkReservedIPGetResponse get(String ipName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (ipName == null) {
        throw new NullPointerException("ipName");
    }

    // 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("ipName", ipName);
        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/networking/reservedips/";
    url = url + URLEncoder.encode(ipName, "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("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
        NetworkReservedIPGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new NetworkReservedIPGetResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

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

                Element addressElement = XmlUtility.getElementByTagNameNS(reservedIPElement,
                        "http://schemas.microsoft.com/windowsazure", "Address");
                if (addressElement != null) {
                    InetAddress addressInstance;
                    addressInstance = InetAddress.getByName(addressElement.getTextContent());
                    result.setAddress(addressInstance);
                }

                Element idElement = XmlUtility.getElementByTagNameNS(reservedIPElement,
                        "http://schemas.microsoft.com/windowsazure", "Id");
                if (idElement != null) {
                    String idInstance;
                    idInstance = idElement.getTextContent();
                    result.setId(idInstance);
                }

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

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

                Element inUseElement = XmlUtility.getElementByTagNameNS(reservedIPElement,
                        "http://schemas.microsoft.com/windowsazure", "InUse");
                if (inUseElement != null) {
                    boolean inUseInstance;
                    inUseInstance = DatatypeConverter.parseBoolean(inUseElement.getTextContent().toLowerCase());
                    result.setInUse(inUseInstance);
                }

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

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

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

                Element virtualIPNameElement = XmlUtility.getElementByTagNameNS(reservedIPElement,
                        "http://schemas.microsoft.com/windowsazure", "VirtualIPName");
                if (virtualIPNameElement != null) {
                    String virtualIPNameInstance;
                    virtualIPNameInstance = virtualIPNameElement.getTextContent();
                    result.setVirtualIPName(virtualIPNameInstance);
                }
            }

        }
        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//  w  w w  .  jav a  2 s.c  o  m
* 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.windowsazure.management.compute.VirtualMachineOSImageOperationsImpl.java

/**
* Gets OS Image'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 imageName Required. The name of the virtual machine image to
* replicate./*from ww w.  j a  va  2  s .  c o m*/
* @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 OS Images operation response.
*/
@Override
public VirtualMachineOSImageGetDetailsResponse getDetails(String imageName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (imageName == null) {
        throw new NullPointerException("imageName");
    }

    // 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("imageName", imageName);
        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/images/";
    url = url + URLEncoder.encode(imageName, "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
        VirtualMachineOSImageGetDetailsResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new VirtualMachineOSImageGetDetailsResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element oSImageDetailsElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "OSImageDetails");
            if (oSImageDetailsElement != null) {
                Element isCorruptedElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "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 replicationProgressSequenceElement = XmlUtility.getElementByTagNameNS(
                        oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure",
                        "ReplicationProgress");
                if (replicationProgressSequenceElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(replicationProgressSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "ReplicationProgressElement")
                            .size(); i1 = i1 + 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(i1));
                        VirtualMachineOSImageGetDetailsResponse.ReplicationProgressElement replicationProgressElementInstance = new VirtualMachineOSImageGetDetailsResponse.ReplicationProgressElement();
                        result.getReplicationProgress().add(replicationProgressElementInstance);

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

                        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(oSImageDetailsElement,
                        "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(
                        oSImageDetailsElement, "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 nameElement = XmlUtility.getElementByTagNameNS(planElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement != null) {
                            String nameInstance;
                            nameInstance = nameElement.getTextContent();
                            planInstance.setName(nameInstance);
                        }

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

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

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

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

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

                Element logicalSizeInGBElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "LogicalSizeInGB");
                if (logicalSizeInGBElement != null) {
                    double logicalSizeInGBInstance;
                    logicalSizeInGBInstance = DatatypeConverter
                            .parseDouble(logicalSizeInGBElement.getTextContent());
                    result.setLogicalSizeInGB(logicalSizeInGBInstance);
                }

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

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

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

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

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

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

                Element showInGuiElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "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 publishedDateElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PublishedDate");
                if (publishedDateElement != null) {
                    Calendar publishedDateInstance;
                    publishedDateInstance = DatatypeConverter
                            .parseDateTime(publishedDateElement.getTextContent());
                    result.setPublishedDate(publishedDateInstance);
                }

                Element isPremiumElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "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 iconUriElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "IconUri");
                if (iconUriElement != null) {
                    String iconUriInstance;
                    iconUriInstance = iconUriElement.getTextContent();
                    result.setIconUri(iconUriInstance);
                }

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

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

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

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

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

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

        }
        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.QueueOperationsImpl.java

/**
* The queue description is an XML AtomPub document that defines the desired
* semantics for a subscription. The queue description contains the
* following properties. For more information, see the QueueDescription
* Properties topic.  (see/*  ww w. ja va2 s  .c  om*/
* http://msdn.microsoft.com/en-us/library/windowsazure/hh780773.aspx for
* more information)
*
* @param namespaceName Required. The namespace name.
* @param queueName Required. The queue 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 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 queue.
*/
@Override
public ServiceBusQueueResponse get(String namespaceName, String queueName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }
    if (queueName == null) {
        throw new NullPointerException("queueName");
    }

    // 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("queueName", queueName);
        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 + "/Queues/";
    url = url + URLEncoder.encode(queueName, "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
        ServiceBusQueueResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServiceBusQueueResponse();
            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 queueDescriptionElement = XmlUtility.getElementByTagNameNS(contentElement,
                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                            "QueueDescription");
                    if (queueDescriptionElement != null) {
                        ServiceBusQueue queueDescriptionInstance = new ServiceBusQueue();
                        result.setQueue(queueDescriptionInstance);

                        Element lockDurationElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "LockDuration");
                        if (lockDurationElement != null) {
                            String lockDurationInstance;
                            lockDurationInstance = lockDurationElement.getTextContent();
                            queueDescriptionInstance.setLockDuration(lockDurationInstance);
                        }

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

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

                        Element requiresSessionElement = XmlUtility.getElementByTagNameNS(
                                queueDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "RequiresSession");
                        if (requiresSessionElement != null) {
                            boolean requiresSessionInstance;
                            requiresSessionInstance = DatatypeConverter
                                    .parseBoolean(requiresSessionElement.getTextContent().toLowerCase());
                            queueDescriptionInstance.setRequiresSession(requiresSessionInstance);
                        }

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

                        Element deadLetteringOnMessageExpirationElement = XmlUtility.getElementByTagNameNS(
                                queueDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "DeadLetteringOnMessageExpiration");
                        if (deadLetteringOnMessageExpirationElement != null) {
                            boolean deadLetteringOnMessageExpirationInstance;
                            deadLetteringOnMessageExpirationInstance = DatatypeConverter.parseBoolean(
                                    deadLetteringOnMessageExpirationElement.getTextContent().toLowerCase());
                            queueDescriptionInstance.setDeadLetteringOnMessageExpiration(
                                    deadLetteringOnMessageExpirationInstance);
                        }

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

                        Element maxDeliveryCountElement = XmlUtility.getElementByTagNameNS(
                                queueDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "MaxDeliveryCount");
                        if (maxDeliveryCountElement != null) {
                            int maxDeliveryCountInstance;
                            maxDeliveryCountInstance = DatatypeConverter
                                    .parseInt(maxDeliveryCountElement.getTextContent());
                            queueDescriptionInstance.setMaxDeliveryCount(maxDeliveryCountInstance);
                        }

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

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

                        Element messageCountElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "MessageCount");
                        if (messageCountElement != null) {
                            int messageCountInstance;
                            messageCountInstance = DatatypeConverter
                                    .parseInt(messageCountElement.getTextContent());
                            queueDescriptionInstance.setMessageCount(messageCountInstance);
                        }

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

                        Element authorizationRulesSequenceElement = XmlUtility.getElementByTagNameNS(
                                queueDescriptionElement,
                                "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();
                                queueDescriptionInstance.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(queueDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "Status");
                        if (statusElement != null) {
                            String statusInstance;
                            statusInstance = statusElement.getTextContent();
                            queueDescriptionInstance.setStatus(statusInstance);
                        }

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

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

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

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

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

                            Element activeMessageCountElement = XmlUtility.getElementByTagNameNS(
                                    countDetailsElement,
                                    "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                    "ActiveMessageCount");
                            if (activeMessageCountElement != null) {
                                int activeMessageCountInstance;
                                activeMessageCountInstance = DatatypeConverter
                                        .parseInt(activeMessageCountElement.getTextContent());
                                countDetailsInstance.setActiveMessageCount(activeMessageCountInstance);
                            }

                            Element deadLetterMessageCountElement = XmlUtility.getElementByTagNameNS(
                                    countDetailsElement,
                                    "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                    "DeadLetterMessageCount");
                            if (deadLetterMessageCountElement != null) {
                                int deadLetterMessageCountInstance;
                                deadLetterMessageCountInstance = DatatypeConverter
                                        .parseInt(deadLetterMessageCountElement.getTextContent());
                                countDetailsInstance.setDeadLetterMessageCount(deadLetterMessageCountInstance);
                            }

                            Element scheduledMessageCountElement = XmlUtility.getElementByTagNameNS(
                                    countDetailsElement,
                                    "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                    "ScheduledMessageCount");
                            if (scheduledMessageCountElement != null) {
                                int scheduledMessageCountInstance;
                                scheduledMessageCountInstance = DatatypeConverter
                                        .parseInt(scheduledMessageCountElement.getTextContent());
                                countDetailsInstance.setScheduledMessageCount(scheduledMessageCountInstance);
                            }

                            Element transferDeadLetterMessageCountElement = XmlUtility.getElementByTagNameNS(
                                    countDetailsElement,
                                    "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                    "TransferDeadLetterMessageCount");
                            if (transferDeadLetterMessageCountElement != null) {
                                int transferDeadLetterMessageCountInstance;
                                transferDeadLetterMessageCountInstance = DatatypeConverter
                                        .parseInt(transferDeadLetterMessageCountElement.getTextContent());
                                countDetailsInstance.setTransferDeadLetterMessageCount(
                                        transferDeadLetterMessageCountInstance);
                            }

                            Element transferMessageCountElement = XmlUtility.getElementByTagNameNS(
                                    countDetailsElement,
                                    "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                    "TransferMessageCount");
                            if (transferMessageCountElement != null) {
                                int transferMessageCountInstance;
                                transferMessageCountInstance = DatatypeConverter
                                        .parseInt(transferMessageCountElement.getTextContent());
                                countDetailsInstance.setTransferMessageCount(transferMessageCountInstance);
                            }
                        }

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

                        Element entityAvailabilityStatusElement = XmlUtility.getElementByTagNameNS(
                                queueDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "EntityAvailabilityStatus");
                        if (entityAvailabilityStatusElement != null) {
                            String entityAvailabilityStatusInstance;
                            entityAvailabilityStatusInstance = entityAvailabilityStatusElement.getTextContent();
                            queueDescriptionInstance
                                    .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.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 ww  w  .  j a  v  a  2 s  . co  m
* @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.windowsazure.management.sql.DatabaseCopyOperationsImpl.java

/**
* Updates a SQL Server database copy./*ww w.  j a v  a 2s  .  c  o  m*/
*
* @param serverName Required. The name of the source or destination SQL
* Server instance.
* @param databaseName Required. The name of the database.
* @param databaseCopyName Required. The unique identifier for the database
* copy to update.
* @param parameters Required. The additional parameters for the update
* database copy operation.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @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 Represents a response to the update request.
*/
@Override
public DatabaseCopyUpdateResponse update(String serverName, String databaseName, String databaseCopyName,
        DatabaseCopyUpdateParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
    // Validate
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }
    if (databaseName == null) {
        throw new NullPointerException("databaseName");
    }
    if (databaseCopyName == null) {
        throw new NullPointerException("databaseCopyName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }

    // 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);
        tracingParameters.put("databaseCopyName", databaseCopyName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "updateAsync", 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 + "/databasecopies/";
    url = url + URLEncoder.encode(databaseCopyName, "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
    HttpPut httpRequest = new HttpPut(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    httpRequest.setHeader("x-ms-version", "2012-03-01");

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "ServiceResource");
    requestDoc.appendChild(serviceResourceElement);

    if (parameters.isForcedTerminate() != null) {
        Element isForcedTerminateElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "IsForcedTerminate");
        isForcedTerminateElement.appendChild(
                requestDoc.createTextNode(Boolean.toString(parameters.isForcedTerminate()).toLowerCase()));
        serviceResourceElement.appendChild(isForcedTerminateElement);
    }

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/xml");

    // 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, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

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

            Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ServiceResource");
            if (serviceResourceElement2 != null) {
                DatabaseCopy serviceResourceInstance = new DatabaseCopy();
                result.setDatabaseCopy(serviceResourceInstance);

                Element sourceServerNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "SourceServerName");
                if (sourceServerNameElement != null) {
                    String sourceServerNameInstance;
                    sourceServerNameInstance = sourceServerNameElement.getTextContent();
                    serviceResourceInstance.setSourceServerName(sourceServerNameInstance);
                }

                Element sourceDatabaseNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "SourceDatabaseName");
                if (sourceDatabaseNameElement != null) {
                    String sourceDatabaseNameInstance;
                    sourceDatabaseNameInstance = sourceDatabaseNameElement.getTextContent();
                    serviceResourceInstance.setSourceDatabaseName(sourceDatabaseNameInstance);
                }

                Element destinationServerNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "DestinationServerName");
                if (destinationServerNameElement != null) {
                    String destinationServerNameInstance;
                    destinationServerNameInstance = destinationServerNameElement.getTextContent();
                    serviceResourceInstance.setDestinationServerName(destinationServerNameInstance);
                }

                Element destinationDatabaseNameElement = XmlUtility.getElementByTagNameNS(
                        serviceResourceElement2, "http://schemas.microsoft.com/windowsazure",
                        "DestinationDatabaseName");
                if (destinationDatabaseNameElement != null) {
                    String destinationDatabaseNameInstance;
                    destinationDatabaseNameInstance = destinationDatabaseNameElement.getTextContent();
                    serviceResourceInstance.setDestinationDatabaseName(destinationDatabaseNameInstance);
                }

                Element isContinuousElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "IsContinuous");
                if (isContinuousElement != null) {
                    boolean isContinuousInstance;
                    isContinuousInstance = DatatypeConverter
                            .parseBoolean(isContinuousElement.getTextContent().toLowerCase());
                    serviceResourceInstance.setIsContinuous(isContinuousInstance);
                }

                Element replicationStateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "ReplicationState");
                if (replicationStateElement != null) {
                    byte replicationStateInstance;
                    replicationStateInstance = DatatypeConverter
                            .parseByte(replicationStateElement.getTextContent());
                    serviceResourceInstance.setReplicationState(replicationStateInstance);
                }

                Element replicationStateDescriptionElement = XmlUtility.getElementByTagNameNS(
                        serviceResourceElement2, "http://schemas.microsoft.com/windowsazure",
                        "ReplicationStateDescription");
                if (replicationStateDescriptionElement != null) {
                    String replicationStateDescriptionInstance;
                    replicationStateDescriptionInstance = replicationStateDescriptionElement.getTextContent();
                    serviceResourceInstance.setReplicationStateDescription(replicationStateDescriptionInstance);
                }

                Element localDatabaseIdElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "LocalDatabaseId");
                if (localDatabaseIdElement != null) {
                    int localDatabaseIdInstance;
                    localDatabaseIdInstance = DatatypeConverter
                            .parseInt(localDatabaseIdElement.getTextContent());
                    serviceResourceInstance.setLocalDatabaseId(localDatabaseIdInstance);
                }

                Element isLocalDatabaseReplicationTargetElement = XmlUtility.getElementByTagNameNS(
                        serviceResourceElement2, "http://schemas.microsoft.com/windowsazure",
                        "IsLocalDatabaseReplicationTarget");
                if (isLocalDatabaseReplicationTargetElement != null) {
                    boolean isLocalDatabaseReplicationTargetInstance;
                    isLocalDatabaseReplicationTargetInstance = DatatypeConverter.parseBoolean(
                            isLocalDatabaseReplicationTargetElement.getTextContent().toLowerCase());
                    serviceResourceInstance
                            .setIsLocalDatabaseReplicationTarget(isLocalDatabaseReplicationTargetInstance);
                }

                Element isInterlinkConnectedElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "IsInterlinkConnected");
                if (isInterlinkConnectedElement != null) {
                    boolean isInterlinkConnectedInstance;
                    isInterlinkConnectedInstance = DatatypeConverter
                            .parseBoolean(isInterlinkConnectedElement.getTextContent().toLowerCase());
                    serviceResourceInstance.setIsInterlinkConnected(isInterlinkConnectedInstance);
                }

                Element startDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "StartDate");
                if (startDateElement != null) {
                    String startDateInstance;
                    startDateInstance = startDateElement.getTextContent();
                    serviceResourceInstance.setStartDate(startDateInstance);
                }

                Element modifyDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "ModifyDate");
                if (modifyDateElement != null) {
                    String modifyDateInstance;
                    modifyDateInstance = modifyDateElement.getTextContent();
                    serviceResourceInstance.setModifyDate(modifyDateInstance);
                }

                Element percentCompleteElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "PercentComplete");
                if (percentCompleteElement != null) {
                    float percentCompleteInstance;
                    percentCompleteInstance = DatatypeConverter
                            .parseFloat(percentCompleteElement.getTextContent());
                    serviceResourceInstance.setPercentComplete(percentCompleteInstance);
                }

                Element isOfflineSecondaryElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "IsOfflineSecondary");
                if (isOfflineSecondaryElement != null) {
                    boolean isOfflineSecondaryInstance;
                    isOfflineSecondaryInstance = DatatypeConverter
                            .parseBoolean(isOfflineSecondaryElement.getTextContent().toLowerCase());
                    serviceResourceInstance.setIsOfflineSecondary(isOfflineSecondaryInstance);
                }

                Element isTerminationAllowedElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "IsTerminationAllowed");
                if (isTerminationAllowedElement != null) {
                    boolean isTerminationAllowedInstance;
                    isTerminationAllowedInstance = DatatypeConverter
                            .parseBoolean(isTerminationAllowedElement.getTextContent().toLowerCase());
                    serviceResourceInstance.setIsTerminationAllowed(isTerminationAllowedInstance);
                }

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

                Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "Type");
                if (typeElement != null) {
                    String typeInstance;
                    typeInstance = typeElement.getTextContent();
                    serviceResourceInstance.setType(typeInstance);
                }

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

        }
        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.network.ReservedIPOperationsImpl.java

/**
* The List Reserved IP operation retrieves all of the virtual IPs reserved
* for the subscription.//from  w w  w. j  a  v  a  2  s  . c o  m
*
* @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 The response structure for the Server List operation.
*/
@Override
public NetworkReservedIPListResponse list()
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // 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/networking/reservedips";
    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
        NetworkReservedIPListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new NetworkReservedIPListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element reservedIPsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ReservedIPs");
            if (reservedIPsSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(reservedIPsSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "ReservedIP")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element reservedIPsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(reservedIPsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "ReservedIP")
                            .get(i1));
                    NetworkReservedIPListResponse.ReservedIP reservedIPInstance = new NetworkReservedIPListResponse.ReservedIP();
                    result.getReservedIPs().add(reservedIPInstance);

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

                    Element addressElement = XmlUtility.getElementByTagNameNS(reservedIPsElement,
                            "http://schemas.microsoft.com/windowsazure", "Address");
                    if (addressElement != null) {
                        InetAddress addressInstance;
                        addressInstance = InetAddress.getByName(addressElement.getTextContent());
                        reservedIPInstance.setAddress(addressInstance);
                    }

                    Element idElement = XmlUtility.getElementByTagNameNS(reservedIPsElement,
                            "http://schemas.microsoft.com/windowsazure", "Id");
                    if (idElement != null) {
                        String idInstance;
                        idInstance = idElement.getTextContent();
                        reservedIPInstance.setId(idInstance);
                    }

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

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

                    Element inUseElement = XmlUtility.getElementByTagNameNS(reservedIPsElement,
                            "http://schemas.microsoft.com/windowsazure", "InUse");
                    if (inUseElement != null) {
                        boolean inUseInstance;
                        inUseInstance = DatatypeConverter
                                .parseBoolean(inUseElement.getTextContent().toLowerCase());
                        reservedIPInstance.setInUse(inUseInstance);
                    }

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

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

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

                    Element virtualIPNameElement = XmlUtility.getElementByTagNameNS(reservedIPsElement,
                            "http://schemas.microsoft.com/windowsazure", "VirtualIPName");
                    if (virtualIPNameElement != null) {
                        String virtualIPNameInstance;
                        virtualIPNameInstance = virtualIPNameElement.getTextContent();
                        reservedIPInstance.setVirtualIPName(virtualIPNameInstance);
                    }
                }
            }

        }
        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.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   w  ww  . j  av  a  2s .c  o m*/
*
* @param webSpaceName Required. The name of the web space.
* @param parameters Required. Parameters supplied to the Create Web Site
* operation.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @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 Site operation response.
*/
@Override
public WebSiteCreateResponse create(String webSpaceName, WebSiteCreateParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException,
        URISyntaxException {
    // Validate
    if (webSpaceName == null) {
        throw new NullPointerException("webSpaceName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getName() == null) {
        throw new NullPointerException("parameters.Name");
    }
    if (parameters.getServerFarm() == null) {
        throw new NullPointerException("parameters.ServerFarm");
    }
    if (parameters.getWebSpace() != null) {
        if (parameters.getWebSpace().getGeoRegion() == null) {
            throw new NullPointerException("parameters.WebSpace.GeoRegion");
        }
        if (parameters.getWebSpace().getName() == null) {
            throw new NullPointerException("parameters.WebSpace.Name");
        }
        if (parameters.getWebSpace().getPlan() == null) {
            throw new NullPointerException("parameters.WebSpace.Plan");
        }
    }

    // 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, "createAsync", 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";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

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

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    httpRequest.setHeader("x-ms-version", "2014-04-01");

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element siteElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Site");
    requestDoc.appendChild(siteElement);

    Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name");
    nameElement.appendChild(requestDoc.createTextNode(parameters.getName()));
    siteElement.appendChild(nameElement);

    Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "ServerFarm");
    serverFarmElement.appendChild(requestDoc.createTextNode(parameters.getServerFarm()));
    siteElement.appendChild(serverFarmElement);

    if (parameters.getWebSpace() != null) {
        Element webSpaceToCreateElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "WebSpaceToCreate");
        siteElement.appendChild(webSpaceToCreateElement);

        Element geoRegionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "GeoRegion");
        geoRegionElement.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getGeoRegion()));
        webSpaceToCreateElement.appendChild(geoRegionElement);

        Element nameElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name");
        nameElement2.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getName()));
        webSpaceToCreateElement.appendChild(nameElement2);

        Element planElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Plan");
        planElement.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getPlan()));
        webSpaceToCreateElement.appendChild(planElement);
    }

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/xml");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) {
            ServiceException ex = ServiceException.createFromXml(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 || statusCode == HttpStatus.SC_CREATED) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new WebSiteCreateResponse();
            DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
            documentBuilderFactory2.setNamespaceAware(true);
            DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
            Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));

            Element siteElement2 = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Site");
            if (siteElement2 != null) {
                WebSite webSiteInstance = new WebSite();
                result.setWebSite(webSiteInstance);

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

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

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

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

                Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2,
                        "http://schemas.microsoft.com/windowsazure", "EnabledHostNames");
                if (enabledHostNamesSequenceElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(enabledHostNamesSequenceElement,
                                    "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string")
                            .size(); i1 = i1 + 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(i1));
                        webSiteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent());
                    }
                }

                Element hostNameSslStatesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2,
                        "http://schemas.microsoft.com/windowsazure", "HostNameSslStates");
                if (hostNameSslStatesSequenceElement != null) {
                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(hostNameSslStatesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "HostNameSslState")
                            .size(); i2 = i2 + 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(i2));
                        WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState();
                        webSiteInstance.getHostNameSslStates().add(hostNameSslStateInstance);

                        Element nameElement3 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement3 != null) {
                            String nameInstance;
                            nameInstance = nameElement3.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(siteElement2,
                        "http://schemas.microsoft.com/windowsazure", "HostNames");
                if (hostNamesSequenceElement != null) {
                    for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(hostNamesSequenceElement,
                                    "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string")
                            .size(); i3 = i3 + 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(i3));
                        webSiteInstance.getHostNames().add(hostNamesElement.getTextContent());
                    }
                }

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

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

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

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

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

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

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

                    Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement,
                            "http://schemas.microsoft.com/windowsazure", "AppSettings");
                    if (appSettingsSequenceElement != null) {
                        for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(appSettingsSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                .size(); i4 = i4 + 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(i4));
                            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 i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(metadataSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                .size(); i5 = i5 + 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(i5));
                            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 i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(propertiesSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "NameValuePair")
                                .size(); i6 = i6 + 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(i6));
                            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(siteElement2,
                        "http://schemas.microsoft.com/windowsazure", "State");
                if (stateElement != null) {
                    String stateInstance;
                    stateInstance = stateElement.getTextContent();
                    webSiteInstance.setState(stateInstance);
                }

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

                Element webSpaceElement = XmlUtility.getElementByTagNameNS(siteElement2,
                        "http://schemas.microsoft.com/windowsazure", "WebSpace");
                if (webSpaceElement != null) {
                    String webSpaceInstance;
                    webSpaceInstance = webSpaceElement.getTextContent();
                    webSiteInstance.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.windowsazure.management.sql.DatabaseOperationsImpl.java

/**
* Returns a collection of Azure SQL Databases.
*
* @param serverName Required. The name of the Azure SQL Database Server
* from which to retrieve the database.//  ww w .j  ava2  s.c o  m
* @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 a collection of databases for a given Azure SQL Database
* Server.
*/
@Override
public DatabaseListResponse list(String serverName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }

    // 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);
        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/sqlservers/servers/";
    url = url + URLEncoder.encode(serverName, "UTF-8");
    url = url + "/databases";
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("contentview=generic");
    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", "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
        DatabaseListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new DatabaseListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ServiceResources");
            if (serviceResourcesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(serviceResourcesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "ServiceResource")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(serviceResourcesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "ServiceResource")
                            .get(i1));
                    Database serviceResourceInstance = new Database();
                    result.getDatabases().add(serviceResourceInstance);

                    Element idElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Id");
                    if (idElement != null) {
                        int idInstance;
                        idInstance = DatatypeConverter.parseInt(idElement.getTextContent());
                        serviceResourceInstance.setId(idInstance);
                    }

                    Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Edition");
                    if (editionElement != null) {
                        String editionInstance;
                        editionInstance = editionElement.getTextContent();
                        serviceResourceInstance.setEdition(editionInstance);
                    }

                    Element maxSizeGBElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "MaxSizeGB");
                    if (maxSizeGBElement != null) {
                        int maxSizeGBInstance;
                        maxSizeGBInstance = DatatypeConverter.parseInt(maxSizeGBElement.getTextContent());
                        serviceResourceInstance.setMaximumDatabaseSizeInGB(maxSizeGBInstance);
                    }

                    Element maxSizeBytesElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes");
                    if (maxSizeBytesElement != null) {
                        long maxSizeBytesInstance;
                        maxSizeBytesInstance = DatatypeConverter
                                .parseLong(maxSizeBytesElement.getTextContent());
                        serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance);
                    }

                    Element collationNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "CollationName");
                    if (collationNameElement != null) {
                        String collationNameInstance;
                        collationNameInstance = collationNameElement.getTextContent();
                        serviceResourceInstance.setCollationName(collationNameInstance);
                    }

                    Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "CreationDate");
                    if (creationDateElement != null) {
                        Calendar creationDateInstance;
                        creationDateInstance = DatatypeConverter
                                .parseDateTime(creationDateElement.getTextContent());
                        serviceResourceInstance.setCreationDate(creationDateInstance);
                    }

                    Element isFederationRootElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "IsFederationRoot");
                    if (isFederationRootElement != null) {
                        boolean isFederationRootInstance;
                        isFederationRootInstance = DatatypeConverter
                                .parseBoolean(isFederationRootElement.getTextContent().toLowerCase());
                        serviceResourceInstance.setIsFederationRoot(isFederationRootInstance);
                    }

                    Element isSystemObjectElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "IsSystemObject");
                    if (isSystemObjectElement != null) {
                        boolean isSystemObjectInstance;
                        isSystemObjectInstance = DatatypeConverter
                                .parseBoolean(isSystemObjectElement.getTextContent().toLowerCase());
                        serviceResourceInstance.setIsSystemObject(isSystemObjectInstance);
                    }

                    Element sizeMBElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "SizeMB");
                    if (sizeMBElement != null) {
                        String sizeMBInstance;
                        sizeMBInstance = sizeMBElement.getTextContent();
                        serviceResourceInstance.setSizeMB(sizeMBInstance);
                    }

                    Element serviceObjectiveAssignmentErrorCodeElement = XmlUtility.getElementByTagNameNS(
                            serviceResourcesElement, "http://schemas.microsoft.com/windowsazure",
                            "ServiceObjectiveAssignmentErrorCode");
                    if (serviceObjectiveAssignmentErrorCodeElement != null) {
                        String serviceObjectiveAssignmentErrorCodeInstance;
                        serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement
                                .getTextContent();
                        serviceResourceInstance.setServiceObjectiveAssignmentErrorCode(
                                serviceObjectiveAssignmentErrorCodeInstance);
                    }

                    Element serviceObjectiveAssignmentErrorDescriptionElement = XmlUtility
                            .getElementByTagNameNS(serviceResourcesElement,
                                    "http://schemas.microsoft.com/windowsazure",
                                    "ServiceObjectiveAssignmentErrorDescription");
                    if (serviceObjectiveAssignmentErrorDescriptionElement != null) {
                        String serviceObjectiveAssignmentErrorDescriptionInstance;
                        serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement
                                .getTextContent();
                        serviceResourceInstance.setServiceObjectiveAssignmentErrorDescription(
                                serviceObjectiveAssignmentErrorDescriptionInstance);
                    }

                    Element serviceObjectiveAssignmentStateElement = XmlUtility.getElementByTagNameNS(
                            serviceResourcesElement, "http://schemas.microsoft.com/windowsazure",
                            "ServiceObjectiveAssignmentState");
                    if (serviceObjectiveAssignmentStateElement != null) {
                        String serviceObjectiveAssignmentStateInstance;
                        serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement
                                .getTextContent();
                        serviceResourceInstance
                                .setServiceObjectiveAssignmentState(serviceObjectiveAssignmentStateInstance);
                    }

                    Element serviceObjectiveAssignmentStateDescriptionElement = XmlUtility
                            .getElementByTagNameNS(serviceResourcesElement,
                                    "http://schemas.microsoft.com/windowsazure",
                                    "ServiceObjectiveAssignmentStateDescription");
                    if (serviceObjectiveAssignmentStateDescriptionElement != null) {
                        String serviceObjectiveAssignmentStateDescriptionInstance;
                        serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement
                                .getTextContent();
                        serviceResourceInstance.setServiceObjectiveAssignmentStateDescription(
                                serviceObjectiveAssignmentStateDescriptionInstance);
                    }

                    Element serviceObjectiveAssignmentSuccessDateElement = XmlUtility.getElementByTagNameNS(
                            serviceResourcesElement, "http://schemas.microsoft.com/windowsazure",
                            "ServiceObjectiveAssignmentSuccessDate");
                    if (serviceObjectiveAssignmentSuccessDateElement != null) {
                        String serviceObjectiveAssignmentSuccessDateInstance;
                        serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement
                                .getTextContent();
                        serviceResourceInstance.setServiceObjectiveAssignmentSuccessDate(
                                serviceObjectiveAssignmentSuccessDateInstance);
                    }

                    Element serviceObjectiveIdElement = XmlUtility.getElementByTagNameNS(
                            serviceResourcesElement, "http://schemas.microsoft.com/windowsazure",
                            "ServiceObjectiveId");
                    if (serviceObjectiveIdElement != null) {
                        String serviceObjectiveIdInstance;
                        serviceObjectiveIdInstance = serviceObjectiveIdElement.getTextContent();
                        serviceResourceInstance.setServiceObjectiveId(serviceObjectiveIdInstance);
                    }

                    Element assignedServiceObjectiveIdElement = XmlUtility.getElementByTagNameNS(
                            serviceResourcesElement, "http://schemas.microsoft.com/windowsazure",
                            "AssignedServiceObjectiveId");
                    if (assignedServiceObjectiveIdElement != null) {
                        String assignedServiceObjectiveIdInstance;
                        assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement.getTextContent();
                        serviceResourceInstance
                                .setAssignedServiceObjectiveId(assignedServiceObjectiveIdInstance);
                    }

                    Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS(
                            serviceResourcesElement, "http://schemas.microsoft.com/windowsazure",
                            "RecoveryPeriodStartDate");
                    if (recoveryPeriodStartDateElement != null
                            && recoveryPeriodStartDateElement.getTextContent() != null
                            && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) {
                        Calendar recoveryPeriodStartDateInstance;
                        recoveryPeriodStartDateInstance = DatatypeConverter
                                .parseDateTime(recoveryPeriodStartDateElement.getTextContent());
                        serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance);
                    }

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

                    Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Type");
                    if (typeElement != null) {
                        String typeInstance;
                        typeInstance = typeElement.getTextContent();
                        serviceResourceInstance.setType(typeInstance);
                    }

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

        }
        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.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 a2  s .  c  o  m
*
* @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 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 response to a request for a particular namespace.
*/
@Override
public ServiceBusNamespaceResponse get(String namespaceName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    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("namespaceName", namespaceName);
        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");
    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("Accept", "application/atom+xml");
    httpRequest.setHeader("Content-Type", "application/atom+xml");
    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
        ServiceBusNamespaceResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServiceBusNamespaceResponse();
            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 contentElement = XmlUtility.getElementByTagNameNS(entryElement,
                        "http://www.w3.org/2005/Atom", "content");
                if (contentElement != null) {
                    Element namespaceDescriptionElement = XmlUtility.getElementByTagNameNS(contentElement,
                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                            "NamespaceDescription");
                    if (namespaceDescriptionElement != null) {
                        ServiceBusNamespace namespaceDescriptionInstance = new ServiceBusNamespace();
                        result.setNamespace(namespaceDescriptionInstance);

                        Element nameElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Name");
                        if (nameElement != null) {
                            String nameInstance;
                            nameInstance = nameElement.getTextContent();
                            namespaceDescriptionInstance.setName(nameInstance);
                        }

                        Element regionElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "Region");
                        if (regionElement != null) {
                            String regionInstance;
                            regionInstance = regionElement.getTextContent();
                            namespaceDescriptionInstance.setRegion(regionInstance);
                        }

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

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

                        Element acsManagementEndpointElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "AcsManagementEndpoint");
                        if (acsManagementEndpointElement != null) {
                            URI acsManagementEndpointInstance;
                            acsManagementEndpointInstance = new URI(
                                    acsManagementEndpointElement.getTextContent());
                            namespaceDescriptionInstance
                                    .setAcsManagementEndpoint(acsManagementEndpointInstance);
                        }

                        Element serviceBusEndpointElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "ServiceBusEndpoint");
                        if (serviceBusEndpointElement != null) {
                            URI serviceBusEndpointInstance;
                            serviceBusEndpointInstance = new URI(serviceBusEndpointElement.getTextContent());
                            namespaceDescriptionInstance.setServiceBusEndpoint(serviceBusEndpointInstance);
                        }

                        Element subscriptionIdElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "SubscriptionId");
                        if (subscriptionIdElement != null) {
                            String subscriptionIdInstance;
                            subscriptionIdInstance = subscriptionIdElement.getTextContent();
                            namespaceDescriptionInstance.setSubscriptionId(subscriptionIdInstance);
                        }

                        Element enabledElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "Enabled");
                        if (enabledElement != null) {
                            boolean enabledInstance;
                            enabledInstance = DatatypeConverter
                                    .parseBoolean(enabledElement.getTextContent().toLowerCase());
                            namespaceDescriptionInstance.setEnabled(enabledInstance);
                        }

                        Element createACSNamespaceElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "CreateACSNamespace");
                        if (createACSNamespaceElement != null) {
                            boolean createACSNamespaceInstance;
                            createACSNamespaceInstance = DatatypeConverter
                                    .parseBoolean(createACSNamespaceElement.getTextContent().toLowerCase());
                            namespaceDescriptionInstance.setCreateACSNamespace(createACSNamespaceInstance);
                        }

                        Element namespaceTypeElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "NamespaceType");
                        if (namespaceTypeElement != null && namespaceTypeElement.getTextContent() != null
                                && !namespaceTypeElement.getTextContent().isEmpty()) {
                            NamespaceType namespaceTypeInstance;
                            namespaceTypeInstance = NamespaceType
                                    .valueOf(namespaceTypeElement.getTextContent());
                            namespaceDescriptionInstance.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();
        }
    }
}