List of usage examples for javax.xml.bind DatatypeConverter parseDateTime
public static java.util.Calendar parseDateTime(String lexicalXSDDateTime)
Converts the string argument into a Calendar value.
From source file:com.microsoft.windowsazure.management.compute.VirtualMachineOSImageOperationsImpl.java
/** * Gets OS Image'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 imageName Required. The name of the virtual machine image to * replicate.// ww w.ja v a2 s .com * @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 OS Images operation response. */ @Override public VirtualMachineOSImageGetDetailsResponse getDetails(String imageName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (imageName == null) { throw new NullPointerException("imageName"); } // 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("imageName", imageName); 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/images/"; url = url + URLEncoder.encode(imageName, "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 VirtualMachineOSImageGetDetailsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualMachineOSImageGetDetailsResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element oSImageDetailsElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "OSImageDetails"); if (oSImageDetailsElement != null) { Element isCorruptedElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "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 replicationProgressSequenceElement = XmlUtility.getElementByTagNameNS( oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "ReplicationProgress"); if (replicationProgressSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(replicationProgressSequenceElement, "http://schemas.microsoft.com/windowsazure", "ReplicationProgressElement") .size(); i1 = i1 + 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(i1)); VirtualMachineOSImageGetDetailsResponse.ReplicationProgressElement replicationProgressElementInstance = new VirtualMachineOSImageGetDetailsResponse.ReplicationProgressElement(); result.getReplicationProgress().add(replicationProgressElementInstance); Element locationElement = XmlUtility.getElementByTagNameNS(replicationProgressElement, "http://schemas.microsoft.com/windowsazure", "Location"); if (locationElement != null) { String locationInstance; locationInstance = locationElement.getTextContent(); replicationProgressElementInstance.setLocation(locationInstance); } 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(oSImageDetailsElement, "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( oSImageDetailsElement, "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 nameElement = XmlUtility.getElementByTagNameNS(planElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); planInstance.setName(nameInstance); } 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); } } } Element affinityGroupElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "AffinityGroup"); if (affinityGroupElement != null) { String affinityGroupInstance; affinityGroupInstance = affinityGroupElement.getTextContent(); result.setAffinityGroup(affinityGroupInstance); } Element categoryElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Category"); if (categoryElement != null) { String categoryInstance; categoryInstance = categoryElement.getTextContent(); result.setCategory(categoryInstance); } Element labelElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement != null) { String labelInstance; labelInstance = labelElement.getTextContent(); result.setLabel(labelInstance); } Element locationElement2 = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Location"); if (locationElement2 != null) { String locationInstance2; locationInstance2 = locationElement2.getTextContent(); result.setLocation(locationInstance2); } Element logicalSizeInGBElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "LogicalSizeInGB"); if (logicalSizeInGBElement != null) { double logicalSizeInGBInstance; logicalSizeInGBInstance = DatatypeConverter .parseDouble(logicalSizeInGBElement.getTextContent()); result.setLogicalSizeInGB(logicalSizeInGBInstance); } Element mediaLinkElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "MediaLink"); if (mediaLinkElement != null) { URI mediaLinkInstance; mediaLinkInstance = new URI(mediaLinkElement.getTextContent()); result.setMediaLinkUri(mediaLinkInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance2; nameInstance2 = nameElement2.getTextContent(); result.setName(nameInstance2); } Element osElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "OS"); if (osElement != null) { String osInstance; osInstance = osElement.getTextContent(); result.setOperatingSystemType(osInstance); } Element eulaElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Eula"); if (eulaElement != null) { String eulaInstance; eulaInstance = eulaElement.getTextContent(); result.setEula(eulaInstance); } Element descriptionElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); result.setDescription(descriptionInstance); } Element imageFamilyElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "ImageFamily"); if (imageFamilyElement != null) { String imageFamilyInstance; imageFamilyInstance = imageFamilyElement.getTextContent(); result.setImageFamily(imageFamilyInstance); } Element showInGuiElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "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 publishedDateElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "PublishedDate"); if (publishedDateElement != null) { Calendar publishedDateInstance; publishedDateInstance = DatatypeConverter .parseDateTime(publishedDateElement.getTextContent()); result.setPublishedDate(publishedDateInstance); } Element isPremiumElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "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 iconUriElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "IconUri"); if (iconUriElement != null) { String iconUriInstance; iconUriInstance = iconUriElement.getTextContent(); result.setIconUri(iconUriInstance); } Element privacyUriElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "PrivacyUri"); if (privacyUriElement != null) { URI privacyUriInstance; privacyUriInstance = new URI(privacyUriElement.getTextContent()); result.setPrivacyUri(privacyUriInstance); } Element recommendedVMSizeElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "RecommendedVMSize"); if (recommendedVMSizeElement != null) { String recommendedVMSizeInstance; recommendedVMSizeInstance = recommendedVMSizeElement.getTextContent(); result.setRecommendedVMSize(recommendedVMSizeInstance); } Element publisherNameElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "PublisherName"); if (publisherNameElement != null) { String publisherNameInstance; publisherNameInstance = publisherNameElement.getTextContent(); result.setPublisherName(publisherNameInstance); } Element smallIconUriElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "SmallIconUri"); if (smallIconUriElement != null) { String smallIconUriInstance; smallIconUriInstance = smallIconUriElement.getTextContent(); result.setSmallIconUri(smallIconUriInstance); } Element languageElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure", "Language"); if (languageElement != null) { String languageInstance; languageInstance = languageElement.getTextContent(); result.setLanguage(languageInstance); } Element iOTypeElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement, "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(); } } }
From source file:com.microsoft.azure.management.compute.VirtualMachineExtensionOperationsImpl.java
/** * The operation to get an extension along with its instance view. * * @param resourceGroupName Required. The name of the resource group. * @param vmName Required. The name of the virtual machine containing the * extension.//from w w w .ja va 2s. c om * @param vmExtensionName Required. The name of the virtual machine * extension. * @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 Get VM-Extension operation response. */ @Override public VirtualMachineExtensionGetResponse getWithInstanceView(String resourceGroupName, String vmName, String vmExtensionName) throws IOException, ServiceException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (vmName == null) { throw new NullPointerException("vmName"); } if (vmExtensionName == null) { throw new NullPointerException("vmExtensionName"); } // 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("vmName", vmName); tracingParameters.put("vmExtensionName", vmExtensionName); CloudTracing.enter(invocationId, this, "getWithInstanceViewAsync", 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.Compute"; url = url + "/"; url = url + "virtualMachines"; url = url + "/"; url = url + URLEncoder.encode(vmName, "UTF-8"); url = url + "/extensions/"; url = url + URLEncoder.encode(vmExtensionName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("$expand=instanceView"); queryParameters.add("api-version=" + "2015-06-15"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers // 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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result VirtualMachineExtensionGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualMachineExtensionGetResponse(); ObjectMapper objectMapper = new ObjectMapper(); 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) { VirtualMachineExtension virtualMachineExtensionInstance = new VirtualMachineExtension(); result.setVirtualMachineExtension(virtualMachineExtensionInstance); JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { JsonNode publisherValue = propertiesValue.get("publisher"); if (publisherValue != null && publisherValue instanceof NullNode == false) { String publisherInstance; publisherInstance = publisherValue.getTextValue(); virtualMachineExtensionInstance.setPublisher(publisherInstance); } JsonNode typeValue = propertiesValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); virtualMachineExtensionInstance.setExtensionType(typeInstance); } JsonNode typeHandlerVersionValue = propertiesValue.get("typeHandlerVersion"); if (typeHandlerVersionValue != null && typeHandlerVersionValue instanceof NullNode == false) { String typeHandlerVersionInstance; typeHandlerVersionInstance = typeHandlerVersionValue.getTextValue(); virtualMachineExtensionInstance.setTypeHandlerVersion(typeHandlerVersionInstance); } JsonNode autoUpgradeMinorVersionValue = propertiesValue.get("autoUpgradeMinorVersion"); if (autoUpgradeMinorVersionValue != null && autoUpgradeMinorVersionValue instanceof NullNode == false) { boolean autoUpgradeMinorVersionInstance; autoUpgradeMinorVersionInstance = autoUpgradeMinorVersionValue.getBooleanValue(); virtualMachineExtensionInstance .setAutoUpgradeMinorVersion(autoUpgradeMinorVersionInstance); } JsonNode settingsValue = propertiesValue.get("settings"); if (settingsValue != null && settingsValue instanceof NullNode == false) { String settingsInstance; settingsInstance = settingsValue.getTextValue(); virtualMachineExtensionInstance.setSettings(settingsInstance); } JsonNode protectedSettingsValue = propertiesValue.get("protectedSettings"); if (protectedSettingsValue != null && protectedSettingsValue instanceof NullNode == false) { String protectedSettingsInstance; protectedSettingsInstance = protectedSettingsValue.getTextValue(); virtualMachineExtensionInstance.setProtectedSettings(protectedSettingsInstance); } JsonNode provisioningStateValue = propertiesValue.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); virtualMachineExtensionInstance.setProvisioningState(provisioningStateInstance); } JsonNode instanceViewValue = propertiesValue.get("instanceView"); if (instanceViewValue != null && instanceViewValue instanceof NullNode == false) { VirtualMachineExtensionInstanceView instanceViewInstance = new VirtualMachineExtensionInstanceView(); virtualMachineExtensionInstance.setInstanceView(instanceViewInstance); JsonNode nameValue = instanceViewValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); instanceViewInstance.setName(nameInstance); } JsonNode typeValue2 = instanceViewValue.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); instanceViewInstance.setExtensionType(typeInstance2); } JsonNode typeHandlerVersionValue2 = instanceViewValue.get("typeHandlerVersion"); if (typeHandlerVersionValue2 != null && typeHandlerVersionValue2 instanceof NullNode == false) { String typeHandlerVersionInstance2; typeHandlerVersionInstance2 = typeHandlerVersionValue2.getTextValue(); instanceViewInstance.setTypeHandlerVersion(typeHandlerVersionInstance2); } JsonNode substatusesArray = instanceViewValue.get("substatuses"); if (substatusesArray != null && substatusesArray instanceof NullNode == false) { for (JsonNode substatusesValue : ((ArrayNode) substatusesArray)) { InstanceViewStatus instanceViewStatusInstance = new InstanceViewStatus(); instanceViewInstance.getSubStatuses().add(instanceViewStatusInstance); JsonNode codeValue = substatusesValue.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); instanceViewStatusInstance.setCode(codeInstance); } JsonNode levelValue = substatusesValue.get("level"); if (levelValue != null && levelValue instanceof NullNode == false) { String levelInstance; levelInstance = levelValue.getTextValue(); instanceViewStatusInstance.setLevel(levelInstance); } JsonNode displayStatusValue = substatusesValue.get("displayStatus"); if (displayStatusValue != null && displayStatusValue instanceof NullNode == false) { String displayStatusInstance; displayStatusInstance = displayStatusValue.getTextValue(); instanceViewStatusInstance.setDisplayStatus(displayStatusInstance); } JsonNode messageValue = substatusesValue.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); instanceViewStatusInstance.setMessage(messageInstance); } JsonNode timeValue = substatusesValue.get("time"); if (timeValue != null && timeValue instanceof NullNode == false) { Calendar timeInstance; timeInstance = DatatypeConverter.parseDateTime(timeValue.getTextValue()); instanceViewStatusInstance.setTime(timeInstance); } } } JsonNode statusesArray = instanceViewValue.get("statuses"); if (statusesArray != null && statusesArray instanceof NullNode == false) { for (JsonNode statusesValue : ((ArrayNode) statusesArray)) { InstanceViewStatus instanceViewStatusInstance2 = new InstanceViewStatus(); instanceViewInstance.getStatuses().add(instanceViewStatusInstance2); JsonNode codeValue2 = statusesValue.get("code"); if (codeValue2 != null && codeValue2 instanceof NullNode == false) { String codeInstance2; codeInstance2 = codeValue2.getTextValue(); instanceViewStatusInstance2.setCode(codeInstance2); } JsonNode levelValue2 = statusesValue.get("level"); if (levelValue2 != null && levelValue2 instanceof NullNode == false) { String levelInstance2; levelInstance2 = levelValue2.getTextValue(); instanceViewStatusInstance2.setLevel(levelInstance2); } JsonNode displayStatusValue2 = statusesValue.get("displayStatus"); if (displayStatusValue2 != null && displayStatusValue2 instanceof NullNode == false) { String displayStatusInstance2; displayStatusInstance2 = displayStatusValue2.getTextValue(); instanceViewStatusInstance2.setDisplayStatus(displayStatusInstance2); } JsonNode messageValue2 = statusesValue.get("message"); if (messageValue2 != null && messageValue2 instanceof NullNode == false) { String messageInstance2; messageInstance2 = messageValue2.getTextValue(); instanceViewStatusInstance2.setMessage(messageInstance2); } JsonNode timeValue2 = statusesValue.get("time"); if (timeValue2 != null && timeValue2 instanceof NullNode == false) { Calendar timeInstance2; timeInstance2 = DatatypeConverter.parseDateTime(timeValue2.getTextValue()); instanceViewStatusInstance2.setTime(timeInstance2); } } } } } JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); virtualMachineExtensionInstance.setId(idInstance); } JsonNode nameValue2 = responseDoc.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); virtualMachineExtensionInstance.setName(nameInstance2); } JsonNode typeValue3 = responseDoc.get("type"); if (typeValue3 != null && typeValue3 instanceof NullNode == false) { String typeInstance3; typeInstance3 = typeValue3.getTextValue(); virtualMachineExtensionInstance.setType(typeInstance3); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); virtualMachineExtensionInstance.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 tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); virtualMachineExtensionInstance.getTags().put(tagsKey, tagsValue); } } } } 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.DatabaseOperationsImpl.java
/** * Returns a collection of Azure SQL Databases. * * @param serverName Required. The name of the Azure SQL Database Server * from which to retrieve the database./*w w w . j a v a 2 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. * @return Contains a collection of databases for a given Azure SQL Database * Server. */ @Override public DatabaseListResponse list(String serverName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } // 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); 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/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("contentview=generic"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); Database serviceResourceInstance = new Database(); result.getDatabases().add(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { int idInstance; idInstance = DatatypeConverter.parseInt(idElement.getTextContent()); serviceResourceInstance.setId(idInstance); } Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement != null) { String editionInstance; editionInstance = editionElement.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element maxSizeGBElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); if (maxSizeGBElement != null) { int maxSizeGBInstance; maxSizeGBInstance = DatatypeConverter.parseInt(maxSizeGBElement.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInGB(maxSizeGBInstance); } Element maxSizeBytesElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); if (maxSizeBytesElement != null) { long maxSizeBytesInstance; maxSizeBytesInstance = DatatypeConverter .parseLong(maxSizeBytesElement.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance); } Element collationNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "CollationName"); if (collationNameElement != null) { String collationNameInstance; collationNameInstance = collationNameElement.getTextContent(); serviceResourceInstance.setCollationName(collationNameInstance); } Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "CreationDate"); if (creationDateElement != null) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateElement.getTextContent()); serviceResourceInstance.setCreationDate(creationDateInstance); } Element isFederationRootElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsFederationRoot"); if (isFederationRootElement != null) { boolean isFederationRootInstance; isFederationRootInstance = DatatypeConverter .parseBoolean(isFederationRootElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsFederationRoot(isFederationRootInstance); } Element isSystemObjectElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsSystemObject"); if (isSystemObjectElement != null) { boolean isSystemObjectInstance; isSystemObjectInstance = DatatypeConverter .parseBoolean(isSystemObjectElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsSystemObject(isSystemObjectInstance); } Element sizeMBElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "SizeMB"); if (sizeMBElement != null) { String sizeMBInstance; sizeMBInstance = sizeMBElement.getTextContent(); serviceResourceInstance.setSizeMB(sizeMBInstance); } Element serviceObjectiveAssignmentErrorCodeElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorCode"); if (serviceObjectiveAssignmentErrorCodeElement != null) { String serviceObjectiveAssignmentErrorCodeInstance; serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorCode( serviceObjectiveAssignmentErrorCodeInstance); } Element serviceObjectiveAssignmentErrorDescriptionElement = XmlUtility .getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorDescription"); if (serviceObjectiveAssignmentErrorDescriptionElement != null) { String serviceObjectiveAssignmentErrorDescriptionInstance; serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorDescription( serviceObjectiveAssignmentErrorDescriptionInstance); } Element serviceObjectiveAssignmentStateElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentState"); if (serviceObjectiveAssignmentStateElement != null) { String serviceObjectiveAssignmentStateInstance; serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement .getTextContent(); serviceResourceInstance .setServiceObjectiveAssignmentState(serviceObjectiveAssignmentStateInstance); } Element serviceObjectiveAssignmentStateDescriptionElement = XmlUtility .getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentStateDescription"); if (serviceObjectiveAssignmentStateDescriptionElement != null) { String serviceObjectiveAssignmentStateDescriptionInstance; serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentStateDescription( serviceObjectiveAssignmentStateDescriptionInstance); } Element serviceObjectiveAssignmentSuccessDateElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentSuccessDate"); if (serviceObjectiveAssignmentSuccessDateElement != null) { String serviceObjectiveAssignmentSuccessDateInstance; serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentSuccessDate( serviceObjectiveAssignmentSuccessDateInstance); } Element serviceObjectiveIdElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); if (serviceObjectiveIdElement != null) { String serviceObjectiveIdInstance; serviceObjectiveIdInstance = serviceObjectiveIdElement.getTextContent(); serviceResourceInstance.setServiceObjectiveId(serviceObjectiveIdInstance); } Element assignedServiceObjectiveIdElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "AssignedServiceObjectiveId"); if (assignedServiceObjectiveIdElement != null) { String assignedServiceObjectiveIdInstance; assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement.getTextContent(); serviceResourceInstance .setAssignedServiceObjectiveId(assignedServiceObjectiveIdInstance); } Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "RecoveryPeriodStartDate"); if (recoveryPeriodStartDateElement != null && recoveryPeriodStartDateElement.getTextContent() != null && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) { Calendar recoveryPeriodStartDateInstance; recoveryPeriodStartDateInstance = DatatypeConverter .parseDateTime(recoveryPeriodStartDateElement.getTextContent()); serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.marklogic.client.functionaltest.TestBiTemporal.java
@Test // Create a bitemporal document and update the document with a system time that is less than // the one used durign creation public void testSystemTimeUsingInvalidTime() throws Exception { System.out.println("Inside testSystemTimeUsingInvalidTime"); ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName, temporalLsqtCollectionName, true); String docId = "javaSingleJSONDoc.json"; Calendar firstInsertTime = DatatypeConverter.parseDateTime("2010-01-01T00:00:01"); insertJSONSingleDocument(temporalLsqtCollectionName, docId, null, null, firstInsertTime); // Sleep for 2 seconds for LSQT to be advanced Thread.sleep(2000);//from www. ja v a2 s . c o m // Update by passing a system time that is less than previous one Calendar updateTime = DatatypeConverter.parseDateTime("2010-01-01T00:00:00"); boolean exceptionThrown = false; try { updateJSONSingleDocument(temporalLsqtCollectionName, docId, null, updateTime); } catch (com.marklogic.client.FailedRequestException ex) { String message = ex.getFailedRequest().getMessageCode(); int statusCode = ex.getFailedRequest().getStatusCode(); exceptionThrown = true; System.out.println(message); System.out.println(statusCode); assertTrue("Error Message", message.equals("TEMPORAL-OPNOTAFTERLSQT")); assertTrue("Status code", (statusCode == 400)); } assertTrue("Exception not thrown during invalid update of system time", exceptionThrown); // Delete by passing invalid time Calendar deleteTime = DatatypeConverter.parseDateTime("2010-01-01T00:00:00"); exceptionThrown = false; try { deleteJSONSingleDocument(temporalLsqtCollectionName, docId, null, deleteTime); } catch (com.marklogic.client.FailedRequestException ex) { String message = ex.getFailedRequest().getMessageCode(); int statusCode = ex.getFailedRequest().getStatusCode(); exceptionThrown = true; System.out.println(message); System.out.println(statusCode); assertTrue("Error Message", message.equals("TEMPORAL-SYSTEMTIME-BACKWARDS")); assertTrue("Status code", (statusCode == 400)); } assertTrue("Exception not thrown for invalid extension", exceptionThrown); }
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 v a 2s .c o m * 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.servicebus.NamespaceOperationsImpl.java
/** * Returns the description for the specified namespace. (see * http://msdn.microsoft.com/library/azure/dn140232.aspx for more * information)//from w w w .ja v a 2 s .c o m * * @param namespaceName Required. The namespace name. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @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 response to a request for a particular namespace. */ @Override public ServiceBusNamespaceResponse get(String namespaceName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (namespaceName == null) { throw new NullPointerException("namespaceName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("namespaceName", namespaceName); 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"); 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("Accept", "application/atom+xml"); httpRequest.setHeader("Content-Type", "application/atom+xml"); 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 ServiceBusNamespaceResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServiceBusNamespaceResponse(); 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 contentElement = XmlUtility.getElementByTagNameNS(entryElement, "http://www.w3.org/2005/Atom", "content"); if (contentElement != null) { Element namespaceDescriptionElement = XmlUtility.getElementByTagNameNS(contentElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "NamespaceDescription"); if (namespaceDescriptionElement != null) { ServiceBusNamespace namespaceDescriptionInstance = new ServiceBusNamespace(); result.setNamespace(namespaceDescriptionInstance); Element nameElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); namespaceDescriptionInstance.setName(nameInstance); } Element regionElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Region"); if (regionElement != null) { String regionInstance; regionInstance = regionElement.getTextContent(); namespaceDescriptionInstance.setRegion(regionInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Status"); if (statusElement != null) { String statusInstance; statusInstance = statusElement.getTextContent(); namespaceDescriptionInstance.setStatus(statusInstance); } Element createdAtElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedAt"); if (createdAtElement != null) { Calendar createdAtInstance; createdAtInstance = DatatypeConverter .parseDateTime(createdAtElement.getTextContent()); namespaceDescriptionInstance.setCreatedAt(createdAtInstance); } Element acsManagementEndpointElement = XmlUtility.getElementByTagNameNS( namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AcsManagementEndpoint"); if (acsManagementEndpointElement != null) { URI acsManagementEndpointInstance; acsManagementEndpointInstance = new URI( acsManagementEndpointElement.getTextContent()); namespaceDescriptionInstance .setAcsManagementEndpoint(acsManagementEndpointInstance); } Element serviceBusEndpointElement = XmlUtility.getElementByTagNameNS( namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ServiceBusEndpoint"); if (serviceBusEndpointElement != null) { URI serviceBusEndpointInstance; serviceBusEndpointInstance = new URI(serviceBusEndpointElement.getTextContent()); namespaceDescriptionInstance.setServiceBusEndpoint(serviceBusEndpointInstance); } Element subscriptionIdElement = XmlUtility.getElementByTagNameNS( namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SubscriptionId"); if (subscriptionIdElement != null) { String subscriptionIdInstance; subscriptionIdInstance = subscriptionIdElement.getTextContent(); namespaceDescriptionInstance.setSubscriptionId(subscriptionIdInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Enabled"); if (enabledElement != null) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); namespaceDescriptionInstance.setEnabled(enabledInstance); } Element createACSNamespaceElement = XmlUtility.getElementByTagNameNS( namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreateACSNamespace"); if (createACSNamespaceElement != null) { boolean createACSNamespaceInstance; createACSNamespaceInstance = DatatypeConverter .parseBoolean(createACSNamespaceElement.getTextContent().toLowerCase()); namespaceDescriptionInstance.setCreateACSNamespace(createACSNamespaceInstance); } Element namespaceTypeElement = XmlUtility.getElementByTagNameNS( namespaceDescriptionElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "NamespaceType"); if (namespaceTypeElement != null && namespaceTypeElement.getTextContent() != null && !namespaceTypeElement.getTextContent().isEmpty()) { NamespaceType namespaceTypeInstance; namespaceTypeInstance = NamespaceType .valueOf(namespaceTypeElement.getTextContent()); namespaceDescriptionInstance.setNamespaceType(namespaceTypeInstance); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.azure.management.resources.DeploymentOperationsImpl.java
/** * Get a list of deployments.//from ww w. java 2s .c om * * @param resourceGroupName Required. The name of the resource group to * filter by. The name is case insensitive. * @param parameters Optional. Query parameters. If null is passed returns * all deployments. * @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 List of deployments. */ @Override public DeploymentListResult list(String resourceGroupName, DeploymentListParameters parameters) throws IOException, ServiceException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("resourceGroupName", resourceGroupName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "listAsync", 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 + "/"; url = url + "resourcegroups/" + URLEncoder.encode(resourceGroupName, "UTF-8") + "/"; url = url + "deployments/"; ArrayList<String> queryParameters = new ArrayList<String>(); ArrayList<String> odataFilter = new ArrayList<String>(); if (parameters != null && parameters.getProvisioningState() != null) { odataFilter.add( "provisioningState eq '" + URLEncoder.encode(parameters.getProvisioningState(), "UTF-8") + "'"); } if (odataFilter.size() > 0) { queryParameters.add("$filter=" + CollectionStringBuilder.join(odataFilter, null)); } if (parameters != null && parameters.getTop() != null) { queryParameters.add("$top=" + URLEncoder.encode(Integer.toString(parameters.getTop()), "UTF-8")); } queryParameters.add("api-version=" + "2014-04-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json; charset=utf-8"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DeploymentListResult result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DeploymentListResult(); ObjectMapper objectMapper = new ObjectMapper(); 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) { JsonNode valueArray = responseDoc.get("value"); if (valueArray != null && valueArray instanceof NullNode == false) { for (JsonNode valueValue : ((ArrayNode) valueArray)) { DeploymentExtended deploymentExtendedInstance = new DeploymentExtended(); result.getDeployments().add(deploymentExtendedInstance); JsonNode idValue = valueValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); deploymentExtendedInstance.setId(idInstance); } JsonNode nameValue = valueValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); deploymentExtendedInstance.setName(nameInstance); } JsonNode propertiesValue = valueValue.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { DeploymentPropertiesExtended propertiesInstance = new DeploymentPropertiesExtended(); deploymentExtendedInstance.setProperties(propertiesInstance); JsonNode provisioningStateValue = propertiesValue.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); propertiesInstance.setProvisioningState(provisioningStateInstance); } JsonNode correlationIdValue = propertiesValue.get("correlationId"); if (correlationIdValue != null && correlationIdValue instanceof NullNode == false) { String correlationIdInstance; correlationIdInstance = correlationIdValue.getTextValue(); propertiesInstance.setCorrelationId(correlationIdInstance); } JsonNode timestampValue = propertiesValue.get("timestamp"); if (timestampValue != null && timestampValue instanceof NullNode == false) { Calendar timestampInstance; timestampInstance = DatatypeConverter .parseDateTime(timestampValue.getTextValue()); propertiesInstance.setTimestamp(timestampInstance); } JsonNode outputsValue = propertiesValue.get("outputs"); if (outputsValue != null && outputsValue instanceof NullNode == false) { String outputsInstance; outputsInstance = outputsValue.getTextValue(); propertiesInstance.setOutputs(outputsInstance); } JsonNode providersArray = propertiesValue.get("providers"); if (providersArray != null && providersArray instanceof NullNode == false) { for (JsonNode providersValue : ((ArrayNode) providersArray)) { Provider providerInstance = new Provider(); propertiesInstance.getProviders().add(providerInstance); JsonNode idValue2 = providersValue.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); providerInstance.setId(idInstance2); } JsonNode namespaceValue = providersValue.get("namespace"); if (namespaceValue != null && namespaceValue instanceof NullNode == false) { String namespaceInstance; namespaceInstance = namespaceValue.getTextValue(); providerInstance.setNamespace(namespaceInstance); } JsonNode registrationStateValue = providersValue.get("registrationState"); if (registrationStateValue != null && registrationStateValue instanceof NullNode == false) { String registrationStateInstance; registrationStateInstance = registrationStateValue.getTextValue(); providerInstance.setRegistrationState(registrationStateInstance); } JsonNode resourceTypesArray = providersValue.get("resourceTypes"); if (resourceTypesArray != null && resourceTypesArray instanceof NullNode == false) { for (JsonNode resourceTypesValue : ((ArrayNode) resourceTypesArray)) { ProviderResourceType providerResourceTypeInstance = new ProviderResourceType(); providerInstance.getResourceTypes() .add(providerResourceTypeInstance); JsonNode resourceTypeValue = resourceTypesValue.get("resourceType"); if (resourceTypeValue != null && resourceTypeValue instanceof NullNode == false) { String resourceTypeInstance; resourceTypeInstance = resourceTypeValue.getTextValue(); providerResourceTypeInstance.setName(resourceTypeInstance); } JsonNode locationsArray = resourceTypesValue.get("locations"); if (locationsArray != null && locationsArray instanceof NullNode == false) { for (JsonNode locationsValue : ((ArrayNode) locationsArray)) { providerResourceTypeInstance.getLocations() .add(locationsValue.getTextValue()); } } JsonNode apiVersionsArray = resourceTypesValue.get("apiVersions"); if (apiVersionsArray != null && apiVersionsArray instanceof NullNode == false) { for (JsonNode apiVersionsValue : ((ArrayNode) apiVersionsArray)) { providerResourceTypeInstance.getApiVersions() .add(apiVersionsValue.getTextValue()); } } JsonNode propertiesSequenceElement = ((JsonNode) resourceTypesValue .get("properties")); if (propertiesSequenceElement != null && propertiesSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = propertiesSequenceElement .getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String propertiesKey = property.getKey(); String propertiesValue2 = property.getValue() .getTextValue(); providerResourceTypeInstance.getProperties() .put(propertiesKey, propertiesValue2); } } } } } } JsonNode dependenciesArray = propertiesValue.get("dependencies"); if (dependenciesArray != null && dependenciesArray instanceof NullNode == false) { for (JsonNode dependenciesValue : ((ArrayNode) dependenciesArray)) { Dependency dependencyInstance = new Dependency(); propertiesInstance.getDependencies().add(dependencyInstance); JsonNode dependsOnArray = dependenciesValue.get("dependsOn"); if (dependsOnArray != null && dependsOnArray instanceof NullNode == false) { for (JsonNode dependsOnValue : ((ArrayNode) dependsOnArray)) { BasicDependency basicDependencyInstance = new BasicDependency(); dependencyInstance.getDependsOn().add(basicDependencyInstance); JsonNode idValue3 = dependsOnValue.get("id"); if (idValue3 != null && idValue3 instanceof NullNode == false) { String idInstance3; idInstance3 = idValue3.getTextValue(); basicDependencyInstance.setId(idInstance3); } JsonNode resourceTypeValue2 = dependsOnValue.get("resourceType"); if (resourceTypeValue2 != null && resourceTypeValue2 instanceof NullNode == false) { String resourceTypeInstance2; resourceTypeInstance2 = resourceTypeValue2.getTextValue(); basicDependencyInstance.setResourceType(resourceTypeInstance2); } JsonNode resourceNameValue = dependsOnValue.get("resourceName"); if (resourceNameValue != null && resourceNameValue instanceof NullNode == false) { String resourceNameInstance; resourceNameInstance = resourceNameValue.getTextValue(); basicDependencyInstance.setResourceName(resourceNameInstance); } } } JsonNode idValue4 = dependenciesValue.get("id"); if (idValue4 != null && idValue4 instanceof NullNode == false) { String idInstance4; idInstance4 = idValue4.getTextValue(); dependencyInstance.setId(idInstance4); } JsonNode resourceTypeValue3 = dependenciesValue.get("resourceType"); if (resourceTypeValue3 != null && resourceTypeValue3 instanceof NullNode == false) { String resourceTypeInstance3; resourceTypeInstance3 = resourceTypeValue3.getTextValue(); dependencyInstance.setResourceType(resourceTypeInstance3); } JsonNode resourceNameValue2 = dependenciesValue.get("resourceName"); if (resourceNameValue2 != null && resourceNameValue2 instanceof NullNode == false) { String resourceNameInstance2; resourceNameInstance2 = resourceNameValue2.getTextValue(); dependencyInstance.setResourceName(resourceNameInstance2); } } } JsonNode templateValue = propertiesValue.get("template"); if (templateValue != null && templateValue instanceof NullNode == false) { String templateInstance; templateInstance = templateValue.getTextValue(); propertiesInstance.setTemplate(templateInstance); } JsonNode templateLinkValue = propertiesValue.get("templateLink"); if (templateLinkValue != null && templateLinkValue instanceof NullNode == false) { TemplateLink templateLinkInstance = new TemplateLink(); propertiesInstance.setTemplateLink(templateLinkInstance); JsonNode uriValue = templateLinkValue.get("uri"); if (uriValue != null && uriValue instanceof NullNode == false) { URI uriInstance; uriInstance = new URI(uriValue.getTextValue()); templateLinkInstance.setUri(uriInstance); } JsonNode contentVersionValue = templateLinkValue.get("contentVersion"); if (contentVersionValue != null && contentVersionValue instanceof NullNode == false) { String contentVersionInstance; contentVersionInstance = contentVersionValue.getTextValue(); templateLinkInstance.setContentVersion(contentVersionInstance); } } JsonNode parametersValue = propertiesValue.get("parameters"); if (parametersValue != null && parametersValue instanceof NullNode == false) { String parametersInstance; parametersInstance = parametersValue.getTextValue(); propertiesInstance.setParameters(parametersInstance); } JsonNode parametersLinkValue = propertiesValue.get("parametersLink"); if (parametersLinkValue != null && parametersLinkValue instanceof NullNode == false) { ParametersLink parametersLinkInstance = new ParametersLink(); propertiesInstance.setParametersLink(parametersLinkInstance); JsonNode uriValue2 = parametersLinkValue.get("uri"); if (uriValue2 != null && uriValue2 instanceof NullNode == false) { URI uriInstance2; uriInstance2 = new URI(uriValue2.getTextValue()); parametersLinkInstance.setUri(uriInstance2); } JsonNode contentVersionValue2 = parametersLinkValue.get("contentVersion"); if (contentVersionValue2 != null && contentVersionValue2 instanceof NullNode == false) { String contentVersionInstance2; contentVersionInstance2 = contentVersionValue2.getTextValue(); parametersLinkInstance.setContentVersion(contentVersionInstance2); } } JsonNode modeValue = propertiesValue.get("mode"); if (modeValue != null && modeValue instanceof NullNode == false) { DeploymentMode modeInstance; modeInstance = Enum.valueOf(DeploymentMode.class, modeValue.getTextValue()); propertiesInstance.setMode(modeInstance); } } } } JsonNode nextLinkValue = responseDoc.get("nextLink"); if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) { String nextLinkInstance; nextLinkInstance = nextLinkValue.getTextValue(); result.setNextLink(nextLinkInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * You can create a web site by using a POST request that includes the name * of the web site and other information in the request body. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx for * more information)// w ww .j av a 2 s. com * * @param webSpaceName Required. The name of the web space. * @param parameters Required. Parameters supplied to the Create Web Site * operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Create Web Site operation response. */ @Override public WebSiteCreateResponse create(String webSpaceName, WebSiteCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getName() == null) { throw new NullPointerException("parameters.Name"); } if (parameters.getServerFarm() == null) { throw new NullPointerException("parameters.ServerFarm"); } if (parameters.getWebSpace() != null) { if (parameters.getWebSpace().getGeoRegion() == null) { throw new NullPointerException("parameters.WebSpace.GeoRegion"); } if (parameters.getWebSpace().getName() == null) { throw new NullPointerException("parameters.WebSpace.Name"); } if (parameters.getWebSpace().getPlan() == null) { throw new NullPointerException("parameters.WebSpace.Plan"); } } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2014-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element siteElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Site"); requestDoc.appendChild(siteElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); siteElement.appendChild(nameElement); Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); serverFarmElement.appendChild(requestDoc.createTextNode(parameters.getServerFarm())); siteElement.appendChild(serverFarmElement); if (parameters.getWebSpace() != null) { Element webSpaceToCreateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "WebSpaceToCreate"); siteElement.appendChild(webSpaceToCreateElement); Element geoRegionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "GeoRegion"); geoRegionElement.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getGeoRegion())); webSpaceToCreateElement.appendChild(geoRegionElement); Element nameElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement2.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getName())); webSpaceToCreateElement.appendChild(nameElement2); Element planElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Plan"); planElement.appendChild(requestDoc.createTextNode(parameters.getWebSpace().getPlan())); webSpaceToCreateElement.appendChild(planElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSiteCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element siteElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Site"); if (siteElement2 != null) { WebSite webSiteInstance = new WebSite(); result.setWebSite(webSiteInstance); Element adminEnabledElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "AdminEnabled"); if (adminEnabledElement != null && adminEnabledElement.getTextContent() != null && !adminEnabledElement.getTextContent().isEmpty()) { boolean adminEnabledInstance; adminEnabledInstance = DatatypeConverter .parseBoolean(adminEnabledElement.getTextContent().toLowerCase()); webSiteInstance.setAdminEnabled(adminEnabledInstance); } Element availabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); webSiteInstance.setAvailabilityState(availabilityStateInstance); } Element sKUElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement != null && sKUElement.getTextContent() != null && !sKUElement.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent()); webSiteInstance.setSku(sKUInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null && enabledElement.getTextContent() != null && !enabledElement.getTextContent().isEmpty()) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); webSiteInstance.setEnabled(enabledInstance); } Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "EnabledHostNames"); if (enabledHostNamesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i1 = i1 + 1) { org.w3c.dom.Element enabledHostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i1)); webSiteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent()); } } Element hostNameSslStatesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); if (hostNameSslStatesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .size(); i2 = i2 + 1) { org.w3c.dom.Element hostNameSslStatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .get(i2)); WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState(); webSiteInstance.getHostNameSslStates().add(hostNameSslStateInstance); Element nameElement3 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement3 != null) { String nameInstance; nameInstance = nameElement3.getTextContent(); hostNameSslStateInstance.setName(nameInstance); } Element sslStateElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "SslState"); if (sslStateElement != null && sslStateElement.getTextContent() != null && !sslStateElement.getTextContent().isEmpty()) { WebSiteSslState sslStateInstance; sslStateInstance = WebSiteSslState.valueOf(sslStateElement.getTextContent()); hostNameSslStateInstance.setSslState(sslStateInstance); } Element thumbprintElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Thumbprint"); if (thumbprintElement != null) { boolean isNil = false; Attr nilAttribute = thumbprintElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String thumbprintInstance; thumbprintInstance = thumbprintElement.getTextContent(); hostNameSslStateInstance.setThumbprint(thumbprintInstance); } } Element virtualIPElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP"); if (virtualIPElement != null) { boolean isNil2 = false; Attr nilAttribute2 = virtualIPElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { InetAddress virtualIPInstance; virtualIPInstance = InetAddress.getByName(virtualIPElement.getTextContent()); hostNameSslStateInstance.setVirtualIP(virtualIPInstance); } } } } Element hostNamesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "HostNames"); if (hostNamesSequenceElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i3 = i3 + 1) { org.w3c.dom.Element hostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i3)); webSiteInstance.getHostNames().add(hostNamesElement.getTextContent()); } } Element lastModifiedTimeUtcElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "LastModifiedTimeUtc"); if (lastModifiedTimeUtcElement != null && lastModifiedTimeUtcElement.getTextContent() != null && !lastModifiedTimeUtcElement.getTextContent().isEmpty()) { Calendar lastModifiedTimeUtcInstance; lastModifiedTimeUtcInstance = DatatypeConverter .parseDateTime(lastModifiedTimeUtcElement.getTextContent()); webSiteInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance); } Element nameElement4 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement4 != null) { String nameInstance2; nameInstance2 = nameElement4.getTextContent(); webSiteInstance.setName(nameInstance2); } Element repositorySiteNameElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "RepositorySiteName"); if (repositorySiteNameElement != null) { String repositorySiteNameInstance; repositorySiteNameInstance = repositorySiteNameElement.getTextContent(); webSiteInstance.setRepositorySiteName(repositorySiteNameInstance); } Element runtimeAvailabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "RuntimeAvailabilityState"); if (runtimeAvailabilityStateElement != null && runtimeAvailabilityStateElement.getTextContent() != null && !runtimeAvailabilityStateElement.getTextContent().isEmpty()) { WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance; runtimeAvailabilityStateInstance = WebSiteRuntimeAvailabilityState .valueOf(runtimeAvailabilityStateElement.getTextContent()); webSiteInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance); } Element selfLinkElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SelfLink"); if (selfLinkElement != null) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkElement.getTextContent()); webSiteInstance.setUri(selfLinkInstance); } Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { String serverFarmInstance; serverFarmInstance = serverFarmElement2.getTextContent(); webSiteInstance.setServerFarm(serverFarmInstance); } Element sitePropertiesElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SiteProperties"); if (sitePropertiesElement != null) { WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties(); webSiteInstance.setSiteProperties(sitePropertiesInstance); Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AppSettings"); if (appSettingsSequenceElement != null) { for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i4 = i4 + 1) { org.w3c.dom.Element appSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i4)); String appSettingsKey = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String appSettingsValue = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } Element metadataSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Metadata"); if (metadataSequenceElement != null) { for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i5 = i5 + 1) { org.w3c.dom.Element metadataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i5)); String metadataKey = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String metadataValue = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue); } } Element propertiesSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Properties"); if (propertiesSequenceElement != null) { for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i6 = i6 + 1) { org.w3c.dom.Element propertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i6)); String propertiesKey = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String propertiesValue = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue); } } } Element stateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); webSiteInstance.setState(stateInstance); } Element usageStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "UsageState"); if (usageStateElement != null && usageStateElement.getTextContent() != null && !usageStateElement.getTextContent().isEmpty()) { WebSiteUsageState usageStateInstance; usageStateInstance = WebSiteUsageState.valueOf(usageStateElement.getTextContent()); webSiteInstance.setUsageState(usageStateInstance); } Element webSpaceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { String webSpaceInstance; webSpaceInstance = webSpaceElement.getTextContent(); webSiteInstance.setWebSpace(webSpaceInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.compute.HostedServiceOperationsImpl.java
/** * The Get Hosted Service Properties operation retrieves system properties * for the specified cloud service. These properties include the service * name and service type; and the name of the affinity group to which the * service belongs, or its location if it is not part of an affinity group. * (see http://msdn.microsoft.com/en-us/library/windowsazure/ee460806.aspx * for more information)/*from w w w . j av a 2 s . c o m*/ * * @param serviceName Required. The name of the cloud service. * @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 Hosted Service operation response. */ @Override public HostedServiceGetResponse get(String serviceName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } // 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); 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/hostedservices/"; url = url + URLEncoder.encode(serviceName, "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 HostedServiceGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new HostedServiceGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element hostedServiceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "HostedService"); if (hostedServiceElement != null) { Element urlElement = XmlUtility.getElementByTagNameNS(hostedServiceElement, "http://schemas.microsoft.com/windowsazure", "Url"); if (urlElement != null) { URI urlInstance; urlInstance = new URI(urlElement.getTextContent()); result.setUri(urlInstance); } Element serviceNameElement = XmlUtility.getElementByTagNameNS(hostedServiceElement, "http://schemas.microsoft.com/windowsazure", "ServiceName"); if (serviceNameElement != null) { String serviceNameInstance; serviceNameInstance = serviceNameElement.getTextContent(); result.setServiceName(serviceNameInstance); } Element hostedServicePropertiesElement = XmlUtility.getElementByTagNameNS(hostedServiceElement, "http://schemas.microsoft.com/windowsazure", "HostedServiceProperties"); if (hostedServicePropertiesElement != null) { HostedServiceProperties hostedServicePropertiesInstance = new HostedServiceProperties(); result.setProperties(hostedServicePropertiesInstance); Element descriptionElement = XmlUtility.getElementByTagNameNS( hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); hostedServicePropertiesInstance.setDescription(descriptionInstance); } Element affinityGroupElement = XmlUtility.getElementByTagNameNS( hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AffinityGroup"); if (affinityGroupElement != null) { String affinityGroupInstance; affinityGroupInstance = affinityGroupElement.getTextContent(); hostedServicePropertiesInstance.setAffinityGroup(affinityGroupInstance); } Element locationElement = XmlUtility.getElementByTagNameNS(hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Location"); if (locationElement != null) { String locationInstance; locationInstance = locationElement.getTextContent(); hostedServicePropertiesInstance.setLocation(locationInstance); } Element labelElement = XmlUtility.getElementByTagNameNS(hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement != null) { String labelInstance; labelInstance = labelElement.getTextContent() != null ? new String(Base64.decode(labelElement.getTextContent())) : null; hostedServicePropertiesInstance.setLabel(labelInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { HostedServiceStatus statusInstance; statusInstance = HostedServiceStatus.valueOf(statusElement.getTextContent()); hostedServicePropertiesInstance.setStatus(statusInstance); } Element dateCreatedElement = XmlUtility.getElementByTagNameNS( hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "DateCreated"); if (dateCreatedElement != null) { Calendar dateCreatedInstance; dateCreatedInstance = DatatypeConverter .parseDateTime(dateCreatedElement.getTextContent()); hostedServicePropertiesInstance.setDateCreated(dateCreatedInstance); } Element dateLastModifiedElement = XmlUtility.getElementByTagNameNS( hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "DateLastModified"); if (dateLastModifiedElement != null) { Calendar dateLastModifiedInstance; dateLastModifiedInstance = DatatypeConverter .parseDateTime(dateLastModifiedElement.getTextContent()); hostedServicePropertiesInstance.setDateLastModified(dateLastModifiedInstance); } Element extendedPropertiesSequenceElement = XmlUtility.getElementByTagNameNS( hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperties"); if (extendedPropertiesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(extendedPropertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperty") .size(); i1 = i1 + 1) { org.w3c.dom.Element extendedPropertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(extendedPropertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperty") .get(i1)); String extendedPropertiesKey = XmlUtility .getElementByTagNameNS(extendedPropertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String extendedPropertiesValue = XmlUtility .getElementByTagNameNS(extendedPropertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); hostedServicePropertiesInstance.getExtendedProperties().put(extendedPropertiesKey, extendedPropertiesValue); } } Element reverseDnsFqdnElement = XmlUtility.getElementByTagNameNS( hostedServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "ReverseDnsFqdn"); if (reverseDnsFqdnElement != null) { String reverseDnsFqdnInstance; reverseDnsFqdnInstance = reverseDnsFqdnElement.getTextContent(); hostedServicePropertiesInstance.setReverseDnsFqdn(reverseDnsFqdnInstance); } } Element computeCapabilitiesElement = XmlUtility.getElementByTagNameNS(hostedServiceElement, "http://schemas.microsoft.com/windowsazure", "ComputeCapabilities"); if (computeCapabilitiesElement != null) { ComputeCapabilities computeCapabilitiesInstance = new ComputeCapabilities(); result.setComputeCapabilities(computeCapabilitiesInstance); Element virtualMachinesRoleSizesSequenceElement = XmlUtility.getElementByTagNameNS( computeCapabilitiesElement, "http://schemas.microsoft.com/windowsazure", "VirtualMachinesRoleSizes"); if (virtualMachinesRoleSizesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(virtualMachinesRoleSizesSequenceElement, "http://schemas.microsoft.com/windowsazure", "RoleSize") .size(); i2 = i2 + 1) { org.w3c.dom.Element virtualMachinesRoleSizesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(virtualMachinesRoleSizesSequenceElement, "http://schemas.microsoft.com/windowsazure", "RoleSize") .get(i2)); computeCapabilitiesInstance.getVirtualMachinesRoleSizes() .add(virtualMachinesRoleSizesElement.getTextContent()); } } Element webWorkerRoleSizesSequenceElement = XmlUtility.getElementByTagNameNS( computeCapabilitiesElement, "http://schemas.microsoft.com/windowsazure", "WebWorkerRoleSizes"); if (webWorkerRoleSizesSequenceElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(webWorkerRoleSizesSequenceElement, "http://schemas.microsoft.com/windowsazure", "RoleSize") .size(); i3 = i3 + 1) { org.w3c.dom.Element webWorkerRoleSizesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(webWorkerRoleSizesSequenceElement, "http://schemas.microsoft.com/windowsazure", "RoleSize") .get(i3)); computeCapabilitiesInstance.getWebWorkerRoleSizes() .add(webWorkerRoleSizesElement.getTextContent()); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.azure.management.notificationhubs.NamespaceOperationsImpl.java
/** * The get authorization rule operation gets an authorization rule for a * namespace by name.//from www. ja v a2s. com * * @param resourceGroupName Required. The name of the resource group. * @param namespaceName Required. The namespace to get the authorization * rule for. * @param authorizationRuleName Required. The entity name to get the * authorization rule for. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return The response of the Get Namespace operation. */ @Override public SharedAccessAuthorizationRuleGetResponse getAuthorizationRule(String resourceGroupName, String namespaceName, String authorizationRuleName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (namespaceName == null) { throw new NullPointerException("namespaceName"); } if (authorizationRuleName == null) { throw new NullPointerException("authorizationRuleName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("resourceGroupName", resourceGroupName); tracingParameters.put("namespaceName", namespaceName); tracingParameters.put("authorizationRuleName", authorizationRuleName); CloudTracing.enter(invocationId, this, "getAuthorizationRuleAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.NotificationHubs"; url = url + "/namespaces/"; url = url + URLEncoder.encode(namespaceName, "UTF-8"); url = url + "/AuthorizationRules/"; url = url + URLEncoder.encode(authorizationRuleName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-09-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result SharedAccessAuthorizationRuleGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new SharedAccessAuthorizationRuleGetResponse(); ObjectMapper objectMapper = new ObjectMapper(); 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) { SharedAccessAuthorizationRuleResource valueInstance = new SharedAccessAuthorizationRuleResource(); result.setValue(valueInstance); JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); valueInstance.setId(idInstance); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); valueInstance.setLocation(locationInstance); } JsonNode nameValue = responseDoc.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); valueInstance.setName(nameInstance); } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); valueInstance.setType(typeInstance); } 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 tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); valueInstance.getTags().put(tagsKey, tagsValue); } } JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { SharedAccessAuthorizationRuleProperties propertiesInstance = new SharedAccessAuthorizationRuleProperties(); valueInstance.setProperties(propertiesInstance); JsonNode primaryKeyValue = propertiesValue.get("primaryKey"); if (primaryKeyValue != null && primaryKeyValue instanceof NullNode == false) { String primaryKeyInstance; primaryKeyInstance = primaryKeyValue.getTextValue(); propertiesInstance.setPrimaryKey(primaryKeyInstance); } JsonNode secondaryKeyValue = propertiesValue.get("secondaryKey"); if (secondaryKeyValue != null && secondaryKeyValue instanceof NullNode == false) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyValue.getTextValue(); propertiesInstance.setSecondaryKey(secondaryKeyInstance); } JsonNode keyNameValue = propertiesValue.get("keyName"); if (keyNameValue != null && keyNameValue instanceof NullNode == false) { String keyNameInstance; keyNameInstance = keyNameValue.getTextValue(); propertiesInstance.setKeyName(keyNameInstance); } JsonNode claimTypeValue = propertiesValue.get("claimType"); if (claimTypeValue != null && claimTypeValue instanceof NullNode == false) { String claimTypeInstance; claimTypeInstance = claimTypeValue.getTextValue(); propertiesInstance.setClaimType(claimTypeInstance); } JsonNode claimValueValue = propertiesValue.get("claimValue"); if (claimValueValue != null && claimValueValue instanceof NullNode == false) { String claimValueInstance; claimValueInstance = claimValueValue.getTextValue(); propertiesInstance.setClaimValue(claimValueInstance); } JsonNode rightsArray = propertiesValue.get("rights"); if (rightsArray != null && rightsArray instanceof NullNode == false) { for (JsonNode rightsValue : ((ArrayNode) rightsArray)) { propertiesInstance.getRights() .add(Enum.valueOf(AccessRights.class, rightsValue.getTextValue())); } } JsonNode createdTimeValue = propertiesValue.get("createdTime"); if (createdTimeValue != null && createdTimeValue instanceof NullNode == false) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter.parseDateTime(createdTimeValue.getTextValue()); propertiesInstance.setCreatedTime(createdTimeInstance); } JsonNode modifiedTimeValue = propertiesValue.get("modifiedTime"); if (modifiedTimeValue != null && modifiedTimeValue instanceof NullNode == false) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeValue.getTextValue()); propertiesInstance.setModifiedTime(modifiedTimeInstance); } JsonNode revisionValue = propertiesValue.get("revision"); if (revisionValue != null && revisionValue instanceof NullNode == false) { int revisionInstance; revisionInstance = revisionValue.getIntValue(); propertiesInstance.setRevision(revisionInstance); } } } } 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(); } } }