Example usage for javax.xml.bind DatatypeConverter parseInt

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

Introduction

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

Prototype

public static int parseInt(String lexicalXSDInt) 

Source Link

Document

Convert the string argument into an int value.

Usage

From source file:com.microsoft.windowsazure.management.RoleSizeOperationsImpl.java

/**
* The List Role Sizes operation lists all of the role sizes that are valid
* for your subscription.//from  ww  w. ja va 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.
* @return The List Role Sizes operation response.
*/
@Override
public RoleSizeListResponse 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 + "/rolesizes";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

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

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

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

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

            Element roleSizesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "RoleSizes");
            if (roleSizesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(roleSizesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "RoleSize")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element roleSizesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(roleSizesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "RoleSize")
                            .get(i1));
                    RoleSizeListResponse.RoleSize roleSizeInstance = new RoleSizeListResponse.RoleSize();
                    result.getRoleSizes().add(roleSizeInstance);

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

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

                    Element coresElement = XmlUtility.getElementByTagNameNS(roleSizesElement,
                            "http://schemas.microsoft.com/windowsazure", "Cores");
                    if (coresElement != null) {
                        int coresInstance;
                        coresInstance = DatatypeConverter.parseInt(coresElement.getTextContent());
                        roleSizeInstance.setCores(coresInstance);
                    }

                    Element memoryInMbElement = XmlUtility.getElementByTagNameNS(roleSizesElement,
                            "http://schemas.microsoft.com/windowsazure", "MemoryInMb");
                    if (memoryInMbElement != null) {
                        int memoryInMbInstance;
                        memoryInMbInstance = DatatypeConverter.parseInt(memoryInMbElement.getTextContent());
                        roleSizeInstance.setMemoryInMb(memoryInMbInstance);
                    }

                    Element supportedByWebWorkerRolesElement = XmlUtility.getElementByTagNameNS(
                            roleSizesElement, "http://schemas.microsoft.com/windowsazure",
                            "SupportedByWebWorkerRoles");
                    if (supportedByWebWorkerRolesElement != null) {
                        boolean supportedByWebWorkerRolesInstance;
                        supportedByWebWorkerRolesInstance = DatatypeConverter
                                .parseBoolean(supportedByWebWorkerRolesElement.getTextContent().toLowerCase());
                        roleSizeInstance.setSupportedByWebWorkerRoles(supportedByWebWorkerRolesInstance);
                    }

                    Element supportedByVirtualMachinesElement = XmlUtility.getElementByTagNameNS(
                            roleSizesElement, "http://schemas.microsoft.com/windowsazure",
                            "SupportedByVirtualMachines");
                    if (supportedByVirtualMachinesElement != null) {
                        boolean supportedByVirtualMachinesInstance;
                        supportedByVirtualMachinesInstance = DatatypeConverter
                                .parseBoolean(supportedByVirtualMachinesElement.getTextContent().toLowerCase());
                        roleSizeInstance.setSupportedByVirtualMachines(supportedByVirtualMachinesInstance);
                    }

                    Element maxDataDiskCountElement = XmlUtility.getElementByTagNameNS(roleSizesElement,
                            "http://schemas.microsoft.com/windowsazure", "MaxDataDiskCount");
                    if (maxDataDiskCountElement != null) {
                        int maxDataDiskCountInstance;
                        maxDataDiskCountInstance = DatatypeConverter
                                .parseInt(maxDataDiskCountElement.getTextContent());
                        roleSizeInstance.setMaxDataDiskCount(maxDataDiskCountInstance);
                    }

                    Element webWorkerResourceDiskSizeInMbElement = XmlUtility.getElementByTagNameNS(
                            roleSizesElement, "http://schemas.microsoft.com/windowsazure",
                            "WebWorkerResourceDiskSizeInMb");
                    if (webWorkerResourceDiskSizeInMbElement != null) {
                        int webWorkerResourceDiskSizeInMbInstance;
                        webWorkerResourceDiskSizeInMbInstance = DatatypeConverter
                                .parseInt(webWorkerResourceDiskSizeInMbElement.getTextContent());
                        roleSizeInstance
                                .setWebWorkerResourceDiskSizeInMb(webWorkerResourceDiskSizeInMbInstance);
                    }

                    Element virtualMachineResourceDiskSizeInMbElement = XmlUtility.getElementByTagNameNS(
                            roleSizesElement, "http://schemas.microsoft.com/windowsazure",
                            "VirtualMachineResourceDiskSizeInMb");
                    if (virtualMachineResourceDiskSizeInMbElement != null) {
                        int virtualMachineResourceDiskSizeInMbInstance;
                        virtualMachineResourceDiskSizeInMbInstance = DatatypeConverter
                                .parseInt(virtualMachineResourceDiskSizeInMbElement.getTextContent());
                        roleSizeInstance.setVirtualMachineResourceDiskSizeInMb(
                                virtualMachineResourceDiskSizeInMbInstance);
                    }
                }
            }

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

/**
* Returns information about a specific operation by using the operation
* Guid.//w  w  w .  j  a v  a2 s  .c  o m
*
* @param serverName Required. The name of the Azure SQL Database Server
* where the database is hosted.
* @param operationGuid Required. The Guid of the Azure SQL Database
* operation to be obtained.
* @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 Represents the database operation for a given operation Guid.
*/
@Override
public DatabaseOperationGetResponse get(String serverName, String operationGuid)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }
    if (operationGuid == null) {
        throw new NullPointerException("operationGuid");
    }

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

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

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

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

                Element stateIdElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "StateId");
                if (stateIdElement != null) {
                    int stateIdInstance;
                    stateIdInstance = DatatypeConverter.parseInt(stateIdElement.getTextContent());
                    serviceResourceInstance.setStateId(stateIdInstance);
                }

                Element sessionActivityIdElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "SessionActivityId");
                if (sessionActivityIdElement != null) {
                    String sessionActivityIdInstance;
                    sessionActivityIdInstance = sessionActivityIdElement.getTextContent();
                    serviceResourceInstance.setSessionActivityId(sessionActivityIdInstance);
                }

                Element databaseNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "DatabaseName");
                if (databaseNameElement != null) {
                    String databaseNameInstance;
                    databaseNameInstance = databaseNameElement.getTextContent();
                    serviceResourceInstance.setDatabaseName(databaseNameInstance);
                }

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

                Element errorCodeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "ErrorCode");
                if (errorCodeElement != null) {
                    int errorCodeInstance;
                    errorCodeInstance = DatatypeConverter.parseInt(errorCodeElement.getTextContent());
                    serviceResourceInstance.setErrorCode(errorCodeInstance);
                }

                Element errorElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "Error");
                if (errorElement != null) {
                    String errorInstance;
                    errorInstance = errorElement.getTextContent();
                    serviceResourceInstance.setError(errorInstance);
                }

                Element errorSeverityElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "ErrorSeverity");
                if (errorSeverityElement != null) {
                    int errorSeverityInstance;
                    errorSeverityInstance = DatatypeConverter.parseInt(errorSeverityElement.getTextContent());
                    serviceResourceInstance.setErrorSeverity(errorSeverityInstance);
                }

                Element errorStateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "ErrorState");
                if (errorStateElement != null) {
                    int errorStateInstance;
                    errorStateInstance = DatatypeConverter.parseInt(errorStateElement.getTextContent());
                    serviceResourceInstance.setErrorState(errorStateInstance);
                }

                Element startTimeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "StartTime");
                if (startTimeElement != null) {
                    Calendar startTimeInstance;
                    startTimeInstance = DatatypeConverter.parseDateTime(startTimeElement.getTextContent());
                    serviceResourceInstance.setStartTime(startTimeInstance);
                }

                Element lastModifyTimeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "LastModifyTime");
                if (lastModifyTimeElement != null) {
                    Calendar lastModifyTimeInstance;
                    lastModifyTimeInstance = DatatypeConverter
                            .parseDateTime(lastModifyTimeElement.getTextContent());
                    serviceResourceInstance.setLastModifyTime(lastModifyTimeInstance);
                }

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

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

                Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "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.azure.management.resources.ResourceGroupOperationsImpl.java

