List of usage examples for javax.xml.bind DatatypeConverter parseInt
public static int parseInt(String lexicalXSDInt)
Convert the string argument into an int value.
From source file:com.microsoft.windowsazure.management.websites.WebHostingPlanOperationsImpl.java
/** * You can list the web spaces under the current subscription by issuing a * GET request. (see/*from w ww .java 2s. c o m*/ * http://msdn.microsoft.com/en-us/library/windowsazure/dn166961.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return The List Web Hosting Plans operation response. */ @Override public WebHostingPlanListResponse list(String webSpaceName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); CloudTracing.enter(invocationId, this, "listAsync", tracingParameters); } // Construct URL String url = ""; 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 + "/serverFarms"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; 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 WebHostingPlanListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebHostingPlanListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serverFarmsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServerFarms"); if (serverFarmsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serverFarmsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServerFarm") .size(); i1 = i1 + 1) { org.w3c.dom.Element serverFarmsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serverFarmsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServerFarm") .get(i1)); WebHostingPlan serverFarmInstance = new WebHostingPlan(); result.getWebHostingPlans().add(serverFarmInstance); Element nameElement = XmlUtility.getElementByTagNameNS(serverFarmsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serverFarmInstance.setName(nameInstance); } Element numberOfWorkersElement = XmlUtility.getElementByTagNameNS(serverFarmsElement, "http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); if (numberOfWorkersElement != null && numberOfWorkersElement.getTextContent() != null && !numberOfWorkersElement.getTextContent().isEmpty()) { int numberOfWorkersInstance; numberOfWorkersInstance = DatatypeConverter .parseInt(numberOfWorkersElement.getTextContent()); serverFarmInstance.setNumberOfWorkers(numberOfWorkersInstance); } Element sKUElement = XmlUtility.getElementByTagNameNS(serverFarmsElement, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement != null && sKUElement.getTextContent() != null && !sKUElement.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent()); serverFarmInstance.setSKU(sKUInstance); } Element workerSizeElement = XmlUtility.getElementByTagNameNS(serverFarmsElement, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement != null && workerSizeElement.getTextContent() != null && !workerSizeElement.getTextContent().isEmpty()) { WorkerSizeOptions workerSizeInstance; workerSizeInstance = WorkerSizeOptions.valueOf(workerSizeElement.getTextContent()); serverFarmInstance.setWorkerSize(workerSizeInstance); } Element adminSiteNameElement = XmlUtility.getElementByTagNameNS(serverFarmsElement, "http://schemas.microsoft.com/windowsazure", "AdminSiteName"); if (adminSiteNameElement != null) { String adminSiteNameInstance; adminSiteNameInstance = adminSiteNameElement.getTextContent(); serverFarmInstance.setAdminSiteName(adminSiteNameInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.compute.VirtualMachineVMImageOperationsImpl.java
/** * Gets VMImage's properties and its replication details. This operation is * only for publishers. You have to be registered as image publisher with * Windows Azure to be able to call this. * * @param vmImageName Required. The name of the virtual machine image to * replicate.//w w w .j a v a2 s .c o m * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Get Details VM Images operation response. */ @Override public VirtualMachineVMImageGetDetailsResponse getDetails(String vmImageName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (vmImageName == null) { throw new NullPointerException("vmImageName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("vmImageName", vmImageName); CloudTracing.enter(invocationId, this, "getDetailsAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/vmimages/"; url = url + URLEncoder.encode(vmImageName, "UTF-8"); url = url + "/details"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2015-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result VirtualMachineVMImageGetDetailsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualMachineVMImageGetDetailsResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element vMImageDetailsElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "VMImageDetails"); if (vMImageDetailsElement != null) { Element nameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); result.setName(nameInstance); } Element labelElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement != null) { String labelInstance; labelInstance = labelElement.getTextContent(); result.setLabel(labelInstance); } Element categoryElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Category"); if (categoryElement != null) { String categoryInstance; categoryInstance = categoryElement.getTextContent(); result.setCategory(categoryInstance); } Element descriptionElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); result.setDescription(descriptionInstance); } Element oSDiskConfigurationElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "OSDiskConfiguration"); if (oSDiskConfigurationElement != null) { VirtualMachineVMImageListResponse.OSDiskConfiguration oSDiskConfigurationInstance = new VirtualMachineVMImageListResponse.OSDiskConfiguration(); result.setOSDiskConfiguration(oSDiskConfigurationInstance); Element nameElement2 = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance2; nameInstance2 = nameElement2.getTextContent(); oSDiskConfigurationInstance.setName(nameInstance2); } Element hostCachingElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement, "http://schemas.microsoft.com/windowsazure", "HostCaching"); if (hostCachingElement != null) { String hostCachingInstance; hostCachingInstance = hostCachingElement.getTextContent(); oSDiskConfigurationInstance.setHostCaching(hostCachingInstance); } Element oSStateElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement, "http://schemas.microsoft.com/windowsazure", "OSState"); if (oSStateElement != null) { String oSStateInstance; oSStateInstance = oSStateElement.getTextContent(); oSDiskConfigurationInstance.setOSState(oSStateInstance); } Element osElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement, "http://schemas.microsoft.com/windowsazure", "OS"); if (osElement != null) { String osInstance; osInstance = osElement.getTextContent(); oSDiskConfigurationInstance.setOperatingSystem(osInstance); } Element mediaLinkElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement, "http://schemas.microsoft.com/windowsazure", "MediaLink"); if (mediaLinkElement != null) { URI mediaLinkInstance; mediaLinkInstance = new URI(mediaLinkElement.getTextContent()); oSDiskConfigurationInstance.setMediaLink(mediaLinkInstance); } Element logicalDiskSizeInGBElement = XmlUtility.getElementByTagNameNS( oSDiskConfigurationElement, "http://schemas.microsoft.com/windowsazure", "LogicalDiskSizeInGB"); if (logicalDiskSizeInGBElement != null) { int logicalDiskSizeInGBInstance; logicalDiskSizeInGBInstance = DatatypeConverter .parseInt(logicalDiskSizeInGBElement.getTextContent()); oSDiskConfigurationInstance.setLogicalDiskSizeInGB(logicalDiskSizeInGBInstance); } Element iOTypeElement = XmlUtility.getElementByTagNameNS(oSDiskConfigurationElement, "http://schemas.microsoft.com/windowsazure", "IOType"); if (iOTypeElement != null) { String iOTypeInstance; iOTypeInstance = iOTypeElement.getTextContent(); oSDiskConfigurationInstance.setIOType(iOTypeInstance); } } Element dataDiskConfigurationsSequenceElement = XmlUtility.getElementByTagNameNS( vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "DataDiskConfigurations"); if (dataDiskConfigurationsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(dataDiskConfigurationsSequenceElement, "http://schemas.microsoft.com/windowsazure", "DataDiskConfiguration") .size(); i1 = i1 + 1) { org.w3c.dom.Element dataDiskConfigurationsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(dataDiskConfigurationsSequenceElement, "http://schemas.microsoft.com/windowsazure", "DataDiskConfiguration") .get(i1)); VirtualMachineVMImageListResponse.DataDiskConfiguration dataDiskConfigurationInstance = new VirtualMachineVMImageListResponse.DataDiskConfiguration(); result.getDataDiskConfigurations().add(dataDiskConfigurationInstance); Element nameElement3 = XmlUtility.getElementByTagNameNS(dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement3 != null) { String nameInstance3; nameInstance3 = nameElement3.getTextContent(); dataDiskConfigurationInstance.setName(nameInstance3); } Element hostCachingElement2 = XmlUtility.getElementByTagNameNS( dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure", "HostCaching"); if (hostCachingElement2 != null) { String hostCachingInstance2; hostCachingInstance2 = hostCachingElement2.getTextContent(); dataDiskConfigurationInstance.setHostCaching(hostCachingInstance2); } Element lunElement = XmlUtility.getElementByTagNameNS(dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure", "Lun"); if (lunElement != null && lunElement.getTextContent() != null && !lunElement.getTextContent().isEmpty()) { int lunInstance; lunInstance = DatatypeConverter.parseInt(lunElement.getTextContent()); dataDiskConfigurationInstance.setLogicalUnitNumber(lunInstance); } Element mediaLinkElement2 = XmlUtility.getElementByTagNameNS( dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure", "MediaLink"); if (mediaLinkElement2 != null) { URI mediaLinkInstance2; mediaLinkInstance2 = new URI(mediaLinkElement2.getTextContent()); dataDiskConfigurationInstance.setMediaLink(mediaLinkInstance2); } Element logicalDiskSizeInGBElement2 = XmlUtility.getElementByTagNameNS( dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure", "LogicalDiskSizeInGB"); if (logicalDiskSizeInGBElement2 != null) { int logicalDiskSizeInGBInstance2; logicalDiskSizeInGBInstance2 = DatatypeConverter .parseInt(logicalDiskSizeInGBElement2.getTextContent()); dataDiskConfigurationInstance.setLogicalDiskSizeInGB(logicalDiskSizeInGBInstance2); } Element iOTypeElement2 = XmlUtility.getElementByTagNameNS(dataDiskConfigurationsElement, "http://schemas.microsoft.com/windowsazure", "IOType"); if (iOTypeElement2 != null) { String iOTypeInstance2; iOTypeInstance2 = iOTypeElement2.getTextContent(); dataDiskConfigurationInstance.setIOType(iOTypeInstance2); } } } Element serviceNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "ServiceName"); if (serviceNameElement != null) { String serviceNameInstance; serviceNameInstance = serviceNameElement.getTextContent(); result.setServiceName(serviceNameInstance); } Element deploymentNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "DeploymentName"); if (deploymentNameElement != null) { String deploymentNameInstance; deploymentNameInstance = deploymentNameElement.getTextContent(); result.setDeploymentName(deploymentNameInstance); } Element roleNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "RoleName"); if (roleNameElement != null) { String roleNameInstance; roleNameInstance = roleNameElement.getTextContent(); result.setRoleName(roleNameInstance); } Element affinityGroupElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "AffinityGroup"); if (affinityGroupElement != null) { String affinityGroupInstance; affinityGroupInstance = affinityGroupElement.getTextContent(); result.setAffinityGroup(affinityGroupInstance); } Element locationElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Location"); if (locationElement != null) { String locationInstance; locationInstance = locationElement.getTextContent(); result.setLocation(locationInstance); } Element createdTimeElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "CreatedTime"); if (createdTimeElement != null && createdTimeElement.getTextContent() != null && !createdTimeElement.getTextContent().isEmpty()) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter.parseDateTime(createdTimeElement.getTextContent()); result.setCreatedTime(createdTimeInstance); } Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "ModifiedTime"); if (modifiedTimeElement != null && modifiedTimeElement.getTextContent() != null && !modifiedTimeElement.getTextContent().isEmpty()) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeElement.getTextContent()); result.setModifiedTime(modifiedTimeInstance); } Element languageElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Language"); if (languageElement != null) { String languageInstance; languageInstance = languageElement.getTextContent(); result.setLanguage(languageInstance); } Element imageFamilyElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "ImageFamily"); if (imageFamilyElement != null) { String imageFamilyInstance; imageFamilyInstance = imageFamilyElement.getTextContent(); result.setImageFamily(imageFamilyInstance); } Element recommendedVMSizeElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "RecommendedVMSize"); if (recommendedVMSizeElement != null) { String recommendedVMSizeInstance; recommendedVMSizeInstance = recommendedVMSizeElement.getTextContent(); result.setRecommendedVMSize(recommendedVMSizeInstance); } Element isPremiumElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "IsPremium"); if (isPremiumElement != null && isPremiumElement.getTextContent() != null && !isPremiumElement.getTextContent().isEmpty()) { boolean isPremiumInstance; isPremiumInstance = DatatypeConverter .parseBoolean(isPremiumElement.getTextContent().toLowerCase()); result.setIsPremium(isPremiumInstance); } Element eulaElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Eula"); if (eulaElement != null) { String eulaInstance; eulaInstance = eulaElement.getTextContent(); result.setEula(eulaInstance); } Element iconUriElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "IconUri"); if (iconUriElement != null) { String iconUriInstance; iconUriInstance = iconUriElement.getTextContent(); result.setIconUri(iconUriInstance); } Element smallIconUriElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "SmallIconUri"); if (smallIconUriElement != null) { String smallIconUriInstance; smallIconUriInstance = smallIconUriElement.getTextContent(); result.setSmallIconUri(smallIconUriInstance); } Element privacyUriElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "PrivacyUri"); if (privacyUriElement != null) { URI privacyUriInstance; privacyUriInstance = new URI(privacyUriElement.getTextContent()); result.setPrivacyUri(privacyUriInstance); } Element publisherNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "PublisherName"); if (publisherNameElement != null) { String publisherNameInstance; publisherNameInstance = publisherNameElement.getTextContent(); result.setPublisherName(publisherNameInstance); } Element publishedDateElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "PublishedDate"); if (publishedDateElement != null && publishedDateElement.getTextContent() != null && !publishedDateElement.getTextContent().isEmpty()) { Calendar publishedDateInstance; publishedDateInstance = DatatypeConverter .parseDateTime(publishedDateElement.getTextContent()); result.setPublishedDate(publishedDateInstance); } Element showInGuiElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "ShowInGui"); if (showInGuiElement != null && showInGuiElement.getTextContent() != null && !showInGuiElement.getTextContent().isEmpty()) { boolean showInGuiInstance; showInGuiInstance = DatatypeConverter .parseBoolean(showInGuiElement.getTextContent().toLowerCase()); result.setShowInGui(showInGuiInstance); } Element pricingDetailLinkElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "PricingDetailLink"); if (pricingDetailLinkElement != null) { URI pricingDetailLinkInstance; pricingDetailLinkInstance = new URI(pricingDetailLinkElement.getTextContent()); result.setPricingDetailLink(pricingDetailLinkInstance); } Element isCorruptedElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "IsCorrupted"); if (isCorruptedElement != null && isCorruptedElement.getTextContent() != null && !isCorruptedElement.getTextContent().isEmpty()) { boolean isCorruptedInstance; isCorruptedInstance = DatatypeConverter .parseBoolean(isCorruptedElement.getTextContent().toLowerCase()); result.setIsCorrupted(isCorruptedInstance); } Element publishedNameElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "PublishedName"); if (publishedNameElement != null) { String publishedNameInstance; publishedNameInstance = publishedNameElement.getTextContent(); result.setPublishedName(publishedNameInstance); } Element sharingStatusElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "SharingStatus"); if (sharingStatusElement != null) { String sharingStatusInstance; sharingStatusInstance = sharingStatusElement.getTextContent(); result.setSharingStatus(sharingStatusInstance); } Element replicationProgressSequenceElement = XmlUtility.getElementByTagNameNS( vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "ReplicationProgress"); if (replicationProgressSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(replicationProgressSequenceElement, "http://schemas.microsoft.com/windowsazure", "ReplicationProgressElement") .size(); i2 = i2 + 1) { org.w3c.dom.Element replicationProgressElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(replicationProgressSequenceElement, "http://schemas.microsoft.com/windowsazure", "ReplicationProgressElement") .get(i2)); VirtualMachineVMImageGetDetailsResponse.ReplicationProgressElement replicationProgressElementInstance = new VirtualMachineVMImageGetDetailsResponse.ReplicationProgressElement(); result.getReplicationProgress().add(replicationProgressElementInstance); Element locationElement2 = XmlUtility.getElementByTagNameNS(replicationProgressElement, "http://schemas.microsoft.com/windowsazure", "Location"); if (locationElement2 != null) { String locationInstance2; locationInstance2 = locationElement2.getTextContent(); replicationProgressElementInstance.setLocation(locationInstance2); } Element progressElement = XmlUtility.getElementByTagNameNS(replicationProgressElement, "http://schemas.microsoft.com/windowsazure", "Progress"); if (progressElement != null) { String progressInstance; progressInstance = progressElement.getTextContent(); replicationProgressElementInstance.setProgress(progressInstance); } } } Element computeImageAttributesElement = XmlUtility.getElementByTagNameNS(vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "ComputeImageAttributes"); if (computeImageAttributesElement != null) { ComputeImageAttributes computeImageAttributesInstance = new ComputeImageAttributes(); result.setComputeImageAttributes(computeImageAttributesInstance); Element offerElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement, "http://schemas.microsoft.com/windowsazure", "Offer"); if (offerElement != null) { String offerInstance; offerInstance = offerElement.getTextContent(); computeImageAttributesInstance.setOffer(offerInstance); } Element skuElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement, "http://schemas.microsoft.com/windowsazure", "Sku"); if (skuElement != null) { String skuInstance; skuInstance = skuElement.getTextContent(); computeImageAttributesInstance.setSku(skuInstance); } Element versionElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement, "http://schemas.microsoft.com/windowsazure", "Version"); if (versionElement != null) { String versionInstance; versionInstance = versionElement.getTextContent(); computeImageAttributesInstance.setVersion(versionInstance); } } Element marketplaceImageAttributesElement = XmlUtility.getElementByTagNameNS( vMImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "MarketplaceImageAttributes"); if (marketplaceImageAttributesElement != null) { MarketplaceImageAttributes marketplaceImageAttributesInstance = new MarketplaceImageAttributes(); result.setMarketplaceImageAttributes(marketplaceImageAttributesInstance); Element publisherIdElement = XmlUtility.getElementByTagNameNS( marketplaceImageAttributesElement, "http://schemas.microsoft.com/windowsazure", "PublisherId"); if (publisherIdElement != null) { String publisherIdInstance; publisherIdInstance = publisherIdElement.getTextContent(); marketplaceImageAttributesInstance.setPublisherId(publisherIdInstance); } Element planElement = XmlUtility.getElementByTagNameNS(marketplaceImageAttributesElement, "http://schemas.microsoft.com/windowsazure", "Plan"); if (planElement != null) { Plan planInstance = new Plan(); marketplaceImageAttributesInstance.setPlan(planInstance); Element nameElement4 = XmlUtility.getElementByTagNameNS(planElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement4 != null) { String nameInstance4; nameInstance4 = nameElement4.getTextContent(); planInstance.setName(nameInstance4); } Element publisherElement = XmlUtility.getElementByTagNameNS(planElement, "http://schemas.microsoft.com/windowsazure", "Publisher"); if (publisherElement != null) { String publisherInstance; publisherInstance = publisherElement.getTextContent(); planInstance.setPublisher(publisherInstance); } Element productElement = XmlUtility.getElementByTagNameNS(planElement, "http://schemas.microsoft.com/windowsazure", "Product"); if (productElement != null) { String productInstance; productInstance = productElement.getTextContent(); planInstance.setProduct(productInstance); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.scheduler.JobCollectionOperationsImpl.java
/** * Retreive a job collection.//ww w . j a v a 2 s . c om * * @param cloudServiceName Required. Name of the cloud service. * @param jobCollectionName Required. Name of the job collection. * @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 Job Collection operation response. */ @Override public JobCollectionGetResponse get(String cloudServiceName, String jobCollectionName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (cloudServiceName == null) { throw new NullPointerException("cloudServiceName"); } if (jobCollectionName == null) { throw new NullPointerException("jobCollectionName"); } // 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("cloudServiceName", cloudServiceName); tracingParameters.put("jobCollectionName", jobCollectionName); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/cloudservices/"; url = url + URLEncoder.encode(cloudServiceName, "UTF-8"); url = url + "/resources/"; url = url + "scheduler"; url = url + "/~/"; url = url + "JobCollections"; url = url + "/"; url = url + URLEncoder.encode(jobCollectionName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2013-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 JobCollectionGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new JobCollectionGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element resourceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Resource"); if (resourceElement != null) { Element nameElement = XmlUtility.getElementByTagNameNS(resourceElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); result.setName(nameInstance); } Element eTagElement = XmlUtility.getElementByTagNameNS(resourceElement, "http://schemas.microsoft.com/windowsazure", "ETag"); if (eTagElement != null) { String eTagInstance; eTagInstance = eTagElement.getTextContent(); result.setETag(eTagInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(resourceElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null && stateElement.getTextContent() != null && !stateElement.getTextContent().isEmpty()) { JobCollectionState stateInstance; stateInstance = JobCollectionState.valueOf(stateElement.getTextContent()); result.setState(stateInstance); } Element schemaVersionElement = XmlUtility.getElementByTagNameNS(resourceElement, "http://schemas.microsoft.com/windowsazure", "SchemaVersion"); if (schemaVersionElement != null) { String schemaVersionInstance; schemaVersionInstance = schemaVersionElement.getTextContent(); result.setSchemaVersion(schemaVersionInstance); } Element promotionCodeElement = XmlUtility.getElementByTagNameNS(resourceElement, "http://schemas.microsoft.com/windowsazure", "PromotionCode"); if (promotionCodeElement != null) { String promotionCodeInstance; promotionCodeInstance = promotionCodeElement.getTextContent(); result.setPromotionCode(promotionCodeInstance); } Element intrinsicSettingsElement = XmlUtility.getElementByTagNameNS(resourceElement, "http://schemas.microsoft.com/windowsazure", "IntrinsicSettings"); if (intrinsicSettingsElement != null) { JobCollectionIntrinsicSettings intrinsicSettingsInstance = new JobCollectionIntrinsicSettings(); result.setIntrinsicSettings(intrinsicSettingsInstance); Element planElement = XmlUtility.getElementByTagNameNS(intrinsicSettingsElement, "http://schemas.microsoft.com/windowsazure", "Plan"); if (planElement != null && planElement.getTextContent() != null && !planElement.getTextContent().isEmpty()) { JobCollectionPlan planInstance; planInstance = JobCollectionPlan.valueOf(planElement.getTextContent()); intrinsicSettingsInstance.setPlan(planInstance); } Element quotaElement = XmlUtility.getElementByTagNameNS(intrinsicSettingsElement, "http://schemas.microsoft.com/windowsazure", "Quota"); if (quotaElement != null) { JobCollectionQuota quotaInstance = new JobCollectionQuota(); intrinsicSettingsInstance.setQuota(quotaInstance); Element maxJobCountElement = XmlUtility.getElementByTagNameNS(quotaElement, "http://schemas.microsoft.com/windowsazure", "MaxJobCount"); if (maxJobCountElement != null && maxJobCountElement.getTextContent() != null && !maxJobCountElement.getTextContent().isEmpty()) { int maxJobCountInstance; maxJobCountInstance = DatatypeConverter .parseInt(maxJobCountElement.getTextContent()); quotaInstance.setMaxJobCount(maxJobCountInstance); } Element maxJobOccurrenceElement = XmlUtility.getElementByTagNameNS(quotaElement, "http://schemas.microsoft.com/windowsazure", "MaxJobOccurrence"); if (maxJobOccurrenceElement != null && maxJobOccurrenceElement.getTextContent() != null && !maxJobOccurrenceElement.getTextContent().isEmpty()) { int maxJobOccurrenceInstance; maxJobOccurrenceInstance = DatatypeConverter .parseInt(maxJobOccurrenceElement.getTextContent()); quotaInstance.setMaxJobOccurrence(maxJobOccurrenceInstance); } Element maxRecurrenceElement = XmlUtility.getElementByTagNameNS(quotaElement, "http://schemas.microsoft.com/windowsazure", "MaxRecurrence"); if (maxRecurrenceElement != null) { JobCollectionMaxRecurrence maxRecurrenceInstance = new JobCollectionMaxRecurrence(); quotaInstance.setMaxRecurrence(maxRecurrenceInstance); Element frequencyElement = XmlUtility.getElementByTagNameNS(maxRecurrenceElement, "http://schemas.microsoft.com/windowsazure", "Frequency"); if (frequencyElement != null && frequencyElement.getTextContent() != null && !frequencyElement.getTextContent().isEmpty()) { JobCollectionRecurrenceFrequency frequencyInstance; frequencyInstance = JobCollectionRecurrenceFrequency .valueOf(frequencyElement.getTextContent()); maxRecurrenceInstance.setFrequency(frequencyInstance); } Element intervalElement = XmlUtility.getElementByTagNameNS(maxRecurrenceElement, "http://schemas.microsoft.com/windowsazure", "Interval"); if (intervalElement != null) { int intervalInstance; intervalInstance = DatatypeConverter.parseInt(intervalElement.getTextContent()); maxRecurrenceInstance.setInterval(intervalInstance); } } } } Element labelElement = XmlUtility.getElementByTagNameNS(resourceElement, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement != null) { String labelInstance; labelInstance = labelElement.getTextContent() != null ? new String(Base64.decode(labelElement.getTextContent())) : null; result.setLabel(labelInstance); } Element operationStatusElement = XmlUtility.getElementByTagNameNS(resourceElement, "http://schemas.microsoft.com/windowsazure", "OperationStatus"); if (operationStatusElement != null) { JobCollectionGetResponse.OperationStatus operationStatusInstance = new JobCollectionGetResponse.OperationStatus(); result.setLastOperationStatus(operationStatusInstance); Element errorElement = XmlUtility.getElementByTagNameNS(operationStatusElement, "http://schemas.microsoft.com/windowsazure", "Error"); if (errorElement != null) { JobCollectionGetResponse.OperationStatusResponseDetails errorInstance = new JobCollectionGetResponse.OperationStatusResponseDetails(); operationStatusInstance.setResponseDetails(errorInstance); Element httpCodeElement = XmlUtility.getElementByTagNameNS(errorElement, "http://schemas.microsoft.com/windowsazure", "HttpCode"); if (httpCodeElement != null && httpCodeElement.getTextContent() != null && !httpCodeElement.getTextContent().isEmpty()) { Integer httpCodeInstance; httpCodeInstance = Integer.valueOf(httpCodeElement.getTextContent()); errorInstance.setStatusCode(httpCodeInstance); } Element messageElement = XmlUtility.getElementByTagNameNS(errorElement, "http://schemas.microsoft.com/windowsazure", "Message"); if (messageElement != null) { String messageInstance; messageInstance = messageElement.getTextContent(); errorInstance.setMessage(messageInstance); } } Element resultElement = XmlUtility.getElementByTagNameNS(operationStatusElement, "http://schemas.microsoft.com/windowsazure", "Result"); if (resultElement != null && resultElement.getTextContent() != null && !resultElement.getTextContent().isEmpty()) { SchedulerOperationStatus resultInstance; resultInstance = SchedulerOperationStatus.valueOf(resultElement.getTextContent()); operationStatusInstance.setStatus(resultInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.servicebus.TopicOperationsImpl.java
/** * The topic description is an XML AtomPub document that defines the desired * semantics for a topic. The topic description contains the following * properties. For more information, see the TopicDescription Properties * topic. (see/*from w ww. j a v a 2s . c om*/ * http://msdn.microsoft.com/en-us/library/windowsazure/hh780749.aspx for * more information) * * @param namespaceName Required. The namespace name. * @param topicName Required. The topic. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return A response to a request for a particular topic. */ @Override public ServiceBusTopicResponse get(String namespaceName, String topicName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (namespaceName == null) { throw new NullPointerException("namespaceName"); } if (topicName == null) { throw new NullPointerException("topicName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("namespaceName", namespaceName); tracingParameters.put("topicName", topicName); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/servicebus/namespaces/"; url = url + URLEncoder.encode(namespaceName, "UTF-8"); url = url + "/topics/"; url = url + URLEncoder.encode(topicName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml; charset=utf-8"); httpRequest.setHeader("x-ms-version", "2013-08-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ServiceBusTopicResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServiceBusTopicResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element entryElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom", "entry"); if (entryElement != null) { Element titleElement = XmlUtility.getElementByTagNameNS(entryElement, "http://www.w3.org/2005/Atom", "title"); if (titleElement != null) { } Element contentElement = XmlUtility.getElementByTagNameNS(entryElement, "http://www.w3.org/2005/Atom", "content"); if (contentElement != null) { Element topicDescriptionElement = XmlUtility.getElementByTagNameNS(contentElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "TopicDescription"); if (topicDescriptionElement != null) { ServiceBusTopic topicDescriptionInstance = new ServiceBusTopic(); result.setTopic(topicDescriptionInstance); Element defaultMessageTimeToLiveElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DefaultMessageTimeToLive"); if (defaultMessageTimeToLiveElement != null) { String defaultMessageTimeToLiveInstance; defaultMessageTimeToLiveInstance = defaultMessageTimeToLiveElement.getTextContent(); topicDescriptionInstance .setDefaultMessageTimeToLive(defaultMessageTimeToLiveInstance); } Element maxSizeInMegabytesElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MaxSizeInMegabytes"); if (maxSizeInMegabytesElement != null) { int maxSizeInMegabytesInstance; maxSizeInMegabytesInstance = DatatypeConverter .parseInt(maxSizeInMegabytesElement.getTextContent()); topicDescriptionInstance.setMaxSizeInMegabytes(maxSizeInMegabytesInstance); } Element requiresDuplicateDetectionElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "RequiresDuplicateDetection"); if (requiresDuplicateDetectionElement != null) { boolean requiresDuplicateDetectionInstance; requiresDuplicateDetectionInstance = DatatypeConverter.parseBoolean( requiresDuplicateDetectionElement.getTextContent().toLowerCase()); topicDescriptionInstance .setRequiresDuplicateDetection(requiresDuplicateDetectionInstance); } Element duplicateDetectionHistoryTimeWindowElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DuplicateDetectionHistoryTimeWindow"); if (duplicateDetectionHistoryTimeWindowElement != null) { String duplicateDetectionHistoryTimeWindowInstance; duplicateDetectionHistoryTimeWindowInstance = duplicateDetectionHistoryTimeWindowElement .getTextContent(); topicDescriptionInstance.setDuplicateDetectionHistoryTimeWindow( duplicateDetectionHistoryTimeWindowInstance); } Element enableBatchedOperationsElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "EnableBatchedOperations"); if (enableBatchedOperationsElement != null) { boolean enableBatchedOperationsInstance; enableBatchedOperationsInstance = DatatypeConverter.parseBoolean( enableBatchedOperationsElement.getTextContent().toLowerCase()); topicDescriptionInstance .setEnableBatchedOperations(enableBatchedOperationsInstance); } Element sizeInBytesElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SizeInBytes"); if (sizeInBytesElement != null) { int sizeInBytesInstance; sizeInBytesInstance = DatatypeConverter .parseInt(sizeInBytesElement.getTextContent()); topicDescriptionInstance.setSizeInBytes(sizeInBytesInstance); } Element filteringMessagesBeforePublishingElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "FilteringMessagesBeforePublishing"); if (filteringMessagesBeforePublishingElement != null) { boolean filteringMessagesBeforePublishingInstance; filteringMessagesBeforePublishingInstance = DatatypeConverter.parseBoolean( filteringMessagesBeforePublishingElement.getTextContent().toLowerCase()); topicDescriptionInstance.setFilteringMessagesBeforePublishing( filteringMessagesBeforePublishingInstance); } Element isAnonymousAccessibleElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "IsAnonymousAccessible"); if (isAnonymousAccessibleElement != null) { boolean isAnonymousAccessibleInstance; isAnonymousAccessibleInstance = DatatypeConverter .parseBoolean(isAnonymousAccessibleElement.getTextContent().toLowerCase()); topicDescriptionInstance.setIsAnonymousAccessible(isAnonymousAccessibleInstance); } Element authorizationRulesSequenceElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRules"); if (authorizationRulesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(authorizationRulesSequenceElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRule") .size(); i1 = i1 + 1) { org.w3c.dom.Element authorizationRulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(authorizationRulesSequenceElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRule") .get(i1)); ServiceBusSharedAccessAuthorizationRule authorizationRuleInstance = new ServiceBusSharedAccessAuthorizationRule(); topicDescriptionInstance.getAuthorizationRules().add(authorizationRuleInstance); Element claimTypeElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimType"); if (claimTypeElement != null) { String claimTypeInstance; claimTypeInstance = claimTypeElement.getTextContent(); authorizationRuleInstance.setClaimType(claimTypeInstance); } Element claimValueElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimValue"); if (claimValueElement != null) { String claimValueInstance; claimValueInstance = claimValueElement.getTextContent(); authorizationRuleInstance.setClaimValue(claimValueInstance); } Element rightsSequenceElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Rights"); if (rightsSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(rightsSequenceElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights") .size(); i2 = i2 + 1) { org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(rightsSequenceElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights") .get(i2)); authorizationRuleInstance.getRights() .add(AccessRight.valueOf(rightsElement.getTextContent())); } } Element createdTimeElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedTime"); if (createdTimeElement != null) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter .parseDateTime(createdTimeElement.getTextContent()); authorizationRuleInstance.setCreatedTime(createdTimeInstance); } Element keyNameElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "KeyName"); if (keyNameElement != null) { String keyNameInstance; keyNameInstance = keyNameElement.getTextContent(); authorizationRuleInstance.setKeyName(keyNameInstance); } Element modifiedTimeElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ModifiedTime"); if (modifiedTimeElement != null) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeElement.getTextContent()); authorizationRuleInstance.setModifiedTime(modifiedTimeInstance); } Element primaryKeyElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "PrimaryKey"); if (primaryKeyElement != null) { String primaryKeyInstance; primaryKeyInstance = primaryKeyElement.getTextContent(); authorizationRuleInstance.setPrimaryKey(primaryKeyInstance); } Element secondaryKeyElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SecondaryKey"); if (secondaryKeyElement != null) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyElement.getTextContent(); authorizationRuleInstance.setSecondaryKey(secondaryKeyInstance); } } } Element statusElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Status"); if (statusElement != null) { String statusInstance; statusInstance = statusElement.getTextContent(); topicDescriptionInstance.setStatus(statusInstance); } Element createdAtElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedAt"); if (createdAtElement != null) { Calendar createdAtInstance; createdAtInstance = DatatypeConverter .parseDateTime(createdAtElement.getTextContent()); topicDescriptionInstance.setCreatedAt(createdAtInstance); } Element updatedAtElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "UpdatedAt"); if (updatedAtElement != null) { Calendar updatedAtInstance; updatedAtInstance = DatatypeConverter .parseDateTime(updatedAtElement.getTextContent()); topicDescriptionInstance.setUpdatedAt(updatedAtInstance); } Element accessedAtElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessedAt"); if (accessedAtElement != null) { Calendar accessedAtInstance; accessedAtInstance = DatatypeConverter .parseDateTime(accessedAtElement.getTextContent()); topicDescriptionInstance.setAccessedAt(accessedAtInstance); } Element supportOrderingElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SupportOrdering"); if (supportOrderingElement != null) { boolean supportOrderingInstance; supportOrderingInstance = DatatypeConverter .parseBoolean(supportOrderingElement.getTextContent().toLowerCase()); topicDescriptionInstance.setSupportOrdering(supportOrderingInstance); } Element countDetailsElement = XmlUtility.getElementByTagNameNS(topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CountDetails"); if (countDetailsElement != null) { CountDetails countDetailsInstance = new CountDetails(); topicDescriptionInstance.setCountDetails(countDetailsInstance); } Element subscriptionCountElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SubscriptionCount"); if (subscriptionCountElement != null) { int subscriptionCountInstance; subscriptionCountInstance = DatatypeConverter .parseInt(subscriptionCountElement.getTextContent()); topicDescriptionInstance.setSubscriptionCount(subscriptionCountInstance); } Element autoDeleteOnIdleElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AutoDeleteOnIdle"); if (autoDeleteOnIdleElement != null) { String autoDeleteOnIdleInstance; autoDeleteOnIdleInstance = autoDeleteOnIdleElement.getTextContent(); topicDescriptionInstance.setAutoDeleteOnIdle(autoDeleteOnIdleInstance); } Element entityAvailabilityStatusElement = XmlUtility.getElementByTagNameNS( topicDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "EntityAvailabilityStatus"); if (entityAvailabilityStatusElement != null) { String entityAvailabilityStatusInstance; entityAvailabilityStatusInstance = entityAvailabilityStatusElement.getTextContent(); topicDescriptionInstance .setEntityAvailabilityStatus(entityAvailabilityStatusInstance); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.azure.management.network.VirtualNetworkGatewayOperationsImpl.java
/** * The Reset VirtualNetworkGateway operation resets the primary of the * virtual network gatewayin the specified resource group through Network * resource provider.// w w w. jav a 2s.c o m * * @param resourceGroupName Required. The name of the resource group. * @param virtualNetworkGatewayName Required. The name of the virtual * network gateway. * @param parameters Required. Parameters supplied to the Begin Reset * Virtual Network Gateway operation through Network resource provider. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return Response for PutVirtualNetworkGateway Api servive call */ @Override public VirtualNetworkGatewayPutResponse beginReset(String resourceGroupName, String virtualNetworkGatewayName, VirtualNetworkGateway parameters) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (virtualNetworkGatewayName == null) { throw new NullPointerException("virtualNetworkGatewayName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLocation() == null) { throw new NullPointerException("parameters.Location"); } // 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("virtualNetworkGatewayName", virtualNetworkGatewayName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginResetAsync", 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.Network"; url = url + "/virtualnetworkgateways/"; url = url + URLEncoder.encode(virtualNetworkGatewayName, "UTF-8"); url = url + "/reset"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-05-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json"); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode virtualNetworkGatewayJsonFormatValue = objectMapper.createObjectNode(); requestDoc = virtualNetworkGatewayJsonFormatValue; ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) virtualNetworkGatewayJsonFormatValue).put("properties", propertiesValue); if (parameters.getIpConfigurations() != null) { if (parameters.getIpConfigurations() instanceof LazyCollection == false || ((LazyCollection) parameters.getIpConfigurations()).isInitialized()) { ArrayNode ipConfigurationsArray = objectMapper.createArrayNode(); for (VirtualNetworkGatewayIpConfiguration ipConfigurationsItem : parameters.getIpConfigurations()) { ObjectNode virtualNetworkGatewayIpConfigurationJsonFormatValue = objectMapper .createObjectNode(); ipConfigurationsArray.add(virtualNetworkGatewayIpConfigurationJsonFormatValue); ObjectNode propertiesValue2 = objectMapper.createObjectNode(); ((ObjectNode) virtualNetworkGatewayIpConfigurationJsonFormatValue).put("properties", propertiesValue2); if (ipConfigurationsItem.getPrivateIpAddress() != null) { ((ObjectNode) propertiesValue2).put("privateIPAddress", ipConfigurationsItem.getPrivateIpAddress()); } if (ipConfigurationsItem.getPrivateIpAllocationMethod() != null) { ((ObjectNode) propertiesValue2).put("privateIPAllocationMethod", ipConfigurationsItem.getPrivateIpAllocationMethod()); } if (ipConfigurationsItem.getSubnet() != null) { ObjectNode subnetValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue2).put("subnet", subnetValue); if (ipConfigurationsItem.getSubnet().getId() != null) { ((ObjectNode) subnetValue).put("id", ipConfigurationsItem.getSubnet().getId()); } } if (ipConfigurationsItem.getPublicIpAddress() != null) { ObjectNode publicIPAddressValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue2).put("publicIPAddress", publicIPAddressValue); if (ipConfigurationsItem.getPublicIpAddress().getId() != null) { ((ObjectNode) publicIPAddressValue).put("id", ipConfigurationsItem.getPublicIpAddress().getId()); } } if (ipConfigurationsItem.getProvisioningState() != null) { ((ObjectNode) propertiesValue2).put("provisioningState", ipConfigurationsItem.getProvisioningState()); } if (ipConfigurationsItem.getName() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationJsonFormatValue).put("name", ipConfigurationsItem.getName()); } if (ipConfigurationsItem.getEtag() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationJsonFormatValue).put("etag", ipConfigurationsItem.getEtag()); } if (ipConfigurationsItem.getId() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationJsonFormatValue).put("id", ipConfigurationsItem.getId()); } } ((ObjectNode) propertiesValue).put("ipConfigurations", ipConfigurationsArray); } } if (parameters.getGatewayType() != null) { ((ObjectNode) propertiesValue).put("gatewayType", parameters.getGatewayType()); } if (parameters.getVpnType() != null) { ((ObjectNode) propertiesValue).put("vpnType", parameters.getVpnType()); } ((ObjectNode) propertiesValue).put("enableBgp", parameters.isEnableBgp()); if (parameters.getResourceGuid() != null) { ((ObjectNode) propertiesValue).put("resourceGuid", parameters.getResourceGuid()); } if (parameters.getProvisioningState() != null) { ((ObjectNode) propertiesValue).put("provisioningState", parameters.getProvisioningState()); } if (parameters.getEtag() != null) { ((ObjectNode) virtualNetworkGatewayJsonFormatValue).put("etag", parameters.getEtag()); } if (parameters.getId() != null) { ((ObjectNode) virtualNetworkGatewayJsonFormatValue).put("id", parameters.getId()); } if (parameters.getName() != null) { ((ObjectNode) virtualNetworkGatewayJsonFormatValue).put("name", parameters.getName()); } if (parameters.getType() != null) { ((ObjectNode) virtualNetworkGatewayJsonFormatValue).put("type", parameters.getType()); } ((ObjectNode) virtualNetworkGatewayJsonFormatValue).put("location", parameters.getLocation()); if (parameters.getTags() != null) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) virtualNetworkGatewayJsonFormatValue).put("tags", tagsDictionary); } StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, requestDoc); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/json"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_ACCEPTED) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result VirtualNetworkGatewayPutResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualNetworkGatewayPutResponse(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { VirtualNetworkGateway virtualNetworkGatewayInstance = new VirtualNetworkGateway(); result.setVirtualNetworkGateway(virtualNetworkGatewayInstance); JsonNode propertiesValue3 = responseDoc.get("properties"); if (propertiesValue3 != null && propertiesValue3 instanceof NullNode == false) { JsonNode ipConfigurationsArray2 = propertiesValue3.get("ipConfigurations"); if (ipConfigurationsArray2 != null && ipConfigurationsArray2 instanceof NullNode == false) { for (JsonNode ipConfigurationsValue : ((ArrayNode) ipConfigurationsArray2)) { VirtualNetworkGatewayIpConfiguration virtualNetworkGatewayIpConfigurationJsonFormatInstance = new VirtualNetworkGatewayIpConfiguration(); virtualNetworkGatewayInstance.getIpConfigurations() .add(virtualNetworkGatewayIpConfigurationJsonFormatInstance); JsonNode propertiesValue4 = ipConfigurationsValue.get("properties"); if (propertiesValue4 != null && propertiesValue4 instanceof NullNode == false) { JsonNode privateIPAddressValue = propertiesValue4.get("privateIPAddress"); if (privateIPAddressValue != null && privateIPAddressValue instanceof NullNode == false) { String privateIPAddressInstance; privateIPAddressInstance = privateIPAddressValue.getTextValue(); virtualNetworkGatewayIpConfigurationJsonFormatInstance .setPrivateIpAddress(privateIPAddressInstance); } JsonNode privateIPAllocationMethodValue = propertiesValue4 .get("privateIPAllocationMethod"); if (privateIPAllocationMethodValue != null && privateIPAllocationMethodValue instanceof NullNode == false) { String privateIPAllocationMethodInstance; privateIPAllocationMethodInstance = privateIPAllocationMethodValue .getTextValue(); virtualNetworkGatewayIpConfigurationJsonFormatInstance .setPrivateIpAllocationMethod(privateIPAllocationMethodInstance); } JsonNode subnetValue2 = propertiesValue4.get("subnet"); if (subnetValue2 != null && subnetValue2 instanceof NullNode == false) { ResourceId subnetInstance = new ResourceId(); virtualNetworkGatewayIpConfigurationJsonFormatInstance .setSubnet(subnetInstance); JsonNode idValue = subnetValue2.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); subnetInstance.setId(idInstance); } } JsonNode publicIPAddressValue2 = propertiesValue4.get("publicIPAddress"); if (publicIPAddressValue2 != null && publicIPAddressValue2 instanceof NullNode == false) { ResourceId publicIPAddressInstance = new ResourceId(); virtualNetworkGatewayIpConfigurationJsonFormatInstance .setPublicIpAddress(publicIPAddressInstance); JsonNode idValue2 = publicIPAddressValue2.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); publicIPAddressInstance.setId(idInstance2); } } JsonNode provisioningStateValue = propertiesValue4.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); virtualNetworkGatewayIpConfigurationJsonFormatInstance .setProvisioningState(provisioningStateInstance); } } JsonNode nameValue = ipConfigurationsValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); virtualNetworkGatewayIpConfigurationJsonFormatInstance.setName(nameInstance); } JsonNode etagValue = ipConfigurationsValue.get("etag"); if (etagValue != null && etagValue instanceof NullNode == false) { String etagInstance; etagInstance = etagValue.getTextValue(); virtualNetworkGatewayIpConfigurationJsonFormatInstance.setEtag(etagInstance); } JsonNode idValue3 = ipConfigurationsValue.get("id"); if (idValue3 != null && idValue3 instanceof NullNode == false) { String idInstance3; idInstance3 = idValue3.getTextValue(); virtualNetworkGatewayIpConfigurationJsonFormatInstance.setId(idInstance3); } } } JsonNode gatewayTypeValue = propertiesValue3.get("gatewayType"); if (gatewayTypeValue != null && gatewayTypeValue instanceof NullNode == false) { String gatewayTypeInstance; gatewayTypeInstance = gatewayTypeValue.getTextValue(); virtualNetworkGatewayInstance.setGatewayType(gatewayTypeInstance); } JsonNode vpnTypeValue = propertiesValue3.get("vpnType"); if (vpnTypeValue != null && vpnTypeValue instanceof NullNode == false) { String vpnTypeInstance; vpnTypeInstance = vpnTypeValue.getTextValue(); virtualNetworkGatewayInstance.setVpnType(vpnTypeInstance); } JsonNode enableBgpValue = propertiesValue3.get("enableBgp"); if (enableBgpValue != null && enableBgpValue instanceof NullNode == false) { boolean enableBgpInstance; enableBgpInstance = enableBgpValue.getBooleanValue(); virtualNetworkGatewayInstance.setEnableBgp(enableBgpInstance); } JsonNode resourceGuidValue = propertiesValue3.get("resourceGuid"); if (resourceGuidValue != null && resourceGuidValue instanceof NullNode == false) { String resourceGuidInstance; resourceGuidInstance = resourceGuidValue.getTextValue(); virtualNetworkGatewayInstance.setResourceGuid(resourceGuidInstance); } JsonNode provisioningStateValue2 = propertiesValue3.get("provisioningState"); if (provisioningStateValue2 != null && provisioningStateValue2 instanceof NullNode == false) { String provisioningStateInstance2; provisioningStateInstance2 = provisioningStateValue2.getTextValue(); virtualNetworkGatewayInstance.setProvisioningState(provisioningStateInstance2); } } JsonNode etagValue2 = responseDoc.get("etag"); if (etagValue2 != null && etagValue2 instanceof NullNode == false) { String etagInstance2; etagInstance2 = etagValue2.getTextValue(); virtualNetworkGatewayInstance.setEtag(etagInstance2); } JsonNode idValue4 = responseDoc.get("id"); if (idValue4 != null && idValue4 instanceof NullNode == false) { String idInstance4; idInstance4 = idValue4.getTextValue(); virtualNetworkGatewayInstance.setId(idInstance4); } JsonNode nameValue2 = responseDoc.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); virtualNetworkGatewayInstance.setName(nameInstance2); } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); virtualNetworkGatewayInstance.setType(typeInstance); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); virtualNetworkGatewayInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey2 = property.getKey(); String tagsValue2 = property.getValue().getTextValue(); virtualNetworkGatewayInstance.getTags().put(tagsKey2, tagsValue2); } } JsonNode errorValue = responseDoc.get("error"); if (errorValue != null && errorValue instanceof NullNode == false) { Error errorInstance = new Error(); result.setError(errorInstance); JsonNode codeValue = errorValue.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); errorInstance.setCode(codeInstance); } JsonNode messageValue = errorValue.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); errorInstance.setMessage(messageInstance); } JsonNode targetValue = errorValue.get("target"); if (targetValue != null && targetValue instanceof NullNode == false) { String targetInstance; targetInstance = targetValue.getTextValue(); errorInstance.setTarget(targetInstance); } JsonNode detailsArray = errorValue.get("details"); if (detailsArray != null && detailsArray instanceof NullNode == false) { for (JsonNode detailsValue : ((ArrayNode) detailsArray)) { ErrorDetails errorDetailsInstance = new ErrorDetails(); errorInstance.getDetails().add(errorDetailsInstance); JsonNode codeValue2 = detailsValue.get("code"); if (codeValue2 != null && codeValue2 instanceof NullNode == false) { String codeInstance2; codeInstance2 = codeValue2.getTextValue(); errorDetailsInstance.setCode(codeInstance2); } JsonNode targetValue2 = detailsValue.get("target"); if (targetValue2 != null && targetValue2 instanceof NullNode == false) { String targetInstance2; targetInstance2 = targetValue2.getTextValue(); errorDetailsInstance.setTarget(targetInstance2); } JsonNode messageValue2 = detailsValue.get("message"); if (messageValue2 != null && messageValue2 instanceof NullNode == false) { String messageInstance2; messageInstance2 = messageValue2.getTextValue(); errorDetailsInstance.setMessage(messageInstance2); } } } JsonNode innerErrorValue = errorValue.get("innerError"); if (innerErrorValue != null && innerErrorValue instanceof NullNode == false) { String innerErrorInstance; innerErrorInstance = innerErrorValue.getTextValue(); errorInstance.setInnerError(innerErrorInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("Azure-AsyncOperation").length > 0) { result.setAzureAsyncOperation(httpResponse.getFirstHeader("Azure-AsyncOperation").getValue()); } if (httpResponse.getHeaders("Retry-After").length > 0) { result.setRetryAfter( DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue())); } if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.servicebus.QueueOperationsImpl.java
/** * The queue description is an XML AtomPub document that defines the desired * semantics for a subscription. The queue description contains the * following properties. For more information, see the QueueDescription * Properties topic. (see//from w w w .ja va 2 s . com * http://msdn.microsoft.com/en-us/library/windowsazure/hh780773.aspx for * more information) * * @param namespaceName Required. The namespace name. * @param queueName Required. The queue name. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return A response to a request for a particular queue. */ @Override public ServiceBusQueueResponse get(String namespaceName, String queueName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (namespaceName == null) { throw new NullPointerException("namespaceName"); } if (queueName == null) { throw new NullPointerException("queueName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("namespaceName", namespaceName); tracingParameters.put("queueName", queueName); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/servicebus/namespaces/"; url = url + URLEncoder.encode(namespaceName, "UTF-8"); url = url + "/Queues/"; url = url + URLEncoder.encode(queueName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml; charset=utf-8"); httpRequest.setHeader("x-ms-version", "2013-08-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ServiceBusQueueResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServiceBusQueueResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element entryElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom", "entry"); if (entryElement != null) { Element titleElement = XmlUtility.getElementByTagNameNS(entryElement, "http://www.w3.org/2005/Atom", "title"); if (titleElement != null) { } Element contentElement = XmlUtility.getElementByTagNameNS(entryElement, "http://www.w3.org/2005/Atom", "content"); if (contentElement != null) { Element queueDescriptionElement = XmlUtility.getElementByTagNameNS(contentElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "QueueDescription"); if (queueDescriptionElement != null) { ServiceBusQueue queueDescriptionInstance = new ServiceBusQueue(); result.setQueue(queueDescriptionInstance); Element lockDurationElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "LockDuration"); if (lockDurationElement != null) { String lockDurationInstance; lockDurationInstance = lockDurationElement.getTextContent(); queueDescriptionInstance.setLockDuration(lockDurationInstance); } Element maxSizeInMegabytesElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MaxSizeInMegabytes"); if (maxSizeInMegabytesElement != null) { int maxSizeInMegabytesInstance; maxSizeInMegabytesInstance = DatatypeConverter .parseInt(maxSizeInMegabytesElement.getTextContent()); queueDescriptionInstance.setMaxSizeInMegabytes(maxSizeInMegabytesInstance); } Element requiresDuplicateDetectionElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "RequiresDuplicateDetection"); if (requiresDuplicateDetectionElement != null) { boolean requiresDuplicateDetectionInstance; requiresDuplicateDetectionInstance = DatatypeConverter.parseBoolean( requiresDuplicateDetectionElement.getTextContent().toLowerCase()); queueDescriptionInstance .setRequiresDuplicateDetection(requiresDuplicateDetectionInstance); } Element requiresSessionElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "RequiresSession"); if (requiresSessionElement != null) { boolean requiresSessionInstance; requiresSessionInstance = DatatypeConverter .parseBoolean(requiresSessionElement.getTextContent().toLowerCase()); queueDescriptionInstance.setRequiresSession(requiresSessionInstance); } Element defaultMessageTimeToLiveElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DefaultMessageTimeToLive"); if (defaultMessageTimeToLiveElement != null) { String defaultMessageTimeToLiveInstance; defaultMessageTimeToLiveInstance = defaultMessageTimeToLiveElement.getTextContent(); queueDescriptionInstance .setDefaultMessageTimeToLive(defaultMessageTimeToLiveInstance); } Element deadLetteringOnMessageExpirationElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DeadLetteringOnMessageExpiration"); if (deadLetteringOnMessageExpirationElement != null) { boolean deadLetteringOnMessageExpirationInstance; deadLetteringOnMessageExpirationInstance = DatatypeConverter.parseBoolean( deadLetteringOnMessageExpirationElement.getTextContent().toLowerCase()); queueDescriptionInstance.setDeadLetteringOnMessageExpiration( deadLetteringOnMessageExpirationInstance); } Element duplicateDetectionHistoryTimeWindowElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DuplicateDetectionHistoryTimeWindow"); if (duplicateDetectionHistoryTimeWindowElement != null) { String duplicateDetectionHistoryTimeWindowInstance; duplicateDetectionHistoryTimeWindowInstance = duplicateDetectionHistoryTimeWindowElement .getTextContent(); queueDescriptionInstance.setDuplicateDetectionHistoryTimeWindow( duplicateDetectionHistoryTimeWindowInstance); } Element maxDeliveryCountElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MaxDeliveryCount"); if (maxDeliveryCountElement != null) { int maxDeliveryCountInstance; maxDeliveryCountInstance = DatatypeConverter .parseInt(maxDeliveryCountElement.getTextContent()); queueDescriptionInstance.setMaxDeliveryCount(maxDeliveryCountInstance); } Element enableBatchedOperationsElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "EnableBatchedOperations"); if (enableBatchedOperationsElement != null) { boolean enableBatchedOperationsInstance; enableBatchedOperationsInstance = DatatypeConverter.parseBoolean( enableBatchedOperationsElement.getTextContent().toLowerCase()); queueDescriptionInstance .setEnableBatchedOperations(enableBatchedOperationsInstance); } Element sizeInBytesElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SizeInBytes"); if (sizeInBytesElement != null) { int sizeInBytesInstance; sizeInBytesInstance = DatatypeConverter .parseInt(sizeInBytesElement.getTextContent()); queueDescriptionInstance.setSizeInBytes(sizeInBytesInstance); } Element messageCountElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MessageCount"); if (messageCountElement != null) { int messageCountInstance; messageCountInstance = DatatypeConverter .parseInt(messageCountElement.getTextContent()); queueDescriptionInstance.setMessageCount(messageCountInstance); } Element isAnonymousAccessibleElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "IsAnonymousAccessible"); if (isAnonymousAccessibleElement != null) { boolean isAnonymousAccessibleInstance; isAnonymousAccessibleInstance = DatatypeConverter .parseBoolean(isAnonymousAccessibleElement.getTextContent().toLowerCase()); queueDescriptionInstance.setIsAnonymousAccessible(isAnonymousAccessibleInstance); } Element authorizationRulesSequenceElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRules"); if (authorizationRulesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(authorizationRulesSequenceElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRule") .size(); i1 = i1 + 1) { org.w3c.dom.Element authorizationRulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(authorizationRulesSequenceElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRule") .get(i1)); ServiceBusSharedAccessAuthorizationRule authorizationRuleInstance = new ServiceBusSharedAccessAuthorizationRule(); queueDescriptionInstance.getAuthorizationRules().add(authorizationRuleInstance); Element claimTypeElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimType"); if (claimTypeElement != null) { String claimTypeInstance; claimTypeInstance = claimTypeElement.getTextContent(); authorizationRuleInstance.setClaimType(claimTypeInstance); } Element claimValueElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimValue"); if (claimValueElement != null) { String claimValueInstance; claimValueInstance = claimValueElement.getTextContent(); authorizationRuleInstance.setClaimValue(claimValueInstance); } Element rightsSequenceElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Rights"); if (rightsSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(rightsSequenceElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights") .size(); i2 = i2 + 1) { org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(rightsSequenceElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights") .get(i2)); authorizationRuleInstance.getRights() .add(AccessRight.valueOf(rightsElement.getTextContent())); } } Element createdTimeElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedTime"); if (createdTimeElement != null) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter .parseDateTime(createdTimeElement.getTextContent()); authorizationRuleInstance.setCreatedTime(createdTimeInstance); } Element keyNameElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "KeyName"); if (keyNameElement != null) { String keyNameInstance; keyNameInstance = keyNameElement.getTextContent(); authorizationRuleInstance.setKeyName(keyNameInstance); } Element modifiedTimeElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ModifiedTime"); if (modifiedTimeElement != null) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeElement.getTextContent()); authorizationRuleInstance.setModifiedTime(modifiedTimeInstance); } Element primaryKeyElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "PrimaryKey"); if (primaryKeyElement != null) { String primaryKeyInstance; primaryKeyInstance = primaryKeyElement.getTextContent(); authorizationRuleInstance.setPrimaryKey(primaryKeyInstance); } Element secondaryKeyElement = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SecondaryKey"); if (secondaryKeyElement != null) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyElement.getTextContent(); authorizationRuleInstance.setSecondaryKey(secondaryKeyInstance); } } } Element statusElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Status"); if (statusElement != null) { String statusInstance; statusInstance = statusElement.getTextContent(); queueDescriptionInstance.setStatus(statusInstance); } Element createdAtElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedAt"); if (createdAtElement != null) { Calendar createdAtInstance; createdAtInstance = DatatypeConverter .parseDateTime(createdAtElement.getTextContent()); queueDescriptionInstance.setCreatedAt(createdAtInstance); } Element updatedAtElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "UpdatedAt"); if (updatedAtElement != null) { Calendar updatedAtInstance; updatedAtInstance = DatatypeConverter .parseDateTime(updatedAtElement.getTextContent()); queueDescriptionInstance.setUpdatedAt(updatedAtInstance); } Element accessedAtElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessedAt"); if (accessedAtElement != null) { Calendar accessedAtInstance; accessedAtInstance = DatatypeConverter .parseDateTime(accessedAtElement.getTextContent()); queueDescriptionInstance.setAccessedAt(accessedAtInstance); } Element supportOrderingElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SupportOrdering"); if (supportOrderingElement != null) { boolean supportOrderingInstance; supportOrderingInstance = DatatypeConverter .parseBoolean(supportOrderingElement.getTextContent().toLowerCase()); queueDescriptionInstance.setSupportOrdering(supportOrderingInstance); } Element countDetailsElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CountDetails"); if (countDetailsElement != null) { CountDetails countDetailsInstance = new CountDetails(); queueDescriptionInstance.setCountDetails(countDetailsInstance); Element activeMessageCountElement = XmlUtility.getElementByTagNameNS( countDetailsElement, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "ActiveMessageCount"); if (activeMessageCountElement != null) { int activeMessageCountInstance; activeMessageCountInstance = DatatypeConverter .parseInt(activeMessageCountElement.getTextContent()); countDetailsInstance.setActiveMessageCount(activeMessageCountInstance); } Element deadLetterMessageCountElement = XmlUtility.getElementByTagNameNS( countDetailsElement, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "DeadLetterMessageCount"); if (deadLetterMessageCountElement != null) { int deadLetterMessageCountInstance; deadLetterMessageCountInstance = DatatypeConverter .parseInt(deadLetterMessageCountElement.getTextContent()); countDetailsInstance.setDeadLetterMessageCount(deadLetterMessageCountInstance); } Element scheduledMessageCountElement = XmlUtility.getElementByTagNameNS( countDetailsElement, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "ScheduledMessageCount"); if (scheduledMessageCountElement != null) { int scheduledMessageCountInstance; scheduledMessageCountInstance = DatatypeConverter .parseInt(scheduledMessageCountElement.getTextContent()); countDetailsInstance.setScheduledMessageCount(scheduledMessageCountInstance); } Element transferDeadLetterMessageCountElement = XmlUtility.getElementByTagNameNS( countDetailsElement, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "TransferDeadLetterMessageCount"); if (transferDeadLetterMessageCountElement != null) { int transferDeadLetterMessageCountInstance; transferDeadLetterMessageCountInstance = DatatypeConverter .parseInt(transferDeadLetterMessageCountElement.getTextContent()); countDetailsInstance.setTransferDeadLetterMessageCount( transferDeadLetterMessageCountInstance); } Element transferMessageCountElement = XmlUtility.getElementByTagNameNS( countDetailsElement, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "TransferMessageCount"); if (transferMessageCountElement != null) { int transferMessageCountInstance; transferMessageCountInstance = DatatypeConverter .parseInt(transferMessageCountElement.getTextContent()); countDetailsInstance.setTransferMessageCount(transferMessageCountInstance); } } Element autoDeleteOnIdleElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AutoDeleteOnIdle"); if (autoDeleteOnIdleElement != null) { String autoDeleteOnIdleInstance; autoDeleteOnIdleInstance = autoDeleteOnIdleElement.getTextContent(); queueDescriptionInstance.setAutoDeleteOnIdle(autoDeleteOnIdleInstance); } Element entityAvailabilityStatusElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "EntityAvailabilityStatus"); if (entityAvailabilityStatusElement != null) { String entityAvailabilityStatusInstance; entityAvailabilityStatusInstance = entityAvailabilityStatusElement.getTextContent(); queueDescriptionInstance .setEntityAvailabilityStatus(entityAvailabilityStatusInstance); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebHostingPlanOperationsImpl.java
/** * Updates an existing Web Hosting Plan. (see * http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/ * for more information)// w w w . j av a 2s . c om * * @param webSpaceName Required. The name of the web space. * @param webHostingPlanName Required. The name of the web hosting plan. * @param parameters Required. Parameters supplied to the Update Web Hosting * Plan 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 Hosting Plan operation response. */ @Override public WebHostingPlanUpdateResponse update(String webSpaceName, String webHostingPlanName, WebHostingPlanUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webHostingPlanName == null) { throw new NullPointerException("webHostingPlanName"); } 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("webHostingPlanName", webHostingPlanName); 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 + "/ServerFarms/"; url = url + URLEncoder.encode(webHostingPlanName, "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 serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); requestDoc.appendChild(serverFarmElement); if (parameters.getNumberOfWorkers() != null) { Element numberOfWorkersElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); numberOfWorkersElement .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getNumberOfWorkers()))); serverFarmElement.appendChild(numberOfWorkersElement); } if (parameters.getSKU() != null) { Element sKUElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SKU"); sKUElement.appendChild(requestDoc.createTextNode(parameters.getSKU().toString())); serverFarmElement.appendChild(sKUElement); } if (parameters.getWorkerSize() != null) { Element workerSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "WorkerSize"); workerSizeElement.appendChild(requestDoc.createTextNode(parameters.getWorkerSize().toString())); serverFarmElement.appendChild(workerSizeElement); } if (parameters.getAdminSiteName() != null) { Element adminSiteNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "AdminSiteName"); adminSiteNameElement.appendChild(requestDoc.createTextNode(parameters.getAdminSiteName())); serverFarmElement.appendChild(adminSiteNameElement); } 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 WebHostingPlanUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebHostingPlanUpdateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { WebHostingPlan webHostingPlanInstance = new WebHostingPlan(); result.setWebHostingPlan(webHostingPlanInstance); Element nameElement = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); webHostingPlanInstance.setName(nameInstance); } Element numberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); if (numberOfWorkersElement2 != null && numberOfWorkersElement2.getTextContent() != null && !numberOfWorkersElement2.getTextContent().isEmpty()) { int numberOfWorkersInstance; numberOfWorkersInstance = DatatypeConverter .parseInt(numberOfWorkersElement2.getTextContent()); webHostingPlanInstance.setNumberOfWorkers(numberOfWorkersInstance); } Element sKUElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement2 != null && sKUElement2.getTextContent() != null && !sKUElement2.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement2.getTextContent()); webHostingPlanInstance.setSKU(sKUInstance); } Element workerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement2 != null && workerSizeElement2.getTextContent() != null && !workerSizeElement2.getTextContent().isEmpty()) { WorkerSizeOptions workerSizeInstance; workerSizeInstance = WorkerSizeOptions.valueOf(workerSizeElement2.getTextContent()); webHostingPlanInstance.setWorkerSize(workerSizeInstance); } Element adminSiteNameElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "AdminSiteName"); if (adminSiteNameElement2 != null) { String adminSiteNameInstance; adminSiteNameInstance = adminSiteNameElement2.getTextContent(); webHostingPlanInstance.setAdminSiteName(adminSiteNameInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseCopyOperationsImpl.java
/** * Updates a SQL Server database copy./*from www . ja va 2 s . c om*/ * * @param serverName Required. The name of the source or destination SQL * Server instance. * @param databaseName Required. The name of the database. * @param databaseCopyName Required. The unique identifier for the database * copy to update. * @param parameters Required. The additional parameters for the update * database copy operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return Represents a response to the update request. */ @Override public DatabaseCopyUpdateResponse update(String serverName, String databaseName, String databaseCopyName, DatabaseCopyUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } if (databaseCopyName == null) { throw new NullPointerException("databaseCopyName"); } if (parameters == null) { throw new NullPointerException("parameters"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("databaseName", databaseName); tracingParameters.put("databaseCopyName", databaseCopyName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "updateAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases/"; url = url + URLEncoder.encode(databaseName, "UTF-8"); url = url + "/databasecopies/"; url = url + URLEncoder.encode(databaseCopyName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2012-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceResource"); requestDoc.appendChild(serviceResourceElement); if (parameters.isForcedTerminate() != null) { Element isForcedTerminateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IsForcedTerminate"); isForcedTerminateElement.appendChild( requestDoc.createTextNode(Boolean.toString(parameters.isForcedTerminate()).toLowerCase())); serviceResourceElement.appendChild(isForcedTerminateElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseCopyUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseCopyUpdateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement2 != null) { DatabaseCopy serviceResourceInstance = new DatabaseCopy(); result.setDatabaseCopy(serviceResourceInstance); Element sourceServerNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SourceServerName"); if (sourceServerNameElement != null) { String sourceServerNameInstance; sourceServerNameInstance = sourceServerNameElement.getTextContent(); serviceResourceInstance.setSourceServerName(sourceServerNameInstance); } Element sourceDatabaseNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SourceDatabaseName"); if (sourceDatabaseNameElement != null) { String sourceDatabaseNameInstance; sourceDatabaseNameInstance = sourceDatabaseNameElement.getTextContent(); serviceResourceInstance.setSourceDatabaseName(sourceDatabaseNameInstance); } Element destinationServerNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "DestinationServerName"); if (destinationServerNameElement != null) { String destinationServerNameInstance; destinationServerNameInstance = destinationServerNameElement.getTextContent(); serviceResourceInstance.setDestinationServerName(destinationServerNameInstance); } Element destinationDatabaseNameElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "DestinationDatabaseName"); if (destinationDatabaseNameElement != null) { String destinationDatabaseNameInstance; destinationDatabaseNameInstance = destinationDatabaseNameElement.getTextContent(); serviceResourceInstance.setDestinationDatabaseName(destinationDatabaseNameInstance); } Element isContinuousElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsContinuous"); if (isContinuousElement != null) { boolean isContinuousInstance; isContinuousInstance = DatatypeConverter .parseBoolean(isContinuousElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsContinuous(isContinuousInstance); } Element replicationStateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ReplicationState"); if (replicationStateElement != null) { byte replicationStateInstance; replicationStateInstance = DatatypeConverter .parseByte(replicationStateElement.getTextContent()); serviceResourceInstance.setReplicationState(replicationStateInstance); } Element replicationStateDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ReplicationStateDescription"); if (replicationStateDescriptionElement != null) { String replicationStateDescriptionInstance; replicationStateDescriptionInstance = replicationStateDescriptionElement.getTextContent(); serviceResourceInstance.setReplicationStateDescription(replicationStateDescriptionInstance); } Element localDatabaseIdElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "LocalDatabaseId"); if (localDatabaseIdElement != null) { int localDatabaseIdInstance; localDatabaseIdInstance = DatatypeConverter .parseInt(localDatabaseIdElement.getTextContent()); serviceResourceInstance.setLocalDatabaseId(localDatabaseIdInstance); } Element isLocalDatabaseReplicationTargetElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsLocalDatabaseReplicationTarget"); if (isLocalDatabaseReplicationTargetElement != null) { boolean isLocalDatabaseReplicationTargetInstance; isLocalDatabaseReplicationTargetInstance = DatatypeConverter.parseBoolean( isLocalDatabaseReplicationTargetElement.getTextContent().toLowerCase()); serviceResourceInstance .setIsLocalDatabaseReplicationTarget(isLocalDatabaseReplicationTargetInstance); } Element isInterlinkConnectedElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsInterlinkConnected"); if (isInterlinkConnectedElement != null) { boolean isInterlinkConnectedInstance; isInterlinkConnectedInstance = DatatypeConverter .parseBoolean(isInterlinkConnectedElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsInterlinkConnected(isInterlinkConnectedInstance); } Element startDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "StartDate"); if (startDateElement != null) { String startDateInstance; startDateInstance = startDateElement.getTextContent(); serviceResourceInstance.setStartDate(startDateInstance); } Element modifyDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ModifyDate"); if (modifyDateElement != null) { String modifyDateInstance; modifyDateInstance = modifyDateElement.getTextContent(); serviceResourceInstance.setModifyDate(modifyDateInstance); } Element percentCompleteElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "PercentComplete"); if (percentCompleteElement != null) { float percentCompleteInstance; percentCompleteInstance = DatatypeConverter .parseFloat(percentCompleteElement.getTextContent()); serviceResourceInstance.setPercentComplete(percentCompleteInstance); } Element isOfflineSecondaryElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsOfflineSecondary"); if (isOfflineSecondaryElement != null) { boolean isOfflineSecondaryInstance; isOfflineSecondaryInstance = DatatypeConverter .parseBoolean(isOfflineSecondaryElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsOfflineSecondary(isOfflineSecondaryInstance); } Element isTerminationAllowedElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsTerminationAllowed"); if (isTerminationAllowedElement != null) { boolean isTerminationAllowedInstance; isTerminationAllowedInstance = DatatypeConverter .parseBoolean(isTerminationAllowedElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsTerminationAllowed(isTerminationAllowedInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.azure.management.network.VirtualNetworkGatewayConnectionOperationsImpl.java
/** * The Put VirtualNetworkGatewayConnection operation creates/updates a * virtual network gateway connection in the specified resource group * through Network resource provider.// w ww . j av a2 s . co m * * @param resourceGroupName Required. The name of the resource group. * @param virtualNetworkGatewayConnectionName Required. The name of the * virtual network gateway conenction. * @param parameters Required. Parameters supplied to the Begin Create or * update Virtual Network Gateway connection operation through Network * resource provider. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return Response for CreateOrUpdateVirtualNetworkGatewayConnection Api * servive call */ @Override public VirtualNetworkGatewayConnectionPutResponse beginCreateOrUpdating(String resourceGroupName, String virtualNetworkGatewayConnectionName, VirtualNetworkGatewayConnection parameters) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (virtualNetworkGatewayConnectionName == null) { throw new NullPointerException("virtualNetworkGatewayConnectionName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLocalNetworkGateway2() != null) { if (parameters.getLocalNetworkGateway2().getLocation() == null) { throw new NullPointerException("parameters.LocalNetworkGateway2.Location"); } } if (parameters.getLocation() == null) { throw new NullPointerException("parameters.Location"); } if (parameters.getVirtualNetworkGateway1() != null) { if (parameters.getVirtualNetworkGateway1().getLocation() == null) { throw new NullPointerException("parameters.VirtualNetworkGateway1.Location"); } } if (parameters.getVirtualNetworkGateway2() != null) { if (parameters.getVirtualNetworkGateway2().getLocation() == null) { throw new NullPointerException("parameters.VirtualNetworkGateway2.Location"); } } // 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("virtualNetworkGatewayConnectionName", virtualNetworkGatewayConnectionName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCreateOrUpdatingAsync", 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.Network"; url = url + "/connections/"; url = url + URLEncoder.encode(virtualNetworkGatewayConnectionName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-05-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json"); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode virtualNetworkGatewayConnectionJsonFormatValue = objectMapper.createObjectNode(); requestDoc = virtualNetworkGatewayConnectionJsonFormatValue; ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) virtualNetworkGatewayConnectionJsonFormatValue).put("properties", propertiesValue); if (parameters.getVirtualNetworkGateway1() != null) { ObjectNode virtualNetworkGateway1Value = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("virtualNetworkGateway1", virtualNetworkGateway1Value); if (parameters.getVirtualNetworkGateway1().getIpConfigurations() != null) { if (parameters.getVirtualNetworkGateway1().getIpConfigurations() instanceof LazyCollection == false || ((LazyCollection) parameters.getVirtualNetworkGateway1().getIpConfigurations()) .isInitialized()) { ArrayNode ipConfigurationsArray = objectMapper.createArrayNode(); for (VirtualNetworkGatewayIpConfiguration ipConfigurationsItem : parameters .getVirtualNetworkGateway1().getIpConfigurations()) { ObjectNode virtualNetworkGatewayIpConfigurationValue = objectMapper.createObjectNode(); ipConfigurationsArray.add(virtualNetworkGatewayIpConfigurationValue); if (ipConfigurationsItem.getPrivateIpAddress() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue).put("privateIPAddress", ipConfigurationsItem.getPrivateIpAddress()); } if (ipConfigurationsItem.getPrivateIpAllocationMethod() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue).put( "privateIPAllocationMethod", ipConfigurationsItem.getPrivateIpAllocationMethod()); } if (ipConfigurationsItem.getSubnet() != null) { ObjectNode subnetValue = objectMapper.createObjectNode(); ((ObjectNode) virtualNetworkGatewayIpConfigurationValue).put("subnet", subnetValue); if (ipConfigurationsItem.getSubnet().getId() != null) { ((ObjectNode) subnetValue).put("id", ipConfigurationsItem.getSubnet().getId()); } } if (ipConfigurationsItem.getPublicIpAddress() != null) { ObjectNode publicIPAddressValue = objectMapper.createObjectNode(); ((ObjectNode) virtualNetworkGatewayIpConfigurationValue).put("publicIPAddress", publicIPAddressValue); if (ipConfigurationsItem.getPublicIpAddress().getId() != null) { ((ObjectNode) publicIPAddressValue).put("id", ipConfigurationsItem.getPublicIpAddress().getId()); } } if (ipConfigurationsItem.getProvisioningState() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue).put("provisioningState", ipConfigurationsItem.getProvisioningState()); } if (ipConfigurationsItem.getName() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue).put("name", ipConfigurationsItem.getName()); } if (ipConfigurationsItem.getEtag() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue).put("etag", ipConfigurationsItem.getEtag()); } if (ipConfigurationsItem.getId() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue).put("id", ipConfigurationsItem.getId()); } } ((ObjectNode) virtualNetworkGateway1Value).put("ipConfigurations", ipConfigurationsArray); } } if (parameters.getVirtualNetworkGateway1().getGatewayType() != null) { ((ObjectNode) virtualNetworkGateway1Value).put("gatewayType", parameters.getVirtualNetworkGateway1().getGatewayType()); } if (parameters.getVirtualNetworkGateway1().getVpnType() != null) { ((ObjectNode) virtualNetworkGateway1Value).put("vpnType", parameters.getVirtualNetworkGateway1().getVpnType()); } ((ObjectNode) virtualNetworkGateway1Value).put("enableBgp", parameters.getVirtualNetworkGateway1().isEnableBgp()); if (parameters.getVirtualNetworkGateway1().getProvisioningState() != null) { ((ObjectNode) virtualNetworkGateway1Value).put("provisioningState", parameters.getVirtualNetworkGateway1().getProvisioningState()); } if (parameters.getVirtualNetworkGateway1().getResourceGuid() != null) { ((ObjectNode) virtualNetworkGateway1Value).put("resourceGuid", parameters.getVirtualNetworkGateway1().getResourceGuid()); } if (parameters.getVirtualNetworkGateway1().getEtag() != null) { ((ObjectNode) virtualNetworkGateway1Value).put("etag", parameters.getVirtualNetworkGateway1().getEtag()); } if (parameters.getVirtualNetworkGateway1().getId() != null) { ((ObjectNode) virtualNetworkGateway1Value).put("id", parameters.getVirtualNetworkGateway1().getId()); } if (parameters.getVirtualNetworkGateway1().getName() != null) { ((ObjectNode) virtualNetworkGateway1Value).put("name", parameters.getVirtualNetworkGateway1().getName()); } if (parameters.getVirtualNetworkGateway1().getType() != null) { ((ObjectNode) virtualNetworkGateway1Value).put("type", parameters.getVirtualNetworkGateway1().getType()); } ((ObjectNode) virtualNetworkGateway1Value).put("location", parameters.getVirtualNetworkGateway1().getLocation()); if (parameters.getVirtualNetworkGateway1().getTags() != null) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getVirtualNetworkGateway1().getTags() .entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) virtualNetworkGateway1Value).put("tags", tagsDictionary); } } if (parameters.getVirtualNetworkGateway2() != null) { ObjectNode virtualNetworkGateway2Value = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("virtualNetworkGateway2", virtualNetworkGateway2Value); if (parameters.getVirtualNetworkGateway2().getIpConfigurations() != null) { if (parameters.getVirtualNetworkGateway2().getIpConfigurations() instanceof LazyCollection == false || ((LazyCollection) parameters.getVirtualNetworkGateway2().getIpConfigurations()) .isInitialized()) { ArrayNode ipConfigurationsArray2 = objectMapper.createArrayNode(); for (VirtualNetworkGatewayIpConfiguration ipConfigurationsItem2 : parameters .getVirtualNetworkGateway2().getIpConfigurations()) { ObjectNode virtualNetworkGatewayIpConfigurationValue2 = objectMapper.createObjectNode(); ipConfigurationsArray2.add(virtualNetworkGatewayIpConfigurationValue2); if (ipConfigurationsItem2.getPrivateIpAddress() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue2).put("privateIPAddress", ipConfigurationsItem2.getPrivateIpAddress()); } if (ipConfigurationsItem2.getPrivateIpAllocationMethod() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue2).put( "privateIPAllocationMethod", ipConfigurationsItem2.getPrivateIpAllocationMethod()); } if (ipConfigurationsItem2.getSubnet() != null) { ObjectNode subnetValue2 = objectMapper.createObjectNode(); ((ObjectNode) virtualNetworkGatewayIpConfigurationValue2).put("subnet", subnetValue2); if (ipConfigurationsItem2.getSubnet().getId() != null) { ((ObjectNode) subnetValue2).put("id", ipConfigurationsItem2.getSubnet().getId()); } } if (ipConfigurationsItem2.getPublicIpAddress() != null) { ObjectNode publicIPAddressValue2 = objectMapper.createObjectNode(); ((ObjectNode) virtualNetworkGatewayIpConfigurationValue2).put("publicIPAddress", publicIPAddressValue2); if (ipConfigurationsItem2.getPublicIpAddress().getId() != null) { ((ObjectNode) publicIPAddressValue2).put("id", ipConfigurationsItem2.getPublicIpAddress().getId()); } } if (ipConfigurationsItem2.getProvisioningState() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue2).put("provisioningState", ipConfigurationsItem2.getProvisioningState()); } if (ipConfigurationsItem2.getName() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue2).put("name", ipConfigurationsItem2.getName()); } if (ipConfigurationsItem2.getEtag() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue2).put("etag", ipConfigurationsItem2.getEtag()); } if (ipConfigurationsItem2.getId() != null) { ((ObjectNode) virtualNetworkGatewayIpConfigurationValue2).put("id", ipConfigurationsItem2.getId()); } } ((ObjectNode) virtualNetworkGateway2Value).put("ipConfigurations", ipConfigurationsArray2); } } if (parameters.getVirtualNetworkGateway2().getGatewayType() != null) { ((ObjectNode) virtualNetworkGateway2Value).put("gatewayType", parameters.getVirtualNetworkGateway2().getGatewayType()); } if (parameters.getVirtualNetworkGateway2().getVpnType() != null) { ((ObjectNode) virtualNetworkGateway2Value).put("vpnType", parameters.getVirtualNetworkGateway2().getVpnType()); } ((ObjectNode) virtualNetworkGateway2Value).put("enableBgp", parameters.getVirtualNetworkGateway2().isEnableBgp()); if (parameters.getVirtualNetworkGateway2().getProvisioningState() != null) { ((ObjectNode) virtualNetworkGateway2Value).put("provisioningState", parameters.getVirtualNetworkGateway2().getProvisioningState()); } if (parameters.getVirtualNetworkGateway2().getResourceGuid() != null) { ((ObjectNode) virtualNetworkGateway2Value).put("resourceGuid", parameters.getVirtualNetworkGateway2().getResourceGuid()); } if (parameters.getVirtualNetworkGateway2().getEtag() != null) { ((ObjectNode) virtualNetworkGateway2Value).put("etag", parameters.getVirtualNetworkGateway2().getEtag()); } if (parameters.getVirtualNetworkGateway2().getId() != null) { ((ObjectNode) virtualNetworkGateway2Value).put("id", parameters.getVirtualNetworkGateway2().getId()); } if (parameters.getVirtualNetworkGateway2().getName() != null) { ((ObjectNode) virtualNetworkGateway2Value).put("name", parameters.getVirtualNetworkGateway2().getName()); } if (parameters.getVirtualNetworkGateway2().getType() != null) { ((ObjectNode) virtualNetworkGateway2Value).put("type", parameters.getVirtualNetworkGateway2().getType()); } ((ObjectNode) virtualNetworkGateway2Value).put("location", parameters.getVirtualNetworkGateway2().getLocation()); if (parameters.getVirtualNetworkGateway2().getTags() != null) { ObjectNode tagsDictionary2 = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry2 : parameters.getVirtualNetworkGateway2().getTags() .entrySet()) { String tagsKey2 = entry2.getKey(); String tagsValue2 = entry2.getValue(); ((ObjectNode) tagsDictionary2).put(tagsKey2, tagsValue2); } ((ObjectNode) virtualNetworkGateway2Value).put("tags", tagsDictionary2); } } if (parameters.getLocalNetworkGateway2() != null) { ObjectNode localNetworkGateway2Value = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("localNetworkGateway2", localNetworkGateway2Value); if (parameters.getLocalNetworkGateway2().getLocalNetworkAddressSpace() != null) { ObjectNode localNetworkAddressSpaceValue = objectMapper.createObjectNode(); ((ObjectNode) localNetworkGateway2Value).put("localNetworkAddressSpace", localNetworkAddressSpaceValue); if (parameters.getLocalNetworkGateway2().getLocalNetworkAddressSpace() .getAddressPrefixes() != null) { if (parameters.getLocalNetworkGateway2().getLocalNetworkAddressSpace() .getAddressPrefixes() instanceof LazyCollection == false || ((LazyCollection) parameters.getLocalNetworkGateway2().getLocalNetworkAddressSpace() .getAddressPrefixes()).isInitialized()) { ArrayNode addressPrefixesArray = objectMapper.createArrayNode(); for (String addressPrefixesItem : parameters.getLocalNetworkGateway2() .getLocalNetworkAddressSpace().getAddressPrefixes()) { addressPrefixesArray.add(addressPrefixesItem); } ((ObjectNode) localNetworkAddressSpaceValue).put("addressPrefixes", addressPrefixesArray); } } } if (parameters.getLocalNetworkGateway2().getGatewayIpAddress() != null) { ((ObjectNode) localNetworkGateway2Value).put("gatewayIpAddress", parameters.getLocalNetworkGateway2().getGatewayIpAddress()); } if (parameters.getLocalNetworkGateway2().getProvisioningState() != null) { ((ObjectNode) localNetworkGateway2Value).put("provisioningState", parameters.getLocalNetworkGateway2().getProvisioningState()); } if (parameters.getLocalNetworkGateway2().getResourceGuid() != null) { ((ObjectNode) localNetworkGateway2Value).put("resourceGuid", parameters.getLocalNetworkGateway2().getResourceGuid()); } if (parameters.getLocalNetworkGateway2().getEtag() != null) { ((ObjectNode) localNetworkGateway2Value).put("etag", parameters.getLocalNetworkGateway2().getEtag()); } if (parameters.getLocalNetworkGateway2().getId() != null) { ((ObjectNode) localNetworkGateway2Value).put("id", parameters.getLocalNetworkGateway2().getId()); } if (parameters.getLocalNetworkGateway2().getName() != null) { ((ObjectNode) localNetworkGateway2Value).put("name", parameters.getLocalNetworkGateway2().getName()); } if (parameters.getLocalNetworkGateway2().getType() != null) { ((ObjectNode) localNetworkGateway2Value).put("type", parameters.getLocalNetworkGateway2().getType()); } ((ObjectNode) localNetworkGateway2Value).put("location", parameters.getLocalNetworkGateway2().getLocation()); if (parameters.getLocalNetworkGateway2().getTags() != null) { ObjectNode tagsDictionary3 = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry3 : parameters.getLocalNetworkGateway2().getTags().entrySet()) { String tagsKey3 = entry3.getKey(); String tagsValue3 = entry3.getValue(); ((ObjectNode) tagsDictionary3).put(tagsKey3, tagsValue3); } ((ObjectNode) localNetworkGateway2Value).put("tags", tagsDictionary3); } } if (parameters.getConnectionType() != null) { ((ObjectNode) propertiesValue).put("connectionType", parameters.getConnectionType()); } ((ObjectNode) propertiesValue).put("routingWeight", parameters.getRoutingWeight()); if (parameters.getSharedKey() != null) { ((ObjectNode) propertiesValue).put("sharedKey", parameters.getSharedKey()); } if (parameters.getResourceGuid() != null) { ((ObjectNode) propertiesValue).put("resourceGuid", parameters.getResourceGuid()); } if (parameters.getProvisioningState() != null) { ((ObjectNode) propertiesValue).put("provisioningState", parameters.getProvisioningState()); } if (parameters.getEtag() != null) { ((ObjectNode) virtualNetworkGatewayConnectionJsonFormatValue).put("etag", parameters.getEtag()); } if (parameters.getId() != null) { ((ObjectNode) virtualNetworkGatewayConnectionJsonFormatValue).put("id", parameters.getId()); } if (parameters.getName() != null) { ((ObjectNode) virtualNetworkGatewayConnectionJsonFormatValue).put("name", parameters.getName()); } if (parameters.getType() != null) { ((ObjectNode) virtualNetworkGatewayConnectionJsonFormatValue).put("type", parameters.getType()); } ((ObjectNode) virtualNetworkGatewayConnectionJsonFormatValue).put("location", parameters.getLocation()); if (parameters.getTags() != null) { ObjectNode tagsDictionary4 = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry4 : parameters.getTags().entrySet()) { String tagsKey4 = entry4.getKey(); String tagsValue4 = entry4.getValue(); ((ObjectNode) tagsDictionary4).put(tagsKey4, tagsValue4); } ((ObjectNode) virtualNetworkGatewayConnectionJsonFormatValue).put("tags", tagsDictionary4); } StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, requestDoc); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/json"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result VirtualNetworkGatewayConnectionPutResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualNetworkGatewayConnectionPutResponse(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { VirtualNetworkGatewayConnection virtualNetworkGatewayConnectionInstance = new VirtualNetworkGatewayConnection(); result.setVirtualNetworkGatewayConnection(virtualNetworkGatewayConnectionInstance); JsonNode propertiesValue2 = responseDoc.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { JsonNode virtualNetworkGateway1Value2 = propertiesValue2.get("virtualNetworkGateway1"); if (virtualNetworkGateway1Value2 != null && virtualNetworkGateway1Value2 instanceof NullNode == false) { VirtualNetworkGateway virtualNetworkGateway1Instance = new VirtualNetworkGateway(); virtualNetworkGatewayConnectionInstance .setVirtualNetworkGateway1(virtualNetworkGateway1Instance); JsonNode ipConfigurationsArray3 = virtualNetworkGateway1Value2.get("ipConfigurations"); if (ipConfigurationsArray3 != null && ipConfigurationsArray3 instanceof NullNode == false) { for (JsonNode ipConfigurationsValue : ((ArrayNode) ipConfigurationsArray3)) { VirtualNetworkGatewayIpConfiguration virtualNetworkGatewayIpConfigurationInstance = new VirtualNetworkGatewayIpConfiguration(); virtualNetworkGateway1Instance.getIpConfigurations() .add(virtualNetworkGatewayIpConfigurationInstance); JsonNode privateIPAddressValue = ipConfigurationsValue.get("privateIPAddress"); if (privateIPAddressValue != null && privateIPAddressValue instanceof NullNode == false) { String privateIPAddressInstance; privateIPAddressInstance = privateIPAddressValue.getTextValue(); virtualNetworkGatewayIpConfigurationInstance .setPrivateIpAddress(privateIPAddressInstance); } JsonNode privateIPAllocationMethodValue = ipConfigurationsValue .get("privateIPAllocationMethod"); if (privateIPAllocationMethodValue != null && privateIPAllocationMethodValue instanceof NullNode == false) { String privateIPAllocationMethodInstance; privateIPAllocationMethodInstance = privateIPAllocationMethodValue .getTextValue(); virtualNetworkGatewayIpConfigurationInstance .setPrivateIpAllocationMethod(privateIPAllocationMethodInstance); } JsonNode subnetValue3 = ipConfigurationsValue.get("subnet"); if (subnetValue3 != null && subnetValue3 instanceof NullNode == false) { ResourceId subnetInstance = new ResourceId(); virtualNetworkGatewayIpConfigurationInstance.setSubnet(subnetInstance); JsonNode idValue = subnetValue3.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); subnetInstance.setId(idInstance); } } JsonNode publicIPAddressValue3 = ipConfigurationsValue.get("publicIPAddress"); if (publicIPAddressValue3 != null && publicIPAddressValue3 instanceof NullNode == false) { ResourceId publicIPAddressInstance = new ResourceId(); virtualNetworkGatewayIpConfigurationInstance .setPublicIpAddress(publicIPAddressInstance); JsonNode idValue2 = publicIPAddressValue3.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); publicIPAddressInstance.setId(idInstance2); } } JsonNode provisioningStateValue = ipConfigurationsValue .get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); virtualNetworkGatewayIpConfigurationInstance .setProvisioningState(provisioningStateInstance); } JsonNode nameValue = ipConfigurationsValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); virtualNetworkGatewayIpConfigurationInstance.setName(nameInstance); } JsonNode etagValue = ipConfigurationsValue.get("etag"); if (etagValue != null && etagValue instanceof NullNode == false) { String etagInstance; etagInstance = etagValue.getTextValue(); virtualNetworkGatewayIpConfigurationInstance.setEtag(etagInstance); } JsonNode idValue3 = ipConfigurationsValue.get("id"); if (idValue3 != null && idValue3 instanceof NullNode == false) { String idInstance3; idInstance3 = idValue3.getTextValue(); virtualNetworkGatewayIpConfigurationInstance.setId(idInstance3); } } } JsonNode gatewayTypeValue = virtualNetworkGateway1Value2.get("gatewayType"); if (gatewayTypeValue != null && gatewayTypeValue instanceof NullNode == false) { String gatewayTypeInstance; gatewayTypeInstance = gatewayTypeValue.getTextValue(); virtualNetworkGateway1Instance.setGatewayType(gatewayTypeInstance); } JsonNode vpnTypeValue = virtualNetworkGateway1Value2.get("vpnType"); if (vpnTypeValue != null && vpnTypeValue instanceof NullNode == false) { String vpnTypeInstance; vpnTypeInstance = vpnTypeValue.getTextValue(); virtualNetworkGateway1Instance.setVpnType(vpnTypeInstance); } JsonNode enableBgpValue = virtualNetworkGateway1Value2.get("enableBgp"); if (enableBgpValue != null && enableBgpValue instanceof NullNode == false) { boolean enableBgpInstance; enableBgpInstance = enableBgpValue.getBooleanValue(); virtualNetworkGateway1Instance.setEnableBgp(enableBgpInstance); } JsonNode provisioningStateValue2 = virtualNetworkGateway1Value2 .get("provisioningState"); if (provisioningStateValue2 != null && provisioningStateValue2 instanceof NullNode == false) { String provisioningStateInstance2; provisioningStateInstance2 = provisioningStateValue2.getTextValue(); virtualNetworkGateway1Instance.setProvisioningState(provisioningStateInstance2); } JsonNode resourceGuidValue = virtualNetworkGateway1Value2.get("resourceGuid"); if (resourceGuidValue != null && resourceGuidValue instanceof NullNode == false) { String resourceGuidInstance; resourceGuidInstance = resourceGuidValue.getTextValue(); virtualNetworkGateway1Instance.setResourceGuid(resourceGuidInstance); } JsonNode etagValue2 = virtualNetworkGateway1Value2.get("etag"); if (etagValue2 != null && etagValue2 instanceof NullNode == false) { String etagInstance2; etagInstance2 = etagValue2.getTextValue(); virtualNetworkGateway1Instance.setEtag(etagInstance2); } JsonNode idValue4 = virtualNetworkGateway1Value2.get("id"); if (idValue4 != null && idValue4 instanceof NullNode == false) { String idInstance4; idInstance4 = idValue4.getTextValue(); virtualNetworkGateway1Instance.setId(idInstance4); } JsonNode nameValue2 = virtualNetworkGateway1Value2.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); virtualNetworkGateway1Instance.setName(nameInstance2); } JsonNode typeValue = virtualNetworkGateway1Value2.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); virtualNetworkGateway1Instance.setType(typeInstance); } JsonNode locationValue = virtualNetworkGateway1Value2.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); virtualNetworkGateway1Instance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) virtualNetworkGateway1Value2.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey5 = property.getKey(); String tagsValue5 = property.getValue().getTextValue(); virtualNetworkGateway1Instance.getTags().put(tagsKey5, tagsValue5); } } } JsonNode virtualNetworkGateway2Value2 = propertiesValue2.get("virtualNetworkGateway2"); if (virtualNetworkGateway2Value2 != null && virtualNetworkGateway2Value2 instanceof NullNode == false) { VirtualNetworkGateway virtualNetworkGateway2Instance = new VirtualNetworkGateway(); virtualNetworkGatewayConnectionInstance .setVirtualNetworkGateway2(virtualNetworkGateway2Instance); JsonNode ipConfigurationsArray4 = virtualNetworkGateway2Value2.get("ipConfigurations"); if (ipConfigurationsArray4 != null && ipConfigurationsArray4 instanceof NullNode == false) { for (JsonNode ipConfigurationsValue2 : ((ArrayNode) ipConfigurationsArray4)) { VirtualNetworkGatewayIpConfiguration virtualNetworkGatewayIpConfigurationInstance2 = new VirtualNetworkGatewayIpConfiguration(); virtualNetworkGateway2Instance.getIpConfigurations() .add(virtualNetworkGatewayIpConfigurationInstance2); JsonNode privateIPAddressValue2 = ipConfigurationsValue2 .get("privateIPAddress"); if (privateIPAddressValue2 != null && privateIPAddressValue2 instanceof NullNode == false) { String privateIPAddressInstance2; privateIPAddressInstance2 = privateIPAddressValue2.getTextValue(); virtualNetworkGatewayIpConfigurationInstance2 .setPrivateIpAddress(privateIPAddressInstance2); } JsonNode privateIPAllocationMethodValue2 = ipConfigurationsValue2 .get("privateIPAllocationMethod"); if (privateIPAllocationMethodValue2 != null && privateIPAllocationMethodValue2 instanceof NullNode == false) { String privateIPAllocationMethodInstance2; privateIPAllocationMethodInstance2 = privateIPAllocationMethodValue2 .getTextValue(); virtualNetworkGatewayIpConfigurationInstance2 .setPrivateIpAllocationMethod(privateIPAllocationMethodInstance2); } JsonNode subnetValue4 = ipConfigurationsValue2.get("subnet"); if (subnetValue4 != null && subnetValue4 instanceof NullNode == false) { ResourceId subnetInstance2 = new ResourceId(); virtualNetworkGatewayIpConfigurationInstance2.setSubnet(subnetInstance2); JsonNode idValue5 = subnetValue4.get("id"); if (idValue5 != null && idValue5 instanceof NullNode == false) { String idInstance5; idInstance5 = idValue5.getTextValue(); subnetInstance2.setId(idInstance5); } } JsonNode publicIPAddressValue4 = ipConfigurationsValue2.get("publicIPAddress"); if (publicIPAddressValue4 != null && publicIPAddressValue4 instanceof NullNode == false) { ResourceId publicIPAddressInstance2 = new ResourceId(); virtualNetworkGatewayIpConfigurationInstance2 .setPublicIpAddress(publicIPAddressInstance2); JsonNode idValue6 = publicIPAddressValue4.get("id"); if (idValue6 != null && idValue6 instanceof NullNode == false) { String idInstance6; idInstance6 = idValue6.getTextValue(); publicIPAddressInstance2.setId(idInstance6); } } JsonNode provisioningStateValue3 = ipConfigurationsValue2 .get("provisioningState"); if (provisioningStateValue3 != null && provisioningStateValue3 instanceof NullNode == false) { String provisioningStateInstance3; provisioningStateInstance3 = provisioningStateValue3.getTextValue(); virtualNetworkGatewayIpConfigurationInstance2 .setProvisioningState(provisioningStateInstance3); } JsonNode nameValue3 = ipConfigurationsValue2.get("name"); if (nameValue3 != null && nameValue3 instanceof NullNode == false) { String nameInstance3; nameInstance3 = nameValue3.getTextValue(); virtualNetworkGatewayIpConfigurationInstance2.setName(nameInstance3); } JsonNode etagValue3 = ipConfigurationsValue2.get("etag"); if (etagValue3 != null && etagValue3 instanceof NullNode == false) { String etagInstance3; etagInstance3 = etagValue3.getTextValue(); virtualNetworkGatewayIpConfigurationInstance2.setEtag(etagInstance3); } JsonNode idValue7 = ipConfigurationsValue2.get("id"); if (idValue7 != null && idValue7 instanceof NullNode == false) { String idInstance7; idInstance7 = idValue7.getTextValue(); virtualNetworkGatewayIpConfigurationInstance2.setId(idInstance7); } } } JsonNode gatewayTypeValue2 = virtualNetworkGateway2Value2.get("gatewayType"); if (gatewayTypeValue2 != null && gatewayTypeValue2 instanceof NullNode == false) { String gatewayTypeInstance2; gatewayTypeInstance2 = gatewayTypeValue2.getTextValue(); virtualNetworkGateway2Instance.setGatewayType(gatewayTypeInstance2); } JsonNode vpnTypeValue2 = virtualNetworkGateway2Value2.get("vpnType"); if (vpnTypeValue2 != null && vpnTypeValue2 instanceof NullNode == false) { String vpnTypeInstance2; vpnTypeInstance2 = vpnTypeValue2.getTextValue(); virtualNetworkGateway2Instance.setVpnType(vpnTypeInstance2); } JsonNode enableBgpValue2 = virtualNetworkGateway2Value2.get("enableBgp"); if (enableBgpValue2 != null && enableBgpValue2 instanceof NullNode == false) { boolean enableBgpInstance2; enableBgpInstance2 = enableBgpValue2.getBooleanValue(); virtualNetworkGateway2Instance.setEnableBgp(enableBgpInstance2); } JsonNode provisioningStateValue4 = virtualNetworkGateway2Value2 .get("provisioningState"); if (provisioningStateValue4 != null && provisioningStateValue4 instanceof NullNode == false) { String provisioningStateInstance4; provisioningStateInstance4 = provisioningStateValue4.getTextValue(); virtualNetworkGateway2Instance.setProvisioningState(provisioningStateInstance4); } JsonNode resourceGuidValue2 = virtualNetworkGateway2Value2.get("resourceGuid"); if (resourceGuidValue2 != null && resourceGuidValue2 instanceof NullNode == false) { String resourceGuidInstance2; resourceGuidInstance2 = resourceGuidValue2.getTextValue(); virtualNetworkGateway2Instance.setResourceGuid(resourceGuidInstance2); } JsonNode etagValue4 = virtualNetworkGateway2Value2.get("etag"); if (etagValue4 != null && etagValue4 instanceof NullNode == false) { String etagInstance4; etagInstance4 = etagValue4.getTextValue(); virtualNetworkGateway2Instance.setEtag(etagInstance4); } JsonNode idValue8 = virtualNetworkGateway2Value2.get("id"); if (idValue8 != null && idValue8 instanceof NullNode == false) { String idInstance8; idInstance8 = idValue8.getTextValue(); virtualNetworkGateway2Instance.setId(idInstance8); } JsonNode nameValue4 = virtualNetworkGateway2Value2.get("name"); if (nameValue4 != null && nameValue4 instanceof NullNode == false) { String nameInstance4; nameInstance4 = nameValue4.getTextValue(); virtualNetworkGateway2Instance.setName(nameInstance4); } JsonNode typeValue2 = virtualNetworkGateway2Value2.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); virtualNetworkGateway2Instance.setType(typeInstance2); } JsonNode locationValue2 = virtualNetworkGateway2Value2.get("location"); if (locationValue2 != null && locationValue2 instanceof NullNode == false) { String locationInstance2; locationInstance2 = locationValue2.getTextValue(); virtualNetworkGateway2Instance.setLocation(locationInstance2); } JsonNode tagsSequenceElement2 = ((JsonNode) virtualNetworkGateway2Value2.get("tags")); if (tagsSequenceElement2 != null && tagsSequenceElement2 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr2 = tagsSequenceElement2.getFields(); while (itr2.hasNext()) { Map.Entry<String, JsonNode> property2 = itr2.next(); String tagsKey6 = property2.getKey(); String tagsValue6 = property2.getValue().getTextValue(); virtualNetworkGateway2Instance.getTags().put(tagsKey6, tagsValue6); } } } JsonNode localNetworkGateway2Value2 = propertiesValue2.get("localNetworkGateway2"); if (localNetworkGateway2Value2 != null && localNetworkGateway2Value2 instanceof NullNode == false) { LocalNetworkGateway localNetworkGateway2Instance = new LocalNetworkGateway(); virtualNetworkGatewayConnectionInstance .setLocalNetworkGateway2(localNetworkGateway2Instance); JsonNode localNetworkAddressSpaceValue2 = localNetworkGateway2Value2 .get("localNetworkAddressSpace"); if (localNetworkAddressSpaceValue2 != null && localNetworkAddressSpaceValue2 instanceof NullNode == false) { AddressSpace localNetworkAddressSpaceInstance = new AddressSpace(); localNetworkGateway2Instance .setLocalNetworkAddressSpace(localNetworkAddressSpaceInstance); JsonNode addressPrefixesArray2 = localNetworkAddressSpaceValue2 .get("addressPrefixes"); if (addressPrefixesArray2 != null && addressPrefixesArray2 instanceof NullNode == false) { for (JsonNode addressPrefixesValue : ((ArrayNode) addressPrefixesArray2)) { localNetworkAddressSpaceInstance.getAddressPrefixes() .add(addressPrefixesValue.getTextValue()); } } } JsonNode gatewayIpAddressValue = localNetworkGateway2Value2.get("gatewayIpAddress"); if (gatewayIpAddressValue != null && gatewayIpAddressValue instanceof NullNode == false) { String gatewayIpAddressInstance; gatewayIpAddressInstance = gatewayIpAddressValue.getTextValue(); localNetworkGateway2Instance.setGatewayIpAddress(gatewayIpAddressInstance); } JsonNode provisioningStateValue5 = localNetworkGateway2Value2.get("provisioningState"); if (provisioningStateValue5 != null && provisioningStateValue5 instanceof NullNode == false) { String provisioningStateInstance5; provisioningStateInstance5 = provisioningStateValue5.getTextValue(); localNetworkGateway2Instance.setProvisioningState(provisioningStateInstance5); } JsonNode resourceGuidValue3 = localNetworkGateway2Value2.get("resourceGuid"); if (resourceGuidValue3 != null && resourceGuidValue3 instanceof NullNode == false) { String resourceGuidInstance3; resourceGuidInstance3 = resourceGuidValue3.getTextValue(); localNetworkGateway2Instance.setResourceGuid(resourceGuidInstance3); } JsonNode etagValue5 = localNetworkGateway2Value2.get("etag"); if (etagValue5 != null && etagValue5 instanceof NullNode == false) { String etagInstance5; etagInstance5 = etagValue5.getTextValue(); localNetworkGateway2Instance.setEtag(etagInstance5); } JsonNode idValue9 = localNetworkGateway2Value2.get("id"); if (idValue9 != null && idValue9 instanceof NullNode == false) { String idInstance9; idInstance9 = idValue9.getTextValue(); localNetworkGateway2Instance.setId(idInstance9); } JsonNode nameValue5 = localNetworkGateway2Value2.get("name"); if (nameValue5 != null && nameValue5 instanceof NullNode == false) { String nameInstance5; nameInstance5 = nameValue5.getTextValue(); localNetworkGateway2Instance.setName(nameInstance5); } JsonNode typeValue3 = localNetworkGateway2Value2.get("type"); if (typeValue3 != null && typeValue3 instanceof NullNode == false) { String typeInstance3; typeInstance3 = typeValue3.getTextValue(); localNetworkGateway2Instance.setType(typeInstance3); } JsonNode locationValue3 = localNetworkGateway2Value2.get("location"); if (locationValue3 != null && locationValue3 instanceof NullNode == false) { String locationInstance3; locationInstance3 = locationValue3.getTextValue(); localNetworkGateway2Instance.setLocation(locationInstance3); } JsonNode tagsSequenceElement3 = ((JsonNode) localNetworkGateway2Value2.get("tags")); if (tagsSequenceElement3 != null && tagsSequenceElement3 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr3 = tagsSequenceElement3.getFields(); while (itr3.hasNext()) { Map.Entry<String, JsonNode> property3 = itr3.next(); String tagsKey7 = property3.getKey(); String tagsValue7 = property3.getValue().getTextValue(); localNetworkGateway2Instance.getTags().put(tagsKey7, tagsValue7); } } } JsonNode connectionTypeValue = propertiesValue2.get("connectionType"); if (connectionTypeValue != null && connectionTypeValue instanceof NullNode == false) { String connectionTypeInstance; connectionTypeInstance = connectionTypeValue.getTextValue(); virtualNetworkGatewayConnectionInstance.setConnectionType(connectionTypeInstance); } JsonNode routingWeightValue = propertiesValue2.get("routingWeight"); if (routingWeightValue != null && routingWeightValue instanceof NullNode == false) { int routingWeightInstance; routingWeightInstance = routingWeightValue.getIntValue(); virtualNetworkGatewayConnectionInstance.setRoutingWeight(routingWeightInstance); } JsonNode sharedKeyValue = propertiesValue2.get("sharedKey"); if (sharedKeyValue != null && sharedKeyValue instanceof NullNode == false) { String sharedKeyInstance; sharedKeyInstance = sharedKeyValue.getTextValue(); virtualNetworkGatewayConnectionInstance.setSharedKey(sharedKeyInstance); } JsonNode resourceGuidValue4 = propertiesValue2.get("resourceGuid"); if (resourceGuidValue4 != null && resourceGuidValue4 instanceof NullNode == false) { String resourceGuidInstance4; resourceGuidInstance4 = resourceGuidValue4.getTextValue(); virtualNetworkGatewayConnectionInstance.setResourceGuid(resourceGuidInstance4); } JsonNode provisioningStateValue6 = propertiesValue2.get("provisioningState"); if (provisioningStateValue6 != null && provisioningStateValue6 instanceof NullNode == false) { String provisioningStateInstance6; provisioningStateInstance6 = provisioningStateValue6.getTextValue(); virtualNetworkGatewayConnectionInstance .setProvisioningState(provisioningStateInstance6); } } JsonNode etagValue6 = responseDoc.get("etag"); if (etagValue6 != null && etagValue6 instanceof NullNode == false) { String etagInstance6; etagInstance6 = etagValue6.getTextValue(); virtualNetworkGatewayConnectionInstance.setEtag(etagInstance6); } JsonNode idValue10 = responseDoc.get("id"); if (idValue10 != null && idValue10 instanceof NullNode == false) { String idInstance10; idInstance10 = idValue10.getTextValue(); virtualNetworkGatewayConnectionInstance.setId(idInstance10); } JsonNode nameValue6 = responseDoc.get("name"); if (nameValue6 != null && nameValue6 instanceof NullNode == false) { String nameInstance6; nameInstance6 = nameValue6.getTextValue(); virtualNetworkGatewayConnectionInstance.setName(nameInstance6); } JsonNode typeValue4 = responseDoc.get("type"); if (typeValue4 != null && typeValue4 instanceof NullNode == false) { String typeInstance4; typeInstance4 = typeValue4.getTextValue(); virtualNetworkGatewayConnectionInstance.setType(typeInstance4); } JsonNode locationValue4 = responseDoc.get("location"); if (locationValue4 != null && locationValue4 instanceof NullNode == false) { String locationInstance4; locationInstance4 = locationValue4.getTextValue(); virtualNetworkGatewayConnectionInstance.setLocation(locationInstance4); } JsonNode tagsSequenceElement4 = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement4 != null && tagsSequenceElement4 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr4 = tagsSequenceElement4.getFields(); while (itr4.hasNext()) { Map.Entry<String, JsonNode> property4 = itr4.next(); String tagsKey8 = property4.getKey(); String tagsValue8 = property4.getValue().getTextValue(); virtualNetworkGatewayConnectionInstance.getTags().put(tagsKey8, tagsValue8); } } JsonNode errorValue = responseDoc.get("error"); if (errorValue != null && errorValue instanceof NullNode == false) { Error errorInstance = new Error(); result.setError(errorInstance); JsonNode codeValue = errorValue.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); errorInstance.setCode(codeInstance); } JsonNode messageValue = errorValue.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); errorInstance.setMessage(messageInstance); } JsonNode targetValue = errorValue.get("target"); if (targetValue != null && targetValue instanceof NullNode == false) { String targetInstance; targetInstance = targetValue.getTextValue(); errorInstance.setTarget(targetInstance); } JsonNode detailsArray = errorValue.get("details"); if (detailsArray != null && detailsArray instanceof NullNode == false) { for (JsonNode detailsValue : ((ArrayNode) detailsArray)) { ErrorDetails errorDetailsInstance = new ErrorDetails(); errorInstance.getDetails().add(errorDetailsInstance); JsonNode codeValue2 = detailsValue.get("code"); if (codeValue2 != null && codeValue2 instanceof NullNode == false) { String codeInstance2; codeInstance2 = codeValue2.getTextValue(); errorDetailsInstance.setCode(codeInstance2); } JsonNode targetValue2 = detailsValue.get("target"); if (targetValue2 != null && targetValue2 instanceof NullNode == false) { String targetInstance2; targetInstance2 = targetValue2.getTextValue(); errorDetailsInstance.setTarget(targetInstance2); } JsonNode messageValue2 = detailsValue.get("message"); if (messageValue2 != null && messageValue2 instanceof NullNode == false) { String messageInstance2; messageInstance2 = messageValue2.getTextValue(); errorDetailsInstance.setMessage(messageInstance2); } } } JsonNode innerErrorValue = errorValue.get("innerError"); if (innerErrorValue != null && innerErrorValue instanceof NullNode == false) { String innerErrorInstance; innerErrorInstance = innerErrorValue.getTextValue(); errorInstance.setInnerError(innerErrorInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("Azure-AsyncOperation").length > 0) { result.setAzureAsyncOperation(httpResponse.getFirstHeader("Azure-AsyncOperation").getValue()); } if (httpResponse.getHeaders("Retry-After").length > 0) { result.setRetryAfter( DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue())); } if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.compute.VirtualMachineDiskOperationsImpl.java
/** * The Get Data Disk operation retrieves the specified data disk from a * virtual machine. (see/*from w w w .j a v a 2 s. co m*/ * http://msdn.microsoft.com/en-us/library/windowsazure/jj157180.aspx for * more information) * * @param serviceName Required. The name of your service. * @param deploymentName Required. The name of the deployment. * @param roleName Required. The name of the role. * @param logicalUnitNumber Required. The logical unit number of the disk. * @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 Data Disk operation response. */ @Override public VirtualMachineDataDiskGetResponse getDataDisk(String serviceName, String deploymentName, String roleName, int logicalUnitNumber) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (roleName == null) { throw new NullPointerException("roleName"); } // 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("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("roleName", roleName); tracingParameters.put("logicalUnitNumber", logicalUnitNumber); CloudTracing.enter(invocationId, this, "getDataDiskAsync", 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/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); url = url + "/roles/"; url = url + URLEncoder.encode(roleName, "UTF-8"); url = url + "/DataDisks/"; url = url + URLEncoder.encode(Integer.toString(logicalUnitNumber), "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2015-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result VirtualMachineDataDiskGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualMachineDataDiskGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element dataVirtualHardDiskElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "DataVirtualHardDisk"); if (dataVirtualHardDiskElement != null) { Element hostCachingElement = XmlUtility.getElementByTagNameNS(dataVirtualHardDiskElement, "http://schemas.microsoft.com/windowsazure", "HostCaching"); if (hostCachingElement != null) { String hostCachingInstance; hostCachingInstance = hostCachingElement.getTextContent(); result.setHostCaching(hostCachingInstance); } Element diskLabelElement = XmlUtility.getElementByTagNameNS(dataVirtualHardDiskElement, "http://schemas.microsoft.com/windowsazure", "DiskLabel"); if (diskLabelElement != null) { String diskLabelInstance; diskLabelInstance = diskLabelElement.getTextContent(); result.setLabel(diskLabelInstance); } Element diskNameElement = XmlUtility.getElementByTagNameNS(dataVirtualHardDiskElement, "http://schemas.microsoft.com/windowsazure", "DiskName"); if (diskNameElement != null) { String diskNameInstance; diskNameInstance = diskNameElement.getTextContent(); result.setName(diskNameInstance); } Element lunElement = XmlUtility.getElementByTagNameNS(dataVirtualHardDiskElement, "http://schemas.microsoft.com/windowsazure", "Lun"); if (lunElement != null && lunElement.getTextContent() != null && !lunElement.getTextContent().isEmpty()) { int lunInstance; lunInstance = DatatypeConverter.parseInt(lunElement.getTextContent()); result.setLogicalUnitNumber(lunInstance); } Element logicalDiskSizeInGBElement = XmlUtility.getElementByTagNameNS( dataVirtualHardDiskElement, "http://schemas.microsoft.com/windowsazure", "LogicalDiskSizeInGB"); if (logicalDiskSizeInGBElement != null) { int logicalDiskSizeInGBInstance; logicalDiskSizeInGBInstance = DatatypeConverter .parseInt(logicalDiskSizeInGBElement.getTextContent()); result.setLogicalDiskSizeInGB(logicalDiskSizeInGBInstance); } Element mediaLinkElement = XmlUtility.getElementByTagNameNS(dataVirtualHardDiskElement, "http://schemas.microsoft.com/windowsazure", "MediaLink"); if (mediaLinkElement != null) { URI mediaLinkInstance; mediaLinkInstance = new URI(mediaLinkElement.getTextContent()); result.setMediaLinkUri(mediaLinkInstance); } Element iOTypeElement = XmlUtility.getElementByTagNameNS(dataVirtualHardDiskElement, "http://schemas.microsoft.com/windowsazure", "IOType"); if (iOTypeElement != null) { String iOTypeInstance; iOTypeInstance = iOTypeElement.getTextContent(); result.setIOType(iOTypeInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }