List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationsImpl.java
/** * Returns information about an Azure SQL Database event logs. * * @param serverName Required. The name of the Azure SQL Database Server on * which the database is hosted./*from w ww . java 2 s. co m*/ * @param databaseName Required. The name of the Azure SQL Database to be * retrieved. * @param parameters Required. The parameters for the Get Database Event * Logs operation. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return Contains the response to a Get Database Event Logs request. */ @Override public DatabaseGetEventLogsResponse getEventLogs(String serverName, String databaseName, DatabaseGetEventLogsParameters parameters) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getEventTypes() == null) { throw new NullPointerException("parameters.EventTypes"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("databaseName", databaseName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "getEventLogsAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases/"; url = url + URLEncoder.encode(databaseName, "UTF-8"); url = url + "/events"; ArrayList<String> queryParameters = new ArrayList<String>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); queryParameters.add("startDate=" + URLEncoder.encode(simpleDateFormat.format(parameters.getStartDate().getTime()), "UTF-8")); queryParameters.add("intervalSizeInMinutes=" + URLEncoder.encode(Integer.toString(parameters.getIntervalSizeInMinutes()), "UTF-8")); queryParameters.add("eventTypes=" + URLEncoder.encode(parameters.getEventTypes(), "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", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseGetEventLogsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseGetEventLogsResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); DatabaseEventLog serviceResourceInstance = new DatabaseEventLog(); result.getEventLogs().add(serviceResourceInstance); Element databaseNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "DatabaseName"); if (databaseNameElement != null) { String databaseNameInstance; databaseNameInstance = databaseNameElement.getTextContent(); serviceResourceInstance.setDatabaseName(databaseNameInstance); } Element startTimeUtcElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "StartTimeUtc"); if (startTimeUtcElement != null) { Calendar startTimeUtcInstance; startTimeUtcInstance = DatatypeConverter .parseDateTime(startTimeUtcElement.getTextContent()); serviceResourceInstance.setStartTimeUtc(startTimeUtcInstance); } Element intervalSizeInMinutesElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IntervalSizeInMinutes"); if (intervalSizeInMinutesElement != null) { int intervalSizeInMinutesInstance; intervalSizeInMinutesInstance = DatatypeConverter .parseInt(intervalSizeInMinutesElement.getTextContent()); serviceResourceInstance.setIntervalSizeInMinutes(intervalSizeInMinutesInstance); } Element eventCategoryElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EventCategory"); if (eventCategoryElement != null) { String eventCategoryInstance; eventCategoryInstance = eventCategoryElement.getTextContent(); serviceResourceInstance.setEventCategory(eventCategoryInstance); } Element eventTypeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EventType"); if (eventTypeElement != null) { String eventTypeInstance; eventTypeInstance = eventTypeElement.getTextContent(); serviceResourceInstance.setEventType(eventTypeInstance); } Element eventSubtypeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EventSubtype"); if (eventSubtypeElement != null) { String eventSubtypeInstance; eventSubtypeInstance = eventSubtypeElement.getTextContent(); serviceResourceInstance.setEventSubtype(eventSubtypeInstance); } Element eventSubtypeDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EventSubtypeDescription"); if (eventSubtypeDescriptionElement != null) { String eventSubtypeDescriptionInstance; eventSubtypeDescriptionInstance = eventSubtypeDescriptionElement.getTextContent(); serviceResourceInstance.setEventSubtypeDescription(eventSubtypeDescriptionInstance); } Element numberOfEventsElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "NumberOfEvents"); if (numberOfEventsElement != null) { int numberOfEventsInstance; numberOfEventsInstance = DatatypeConverter .parseInt(numberOfEventsElement.getTextContent()); serviceResourceInstance.setNumberOfEvents(numberOfEventsInstance); } Element severityElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Severity"); if (severityElement != null) { int severityInstance; severityInstance = DatatypeConverter.parseInt(severityElement.getTextContent()); serviceResourceInstance.setSeverity(severityInstance); } Element descriptionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); serviceResourceInstance.setDescription(descriptionInstance); } Element additionalDataElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "AdditionalData"); if (additionalDataElement != null) { boolean isNil = false; Attr nilAttribute = additionalDataElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String additionalDataInstance; additionalDataInstance = additionalDataElement.getTextContent(); serviceResourceInstance.setAdditionalData(additionalDataInstance); } } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * You can retrieve the publish settings information for a web site by * issuing an HTTP GET request. (see/*from w w w . java 2 s. c om*/ * http://msdn.microsoft.com/en-us/library/windowsazure/dn166996.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @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 Publish Profile Web Site operation response. */ @Override public WebSiteGetPublishProfileResponse getPublishProfile(String webSpaceName, String webSiteName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } // 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("webSiteName", webSiteName); CloudTracing.enter(invocationId, this, "getPublishProfileAsync", 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/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); url = url + "/publishxml"; 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 WebSiteGetPublishProfileResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetPublishProfileResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element publishDataElement = XmlUtility.getElementByTagNameNS(responseDoc, "", "publishData"); if (publishDataElement != null) { if (publishDataElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(publishDataElement, "", "publishProfile") .size(); i1 = i1 + 1) { org.w3c.dom.Element publishProfilesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(publishDataElement, "", "publishProfile").get(i1)); WebSiteGetPublishProfileResponse.PublishProfile publishProfileInstance = new WebSiteGetPublishProfileResponse.PublishProfile(); result.getPublishProfiles().add(publishProfileInstance); Attr profileNameAttribute = publishProfilesElement.getAttributeNodeNS("", "profileName"); if (profileNameAttribute != null) { publishProfileInstance.setProfileName(profileNameAttribute.getValue()); } Attr publishMethodAttribute = publishProfilesElement.getAttributeNodeNS("", "publishMethod"); if (publishMethodAttribute != null) { publishProfileInstance.setPublishMethod(publishMethodAttribute.getValue()); } Attr publishUrlAttribute = publishProfilesElement.getAttributeNodeNS("", "publishUrl"); if (publishUrlAttribute != null) { publishProfileInstance.setPublishUrl(publishUrlAttribute.getValue()); } Attr msdeploySiteAttribute = publishProfilesElement.getAttributeNodeNS("", "msdeploySite"); if (msdeploySiteAttribute != null) { publishProfileInstance.setMSDeploySite(msdeploySiteAttribute.getValue()); } Attr ftpPassiveModeAttribute = publishProfilesElement.getAttributeNodeNS("", "ftpPassiveMode"); if (ftpPassiveModeAttribute != null) { publishProfileInstance.setFtpPassiveMode(DatatypeConverter .parseBoolean(ftpPassiveModeAttribute.getValue().toLowerCase())); } Attr userNameAttribute = publishProfilesElement.getAttributeNodeNS("", "userName"); if (userNameAttribute != null) { publishProfileInstance.setUserName(userNameAttribute.getValue()); } Attr userPWDAttribute = publishProfilesElement.getAttributeNodeNS("", "userPWD"); if (userPWDAttribute != null) { publishProfileInstance.setUserPassword(userPWDAttribute.getValue()); } Attr destinationAppUrlAttribute = publishProfilesElement.getAttributeNodeNS("", "destinationAppUrl"); if (destinationAppUrlAttribute != null) { publishProfileInstance .setDestinationAppUri(new URI(destinationAppUrlAttribute.getValue())); } Attr sQLServerDBConnectionStringAttribute = publishProfilesElement .getAttributeNodeNS("", "SQLServerDBConnectionString"); if (sQLServerDBConnectionStringAttribute != null) { publishProfileInstance.setSqlServerConnectionString( sQLServerDBConnectionStringAttribute.getValue()); } Attr mySQLDBConnectionStringAttribute = publishProfilesElement.getAttributeNodeNS("", "mySQLDBConnectionString"); if (mySQLDBConnectionStringAttribute != null) { publishProfileInstance .setMySqlConnectionString(mySQLDBConnectionStringAttribute.getValue()); } Attr hostingProviderForumLinkAttribute = publishProfilesElement.getAttributeNodeNS("", "hostingProviderForumLink"); if (hostingProviderForumLinkAttribute != null) { publishProfileInstance.setHostingProviderForumUri( new URI(hostingProviderForumLinkAttribute.getValue())); } Attr controlPanelLinkAttribute = publishProfilesElement.getAttributeNodeNS("", "controlPanelLink"); if (controlPanelLinkAttribute != null) { publishProfileInstance .setControlPanelUri(new URI(controlPanelLinkAttribute.getValue())); } Element databasesSequenceElement = XmlUtility .getElementByTagNameNS(publishProfilesElement, "", "databases"); if (databasesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement, "", "add") .size(); i2 = i2 + 1) { org.w3c.dom.Element databasesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement, "", "add").get(i2)); WebSiteGetPublishProfileResponse.Database addInstance = new WebSiteGetPublishProfileResponse.Database(); publishProfileInstance.getDatabases().add(addInstance); Attr nameAttribute = databasesElement.getAttributeNodeNS("", "name"); if (nameAttribute != null) { addInstance.setName(nameAttribute.getValue()); } Attr connectionStringAttribute = databasesElement.getAttributeNodeNS("", "connectionString"); if (connectionStringAttribute != null) { addInstance.setConnectionString(connectionStringAttribute.getValue()); } Attr providerNameAttribute = databasesElement.getAttributeNodeNS("", "providerName"); if (providerNameAttribute != null) { addInstance.setProviderName(providerNameAttribute.getValue()); } Attr typeAttribute = databasesElement.getAttributeNodeNS("", "type"); if (typeAttribute != null) { addInstance.setType(typeAttribute.getValue()); } } } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * You can swap a web site from one slot to another slot. * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @param sourceSlotName Required. The name of the first web site slot to * swap (source)./* w w w . j av a2s. c o m*/ * @param targetSlotName Required. The name of the second web site slot to * swap with (target). * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return The response body contains the status of the specified * long-running operation, indicating whether it has succeeded, is * inprogress, has timed out, or has failed. Note that this status is * distinct from the HTTP status code returned for the Get Operation Status * operation itself. If the long-running operation failed, the response * body includes error information regarding the failure. */ @Override public WebSiteOperationStatusResponse beginSwappingSlots(String webSpaceName, String webSiteName, String sourceSlotName, String targetSlotName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } if (sourceSlotName == null) { throw new NullPointerException("sourceSlotName"); } if (targetSlotName == null) { throw new NullPointerException("targetSlotName"); } // 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("webSiteName", webSiteName); tracingParameters.put("sourceSlotName", sourceSlotName); tracingParameters.put("targetSlotName", targetSlotName); CloudTracing.enter(invocationId, this, "beginSwappingSlotsAsync", 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/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); url = url + "("; url = url + URLEncoder.encode(sourceSlotName, "UTF-8"); url = url + ")/slots"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("Command=swap"); queryParameters.add("targetSlot=" + URLEncoder.encode(targetSlotName, "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 HttpPost httpRequest = new HttpPost(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 WebSiteOperationStatusResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteOperationStatusResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element operationElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Operation"); if (operationElement != null) { Element createdTimeElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "CreatedTime"); if (createdTimeElement != null) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter.parseDateTime(createdTimeElement.getTextContent()); result.setCreatedTime(createdTimeInstance); } Element errorsSequenceElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "Errors"); if (errorsSequenceElement != null) { boolean isNil = false; Attr nilAttribute = errorsSequenceElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(errorsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Error") .size(); i1 = i1 + 1) { org.w3c.dom.Element errorsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(errorsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Error") .get(i1)); WebSiteOperationStatusResponse.Error errorInstance = new WebSiteOperationStatusResponse.Error(); result.getErrors().add(errorInstance); Element codeElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "Code"); if (codeElement != null) { boolean isNil2 = false; Attr nilAttribute2 = codeElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { String codeInstance; codeInstance = codeElement.getTextContent(); errorInstance.setCode(codeInstance); } } Element messageElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "Message"); if (messageElement != null) { boolean isNil3 = false; Attr nilAttribute3 = messageElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute3 != null) { isNil3 = "true".equals(nilAttribute3.getValue()); } if (isNil3 == false) { String messageInstance; messageInstance = messageElement.getTextContent(); errorInstance.setMessage(messageInstance); } } Element extendedCodeElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "ExtendedCode"); if (extendedCodeElement != null) { boolean isNil4 = false; Attr nilAttribute4 = extendedCodeElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute4 != null) { isNil4 = "true".equals(nilAttribute4.getValue()); } if (isNil4 == false) { String extendedCodeInstance; extendedCodeInstance = extendedCodeElement.getTextContent(); errorInstance.setExtendedCode(extendedCodeInstance); } } Element messageTemplateElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "MessageTemplate"); if (messageTemplateElement != null) { boolean isNil5 = false; Attr nilAttribute5 = messageTemplateElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute5 != null) { isNil5 = "true".equals(nilAttribute5.getValue()); } if (isNil5 == false) { String messageTemplateInstance; messageTemplateInstance = messageTemplateElement.getTextContent(); errorInstance.setMessageTemplate(messageTemplateInstance); } } Element parametersSequenceElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "Parameters"); if (parametersSequenceElement != null) { boolean isNil6 = false; Attr nilAttribute6 = parametersSequenceElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute6 != null) { isNil6 = "true".equals(nilAttribute6.getValue()); } if (isNil6 == false) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(parametersSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i2 = i2 + 1) { org.w3c.dom.Element parametersElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(parametersSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i2)); errorInstance.getParameters().add(parametersElement.getTextContent()); } } else { errorInstance.setParameters(null); } } Element innerErrorsElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "InnerErrors"); if (innerErrorsElement != null) { boolean isNil7 = false; Attr nilAttribute7 = innerErrorsElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute7 != null) { isNil7 = "true".equals(nilAttribute7.getValue()); } if (isNil7 == false) { String innerErrorsInstance; innerErrorsInstance = innerErrorsElement.getTextContent(); errorInstance.setInnerErrors(innerErrorsInstance); } } } } else { result.setErrors(null); } } Element expirationTimeElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "ExpirationTime"); if (expirationTimeElement != null) { Calendar expirationTimeInstance; expirationTimeInstance = DatatypeConverter .parseDateTime(expirationTimeElement.getTextContent()); result.setExpirationTime(expirationTimeInstance); } Element geoMasterOperationIdElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "GeoMasterOperationId"); if (geoMasterOperationIdElement != null) { boolean isNil8 = false; Attr nilAttribute8 = geoMasterOperationIdElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute8 != null) { isNil8 = "true".equals(nilAttribute8.getValue()); } if (isNil8 == false) { String geoMasterOperationIdInstance; geoMasterOperationIdInstance = geoMasterOperationIdElement.getTextContent(); result.setGeoMasterOperationId(geoMasterOperationIdInstance); } } Element idElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { boolean isNil9 = false; Attr nilAttribute9 = idElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute9 != null) { isNil9 = "true".equals(nilAttribute9.getValue()); } if (isNil9 == false) { String idInstance; idInstance = idElement.getTextContent(); result.setOperationId(idInstance); } } Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "ModifiedTime"); if (modifiedTimeElement != null) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeElement.getTextContent()); result.setModifiedTime(modifiedTimeInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { boolean isNil10 = false; Attr nilAttribute10 = nameElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute10 != null) { isNil10 = "true".equals(nilAttribute10.getValue()); } if (isNil10 == false) { String nameInstance; nameInstance = nameElement.getTextContent(); result.setName(nameInstance); } } Element statusElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { WebSiteOperationStatus statusInstance; statusInstance = WebSiteOperationStatus.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(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * You can retrieve historical usage metrics for a site by issuing an HTTP * GET request. (see/*from ww w . j a va 2 s .c o m*/ * http://msdn.microsoft.com/en-us/library/windowsazure/dn166964.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @param parameters Required. Parameters supplied to the Get Historical * Usage Metrics Web Site operation. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws 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 Historical Usage Metrics Web Site operation response. */ @Override public WebSiteGetHistoricalUsageMetricsResponse getHistoricalUsageMetrics(String webSpaceName, String webSiteName, WebSiteGetHistoricalUsageMetricsParameters parameters) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } 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("webSiteName", webSiteName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "getHistoricalUsageMetricsAsync", 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/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); url = url + "/metrics"; ArrayList<String> queryParameters = new ArrayList<String>(); if (parameters.getMetricNames() != null && parameters.getMetricNames().size() > 0) { queryParameters.add("names=" + URLEncoder.encode(CollectionStringBuilder.join(parameters.getMetricNames(), ","), "UTF-8")); } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); if (parameters.getStartTime() != null) { queryParameters.add("StartTime=" + URLEncoder.encode(simpleDateFormat.format(parameters.getStartTime().getTime()), "UTF-8")); } SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC")); if (parameters.getEndTime() != null) { queryParameters.add("EndTime=" + URLEncoder.encode(simpleDateFormat2.format(parameters.getEndTime().getTime()), "UTF-8")); } if (parameters.getTimeGrain() != null) { queryParameters.add("timeGrain=" + URLEncoder.encode(parameters.getTimeGrain(), "UTF-8")); } queryParameters.add("details=" + URLEncoder .encode(Boolean.toString(parameters.isIncludeInstanceBreakdown()).toLowerCase(), "UTF-8")); queryParameters.add( "slotView=" + URLEncoder.encode(Boolean.toString(parameters.isSlotView()).toLowerCase(), "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 WebSiteGetHistoricalUsageMetricsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetHistoricalUsageMetricsResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element metricResponsesElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "MetricResponses"); if (metricResponsesElement != null) { if (metricResponsesElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metricResponsesElement, "http://schemas.microsoft.com/windowsazure", "MetricResponse") .size(); i1 = i1 + 1) { org.w3c.dom.Element usageMetricsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metricResponsesElement, "http://schemas.microsoft.com/windowsazure", "MetricResponse") .get(i1)); HistoricalUsageMetric metricResponseInstance = new HistoricalUsageMetric(); result.getUsageMetrics().add(metricResponseInstance); Element codeElement = XmlUtility.getElementByTagNameNS(usageMetricsElement, "http://schemas.microsoft.com/windowsazure", "Code"); if (codeElement != null) { String codeInstance; codeInstance = codeElement.getTextContent(); metricResponseInstance.setCode(codeInstance); } Element dataElement = XmlUtility.getElementByTagNameNS(usageMetricsElement, "http://schemas.microsoft.com/windowsazure", "Data"); if (dataElement != null) { HistoricalUsageMetricData dataInstance = new HistoricalUsageMetricData(); metricResponseInstance.setData(dataInstance); Element displayNameElement = XmlUtility.getElementByTagNameNS(dataElement, "http://schemas.microsoft.com/windowsazure", "DisplayName"); if (displayNameElement != null) { String displayNameInstance; displayNameInstance = displayNameElement.getTextContent(); dataInstance.setDisplayName(displayNameInstance); } Element endTimeElement = XmlUtility.getElementByTagNameNS(dataElement, "http://schemas.microsoft.com/windowsazure", "EndTime"); if (endTimeElement != null) { Calendar endTimeInstance; endTimeInstance = DatatypeConverter .parseDateTime(endTimeElement.getTextContent()); dataInstance.setEndTime(endTimeInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(dataElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); dataInstance.setName(nameInstance); } Element primaryAggregationTypeElement = XmlUtility.getElementByTagNameNS( dataElement, "http://schemas.microsoft.com/windowsazure", "PrimaryAggregationType"); if (primaryAggregationTypeElement != null) { String primaryAggregationTypeInstance; primaryAggregationTypeInstance = primaryAggregationTypeElement.getTextContent(); dataInstance.setPrimaryAggregationType(primaryAggregationTypeInstance); } Element startTimeElement = XmlUtility.getElementByTagNameNS(dataElement, "http://schemas.microsoft.com/windowsazure", "StartTime"); if (startTimeElement != null) { Calendar startTimeInstance; startTimeInstance = DatatypeConverter .parseDateTime(startTimeElement.getTextContent()); dataInstance.setStartTime(startTimeInstance); } Element timeGrainElement = XmlUtility.getElementByTagNameNS(dataElement, "http://schemas.microsoft.com/windowsazure", "TimeGrain"); if (timeGrainElement != null) { String timeGrainInstance; timeGrainInstance = timeGrainElement.getTextContent(); dataInstance.setTimeGrain(timeGrainInstance); } Element unitElement = XmlUtility.getElementByTagNameNS(dataElement, "http://schemas.microsoft.com/windowsazure", "Unit"); if (unitElement != null) { String unitInstance; unitInstance = unitElement.getTextContent(); dataInstance.setUnit(unitInstance); } Element valuesSequenceElement = XmlUtility.getElementByTagNameNS(dataElement, "http://schemas.microsoft.com/windowsazure", "Values"); if (valuesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(valuesSequenceElement, "http://schemas.microsoft.com/windowsazure", "MetricSample") .size(); i2 = i2 + 1) { org.w3c.dom.Element valuesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(valuesSequenceElement, "http://schemas.microsoft.com/windowsazure", "MetricSample") .get(i2)); HistoricalUsageMetricSample metricSampleInstance = new HistoricalUsageMetricSample(); dataInstance.getValues().add(metricSampleInstance); Element countElement = XmlUtility.getElementByTagNameNS(valuesElement, "http://schemas.microsoft.com/windowsazure", "Count"); if (countElement != null) { int countInstance; countInstance = DatatypeConverter .parseInt(countElement.getTextContent()); metricSampleInstance.setCount(countInstance); } Element maximumElement = XmlUtility.getElementByTagNameNS(valuesElement, "http://schemas.microsoft.com/windowsazure", "Maximum"); if (maximumElement != null) { boolean isNil = false; Attr nilAttribute = maximumElement.getAttributeNodeNS( "http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String maximumInstance; maximumInstance = maximumElement.getTextContent(); metricSampleInstance.setMaximum(maximumInstance); } } Element minimumElement = XmlUtility.getElementByTagNameNS(valuesElement, "http://schemas.microsoft.com/windowsazure", "Minimum"); if (minimumElement != null) { boolean isNil2 = false; Attr nilAttribute2 = minimumElement.getAttributeNodeNS( "http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { String minimumInstance; minimumInstance = minimumElement.getTextContent(); metricSampleInstance.setMinimum(minimumInstance); } } Element timeCreatedElement = XmlUtility.getElementByTagNameNS(valuesElement, "http://schemas.microsoft.com/windowsazure", "TimeCreated"); if (timeCreatedElement != null) { Calendar timeCreatedInstance; timeCreatedInstance = DatatypeConverter .parseDateTime(timeCreatedElement.getTextContent()); metricSampleInstance.setTimeCreated(timeCreatedInstance); } Element totalElement = XmlUtility.getElementByTagNameNS(valuesElement, "http://schemas.microsoft.com/windowsazure", "Total"); if (totalElement != null) { String totalInstance; totalInstance = totalElement.getTextContent(); metricSampleInstance.setTotal(totalInstance); } Element instanceNameElement = XmlUtility.getElementByTagNameNS( valuesElement, "http://schemas.microsoft.com/windowsazure", "InstanceName"); if (instanceNameElement != null) { String instanceNameInstance; instanceNameInstance = instanceNameElement.getTextContent(); metricSampleInstance.setInstanceName(instanceNameInstance); } } } } Element messageElement = XmlUtility.getElementByTagNameNS(usageMetricsElement, "http://schemas.microsoft.com/windowsazure", "Message"); if (messageElement != null) { String messageInstance; messageInstance = messageElement.getTextContent(); metricResponseInstance.setMessage(messageInstance); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * You can retrieve details for a web site by issuing an HTTP GET request. * (see http://msdn.microsoft.com/en-us/library/windowsazure/dn167007.aspx * for more information)// www . j a v a2s . com * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @param parameters Optional. Parameters supplied to the Get Web Site * Operation. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws 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 Site operation response. */ @Override public WebSiteGetResponse get(String webSpaceName, String webSiteName, WebSiteGetParameters parameters) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } // 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("webSiteName", webSiteName); tracingParameters.put("parameters", parameters); 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"); url = url + "/sites/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); 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 WebSiteGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element siteElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Site"); if (siteElement != null) { WebSite webSiteInstance = new WebSite(); result.setWebSite(webSiteInstance); Element adminEnabledElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "AdminEnabled"); if (adminEnabledElement != null && adminEnabledElement.getTextContent() != null && !adminEnabledElement.getTextContent().isEmpty()) { boolean adminEnabledInstance; adminEnabledInstance = DatatypeConverter .parseBoolean(adminEnabledElement.getTextContent().toLowerCase()); webSiteInstance.setAdminEnabled(adminEnabledInstance); } Element availabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); webSiteInstance.setAvailabilityState(availabilityStateInstance); } Element sKUElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement != null && sKUElement.getTextContent() != null && !sKUElement.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent()); webSiteInstance.setSku(sKUInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null && enabledElement.getTextContent() != null && !enabledElement.getTextContent().isEmpty()) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); webSiteInstance.setEnabled(enabledInstance); } Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "EnabledHostNames"); if (enabledHostNamesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i1 = i1 + 1) { org.w3c.dom.Element enabledHostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i1)); webSiteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent()); } } Element hostNameSslStatesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); if (hostNameSslStatesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .size(); i2 = i2 + 1) { org.w3c.dom.Element hostNameSslStatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .get(i2)); WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState(); webSiteInstance.getHostNameSslStates().add(hostNameSslStateInstance); Element 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(siteElement, "http://schemas.microsoft.com/windowsazure", "HostNames"); if (hostNamesSequenceElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i3 = i3 + 1) { org.w3c.dom.Element hostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i3)); webSiteInstance.getHostNames().add(hostNamesElement.getTextContent()); } } Element lastModifiedTimeUtcElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "LastModifiedTimeUtc"); if (lastModifiedTimeUtcElement != null && lastModifiedTimeUtcElement.getTextContent() != null && !lastModifiedTimeUtcElement.getTextContent().isEmpty()) { Calendar lastModifiedTimeUtcInstance; lastModifiedTimeUtcInstance = DatatypeConverter .parseDateTime(lastModifiedTimeUtcElement.getTextContent()); webSiteInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance2; nameInstance2 = nameElement2.getTextContent(); webSiteInstance.setName(nameInstance2); } Element repositorySiteNameElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "RepositorySiteName"); if (repositorySiteNameElement != null) { String repositorySiteNameInstance; repositorySiteNameInstance = repositorySiteNameElement.getTextContent(); webSiteInstance.setRepositorySiteName(repositorySiteNameInstance); } Element runtimeAvailabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "RuntimeAvailabilityState"); if (runtimeAvailabilityStateElement != null && runtimeAvailabilityStateElement.getTextContent() != null && !runtimeAvailabilityStateElement.getTextContent().isEmpty()) { WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance; runtimeAvailabilityStateInstance = WebSiteRuntimeAvailabilityState .valueOf(runtimeAvailabilityStateElement.getTextContent()); webSiteInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance); } Element selfLinkElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "SelfLink"); if (selfLinkElement != null) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkElement.getTextContent()); webSiteInstance.setUri(selfLinkInstance); } Element serverFarmElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement != null) { String serverFarmInstance; serverFarmInstance = serverFarmElement.getTextContent(); webSiteInstance.setServerFarm(serverFarmInstance); } Element sitePropertiesElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "SiteProperties"); if (sitePropertiesElement != null) { WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties(); webSiteInstance.setSiteProperties(sitePropertiesInstance); Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AppSettings"); if (appSettingsSequenceElement != null) { for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i4 = i4 + 1) { org.w3c.dom.Element appSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i4)); String appSettingsKey = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String appSettingsValue = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } Element metadataSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Metadata"); if (metadataSequenceElement != null) { for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i5 = i5 + 1) { org.w3c.dom.Element metadataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i5)); String metadataKey = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String metadataValue = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue); } } Element propertiesSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Properties"); if (propertiesSequenceElement != null) { for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i6 = i6 + 1) { org.w3c.dom.Element propertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i6)); String propertiesKey = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String propertiesValue = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue); } } } Element stateElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); webSiteInstance.setState(stateInstance); } Element usageStateElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "UsageState"); if (usageStateElement != null && usageStateElement.getTextContent() != null && !usageStateElement.getTextContent().isEmpty()) { WebSiteUsageState usageStateInstance; usageStateInstance = WebSiteUsageState.valueOf(usageStateElement.getTextContent()); webSiteInstance.setUsageState(usageStateInstance); } Element webSpaceElement = XmlUtility.getElementByTagNameNS(siteElement, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { String webSpaceInstance; webSpaceInstance = webSpaceElement.getTextContent(); webSiteInstance.setWebSpace(webSpaceInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * You can create a web site by using a POST request that includes the name * of the web site and other information in the request body. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx for * more information)//from w w w.ja v a 2s .c o m * * @param webSpaceName Required. The name of the web space. * @param parameters Required. Parameters supplied to the Create Web Site * operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Create Web Site operation response. */ @Override public WebSiteCreateResponse create(String webSpaceName, WebSiteCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getName() == null) { throw new NullPointerException("parameters.Name"); } if (parameters.getServerFarm() == null) { throw new NullPointerException("parameters.ServerFarm"); } if (parameters.getWebSpace() != null) { if (parameters.getWebSpace().getGeoRegion() == null) { throw new NullPointerException("parameters.WebSpace.GeoRegion"); } if (parameters.getWebSpace().getName() == null) { throw new NullPointerException("parameters.WebSpace.Name"); } if (parameters.getWebSpace().getPlan() == null) { throw new NullPointerException("parameters.WebSpace.Plan"); } } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2014-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element siteElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Site"); requestDoc.appendChild(siteElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); siteElement.appendChild(nameElement); Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); serverFarmElement.appendChild(requestDoc.createTextNode(parameters.getServerFarm())); siteElement.appendChild(serverFarmElement); if (parameters.getWebSpace() != null) { Element webSpaceToCreateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "WebSpaceToCreate"); siteElement.appendChild(webSpaceToCreateElement); Element geoRegionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "GeoRegion"); geoRegionElement.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getGeoRegion())); webSpaceToCreateElement.appendChild(geoRegionElement); Element nameElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement2.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getName())); webSpaceToCreateElement.appendChild(nameElement2); Element planElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Plan"); planElement.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getPlan())); webSpaceToCreateElement.appendChild(planElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSiteCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element siteElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Site"); if (siteElement2 != null) { WebSite webSiteInstance = new WebSite(); result.setWebSite(webSiteInstance); Element adminEnabledElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "AdminEnabled"); if (adminEnabledElement != null && adminEnabledElement.getTextContent() != null && !adminEnabledElement.getTextContent().isEmpty()) { boolean adminEnabledInstance; adminEnabledInstance = DatatypeConverter .parseBoolean(adminEnabledElement.getTextContent().toLowerCase()); webSiteInstance.setAdminEnabled(adminEnabledInstance); } Element availabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); webSiteInstance.setAvailabilityState(availabilityStateInstance); } Element sKUElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement != null && sKUElement.getTextContent() != null && !sKUElement.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent()); webSiteInstance.setSku(sKUInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null && enabledElement.getTextContent() != null && !enabledElement.getTextContent().isEmpty()) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); webSiteInstance.setEnabled(enabledInstance); } Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "EnabledHostNames"); if (enabledHostNamesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i1 = i1 + 1) { org.w3c.dom.Element enabledHostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i1)); webSiteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent()); } } Element hostNameSslStatesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); if (hostNameSslStatesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .size(); i2 = i2 + 1) { org.w3c.dom.Element hostNameSslStatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .get(i2)); WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState(); webSiteInstance.getHostNameSslStates().add(hostNameSslStateInstance); Element nameElement3 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement3 != null) { String nameInstance; nameInstance = nameElement3.getTextContent(); hostNameSslStateInstance.setName(nameInstance); } Element sslStateElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "SslState"); if (sslStateElement != null && sslStateElement.getTextContent() != null && !sslStateElement.getTextContent().isEmpty()) { WebSiteSslState sslStateInstance; sslStateInstance = WebSiteSslState.valueOf(sslStateElement.getTextContent()); hostNameSslStateInstance.setSslState(sslStateInstance); } Element thumbprintElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Thumbprint"); if (thumbprintElement != null) { boolean isNil = false; Attr nilAttribute = thumbprintElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String thumbprintInstance; thumbprintInstance = thumbprintElement.getTextContent(); hostNameSslStateInstance.setThumbprint(thumbprintInstance); } } Element virtualIPElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP"); if (virtualIPElement != null) { boolean isNil2 = false; Attr nilAttribute2 = virtualIPElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { InetAddress virtualIPInstance; virtualIPInstance = InetAddress.getByName(virtualIPElement.getTextContent()); hostNameSslStateInstance.setVirtualIP(virtualIPInstance); } } } } Element hostNamesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "HostNames"); if (hostNamesSequenceElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i3 = i3 + 1) { org.w3c.dom.Element hostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i3)); webSiteInstance.getHostNames().add(hostNamesElement.getTextContent()); } } Element lastModifiedTimeUtcElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "LastModifiedTimeUtc"); if (lastModifiedTimeUtcElement != null && lastModifiedTimeUtcElement.getTextContent() != null && !lastModifiedTimeUtcElement.getTextContent().isEmpty()) { Calendar lastModifiedTimeUtcInstance; lastModifiedTimeUtcInstance = DatatypeConverter .parseDateTime(lastModifiedTimeUtcElement.getTextContent()); webSiteInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance); } Element nameElement4 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement4 != null) { String nameInstance2; nameInstance2 = nameElement4.getTextContent(); webSiteInstance.setName(nameInstance2); } Element repositorySiteNameElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "RepositorySiteName"); if (repositorySiteNameElement != null) { String repositorySiteNameInstance; repositorySiteNameInstance = repositorySiteNameElement.getTextContent(); webSiteInstance.setRepositorySiteName(repositorySiteNameInstance); } Element runtimeAvailabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "RuntimeAvailabilityState"); if (runtimeAvailabilityStateElement != null && runtimeAvailabilityStateElement.getTextContent() != null && !runtimeAvailabilityStateElement.getTextContent().isEmpty()) { WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance; runtimeAvailabilityStateInstance = WebSiteRuntimeAvailabilityState .valueOf(runtimeAvailabilityStateElement.getTextContent()); webSiteInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance); } Element selfLinkElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SelfLink"); if (selfLinkElement != null) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkElement.getTextContent()); webSiteInstance.setUri(selfLinkInstance); } Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { String serverFarmInstance; serverFarmInstance = serverFarmElement2.getTextContent(); webSiteInstance.setServerFarm(serverFarmInstance); } Element sitePropertiesElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SiteProperties"); if (sitePropertiesElement != null) { WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties(); webSiteInstance.setSiteProperties(sitePropertiesInstance); Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AppSettings"); if (appSettingsSequenceElement != null) { for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i4 = i4 + 1) { org.w3c.dom.Element appSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i4)); String appSettingsKey = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String appSettingsValue = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } Element metadataSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Metadata"); if (metadataSequenceElement != null) { for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i5 = i5 + 1) { org.w3c.dom.Element metadataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i5)); String metadataKey = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String metadataValue = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue); } } Element propertiesSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Properties"); if (propertiesSequenceElement != null) { for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i6 = i6 + 1) { org.w3c.dom.Element propertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i6)); String propertiesKey = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String propertiesValue = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue); } } } Element stateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); webSiteInstance.setState(stateInstance); } Element usageStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "UsageState"); if (usageStateElement != null && usageStateElement.getTextContent() != null && !usageStateElement.getTextContent().isEmpty()) { WebSiteUsageState usageStateInstance; usageStateInstance = WebSiteUsageState.valueOf(usageStateElement.getTextContent()); webSiteInstance.setUsageState(usageStateInstance); } Element webSpaceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { String webSpaceInstance; webSpaceInstance = webSpaceElement.getTextContent(); webSiteInstance.setWebSpace(webSpaceInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * You can update the settings for a web site by using the HTTP PUT method * and by specifying the settings in the request body. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn167005.aspx for * more information)// w ww . j a va 2s . co m * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @param parameters Required. Parameters supplied to the Update Web Site * operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Update Web Site operation response. */ @Override public WebSiteUpdateResponse update(String webSpaceName, String webSiteName, WebSiteUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getHostNameSslStates() != null) { for (WebSiteUpdateParameters.WebSiteHostNameSslState hostNameSslStatesParameterItem : parameters .getHostNameSslStates()) { if (hostNameSslStatesParameterItem.getName() == null) { throw new NullPointerException("parameters.HostNameSslStates.Name"); } if (hostNameSslStatesParameterItem.getSslState() == null) { throw new NullPointerException("parameters.HostNameSslStates.SslState"); } } } // 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("webSiteName", webSiteName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "updateAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2014-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element siteElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Site"); requestDoc.appendChild(siteElement); if (parameters.getHostNameSslStates() != null) { if (parameters.getHostNameSslStates() instanceof LazyCollection == false || ((LazyCollection) parameters.getHostNameSslStates()).isInitialized()) { Element hostNameSslStatesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); for (WebSiteUpdateParameters.WebSiteHostNameSslState hostNameSslStatesItem : parameters .getHostNameSslStates()) { Element webSiteHostNameSslStateElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "WebSiteHostNameSslState"); hostNameSslStatesSequenceElement.appendChild(webSiteHostNameSslStateElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(hostNameSslStatesItem.getName())); webSiteHostNameSslStateElement.appendChild(nameElement); Element sslStateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SslState"); sslStateElement .appendChild(requestDoc.createTextNode(hostNameSslStatesItem.getSslState().toString())); webSiteHostNameSslStateElement.appendChild(sslStateElement); if (hostNameSslStatesItem.getThumbprint() != null) { Element thumbprintElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Thumbprint"); thumbprintElement .appendChild(requestDoc.createTextNode(hostNameSslStatesItem.getThumbprint())); webSiteHostNameSslStateElement.appendChild(thumbprintElement); } else { Element emptyElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Thumbprint"); Attr nilAttribute = requestDoc .createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); nilAttribute.setValue("true"); emptyElement.setAttributeNode(nilAttribute); webSiteHostNameSslStateElement.appendChild(emptyElement); } Element toUpdateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ToUpdate"); toUpdateElement.appendChild(requestDoc.createTextNode("true")); webSiteHostNameSslStateElement.appendChild(toUpdateElement); } siteElement.appendChild(hostNameSslStatesSequenceElement); } } if (parameters.getHostNames() != null) { if (parameters.getHostNames() instanceof LazyCollection == false || ((LazyCollection) parameters.getHostNames()).isInitialized()) { Element hostNamesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostNames"); for (String hostNamesItem : parameters.getHostNames()) { Element hostNamesItemElement = requestDoc .createElementNS("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string"); hostNamesItemElement.appendChild(requestDoc.createTextNode(hostNamesItem)); hostNamesSequenceElement.appendChild(hostNamesItemElement); } siteElement.appendChild(hostNamesSequenceElement); } } if (parameters.getServerFarm() != null) { Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); serverFarmElement.appendChild(requestDoc.createTextNode(parameters.getServerFarm())); siteElement.appendChild(serverFarmElement); } if (parameters.getState() != null) { Element stateElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "State"); stateElement.appendChild(requestDoc.createTextNode(parameters.getState())); siteElement.appendChild(stateElement); } 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 WebSiteUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteUpdateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element siteElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Site"); if (siteElement2 != null) { WebSite webSiteInstance = new WebSite(); result.setWebSite(webSiteInstance); Element adminEnabledElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "AdminEnabled"); if (adminEnabledElement != null && adminEnabledElement.getTextContent() != null && !adminEnabledElement.getTextContent().isEmpty()) { boolean adminEnabledInstance; adminEnabledInstance = DatatypeConverter .parseBoolean(adminEnabledElement.getTextContent().toLowerCase()); webSiteInstance.setAdminEnabled(adminEnabledInstance); } Element availabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); webSiteInstance.setAvailabilityState(availabilityStateInstance); } Element sKUElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement != null && sKUElement.getTextContent() != null && !sKUElement.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent()); webSiteInstance.setSku(sKUInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null && enabledElement.getTextContent() != null && !enabledElement.getTextContent().isEmpty()) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); webSiteInstance.setEnabled(enabledInstance); } Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "EnabledHostNames"); if (enabledHostNamesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i1 = i1 + 1) { org.w3c.dom.Element enabledHostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i1)); webSiteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent()); } } Element hostNameSslStatesSequenceElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); if (hostNameSslStatesSequenceElement2 != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement2, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .size(); i2 = i2 + 1) { org.w3c.dom.Element hostNameSslStatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement2, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .get(i2)); WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState(); webSiteInstance.getHostNameSslStates().add(hostNameSslStateInstance); Element nameElement2 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); hostNameSslStateInstance.setName(nameInstance); } Element sslStateElement2 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "SslState"); if (sslStateElement2 != null && sslStateElement2.getTextContent() != null && !sslStateElement2.getTextContent().isEmpty()) { WebSiteSslState sslStateInstance; sslStateInstance = WebSiteSslState.valueOf(sslStateElement2.getTextContent()); hostNameSslStateInstance.setSslState(sslStateInstance); } Element thumbprintElement2 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Thumbprint"); if (thumbprintElement2 != null) { boolean isNil = false; Attr nilAttribute2 = thumbprintElement2 .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil = "true".equals(nilAttribute2.getValue()); } if (isNil == false) { String thumbprintInstance; thumbprintInstance = thumbprintElement2.getTextContent(); hostNameSslStateInstance.setThumbprint(thumbprintInstance); } } Element virtualIPElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP"); if (virtualIPElement != null) { boolean isNil2 = false; Attr nilAttribute3 = virtualIPElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute3 != null) { isNil2 = "true".equals(nilAttribute3.getValue()); } if (isNil2 == false) { InetAddress virtualIPInstance; virtualIPInstance = InetAddress.getByName(virtualIPElement.getTextContent()); hostNameSslStateInstance.setVirtualIP(virtualIPInstance); } } } } Element hostNamesSequenceElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "HostNames"); if (hostNamesSequenceElement2 != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement2, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i3 = i3 + 1) { org.w3c.dom.Element hostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement2, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i3)); webSiteInstance.getHostNames().add(hostNamesElement.getTextContent()); } } Element lastModifiedTimeUtcElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "LastModifiedTimeUtc"); if (lastModifiedTimeUtcElement != null && lastModifiedTimeUtcElement.getTextContent() != null && !lastModifiedTimeUtcElement.getTextContent().isEmpty()) { Calendar lastModifiedTimeUtcInstance; lastModifiedTimeUtcInstance = DatatypeConverter .parseDateTime(lastModifiedTimeUtcElement.getTextContent()); webSiteInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance); } Element nameElement3 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement3 != null) { String nameInstance2; nameInstance2 = nameElement3.getTextContent(); webSiteInstance.setName(nameInstance2); } Element repositorySiteNameElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "RepositorySiteName"); if (repositorySiteNameElement != null) { String repositorySiteNameInstance; repositorySiteNameInstance = repositorySiteNameElement.getTextContent(); webSiteInstance.setRepositorySiteName(repositorySiteNameInstance); } Element runtimeAvailabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "RuntimeAvailabilityState"); if (runtimeAvailabilityStateElement != null && runtimeAvailabilityStateElement.getTextContent() != null && !runtimeAvailabilityStateElement.getTextContent().isEmpty()) { WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance; runtimeAvailabilityStateInstance = WebSiteRuntimeAvailabilityState .valueOf(runtimeAvailabilityStateElement.getTextContent()); webSiteInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance); } Element selfLinkElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SelfLink"); if (selfLinkElement != null) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkElement.getTextContent()); webSiteInstance.setUri(selfLinkInstance); } Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { String serverFarmInstance; serverFarmInstance = serverFarmElement2.getTextContent(); webSiteInstance.setServerFarm(serverFarmInstance); } Element sitePropertiesElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SiteProperties"); if (sitePropertiesElement != null) { WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties(); webSiteInstance.setSiteProperties(sitePropertiesInstance); Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AppSettings"); if (appSettingsSequenceElement != null) { for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i4 = i4 + 1) { org.w3c.dom.Element appSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i4)); String appSettingsKey = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String appSettingsValue = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } Element metadataSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Metadata"); if (metadataSequenceElement != null) { for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i5 = i5 + 1) { org.w3c.dom.Element metadataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i5)); String metadataKey = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String metadataValue = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue); } } Element propertiesSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Properties"); if (propertiesSequenceElement != null) { for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i6 = i6 + 1) { org.w3c.dom.Element propertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i6)); String propertiesKey = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String propertiesValue = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue); } } } Element stateElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement2 != null) { String stateInstance; stateInstance = stateElement2.getTextContent(); webSiteInstance.setState(stateInstance); } Element usageStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "UsageState"); if (usageStateElement != null && usageStateElement.getTextContent() != null && !usageStateElement.getTextContent().isEmpty()) { WebSiteUsageState usageStateInstance; usageStateInstance = WebSiteUsageState.valueOf(usageStateElement.getTextContent()); webSiteInstance.setUsageState(usageStateInstance); } Element webSpaceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { String webSpaceInstance; webSpaceInstance = webSpaceElement.getTextContent(); webSiteInstance.setWebSpace(webSpaceInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.azure.management.websites.WebSiteOperationsImpl.java
/** * Retrieve the publish settings information for a web site. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn166996.aspx for * more information)/*from w w w . j av a2 s . c o m*/ * * @param resourceGroupName Required. The name of the resource group. * @param webSiteName Required. The name of the web site. * @param slotName Optional. The name of the slot. * @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 Site Publish Profile operation response. */ @Override public WebSiteGetPublishProfileResponse getPublishProfile(String resourceGroupName, String webSiteName, String slotName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("resourceGroupName", resourceGroupName); tracingParameters.put("webSiteName", webSiteName); tracingParameters.put("slotName", slotName); CloudTracing.enter(invocationId, this, "getPublishProfileAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Web"; url = url + "/"; url = url + "sites"; url = url + "/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); if (slotName != null) { url = url + "/slots/" + URLEncoder.encode(slotName, "UTF-8"); } url = url + "/publishxml"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-06-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers 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, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSiteGetPublishProfileResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetPublishProfileResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element publishDataSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "", "publishData"); if (publishDataSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(publishDataSequenceElement, "", "publishProfile") .size(); i1 = i1 + 1) { org.w3c.dom.Element publishDataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(publishDataSequenceElement, "", "publishProfile").get(i1)); WebSiteGetPublishProfileResponse.PublishProfile publishProfileInstance = new WebSiteGetPublishProfileResponse.PublishProfile(); result.getPublishProfiles().add(publishProfileInstance); Attr profileNameAttribute = publishDataElement.getAttributeNodeNS("", "profileName"); if (profileNameAttribute != null) { publishProfileInstance.setProfileName(profileNameAttribute.getValue()); } Attr publishMethodAttribute = publishDataElement.getAttributeNodeNS("", "publishMethod"); if (publishMethodAttribute != null) { publishProfileInstance.setPublishMethod(publishMethodAttribute.getValue()); } Attr publishUrlAttribute = publishDataElement.getAttributeNodeNS("", "publishUrl"); if (publishUrlAttribute != null) { publishProfileInstance.setPublishUrl(publishUrlAttribute.getValue()); } Attr msdeploySiteAttribute = publishDataElement.getAttributeNodeNS("", "msdeploySite"); if (msdeploySiteAttribute != null) { publishProfileInstance.setMSDeploySite(msdeploySiteAttribute.getValue()); } Attr ftpPassiveModeAttribute = publishDataElement.getAttributeNodeNS("", "ftpPassiveMode"); if (ftpPassiveModeAttribute != null) { publishProfileInstance.setFtpPassiveMode(DatatypeConverter .parseBoolean(ftpPassiveModeAttribute.getValue().toLowerCase())); } Attr userNameAttribute = publishDataElement.getAttributeNodeNS("", "userName"); if (userNameAttribute != null) { publishProfileInstance.setUserName(userNameAttribute.getValue()); } Attr userPWDAttribute = publishDataElement.getAttributeNodeNS("", "userPWD"); if (userPWDAttribute != null) { publishProfileInstance.setUserPassword(userPWDAttribute.getValue()); } Attr destinationAppUrlAttribute = publishDataElement.getAttributeNodeNS("", "destinationAppUrl"); if (destinationAppUrlAttribute != null) { publishProfileInstance .setDestinationAppUri(new URI(destinationAppUrlAttribute.getValue())); } Attr sQLServerDBConnectionStringAttribute = publishDataElement.getAttributeNodeNS("", "SQLServerDBConnectionString"); if (sQLServerDBConnectionStringAttribute != null) { publishProfileInstance .setSqlServerConnectionString(sQLServerDBConnectionStringAttribute.getValue()); } Attr mySQLDBConnectionStringAttribute = publishDataElement.getAttributeNodeNS("", "mySQLDBConnectionString"); if (mySQLDBConnectionStringAttribute != null) { publishProfileInstance .setMySqlConnectionString(mySQLDBConnectionStringAttribute.getValue()); } Attr hostingProviderForumLinkAttribute = publishDataElement.getAttributeNodeNS("", "hostingProviderForumLink"); if (hostingProviderForumLinkAttribute != null) { publishProfileInstance.setHostingProviderForumUri( new URI(hostingProviderForumLinkAttribute.getValue())); } Attr controlPanelLinkAttribute = publishDataElement.getAttributeNodeNS("", "controlPanelLink"); if (controlPanelLinkAttribute != null) { publishProfileInstance .setControlPanelUri(new URI(controlPanelLinkAttribute.getValue())); } Element databasesSequenceElement = XmlUtility.getElementByTagNameNS(publishDataElement, "", "databases"); if (databasesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement, "", "add") .size(); i2 = i2 + 1) { org.w3c.dom.Element databasesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement, "", "add").get(i2)); WebSiteGetPublishProfileResponse.Database addInstance = new WebSiteGetPublishProfileResponse.Database(); publishProfileInstance.getDatabases().add(addInstance); Attr nameAttribute = databasesElement.getAttributeNodeNS("", "name"); if (nameAttribute != null) { addInstance.setName(nameAttribute.getValue()); } Attr connectionStringAttribute = databasesElement.getAttributeNodeNS("", "connectionString"); if (connectionStringAttribute != null) { addInstance.setConnectionString(connectionStringAttribute.getValue()); } Attr providerNameAttribute = databasesElement.getAttributeNodeNS("", "providerName"); if (providerNameAttribute != null) { addInstance.setProviderName(providerNameAttribute.getValue()); } Attr typeAttribute = databasesElement.getAttributeNodeNS("", "type"); if (typeAttribute != null) { addInstance.setType(typeAttribute.getValue()); } } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.network.GatewayOperationsImpl.java
/** * The List Virtual Network Gateway Supported Devices operation lists the * supported, on-premise network devices that can connect to the gateway. * (see http://msdn.microsoft.com/en-us/library/windowsazure/jj154102.aspx * for more information)//ww w. j a v a 2s. co m * * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return The response to the list supported devices request. */ @Override public GatewayListSupportedDevicesResponse listSupportedDevices() 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, "listSupportedDevicesAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/supporteddevices"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2015-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result GatewayListSupportedDevicesResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new GatewayListSupportedDevicesResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element vpnDeviceListElement = XmlUtility.getElementByTagNameNS(responseDoc, "", "VpnDeviceList"); if (vpnDeviceListElement != null) { Attr versionAttribute = vpnDeviceListElement.getAttributeNodeNS("", "version"); if (versionAttribute != null) { result.setVersion(versionAttribute.getValue()); } if (vpnDeviceListElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(vpnDeviceListElement, "", "Vendor").size(); i1 = i1 + 1) { org.w3c.dom.Element vendorsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(vpnDeviceListElement, "", "Vendor").get(i1)); GatewayListSupportedDevicesResponse.Vendor vendorInstance = new GatewayListSupportedDevicesResponse.Vendor(); result.getVendors().add(vendorInstance); Attr nameAttribute = vendorsElement.getAttributeNodeNS("", "name"); if (nameAttribute != null) { vendorInstance.setName(nameAttribute.getValue()); } if (vendorsElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(vendorsElement, "", "Platform") .size(); i2 = i2 + 1) { org.w3c.dom.Element platformsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(vendorsElement, "", "Platform").get(i2)); GatewayListSupportedDevicesResponse.Platform platformInstance = new GatewayListSupportedDevicesResponse.Platform(); vendorInstance.getPlatforms().add(platformInstance); Attr nameAttribute2 = platformsElement.getAttributeNodeNS("", "name"); if (nameAttribute2 != null) { platformInstance.setName(nameAttribute2.getValue()); } if (platformsElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(platformsElement, "", "OSFamily") .size(); i3 = i3 + 1) { org.w3c.dom.Element oSFamiliesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(platformsElement, "", "OSFamily") .get(i3)); GatewayListSupportedDevicesResponse.OSFamily oSFamilyInstance = new GatewayListSupportedDevicesResponse.OSFamily(); platformInstance.getOSFamilies().add(oSFamilyInstance); Attr nameAttribute3 = oSFamiliesElement.getAttributeNodeNS("", "name"); if (nameAttribute3 != null) { oSFamilyInstance.setName(nameAttribute3.getValue()); } } } } } } } } } 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(); } } }