/**
* Begin deleting resource group.To determine whether the operation has
* finished processing the request, call GetLongRunningOperationStatus.
*
* @param resourceGroupName Required. The name of the resource group to be
* deleted. The name is case insensitive.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations./*from w  w  w . j  av a  2  s.  c  om*/
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response for long running operations.
*/
@Override
public LongRunningOperationResponse beginDeleting(String resourceGroupName)
        throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (resourceGroupName != null && resourceGroupName.length() > 1000) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) {
        throw new IllegalArgumentException("resourceGroupName");
    }

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

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

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

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

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

        // Create Result
        LongRunningOperationResponse result = null;
        // Deserialize Response
        result = new LongRunningOperationResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_CONFLICT) {
            result.setStatus(OperationStatus.Failed);
        }
        if (statusCode == HttpStatus.SC_OK) {
            result.setStatus(OperationStatus.Succeeded);
        }

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

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

/**
* Begin moving resources.To determine whether the operation has finished
* processing the request, call GetLongRunningOperationStatus.
*
* @param sourceResourceGroupName Required. Source resource group name.
* @param parameters Required. move resources' 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.//from  w w w .j  a  v  a 2 s  .c om
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response for long running operations.
*/
@Override
public LongRunningOperationResponse beginMoving(String sourceResourceGroupName, ResourcesMoveInfo parameters)
        throws IOException, ServiceException {
    // Validate
    if (sourceResourceGroupName == null) {
        throw new NullPointerException("sourceResourceGroupName");
    }
    if (sourceResourceGroupName != null && sourceResourceGroupName.length() > 1000) {
        throw new IllegalArgumentException("sourceResourceGroupName");
    }
    if (Pattern.matches("^[-\\w\\._]+$", sourceResourceGroupName) == false) {
        throw new IllegalArgumentException("sourceResourceGroupName");
    }
    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("sourceResourceGroupName", sourceResourceGroupName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "beginMovingAsync", tracingParameters);
    }

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

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

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

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

        // Create Result
        LongRunningOperationResponse result = null;
        // Deserialize Response
        result = new LongRunningOperationResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_CONFLICT) {
            result.setStatus(OperationStatus.Failed);
        }
        if (statusCode == HttpStatus.SC_ACCEPTED) {
            result.setStatus(OperationStatus.InProgress);
        }
        if (statusCode == HttpStatus.SC_NO_CONTENT) {
            result.setStatus(OperationStatus.Succeeded);
        }

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

From source file:com.microsoft.azure.management.sql.ReplicationLinkOperationsImpl.java

/**
* Begins failover of the Azure SQL Database Replication Link with the given
* id./*from w w  w . j a va 2  s. c  o m*/
*
* @param resourceGroupName Required. The name of the Resource Group to
* which the Azure SQL Server belongs.
* @param serverName Required. The name of the Azure SQL Server on which the
* Azure SQL Database is hosted.
* @param databaseName Required. The name of the Azure SQL Database that has
* the replication link to be failed over.
* @param linkId Required. The id of the replication link to be failed over.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return Response for long running Azure Sql Database replication failover
* operations.
*/
@Override
public ReplicationLinkFailoverResponse beginFailover(String resourceGroupName, String serverName,
        String databaseName, String linkId) throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }
    if (databaseName == null) {
        throw new NullPointerException("databaseName");
    }
    if (linkId == null) {
        throw new NullPointerException("linkId");
    }

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

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

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

    // Set Headers

    // 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_ACCEPTED && statusCode != HttpStatus.SC_NO_CONTENT) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ReplicationLinkFailoverResponse result = null;
        // Deserialize Response
        result = new ReplicationLinkFailoverResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_NO_CONTENT) {
            result.setStatus(OperationStatus.Succeeded);
        }

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

