Java tutorial
/** * * 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.ServiceOperations; import com.microsoft.windowsazure.core.utils.BOMInputStream; import com.microsoft.windowsazure.core.utils.CollectionStringBuilder; import com.microsoft.windowsazure.core.utils.XmlUtility; import com.microsoft.windowsazure.exception.ServiceException; import com.microsoft.windowsazure.management.websites.models.SkuOptions; import com.microsoft.windowsazure.management.websites.models.WebSite; import com.microsoft.windowsazure.management.websites.models.WebSiteListParameters; import com.microsoft.windowsazure.management.websites.models.WebSiteRuntimeAvailabilityState; import com.microsoft.windowsazure.management.websites.models.WebSiteSslState; import com.microsoft.windowsazure.management.websites.models.WebSiteUsageState; import com.microsoft.windowsazure.management.websites.models.WebSpaceAvailabilityState; import com.microsoft.windowsazure.management.websites.models.WebSpaceStatus; import com.microsoft.windowsazure.management.websites.models.WebSpacesCreatePublishingUserParameters; import com.microsoft.windowsazure.management.websites.models.WebSpacesCreatePublishingUserResponse; import com.microsoft.windowsazure.management.websites.models.WebSpacesGetDnsSuffixResponse; import com.microsoft.windowsazure.management.websites.models.WebSpacesGetResponse; import com.microsoft.windowsazure.management.websites.models.WebSpacesListGeoRegionsResponse; import com.microsoft.windowsazure.management.websites.models.WebSpacesListPublishingUsersResponse; import com.microsoft.windowsazure.management.websites.models.WebSpacesListResponse; import com.microsoft.windowsazure.management.websites.models.WebSpacesListWebSitesResponse; import com.microsoft.windowsazure.management.websites.models.WorkerSizeOptions; import com.microsoft.windowsazure.tracing.CloudTracing; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; 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 java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.net.InetAddress; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.concurrent.Callable; import java.util.concurrent.Future; /** * Operations for managing web spaces beneath your subscription. */ public class WebSpaceOperationsImpl implements ServiceOperations<WebSiteManagementClientImpl>, WebSpaceOperations { /** * Initializes a new instance of the WebSpaceOperationsImpl class. * * @param client Reference to the service client. */ WebSpaceOperationsImpl(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; } /** * Creates a source control user with permissions to publish to this web * space. * * @param username Required. The user name. * @param password Required. The user password. * @param parameters Optional. Parameters supplied to the Create Publishing * User operation. * @return The Create Publishing User operation response. */ @Override public Future<WebSpacesCreatePublishingUserResponse> createPublishingUserAsync(final String username, final String password, final WebSpacesCreatePublishingUserParameters parameters) { return this.getClient().getExecutorService().submit(new Callable<WebSpacesCreatePublishingUserResponse>() { @Override public WebSpacesCreatePublishingUserResponse call() throws Exception { return createPublishingUser(username, password, parameters); } }); } /** * Creates a source control user with permissions to publish to this web * space. * * @param username Required. The user name. * @param password Required. The user password. * @param parameters Optional. Parameters supplied to the Create Publishing * User operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return The Create Publishing User operation response. */ @Override public WebSpacesCreatePublishingUserResponse createPublishingUser(String username, String password, WebSpacesCreatePublishingUserParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (username == null) { throw new NullPointerException("username"); } if (password == null) { throw new NullPointerException("password"); } if (parameters != null) { if (parameters.getPublishingPassword() == null) { throw new NullPointerException("parameters.PublishingPassword"); } if (parameters.getPublishingUserName() == null) { throw new NullPointerException("parameters.PublishingUserName"); } } // 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("username", username); tracingParameters.put("password", password); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createPublishingUserAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("properties=publishingCredentials"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2014-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); if (parameters != null) { Element userElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "User"); requestDoc.appendChild(userElement); if (parameters.getName() != null) { Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); userElement.appendChild(nameElement); } Element publishingPasswordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublishingPassword"); publishingPasswordElement.appendChild(requestDoc.createTextNode(parameters.getPublishingPassword())); userElement.appendChild(publishingPasswordElement); Element publishingUserNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublishingUserName"); publishingUserNameElement.appendChild(requestDoc.createTextNode(parameters.getPublishingUserName())); userElement.appendChild(publishingUserNameElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSpacesCreatePublishingUserResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesCreatePublishingUserResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element userElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "User"); if (userElement2 != null) { Element nameElement2 = XmlUtility.getElementByTagNameNS(userElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); result.setName(nameInstance); } Element publishingPasswordElement2 = XmlUtility.getElementByTagNameNS(userElement2, "http://schemas.microsoft.com/windowsazure", "PublishingPassword"); if (publishingPasswordElement2 != null) { String publishingPasswordInstance; publishingPasswordInstance = publishingPasswordElement2.getTextContent(); result.setPublishingPassword(publishingPasswordInstance); } Element publishingUserNameElement2 = XmlUtility.getElementByTagNameNS(userElement2, "http://schemas.microsoft.com/windowsazure", "PublishingUserName"); if (publishingUserNameElement2 != null) { String publishingUserNameInstance; publishingUserNameInstance = publishingUserNameElement2.getTextContent(); result.setPublishingUserName(publishingUserNameInstance); } } } 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 retrieve details for a specified web space name by issuing an * HTTP GET request. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn167017.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @return The Get Web Space Details operation response. */ @Override public Future<WebSpacesGetResponse> getAsync(final String webSpaceName) { return this.getClient().getExecutorService().submit(new Callable<WebSpacesGetResponse>() { @Override public WebSpacesGetResponse call() throws Exception { return get(webSpaceName); } }); } /** * You can retrieve details for a specified web space name by issuing an * HTTP GET request. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn167017.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. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Get Web Space Details operation response. */ @Override public WebSpacesGetResponse get(String webSpaceName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "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-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 WebSpacesGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element webSpaceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { Element availabilityStateElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); result.setAvailabilityState(availabilityStateInstance); } Element currentNumberOfWorkersElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); if (currentNumberOfWorkersElement != null && currentNumberOfWorkersElement.getTextContent() != null && !currentNumberOfWorkersElement.getTextContent().isEmpty()) { boolean isNil = false; Attr nilAttribute = currentNumberOfWorkersElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { int currentNumberOfWorkersInstance; currentNumberOfWorkersInstance = DatatypeConverter .parseInt(currentNumberOfWorkersElement.getTextContent()); result.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance); } } Element currentWorkerSizeElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); if (currentWorkerSizeElement != null && currentWorkerSizeElement.getTextContent() != null && !currentWorkerSizeElement.getTextContent().isEmpty()) { boolean isNil2 = false; Attr nilAttribute2 = currentWorkerSizeElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { WorkerSizeOptions currentWorkerSizeInstance; currentWorkerSizeInstance = WorkerSizeOptions .valueOf(currentWorkerSizeElement.getTextContent()); result.setCurrentWorkerSize(currentWorkerSizeInstance); } } Element geoLocationElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "GeoLocation"); if (geoLocationElement != null) { String geoLocationInstance; geoLocationInstance = geoLocationElement.getTextContent(); result.setGeoLocation(geoLocationInstance); } Element geoRegionElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "GeoRegion"); if (geoRegionElement != null) { String geoRegionInstance; geoRegionInstance = geoRegionElement.getTextContent(); result.setGeoRegion(geoRegionInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); result.setName(nameInstance); } Element planElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "Plan"); if (planElement != null) { String planInstance; planInstance = planElement.getTextContent(); result.setPlan(planInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { WebSpaceStatus statusInstance; statusInstance = WebSpaceStatus.valueOf(statusElement.getTextContent()); result.setStatus(statusInstance); } Element subscriptionElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "Subscription"); if (subscriptionElement != null) { String subscriptionInstance; subscriptionInstance = subscriptionElement.getTextContent(); result.setSubscription(subscriptionInstance); } Element workerSizeElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement != null && workerSizeElement.getTextContent() != null && !workerSizeElement.getTextContent().isEmpty()) { WorkerSizeOptions workerSizeInstance; workerSizeInstance = WorkerSizeOptions.valueOf(workerSizeElement.getTextContent()); result.setWorkerSize(workerSizeInstance); } } } 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(); } } } /** * Get the DNS Suffix for this subscription. * * @return The Get DNS Suffix operation response. */ @Override public Future<WebSpacesGetDnsSuffixResponse> getDnsSuffixAsync() { return this.getClient().getExecutorService().submit(new Callable<WebSpacesGetDnsSuffixResponse>() { @Override public WebSpacesGetDnsSuffixResponse call() throws Exception { return getDnsSuffix(); } }); } /** * Get the DNS Suffix for this subscription. * * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws 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 Get DNS Suffix operation response. */ @Override public WebSpacesGetDnsSuffixResponse getDnsSuffix() 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, "getDnsSuffixAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("properties=dnssuffix"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2014-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSpacesGetDnsSuffixResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesGetDnsSuffixResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element stringElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/2003/10/Serialization/", "string"); if (stringElement != null) { result.setDnsSuffix(stringElement.getTextContent()); } } 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 list the web spaces under the current subscription by issuing a * GET request. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn166961.aspx for * more information) * * @return The List Web Spaces operation response. */ @Override public Future<WebSpacesListResponse> listAsync() { return this.getClient().getExecutorService().submit(new Callable<WebSpacesListResponse>() { @Override public WebSpacesListResponse call() throws Exception { return list(); } }); } /** * You can list the web spaces under the current subscription by issuing a * GET request. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn166961.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. * @return The List Web Spaces operation response. */ @Override public WebSpacesListResponse list() throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); CloudTracing.enter(invocationId, this, "listAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2014-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSpacesListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element webSpacesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "WebSpaces"); if (webSpacesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(webSpacesSequenceElement, "http://schemas.microsoft.com/windowsazure", "WebSpace") .size(); i1 = i1 + 1) { org.w3c.dom.Element webSpacesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(webSpacesSequenceElement, "http://schemas.microsoft.com/windowsazure", "WebSpace") .get(i1)); WebSpacesListResponse.WebSpace webSpaceInstance = new WebSpacesListResponse.WebSpace(); result.getWebSpaces().add(webSpaceInstance); Element availabilityStateElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); webSpaceInstance.setAvailabilityState(availabilityStateInstance); } Element currentNumberOfWorkersElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); if (currentNumberOfWorkersElement != null && currentNumberOfWorkersElement.getTextContent() != null && !currentNumberOfWorkersElement.getTextContent().isEmpty()) { boolean isNil = false; Attr nilAttribute = currentNumberOfWorkersElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { int currentNumberOfWorkersInstance; currentNumberOfWorkersInstance = DatatypeConverter .parseInt(currentNumberOfWorkersElement.getTextContent()); webSpaceInstance.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance); } } Element currentWorkerSizeElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); if (currentWorkerSizeElement != null && currentWorkerSizeElement.getTextContent() != null && !currentWorkerSizeElement.getTextContent().isEmpty()) { boolean isNil2 = false; Attr nilAttribute2 = currentWorkerSizeElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { WorkerSizeOptions currentWorkerSizeInstance; currentWorkerSizeInstance = WorkerSizeOptions .valueOf(currentWorkerSizeElement.getTextContent()); webSpaceInstance.setCurrentWorkerSize(currentWorkerSizeInstance); } } Element geoLocationElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "GeoLocation"); if (geoLocationElement != null) { String geoLocationInstance; geoLocationInstance = geoLocationElement.getTextContent(); webSpaceInstance.setGeoLocation(geoLocationInstance); } Element geoRegionElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "GeoRegion"); if (geoRegionElement != null) { String geoRegionInstance; geoRegionInstance = geoRegionElement.getTextContent(); webSpaceInstance.setGeoRegion(geoRegionInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); webSpaceInstance.setName(nameInstance); } Element planElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "Plan"); if (planElement != null) { String planInstance; planInstance = planElement.getTextContent(); webSpaceInstance.setPlan(planInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { WebSpaceStatus statusInstance; statusInstance = WebSpaceStatus.valueOf(statusElement.getTextContent()); webSpaceInstance.setStatus(statusInstance); } Element subscriptionElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "Subscription"); if (subscriptionElement != null) { String subscriptionInstance; subscriptionInstance = subscriptionElement.getTextContent(); webSpaceInstance.setSubscription(subscriptionInstance); } Element workerSizeElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement != null && workerSizeElement.getTextContent() != null && !workerSizeElement.getTextContent().isEmpty()) { WorkerSizeOptions workerSizeInstance; workerSizeInstance = WorkerSizeOptions.valueOf(workerSizeElement.getTextContent()); webSpaceInstance.setWorkerSize(workerSizeInstance); } } } } 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(); } } } /** * Get the available geo regions for this web space. * * @return The List Geo Regions operation response. */ @Override public Future<WebSpacesListGeoRegionsResponse> listGeoRegionsAsync() { return this.getClient().getExecutorService().submit(new Callable<WebSpacesListGeoRegionsResponse>() { @Override public WebSpacesListGeoRegionsResponse call() throws Exception { return listGeoRegions(); } }); } /** * Get the available geo regions for this 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 Geo Regions operation response. */ @Override public WebSpacesListGeoRegionsResponse listGeoRegions() 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, "listGeoRegionsAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("properties=georegions"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2014-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSpacesListGeoRegionsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesListGeoRegionsResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element geoRegionsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GeoRegions"); if (geoRegionsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(geoRegionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "GeoRegion") .size(); i1 = i1 + 1) { org.w3c.dom.Element geoRegionsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(geoRegionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "GeoRegion") .get(i1)); WebSpacesListGeoRegionsResponse.GeoRegion geoRegionInstance = new WebSpacesListGeoRegionsResponse.GeoRegion(); result.getGeoRegions().add(geoRegionInstance); Element descriptionElement = XmlUtility.getElementByTagNameNS(geoRegionsElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); geoRegionInstance.setDescription(descriptionInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(geoRegionsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); geoRegionInstance.setName(nameInstance); } Element sortOrderElement = XmlUtility.getElementByTagNameNS(geoRegionsElement, "http://schemas.microsoft.com/windowsazure", "SortOrder"); if (sortOrderElement != null && sortOrderElement.getTextContent() != null && !sortOrderElement.getTextContent().isEmpty()) { boolean isNil = false; Attr nilAttribute = sortOrderElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { int sortOrderInstance; sortOrderInstance = DatatypeConverter.parseInt(sortOrderElement.getTextContent()); geoRegionInstance.setSortOrder(sortOrderInstance); } } } } } 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(); } } } /** * Get the source control users allowed to publish to this web space. * * @return The List Publishing Users operation response. */ @Override public Future<WebSpacesListPublishingUsersResponse> listPublishingUsersAsync() { return this.getClient().getExecutorService().submit(new Callable<WebSpacesListPublishingUsersResponse>() { @Override public WebSpacesListPublishingUsersResponse call() throws Exception { return listPublishingUsers(); } }); } /** * Get the source control users allowed to publish to this 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 Publishing Users operation response. */ @Override public WebSpacesListPublishingUsersResponse listPublishingUsers() 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, "listPublishingUsersAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("properties=publishingUsers"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2014-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSpacesListPublishingUsersResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesListPublishingUsersResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element arrayOfstringSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring"); if (arrayOfstringSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(arrayOfstringSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i1 = i1 + 1) { org.w3c.dom.Element arrayOfstringElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(arrayOfstringSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i1)); WebSpacesListPublishingUsersResponse.User stringInstance = new WebSpacesListPublishingUsersResponse.User(); result.getUsers().add(stringInstance); String stringInstance2; stringInstance2 = arrayOfstringElement.getTextContent(); stringInstance.setName(stringInstance2); } } } 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 retrieve a list of all web sites in a web space by issuing an * HTTP GET request. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn236429.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param parameters Optional. Additional parameters. * @return The List Web Sites operation response. */ @Override public Future<WebSpacesListWebSitesResponse> listWebSitesAsync(final String webSpaceName, final WebSiteListParameters parameters) { return this.getClient().getExecutorService().submit(new Callable<WebSpacesListWebSitesResponse>() { @Override public WebSpacesListWebSitesResponse call() throws Exception { return listWebSites(webSpaceName, parameters); } }); } /** * You can retrieve a list of all web sites in a web space by issuing an * HTTP GET request. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn236429.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param parameters Optional. Additional parameters. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The List Web Sites operation response. */ @Override public WebSpacesListWebSitesResponse listWebSites(String webSpaceName, WebSiteListParameters parameters) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "listWebSitesAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites"; ArrayList<String> queryParameters = new ArrayList<String>(); if (parameters != null && parameters.getPropertiesToInclude() != null && parameters.getPropertiesToInclude().size() > 0) { queryParameters.add("propertiesToInclude=" + URLEncoder .encode(CollectionStringBuilder.join(parameters.getPropertiesToInclude(), ","), "UTF-8")); } if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2014-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSpacesListWebSitesResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesListWebSitesResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element sitesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Sites"); if (sitesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(sitesSequenceElement, "http://schemas.microsoft.com/windowsazure", "Site") .size(); i1 = i1 + 1) { org.w3c.dom.Element sitesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(sitesSequenceElement, "http://schemas.microsoft.com/windowsazure", "Site") .get(i1)); WebSite siteInstance = new WebSite(); result.getWebSites().add(siteInstance); Element adminEnabledElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "AdminEnabled"); if (adminEnabledElement != null && adminEnabledElement.getTextContent() != null && !adminEnabledElement.getTextContent().isEmpty()) { boolean adminEnabledInstance; adminEnabledInstance = DatatypeConverter .parseBoolean(adminEnabledElement.getTextContent().toLowerCase()); siteInstance.setAdminEnabled(adminEnabledInstance); } Element availabilityStateElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); siteInstance.setAvailabilityState(availabilityStateInstance); } Element sKUElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement != null && sKUElement.getTextContent() != null && !sKUElement.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent()); siteInstance.setSku(sKUInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null && enabledElement.getTextContent() != null && !enabledElement.getTextContent().isEmpty()) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); siteInstance.setEnabled(enabledInstance); } Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "EnabledHostNames"); if (enabledHostNamesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i2 = i2 + 1) { org.w3c.dom.Element enabledHostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i2)); siteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent()); } } Element hostNameSslStatesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); if (hostNameSslStatesSequenceElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .size(); i3 = i3 + 1) { org.w3c.dom.Element hostNameSslStatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .get(i3)); WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState(); siteInstance.getHostNameSslStates().add(hostNameSslStateInstance); Element nameElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); hostNameSslStateInstance.setName(nameInstance); } Element sslStateElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "SslState"); if (sslStateElement != null && sslStateElement.getTextContent() != null && !sslStateElement.getTextContent().isEmpty()) { WebSiteSslState sslStateInstance; sslStateInstance = WebSiteSslState.valueOf(sslStateElement.getTextContent()); hostNameSslStateInstance.setSslState(sslStateInstance); } Element thumbprintElement = XmlUtility.getElementByTagNameNS( hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Thumbprint"); if (thumbprintElement != null) { boolean isNil = false; Attr nilAttribute = thumbprintElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String thumbprintInstance; thumbprintInstance = thumbprintElement.getTextContent(); hostNameSslStateInstance.setThumbprint(thumbprintInstance); } } Element virtualIPElement = XmlUtility.getElementByTagNameNS( hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP"); if (virtualIPElement != null) { boolean isNil2 = false; Attr nilAttribute2 = virtualIPElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { InetAddress virtualIPInstance; virtualIPInstance = InetAddress .getByName(virtualIPElement.getTextContent()); hostNameSslStateInstance.setVirtualIP(virtualIPInstance); } } } } Element hostNamesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "HostNames"); if (hostNamesSequenceElement != null) { for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i4 = i4 + 1) { org.w3c.dom.Element hostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i4)); siteInstance.getHostNames().add(hostNamesElement.getTextContent()); } } Element lastModifiedTimeUtcElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "LastModifiedTimeUtc"); if (lastModifiedTimeUtcElement != null && lastModifiedTimeUtcElement.getTextContent() != null && !lastModifiedTimeUtcElement.getTextContent().isEmpty()) { Calendar lastModifiedTimeUtcInstance; lastModifiedTimeUtcInstance = DatatypeConverter .parseDateTime(lastModifiedTimeUtcElement.getTextContent()); siteInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance2; nameInstance2 = nameElement2.getTextContent(); siteInstance.setName(nameInstance2); } Element repositorySiteNameElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "RepositorySiteName"); if (repositorySiteNameElement != null) { String repositorySiteNameInstance; repositorySiteNameInstance = repositorySiteNameElement.getTextContent(); siteInstance.setRepositorySiteName(repositorySiteNameInstance); } Element runtimeAvailabilityStateElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "RuntimeAvailabilityState"); if (runtimeAvailabilityStateElement != null && runtimeAvailabilityStateElement.getTextContent() != null && !runtimeAvailabilityStateElement.getTextContent().isEmpty()) { WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance; runtimeAvailabilityStateInstance = WebSiteRuntimeAvailabilityState .valueOf(runtimeAvailabilityStateElement.getTextContent()); siteInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance); } Element selfLinkElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "SelfLink"); if (selfLinkElement != null) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkElement.getTextContent()); siteInstance.setUri(selfLinkInstance); } Element serverFarmElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement != null) { String serverFarmInstance; serverFarmInstance = serverFarmElement.getTextContent(); siteInstance.setServerFarm(serverFarmInstance); } Element sitePropertiesElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "SiteProperties"); if (sitePropertiesElement != null) { WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties(); siteInstance.setSiteProperties(sitePropertiesInstance); Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS( sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AppSettings"); if (appSettingsSequenceElement != null) { for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i5 = i5 + 1) { org.w3c.dom.Element appSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i5)); String appSettingsKey = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String appSettingsValue = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } Element metadataSequenceElement = XmlUtility.getElementByTagNameNS( sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Metadata"); if (metadataSequenceElement != null) { for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i6 = i6 + 1) { org.w3c.dom.Element metadataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i6)); String metadataKey = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String metadataValue = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue); } } Element propertiesSequenceElement = XmlUtility.getElementByTagNameNS( sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Properties"); if (propertiesSequenceElement != null) { for (int i7 = 0; i7 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i7 = i7 + 1) { org.w3c.dom.Element propertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i7)); String propertiesKey = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String propertiesValue = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue); } } } Element stateElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); siteInstance.setState(stateInstance); } Element usageStateElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "UsageState"); if (usageStateElement != null && usageStateElement.getTextContent() != null && !usageStateElement.getTextContent().isEmpty()) { WebSiteUsageState usageStateInstance; usageStateInstance = WebSiteUsageState.valueOf(usageStateElement.getTextContent()); siteInstance.setUsageState(usageStateInstance); } Element webSpaceElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { String webSpaceInstance; webSpaceInstance = webSpaceElement.getTextContent(); siteInstance.setWebSpace(webSpaceInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } } }