com.microsoft.windowsazure.management.websites.ServerFarmOperationsImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.microsoft.windowsazure.management.websites.ServerFarmOperationsImpl.java

Source

/**
 * 
 * Copyright (c) Microsoft and contributors.  All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * 
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

// Warning: This code was generated by a tool.
// 
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

package com.microsoft.windowsazure.management.websites;

import com.microsoft.windowsazure.core.OperationResponse;
import com.microsoft.windowsazure.core.ServiceOperations;
import com.microsoft.windowsazure.core.pipeline.apache.CustomHttpDelete;
import com.microsoft.windowsazure.core.utils.BOMInputStream;
import com.microsoft.windowsazure.core.utils.XmlUtility;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.management.websites.models.ServerFarmCreateParameters;
import com.microsoft.windowsazure.management.websites.models.ServerFarmCreateResponse;
import com.microsoft.windowsazure.management.websites.models.ServerFarmGetResponse;
import com.microsoft.windowsazure.management.websites.models.ServerFarmListResponse;
import com.microsoft.windowsazure.management.websites.models.ServerFarmStatus;
import com.microsoft.windowsazure.management.websites.models.ServerFarmUpdateParameters;
import com.microsoft.windowsazure.management.websites.models.ServerFarmUpdateResponse;
import com.microsoft.windowsazure.management.websites.models.ServerFarmWorkerSize;
import com.microsoft.windowsazure.tracing.CloudTracing;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import javax.xml.bind.DatatypeConverter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

/**
* Operations for managing the server farm in a web space.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for more
* information)
*/
public class ServerFarmOperationsImpl
        implements ServiceOperations<WebSiteManagementClientImpl>, ServerFarmOperations {
    /**
    * Initializes a new instance of the ServerFarmOperationsImpl class.
    *
    * @param client Reference to the service client.
    */
    ServerFarmOperationsImpl(WebSiteManagementClientImpl client) {
        this.client = client;
    }

    private WebSiteManagementClientImpl client;

    /**
    * Gets a reference to the
    * microsoft.windowsazure.management.websites.WebSiteManagementClientImpl.
    * @return The Client value.
    */
    public WebSiteManagementClientImpl getClient() {
        return this.client;
    }

    /**
    * 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
    * 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.
    * @return The Create Server Farm operation response.
    */
    @Override
    public Future<ServerFarmCreateResponse> createAsync(final String webSpaceName,
            final ServerFarmCreateParameters parameters) {
        return this.getClient().getExecutorService().submit(new Callable<ServerFarmCreateResponse>() {
            @Override
            public ServerFarmCreateResponse call() throws Exception {
                return create(webSpaceName, parameters);
            }
        });
    }

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

    /**
    * 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
    * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for
    * more information)
    *
    * @param webSpaceName Required. The name of the web space.
    * @return A standard service response including an HTTP status code and
    * request ID.
    */
    @Override
    public Future<OperationResponse> deleteAsync(final String webSpaceName) {
        return this.getClient().getExecutorService().submit(new Callable<OperationResponse>() {
            @Override
            public OperationResponse call() throws Exception {
                return delete(webSpaceName);
            }
        });
    }

    /**
    * 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
    * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for
    * more information)
    *
    * @param webSpaceName Required. The name of the web space.
    * @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 including an HTTP status code and
    * request ID.
    */
    @Override
    public OperationResponse delete(String webSpaceName) throws IOException, ServiceException {
        // 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);
            CloudTracing.enter(invocationId, this, "deleteAsync", tracingParameters);
        }

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

        // Set Headers
        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
            OperationResponse result = null;
            result = new OperationResponse();
            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();
            }
        }
    }

    /**
    * 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
    * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for
    * more information)
    *
    * @param webSpaceName Required. The name of the web space.
    * @param serverFarmName Required. The name of the server farm.
    * @return The Get Server Farm operation response.
    */
    @Override
    public Future<ServerFarmGetResponse> getAsync(final String webSpaceName, final String serverFarmName) {
        return this.getClient().getExecutorService().submit(new Callable<ServerFarmGetResponse>() {
            @Override
            public ServerFarmGetResponse call() throws Exception {
                return get(webSpaceName, serverFarmName);
            }
        });
    }

    /**
    * 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
    * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for
    * more information)
    *
    * @param webSpaceName Required. The name of the web space.
    * @param serverFarmName Required. The name of the server farm.
    * @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 Server Farm operation response.
    */
    @Override
    public ServerFarmGetResponse get(String webSpaceName, String serverFarmName)
            throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
        // Validate
        if (webSpaceName == null) {
            throw new NullPointerException("webSpaceName");
        }
        if (serverFarmName == null) {
            throw new NullPointerException("serverFarmName");
        }

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

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

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

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

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

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

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

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

                Element statusElement = XmlUtility.getElementByTagNameNS(serverFarmElement,
                        "http://schemas.microsoft.com/windowsazure", "Status");
                if (statusElement != null) {
                    ServerFarmStatus statusInstance;
                    statusInstance = ServerFarmStatus.valueOf(statusElement.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();
            }
        }
    }

    /**
    * 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
    * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for
    * more information)
    *
    * @param webSpaceName Required. The name of the web space.
    * @return The List Server Farm operation response.
    */
    @Override
    public Future<ServerFarmListResponse> listAsync(final String webSpaceName) {
        return this.getClient().getExecutorService().submit(new Callable<ServerFarmListResponse>() {
            @Override
            public ServerFarmListResponse call() throws Exception {
                return list(webSpaceName);
            }
        });
    }

    /**
    * 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
    * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for
    * more information)
    *
    * @param webSpaceName Required. The name of the web space.
    * @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 Server Farm operation response.
    */
    @Override
    public ServerFarmListResponse list(String webSpaceName)
            throws IOException, ServiceException, ParserConfigurationException, SAXException {
        // 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);
            CloudTracing.enter(invocationId, this, "listAsync", 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
        HttpGet httpRequest = new HttpGet(url);

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

            Element serverFarmsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ServerFarms");
            if (serverFarmsSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(serverFarmsSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "ServerFarm")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element serverFarmsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(serverFarmsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "ServerFarm")
                            .get(i1));
                    ServerFarmListResponse.ServerFarm serverFarmInstance = new ServerFarmListResponse.ServerFarm();
                    result.getServerFarms().add(serverFarmInstance);

                    Element currentNumberOfWorkersElement = XmlUtility.getElementByTagNameNS(serverFarmsElement,
                            "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers");
                    if (currentNumberOfWorkersElement != null) {
                        int currentNumberOfWorkersInstance;
                        currentNumberOfWorkersInstance = DatatypeConverter
                                .parseInt(currentNumberOfWorkersElement.getTextContent());
                        serverFarmInstance.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance);
                    }

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

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

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

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

                    Element statusElement = XmlUtility.getElementByTagNameNS(serverFarmsElement,
                            "http://schemas.microsoft.com/windowsazure", "Status");
                    if (statusElement != null) {
                        ServerFarmStatus statusInstance;
                        statusInstance = ServerFarmStatus.valueOf(statusElement.getTextContent());
                        serverFarmInstance.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();
            }
        }
    }

    /**
    * 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
    * 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 Update Server Farm
    * operation.
    * @return The Update Server Farm operation response.
    */
    @Override
    public Future<ServerFarmUpdateResponse> updateAsync(final String webSpaceName,
            final ServerFarmUpdateParameters parameters) {
        return this.getClient().getExecutorService().submit(new Callable<ServerFarmUpdateResponse>() {
            @Override
            public ServerFarmUpdateResponse call() throws Exception {
                return update(webSpaceName, parameters);
            }
        });
    }

    /**
    * 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
    * 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 Update 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 Update Server Farm operation response.
    */
    @Override
    public ServerFarmUpdateResponse update(String webSpaceName, ServerFarmUpdateParameters 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, "updateAsync", tracingParameters);
        }

        // Construct URL
        String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null
                ? this.getClient().getCredentials().getSubscriptionId().trim()
                : "") + "/services/WebSpaces/" + webSpaceName.trim() + "/ServerFarms/DefaultServerFarm";
        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
        HttpPut httpRequest = new HttpPut(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
            ServerFarmUpdateResponse result = null;
            // Deserialize Response
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServerFarmUpdateResponse();
            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();
            }
        }
    }
}