From source file:com.microsoft.windowsazure.management.SubscriptionOperationsImpl.java

/**
* The Get Subscription operation returns account and resource allocation
* information for the specified subscription.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/hh403995.aspx for
* more information)//from   ww w  . j  av a2s .  c  om
*
* @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 Subscription operation response.
*/
@Override
public SubscriptionGetResponse get()
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate

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

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "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", "2014-10-01");

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

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

            Element subscriptionElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Subscription");
            if (subscriptionElement != null) {
                Element subscriptionIDElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "SubscriptionID");
                if (subscriptionIDElement != null) {
                    String subscriptionIDInstance;
                    subscriptionIDInstance = subscriptionIDElement.getTextContent();
                    result.setSubscriptionID(subscriptionIDInstance);
                }

                Element subscriptionNameElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "SubscriptionName");
                if (subscriptionNameElement != null) {
                    String subscriptionNameInstance;
                    subscriptionNameInstance = subscriptionNameElement.getTextContent();
                    result.setSubscriptionName(subscriptionNameInstance);
                }

                Element subscriptionStatusElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "SubscriptionStatus");
                if (subscriptionStatusElement != null && subscriptionStatusElement.getTextContent() != null
                        && !subscriptionStatusElement.getTextContent().isEmpty()) {
                    SubscriptionStatus subscriptionStatusInstance;
                    subscriptionStatusInstance = SubscriptionStatus
                            .valueOf(subscriptionStatusElement.getTextContent());
                    result.setSubscriptionStatus(subscriptionStatusInstance);
                }

                Element accountAdminLiveEmailIdElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "AccountAdminLiveEmailId");
                if (accountAdminLiveEmailIdElement != null) {
                    String accountAdminLiveEmailIdInstance;
                    accountAdminLiveEmailIdInstance = accountAdminLiveEmailIdElement.getTextContent();
                    result.setAccountAdminLiveEmailId(accountAdminLiveEmailIdInstance);
                }

                Element serviceAdminLiveEmailIdElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "ServiceAdminLiveEmailId");
                if (serviceAdminLiveEmailIdElement != null) {
                    String serviceAdminLiveEmailIdInstance;
                    serviceAdminLiveEmailIdInstance = serviceAdminLiveEmailIdElement.getTextContent();
                    result.setServiceAdminLiveEmailId(serviceAdminLiveEmailIdInstance);
                }

                Element maxCoreCountElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxCoreCount");
                if (maxCoreCountElement != null) {
                    int maxCoreCountInstance;
                    maxCoreCountInstance = DatatypeConverter.parseInt(maxCoreCountElement.getTextContent());
                    result.setMaximumCoreCount(maxCoreCountInstance);
                }

                Element maxStorageAccountsElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxStorageAccounts");
                if (maxStorageAccountsElement != null) {
                    int maxStorageAccountsInstance;
                    maxStorageAccountsInstance = DatatypeConverter
                            .parseInt(maxStorageAccountsElement.getTextContent());
                    result.setMaximumStorageAccounts(maxStorageAccountsInstance);
                }

                Element maxHostedServicesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxHostedServices");
                if (maxHostedServicesElement != null) {
                    int maxHostedServicesInstance;
                    maxHostedServicesInstance = DatatypeConverter
                            .parseInt(maxHostedServicesElement.getTextContent());
                    result.setMaximumHostedServices(maxHostedServicesInstance);
                }

                Element currentCoreCountElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentCoreCount");
                if (currentCoreCountElement != null) {
                    int currentCoreCountInstance;
                    currentCoreCountInstance = DatatypeConverter
                            .parseInt(currentCoreCountElement.getTextContent());
                    result.setCurrentCoreCount(currentCoreCountInstance);
                }

                Element currentStorageAccountsElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentStorageAccounts");
                if (currentStorageAccountsElement != null) {
                    int currentStorageAccountsInstance;
                    currentStorageAccountsInstance = DatatypeConverter
                            .parseInt(currentStorageAccountsElement.getTextContent());
                    result.setCurrentStorageAccounts(currentStorageAccountsInstance);
                }

                Element currentHostedServicesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentHostedServices");
                if (currentHostedServicesElement != null) {
                    int currentHostedServicesInstance;
                    currentHostedServicesInstance = DatatypeConverter
                            .parseInt(currentHostedServicesElement.getTextContent());
                    result.setCurrentHostedServices(currentHostedServicesInstance);
                }

                Element maxVirtualNetworkSitesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxVirtualNetworkSites");
                if (maxVirtualNetworkSitesElement != null) {
                    int maxVirtualNetworkSitesInstance;
                    maxVirtualNetworkSitesInstance = DatatypeConverter
                            .parseInt(maxVirtualNetworkSitesElement.getTextContent());
                    result.setMaximumVirtualNetworkSites(maxVirtualNetworkSitesInstance);
                }

                Element currentVirtualNetworkSitesElement = XmlUtility.getElementByTagNameNS(
                        subscriptionElement, "http://schemas.microsoft.com/windowsazure",
                        "CurrentVirtualNetworkSites");
                if (currentVirtualNetworkSitesElement != null) {
                    int currentVirtualNetworkSitesInstance;
                    currentVirtualNetworkSitesInstance = DatatypeConverter
                            .parseInt(currentVirtualNetworkSitesElement.getTextContent());
                    result.setCurrentVirtualNetworkSites(currentVirtualNetworkSitesInstance);
                }

                Element maxLocalNetworkSitesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxLocalNetworkSites");
                if (maxLocalNetworkSitesElement != null) {
                    int maxLocalNetworkSitesInstance;
                    maxLocalNetworkSitesInstance = DatatypeConverter
                            .parseInt(maxLocalNetworkSitesElement.getTextContent());
                    result.setMaximumLocalNetworkSites(maxLocalNetworkSitesInstance);
                }

                Element maxDnsServersElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxDnsServers");
                if (maxDnsServersElement != null) {
                    int maxDnsServersInstance;
                    maxDnsServersInstance = DatatypeConverter.parseInt(maxDnsServersElement.getTextContent());
                    result.setMaximumDnsServers(maxDnsServersInstance);
                }

                Element currentLocalNetworkSitesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentLocalNetworkSites");
                if (currentLocalNetworkSitesElement != null) {
                    int currentLocalNetworkSitesInstance;
                    currentLocalNetworkSitesInstance = DatatypeConverter
                            .parseInt(currentLocalNetworkSitesElement.getTextContent());
                    result.setCurrentLocalNetworkSites(currentLocalNetworkSitesInstance);
                }

                Element currentDnsServersElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentDnsServers");
                if (currentDnsServersElement != null) {
                    int currentDnsServersInstance;
                    currentDnsServersInstance = DatatypeConverter
                            .parseInt(currentDnsServersElement.getTextContent());
                    result.setCurrentDnsServers(currentDnsServersInstance);
                }
            }

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

/**
* The List Operating Systems operation lists the versions of the guest
* operating system that are currently available in Windows Azure. The
* 2010-10-28 version of List Operating Systems also indicates what family
* an operating system version belongs to. Currently Azure supports two
* operating system families: the Azure guest operating system that is
* substantially compatible with Windows Server 2008 SP2, and the Azure
* guest operating system that is substantially compatible with Windows
* Server 2008 R2.  (see/*from w w  w.j ava 2 s . co  m*/
* http://msdn.microsoft.com/en-us/library/windowsazure/ff684168.aspx for
* more information)
*
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The List Operating Systems operation response.
*/
@Override
public OperatingSystemListResponse list()
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate

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

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/operatingsystems";
    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
        OperatingSystemListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new OperatingSystemListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element operatingSystemsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "OperatingSystems");
            if (operatingSystemsSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(operatingSystemsSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "OperatingSystem")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element operatingSystemsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(operatingSystemsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "OperatingSystem")
                            .get(i1));
                    OperatingSystemListResponse.OperatingSystem operatingSystemInstance = new OperatingSystemListResponse.OperatingSystem();
                    result.getOperatingSystems().add(operatingSystemInstance);

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

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

                    Element isDefaultElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "IsDefault");
                    if (isDefaultElement != null) {
                        boolean isDefaultInstance;
                        isDefaultInstance = DatatypeConverter
                                .parseBoolean(isDefaultElement.getTextContent().toLowerCase());
                        operatingSystemInstance.setIsDefault(isDefaultInstance);
                    }

                    Element isActiveElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "IsActive");
                    if (isActiveElement != null) {
                        boolean isActiveInstance;
                        isActiveInstance = DatatypeConverter
                                .parseBoolean(isActiveElement.getTextContent().toLowerCase());
                        operatingSystemInstance.setIsActive(isActiveInstance);
                    }

                    Element familyElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "Family");
                    if (familyElement != null) {
                        int familyInstance;
                        familyInstance = DatatypeConverter.parseInt(familyElement.getTextContent());
                        operatingSystemInstance.setFamily(familyInstance);
                    }

                    Element familyLabelElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "FamilyLabel");
                    if (familyLabelElement != null) {
                        String familyLabelInstance;
                        familyLabelInstance = familyLabelElement.getTextContent() != null
                                ? new String(Base64.decode(familyLabelElement.getTextContent()))
                                : null;
                        operatingSystemInstance.setFamilyLabel(familyLabelInstance);
                    }
                }
            }

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

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

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

/**
* Begin deleting deployment.To determine whether the operation has finished
* processing the request, call GetLongRunningOperationStatus.
*
* @param resourceGroupName Required. The name of the resource group. The
* name is case insensitive.//w  w  w.  ja  v a 2s . co  m
* @param deploymentName Required. The name of the deployment to be deleted.
* @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 A standard service response for long running operations.
*/
@Override
public LongRunningOperationResponse beginDeleting(String resourceGroupName, String deploymentName)
        throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (resourceGroupName != null && resourceGroupName.length() > 1000) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (deploymentName == null) {
        throw new NullPointerException("deploymentName");
    }

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

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

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

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

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

        // Create Result
        LongRunningOperationResponse result = null;
        // Deserialize Response
        result = new LongRunningOperationResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_CONFLICT) {
            result.setStatus(OperationStatus.Failed);
        }
        if (statusCode == HttpStatus.SC_ACCEPTED) {
            result.setStatus(OperationStatus.InProgress);
        }
        if (statusCode == HttpStatus.SC_NO_CONTENT) {
            result.setStatus(OperationStatus.Succeeded);
        }

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

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

/**
* Deletes an existing namespace. This operation also removes all associated
* notificationHubs under the namespace.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj856296.aspx for
* more information)/*from ww  w  . j  a  va 2s  . c om*/
*
* @param resourceGroupName Required. The name of the resource group.
* @param namespaceName Required. The namespace name.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return The response of the CreateOrUpdate Api Management service long
* running operation.
*/
@Override
public NamespaceLongRunningResponse beginDelete(String resourceGroupName, String namespaceName)
        throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }

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

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

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

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

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

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

        if (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.ServerFarmOperationsImpl.java

/**
* You can create a server farm by issuing an HTTP POST request. Only one
* server farm per webspace is permitted. You can retrieve server farm
* details by using HTTP GET, change server farm properties by using HTTP
* PUT, and delete a server farm by using HTTP DELETE. A request body is
* required for server farm creation (HTTP POST) and server farm update
* (HTTP PUT). Warning: Creating a server farm changes your webspace's
* Compute Mode from Shared to Dedicated. You will be charged from the
* moment the server farm is created, even if all your sites are still
* running in Free mode.  (see/*from   w w w. ja  v  a2  s  . c o  m*/
* http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for
* more information)
*
* @param webSpaceName Required. The name of the web space.
* @param parameters Required. Parameters supplied to the Create Server Farm
* 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 Server Farm operation response.
*/
@Override
public ServerFarmCreateResponse create(String webSpaceName, ServerFarmCreateParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException,
        URISyntaxException {
    // Validate
    if (webSpaceName == null) {
        throw new NullPointerException("webSpaceName");
    }
    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("webSpaceName", webSpaceName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "createAsync", tracingParameters);
    }

    // Construct URL
    String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null
            ? this.getClient().getCredentials().getSubscriptionId().trim()
            : "") + "/services/WebSpaces/" + webSpaceName.trim() + "/ServerFarms";
    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;

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

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

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

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

    if (parameters.getCurrentNumberOfWorkers() != null) {
        Element currentNumberOfWorkersElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers");
        currentNumberOfWorkersElement.appendChild(
                requestDoc.createTextNode(Integer.toString(parameters.getCurrentNumberOfWorkers())));
        serverFarmElement.appendChild(currentNumberOfWorkersElement);
    }

    if (parameters.getCurrentWorkerSize() != null) {
        Element currentWorkerSizeElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize");
        currentWorkerSizeElement
                .appendChild(requestDoc.createTextNode(parameters.getCurrentWorkerSize().toString()));
        serverFarmElement.appendChild(currentWorkerSizeElement);
    }

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

    Element numberOfWorkersElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "NumberOfWorkers");
    numberOfWorkersElement
            .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getNumberOfWorkers())));
    serverFarmElement.appendChild(numberOfWorkersElement);

    Element workerSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "WorkerSize");
    workerSizeElement.appendChild(requestDoc.createTextNode(parameters.getWorkerSize().toString()));
    serverFarmElement.appendChild(workerSizeElement);

    if (parameters.getStatus() != null) {
        Element statusElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "Status");
        statusElement.appendChild(requestDoc.createTextNode(parameters.getStatus().toString()));
        serverFarmElement.appendChild(statusElement);
    }

    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
        ServerFarmCreateResponse result = null;
        // Deserialize Response
        InputStream responseContent = httpResponse.getEntity().getContent();
        result = new ServerFarmCreateResponse();
        DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
        documentBuilderFactory2.setNamespaceAware(true);
        DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
        Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));

        Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(responseDoc,
                "http://schemas.microsoft.com/windowsazure", "ServerFarm");
        if (serverFarmElement2 != null) {
            Element currentNumberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2,
                    "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers");
            if (currentNumberOfWorkersElement2 != null) {
                int currentNumberOfWorkersInstance;
                currentNumberOfWorkersInstance = DatatypeConverter
                        .parseInt(currentNumberOfWorkersElement2.getTextContent());
                result.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance);
            }

            Element currentWorkerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2,
                    "http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize");
            if (currentWorkerSizeElement2 != null) {
                ServerFarmWorkerSize currentWorkerSizeInstance;
                currentWorkerSizeInstance = ServerFarmWorkerSize
                        .valueOf(currentWorkerSizeElement2.getTextContent());
                result.setCurrentWorkerSize(currentWorkerSizeInstance);
            }

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

            Element numberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2,
                    "http://schemas.microsoft.com/windowsazure", "NumberOfWorkers");
            if (numberOfWorkersElement2 != null) {
                int numberOfWorkersInstance;
                numberOfWorkersInstance = DatatypeConverter.parseInt(numberOfWorkersElement2.getTextContent());
                result.setNumberOfWorkers(numberOfWorkersInstance);
            }

            Element workerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2,
                    "http://schemas.microsoft.com/windowsazure", "WorkerSize");
            if (workerSizeElement2 != null) {
                ServerFarmWorkerSize workerSizeInstance;
                workerSizeInstance = ServerFarmWorkerSize.valueOf(workerSizeElement2.getTextContent());
                result.setWorkerSize(workerSizeInstance);
            }

            Element statusElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2,
                    "http://schemas.microsoft.com/windowsazure", "Status");
            if (statusElement2 != null) {
                ServerFarmStatus statusInstance;
                statusInstance = ServerFarmStatus.valueOf(statusElement2.getTextContent());
                result.setStatus(statusInstance);
            }
        }

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