List of usage examples for javax.xml.bind DatatypeConverter parseInt
public static int parseInt(String lexicalXSDInt)
Convert the string argument into an int value.
From source file:com.microsoft.azure.management.network.NetworkInterfaceOperationsImpl.java
/** * The Put NetworkInterface operation creates/updates a networkInterface * * @param resourceGroupName Required. The name of the resource group. * @param networkInterfaceName Required. The name of the network interface. * @param parameters Required. Parameters supplied to the create/update * NetworkInterface operation/*from ww w . j a v a2 s. co m*/ * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return Response for PutNetworkInterface Api servive call */ @Override public NetworkInterfacePutResponse beginCreateOrUpdating(String resourceGroupName, String networkInterfaceName, NetworkInterface parameters) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (networkInterfaceName == null) { throw new NullPointerException("networkInterfaceName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLocation() == null) { throw new NullPointerException("parameters.Location"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("resourceGroupName", resourceGroupName); tracingParameters.put("networkInterfaceName", networkInterfaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCreateOrUpdatingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Network"; url = url + "/networkInterfaces/"; url = url + URLEncoder.encode(networkInterfaceName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-05-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json"); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode networkInterfaceJsonFormatValue = objectMapper.createObjectNode(); requestDoc = networkInterfaceJsonFormatValue; ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) networkInterfaceJsonFormatValue).put("properties", propertiesValue); if (parameters.getVirtualMachine() != null) { ObjectNode virtualMachineValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("virtualMachine", virtualMachineValue); if (parameters.getVirtualMachine().getId() != null) { ((ObjectNode) virtualMachineValue).put("id", parameters.getVirtualMachine().getId()); } } if (parameters.getNetworkSecurityGroup() != null) { ObjectNode networkSecurityGroupValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("networkSecurityGroup", networkSecurityGroupValue); if (parameters.getNetworkSecurityGroup().getId() != null) { ((ObjectNode) networkSecurityGroupValue).put("id", parameters.getNetworkSecurityGroup().getId()); } } if (parameters.getIpConfigurations() != null) { if (parameters.getIpConfigurations() instanceof LazyCollection == false || ((LazyCollection) parameters.getIpConfigurations()).isInitialized()) { ArrayNode ipConfigurationsArray = objectMapper.createArrayNode(); for (NetworkInterfaceIpConfiguration ipConfigurationsItem : parameters.getIpConfigurations()) { ObjectNode networkInterfaceIpConfigurationJsonFormatValue = objectMapper.createObjectNode(); ipConfigurationsArray.add(networkInterfaceIpConfigurationJsonFormatValue); ObjectNode propertiesValue2 = objectMapper.createObjectNode(); ((ObjectNode) networkInterfaceIpConfigurationJsonFormatValue).put("properties", propertiesValue2); if (ipConfigurationsItem.getPrivateIpAddress() != null) { ((ObjectNode) propertiesValue2).put("privateIPAddress", ipConfigurationsItem.getPrivateIpAddress()); } if (ipConfigurationsItem.getPrivateIpAllocationMethod() != null) { ((ObjectNode) propertiesValue2).put("privateIPAllocationMethod", ipConfigurationsItem.getPrivateIpAllocationMethod()); } if (ipConfigurationsItem.getSubnet() != null) { ObjectNode subnetValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue2).put("subnet", subnetValue); if (ipConfigurationsItem.getSubnet().getId() != null) { ((ObjectNode) subnetValue).put("id", ipConfigurationsItem.getSubnet().getId()); } } if (ipConfigurationsItem.getPublicIpAddress() != null) { ObjectNode publicIPAddressValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue2).put("publicIPAddress", publicIPAddressValue); if (ipConfigurationsItem.getPublicIpAddress().getId() != null) { ((ObjectNode) publicIPAddressValue).put("id", ipConfigurationsItem.getPublicIpAddress().getId()); } } if (ipConfigurationsItem.getLoadBalancerBackendAddressPools() != null) { if (ipConfigurationsItem .getLoadBalancerBackendAddressPools() instanceof LazyCollection == false || ((LazyCollection) ipConfigurationsItem.getLoadBalancerBackendAddressPools()) .isInitialized()) { ArrayNode loadBalancerBackendAddressPoolsArray = objectMapper.createArrayNode(); for (ResourceId loadBalancerBackendAddressPoolsItem : ipConfigurationsItem .getLoadBalancerBackendAddressPools()) { ObjectNode resourceIdValue = objectMapper.createObjectNode(); loadBalancerBackendAddressPoolsArray.add(resourceIdValue); if (loadBalancerBackendAddressPoolsItem.getId() != null) { ((ObjectNode) resourceIdValue).put("id", loadBalancerBackendAddressPoolsItem.getId()); } } ((ObjectNode) propertiesValue2).put("loadBalancerBackendAddressPools", loadBalancerBackendAddressPoolsArray); } } if (ipConfigurationsItem.getLoadBalancerInboundNatRules() != null) { if (ipConfigurationsItem.getLoadBalancerInboundNatRules() instanceof LazyCollection == false || ((LazyCollection) ipConfigurationsItem.getLoadBalancerInboundNatRules()) .isInitialized()) { ArrayNode loadBalancerInboundNatRulesArray = objectMapper.createArrayNode(); for (ResourceId loadBalancerInboundNatRulesItem : ipConfigurationsItem .getLoadBalancerInboundNatRules()) { ObjectNode resourceIdValue2 = objectMapper.createObjectNode(); loadBalancerInboundNatRulesArray.add(resourceIdValue2); if (loadBalancerInboundNatRulesItem.getId() != null) { ((ObjectNode) resourceIdValue2).put("id", loadBalancerInboundNatRulesItem.getId()); } } ((ObjectNode) propertiesValue2).put("loadBalancerInboundNatRules", loadBalancerInboundNatRulesArray); } } if (ipConfigurationsItem.getProvisioningState() != null) { ((ObjectNode) propertiesValue2).put("provisioningState", ipConfigurationsItem.getProvisioningState()); } if (ipConfigurationsItem.getName() != null) { ((ObjectNode) networkInterfaceIpConfigurationJsonFormatValue).put("name", ipConfigurationsItem.getName()); } if (ipConfigurationsItem.getEtag() != null) { ((ObjectNode) networkInterfaceIpConfigurationJsonFormatValue).put("etag", ipConfigurationsItem.getEtag()); } if (ipConfigurationsItem.getId() != null) { ((ObjectNode) networkInterfaceIpConfigurationJsonFormatValue).put("id", ipConfigurationsItem.getId()); } } ((ObjectNode) propertiesValue).put("ipConfigurations", ipConfigurationsArray); } } if (parameters.getDnsSettings() != null) { ObjectNode dnsSettingsValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("dnsSettings", dnsSettingsValue); if (parameters.getDnsSettings().getDnsServers() != null) { if (parameters.getDnsSettings().getDnsServers() instanceof LazyCollection == false || ((LazyCollection) parameters.getDnsSettings().getDnsServers()).isInitialized()) { ArrayNode dnsServersArray = objectMapper.createArrayNode(); for (String dnsServersItem : parameters.getDnsSettings().getDnsServers()) { dnsServersArray.add(dnsServersItem); } ((ObjectNode) dnsSettingsValue).put("dnsServers", dnsServersArray); } } if (parameters.getDnsSettings().getAppliedDnsServers() != null) { if (parameters.getDnsSettings().getAppliedDnsServers() instanceof LazyCollection == false || ((LazyCollection) parameters.getDnsSettings().getAppliedDnsServers()).isInitialized()) { ArrayNode appliedDnsServersArray = objectMapper.createArrayNode(); for (String appliedDnsServersItem : parameters.getDnsSettings().getAppliedDnsServers()) { appliedDnsServersArray.add(appliedDnsServersItem); } ((ObjectNode) dnsSettingsValue).put("appliedDnsServers", appliedDnsServersArray); } } if (parameters.getDnsSettings().getInternalDnsNameLabel() != null) { ((ObjectNode) dnsSettingsValue).put("internalDnsNameLabel", parameters.getDnsSettings().getInternalDnsNameLabel()); } if (parameters.getDnsSettings().getInternalFqdn() != null) { ((ObjectNode) dnsSettingsValue).put("internalFqdn", parameters.getDnsSettings().getInternalFqdn()); } } if (parameters.getMacAddress() != null) { ((ObjectNode) propertiesValue).put("macAddress", parameters.getMacAddress()); } if (parameters.isPrimary() != null) { ((ObjectNode) propertiesValue).put("primary", parameters.isPrimary()); } ((ObjectNode) propertiesValue).put("enableIPForwarding", parameters.isEnableIPForwarding()); if (parameters.getResourceGuid() != null) { ((ObjectNode) propertiesValue).put("resourceGuid", parameters.getResourceGuid()); } if (parameters.getProvisioningState() != null) { ((ObjectNode) propertiesValue).put("provisioningState", parameters.getProvisioningState()); } if (parameters.getEtag() != null) { ((ObjectNode) networkInterfaceJsonFormatValue).put("etag", parameters.getEtag()); } if (parameters.getId() != null) { ((ObjectNode) networkInterfaceJsonFormatValue).put("id", parameters.getId()); } if (parameters.getName() != null) { ((ObjectNode) networkInterfaceJsonFormatValue).put("name", parameters.getName()); } if (parameters.getType() != null) { ((ObjectNode) networkInterfaceJsonFormatValue).put("type", parameters.getType()); } ((ObjectNode) networkInterfaceJsonFormatValue).put("location", parameters.getLocation()); if (parameters.getTags() != null) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) networkInterfaceJsonFormatValue).put("tags", tagsDictionary); } StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, requestDoc); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/json"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result NetworkInterfacePutResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new NetworkInterfacePutResponse(); 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) { NetworkInterface networkInterfaceInstance = new NetworkInterface(); result.setNetworkInterface(networkInterfaceInstance); JsonNode propertiesValue3 = responseDoc.get("properties"); if (propertiesValue3 != null && propertiesValue3 instanceof NullNode == false) { JsonNode virtualMachineValue2 = propertiesValue3.get("virtualMachine"); if (virtualMachineValue2 != null && virtualMachineValue2 instanceof NullNode == false) { ResourceId virtualMachineInstance = new ResourceId(); networkInterfaceInstance.setVirtualMachine(virtualMachineInstance); JsonNode idValue = virtualMachineValue2.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); virtualMachineInstance.setId(idInstance); } } JsonNode networkSecurityGroupValue2 = propertiesValue3.get("networkSecurityGroup"); if (networkSecurityGroupValue2 != null && networkSecurityGroupValue2 instanceof NullNode == false) { ResourceId networkSecurityGroupInstance = new ResourceId(); networkInterfaceInstance.setNetworkSecurityGroup(networkSecurityGroupInstance); JsonNode idValue2 = networkSecurityGroupValue2.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); networkSecurityGroupInstance.setId(idInstance2); } } JsonNode ipConfigurationsArray2 = propertiesValue3.get("ipConfigurations"); if (ipConfigurationsArray2 != null && ipConfigurationsArray2 instanceof NullNode == false) { for (JsonNode ipConfigurationsValue : ((ArrayNode) ipConfigurationsArray2)) { NetworkInterfaceIpConfiguration networkInterfaceIpConfigurationJsonFormatInstance = new NetworkInterfaceIpConfiguration(); networkInterfaceInstance.getIpConfigurations() .add(networkInterfaceIpConfigurationJsonFormatInstance); JsonNode propertiesValue4 = ipConfigurationsValue.get("properties"); if (propertiesValue4 != null && propertiesValue4 instanceof NullNode == false) { JsonNode privateIPAddressValue = propertiesValue4.get("privateIPAddress"); if (privateIPAddressValue != null && privateIPAddressValue instanceof NullNode == false) { String privateIPAddressInstance; privateIPAddressInstance = privateIPAddressValue.getTextValue(); networkInterfaceIpConfigurationJsonFormatInstance .setPrivateIpAddress(privateIPAddressInstance); } JsonNode privateIPAllocationMethodValue = propertiesValue4 .get("privateIPAllocationMethod"); if (privateIPAllocationMethodValue != null && privateIPAllocationMethodValue instanceof NullNode == false) { String privateIPAllocationMethodInstance; privateIPAllocationMethodInstance = privateIPAllocationMethodValue .getTextValue(); networkInterfaceIpConfigurationJsonFormatInstance .setPrivateIpAllocationMethod(privateIPAllocationMethodInstance); } JsonNode subnetValue2 = propertiesValue4.get("subnet"); if (subnetValue2 != null && subnetValue2 instanceof NullNode == false) { ResourceId subnetInstance = new ResourceId(); networkInterfaceIpConfigurationJsonFormatInstance.setSubnet(subnetInstance); JsonNode idValue3 = subnetValue2.get("id"); if (idValue3 != null && idValue3 instanceof NullNode == false) { String idInstance3; idInstance3 = idValue3.getTextValue(); subnetInstance.setId(idInstance3); } } JsonNode publicIPAddressValue2 = propertiesValue4.get("publicIPAddress"); if (publicIPAddressValue2 != null && publicIPAddressValue2 instanceof NullNode == false) { ResourceId publicIPAddressInstance = new ResourceId(); networkInterfaceIpConfigurationJsonFormatInstance .setPublicIpAddress(publicIPAddressInstance); JsonNode idValue4 = publicIPAddressValue2.get("id"); if (idValue4 != null && idValue4 instanceof NullNode == false) { String idInstance4; idInstance4 = idValue4.getTextValue(); publicIPAddressInstance.setId(idInstance4); } } JsonNode loadBalancerBackendAddressPoolsArray2 = propertiesValue4 .get("loadBalancerBackendAddressPools"); if (loadBalancerBackendAddressPoolsArray2 != null && loadBalancerBackendAddressPoolsArray2 instanceof NullNode == false) { for (JsonNode loadBalancerBackendAddressPoolsValue : ((ArrayNode) loadBalancerBackendAddressPoolsArray2)) { ResourceId resourceIdInstance = new ResourceId(); networkInterfaceIpConfigurationJsonFormatInstance .getLoadBalancerBackendAddressPools().add(resourceIdInstance); JsonNode idValue5 = loadBalancerBackendAddressPoolsValue.get("id"); if (idValue5 != null && idValue5 instanceof NullNode == false) { String idInstance5; idInstance5 = idValue5.getTextValue(); resourceIdInstance.setId(idInstance5); } } } JsonNode loadBalancerInboundNatRulesArray2 = propertiesValue4 .get("loadBalancerInboundNatRules"); if (loadBalancerInboundNatRulesArray2 != null && loadBalancerInboundNatRulesArray2 instanceof NullNode == false) { for (JsonNode loadBalancerInboundNatRulesValue : ((ArrayNode) loadBalancerInboundNatRulesArray2)) { ResourceId resourceIdInstance2 = new ResourceId(); networkInterfaceIpConfigurationJsonFormatInstance .getLoadBalancerInboundNatRules().add(resourceIdInstance2); JsonNode idValue6 = loadBalancerInboundNatRulesValue.get("id"); if (idValue6 != null && idValue6 instanceof NullNode == false) { String idInstance6; idInstance6 = idValue6.getTextValue(); resourceIdInstance2.setId(idInstance6); } } } JsonNode provisioningStateValue = propertiesValue4.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); networkInterfaceIpConfigurationJsonFormatInstance .setProvisioningState(provisioningStateInstance); } } JsonNode nameValue = ipConfigurationsValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); networkInterfaceIpConfigurationJsonFormatInstance.setName(nameInstance); } JsonNode etagValue = ipConfigurationsValue.get("etag"); if (etagValue != null && etagValue instanceof NullNode == false) { String etagInstance; etagInstance = etagValue.getTextValue(); networkInterfaceIpConfigurationJsonFormatInstance.setEtag(etagInstance); } JsonNode idValue7 = ipConfigurationsValue.get("id"); if (idValue7 != null && idValue7 instanceof NullNode == false) { String idInstance7; idInstance7 = idValue7.getTextValue(); networkInterfaceIpConfigurationJsonFormatInstance.setId(idInstance7); } } } JsonNode dnsSettingsValue2 = propertiesValue3.get("dnsSettings"); if (dnsSettingsValue2 != null && dnsSettingsValue2 instanceof NullNode == false) { NetworkInterfaceDnsSettings dnsSettingsInstance = new NetworkInterfaceDnsSettings(); networkInterfaceInstance.setDnsSettings(dnsSettingsInstance); JsonNode dnsServersArray2 = dnsSettingsValue2.get("dnsServers"); if (dnsServersArray2 != null && dnsServersArray2 instanceof NullNode == false) { for (JsonNode dnsServersValue : ((ArrayNode) dnsServersArray2)) { dnsSettingsInstance.getDnsServers().add(dnsServersValue.getTextValue()); } } JsonNode appliedDnsServersArray2 = dnsSettingsValue2.get("appliedDnsServers"); if (appliedDnsServersArray2 != null && appliedDnsServersArray2 instanceof NullNode == false) { for (JsonNode appliedDnsServersValue : ((ArrayNode) appliedDnsServersArray2)) { dnsSettingsInstance.getAppliedDnsServers() .add(appliedDnsServersValue.getTextValue()); } } JsonNode internalDnsNameLabelValue = dnsSettingsValue2.get("internalDnsNameLabel"); if (internalDnsNameLabelValue != null && internalDnsNameLabelValue instanceof NullNode == false) { String internalDnsNameLabelInstance; internalDnsNameLabelInstance = internalDnsNameLabelValue.getTextValue(); dnsSettingsInstance.setInternalDnsNameLabel(internalDnsNameLabelInstance); } JsonNode internalFqdnValue = dnsSettingsValue2.get("internalFqdn"); if (internalFqdnValue != null && internalFqdnValue instanceof NullNode == false) { String internalFqdnInstance; internalFqdnInstance = internalFqdnValue.getTextValue(); dnsSettingsInstance.setInternalFqdn(internalFqdnInstance); } } JsonNode macAddressValue = propertiesValue3.get("macAddress"); if (macAddressValue != null && macAddressValue instanceof NullNode == false) { String macAddressInstance; macAddressInstance = macAddressValue.getTextValue(); networkInterfaceInstance.setMacAddress(macAddressInstance); } JsonNode primaryValue = propertiesValue3.get("primary"); if (primaryValue != null && primaryValue instanceof NullNode == false) { boolean primaryInstance; primaryInstance = primaryValue.getBooleanValue(); networkInterfaceInstance.setPrimary(primaryInstance); } JsonNode enableIPForwardingValue = propertiesValue3.get("enableIPForwarding"); if (enableIPForwardingValue != null && enableIPForwardingValue instanceof NullNode == false) { boolean enableIPForwardingInstance; enableIPForwardingInstance = enableIPForwardingValue.getBooleanValue(); networkInterfaceInstance.setEnableIPForwarding(enableIPForwardingInstance); } JsonNode resourceGuidValue = propertiesValue3.get("resourceGuid"); if (resourceGuidValue != null && resourceGuidValue instanceof NullNode == false) { String resourceGuidInstance; resourceGuidInstance = resourceGuidValue.getTextValue(); networkInterfaceInstance.setResourceGuid(resourceGuidInstance); } JsonNode provisioningStateValue2 = propertiesValue3.get("provisioningState"); if (provisioningStateValue2 != null && provisioningStateValue2 instanceof NullNode == false) { String provisioningStateInstance2; provisioningStateInstance2 = provisioningStateValue2.getTextValue(); networkInterfaceInstance.setProvisioningState(provisioningStateInstance2); } } JsonNode etagValue2 = responseDoc.get("etag"); if (etagValue2 != null && etagValue2 instanceof NullNode == false) { String etagInstance2; etagInstance2 = etagValue2.getTextValue(); networkInterfaceInstance.setEtag(etagInstance2); } JsonNode idValue8 = responseDoc.get("id"); if (idValue8 != null && idValue8 instanceof NullNode == false) { String idInstance8; idInstance8 = idValue8.getTextValue(); networkInterfaceInstance.setId(idInstance8); } JsonNode nameValue2 = responseDoc.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); networkInterfaceInstance.setName(nameInstance2); } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); networkInterfaceInstance.setType(typeInstance); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); networkInterfaceInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey2 = property.getKey(); String tagsValue2 = property.getValue().getTextValue(); networkInterfaceInstance.getTags().put(tagsKey2, tagsValue2); } } JsonNode errorValue = responseDoc.get("error"); if (errorValue != null && errorValue instanceof NullNode == false) { Error errorInstance = new Error(); result.setError(errorInstance); JsonNode codeValue = errorValue.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); errorInstance.setCode(codeInstance); } JsonNode messageValue = errorValue.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); errorInstance.setMessage(messageInstance); } JsonNode targetValue = errorValue.get("target"); if (targetValue != null && targetValue instanceof NullNode == false) { String targetInstance; targetInstance = targetValue.getTextValue(); errorInstance.setTarget(targetInstance); } JsonNode detailsArray = errorValue.get("details"); if (detailsArray != null && detailsArray instanceof NullNode == false) { for (JsonNode detailsValue : ((ArrayNode) detailsArray)) { ErrorDetails errorDetailsInstance = new ErrorDetails(); errorInstance.getDetails().add(errorDetailsInstance); JsonNode codeValue2 = detailsValue.get("code"); if (codeValue2 != null && codeValue2 instanceof NullNode == false) { String codeInstance2; codeInstance2 = codeValue2.getTextValue(); errorDetailsInstance.setCode(codeInstance2); } JsonNode targetValue2 = detailsValue.get("target"); if (targetValue2 != null && targetValue2 instanceof NullNode == false) { String targetInstance2; targetInstance2 = targetValue2.getTextValue(); errorDetailsInstance.setTarget(targetInstance2); } JsonNode messageValue2 = detailsValue.get("message"); if (messageValue2 != null && messageValue2 instanceof NullNode == false) { String messageInstance2; messageInstance2 = messageValue2.getTextValue(); errorDetailsInstance.setMessage(messageInstance2); } } } JsonNode innerErrorValue = errorValue.get("innerError"); if (innerErrorValue != null && innerErrorValue instanceof NullNode == false) { String innerErrorInstance; innerErrorInstance = innerErrorValue.getTextValue(); errorInstance.setInnerError(innerErrorInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("Azure-AsyncOperation").length > 0) { result.setAzureAsyncOperation(httpResponse.getFirstHeader("Azure-AsyncOperation").getValue()); } if (httpResponse.getHeaders("Retry-After").length > 0) { result.setRetryAfter( DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue())); } if (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
/** * The create namespace authorization rule operation creates an * authorization rule for a namespace//from ww w . j a va 2 s .c om * * @param namespaceName Required. The namespace name. * @param rule Required. The shared access authorization rule. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return A response to a request for a particular authorization rule. */ @Override public ServiceBusAuthorizationRuleResponse createAuthorizationRule(String namespaceName, ServiceBusSharedAccessAuthorizationRule rule) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (namespaceName == null) { throw new NullPointerException("namespaceName"); } if (rule == null) { throw new NullPointerException("rule"); } // 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("rule", rule); CloudTracing.enter(invocationId, this, "createAuthorizationRuleAsync", 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 + "/AuthorizationRules"; 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("Accept", "application/atom+xml"); httpRequest.setHeader("Content-Type", "application/atom+xml"); httpRequest.setHeader("type", "entry"); httpRequest.setHeader("x-ms-version", "2013-08-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element entryElement = requestDoc.createElementNS("http://www.w3.org/2005/Atom", "entry"); requestDoc.appendChild(entryElement); Element contentElement = requestDoc.createElementNS("http://www.w3.org/2005/Atom", "content"); entryElement.appendChild(contentElement); Attr typeAttribute = requestDoc.createAttribute("type"); typeAttribute.setValue("application/atom+xml"); contentElement.setAttributeNode(typeAttribute); Element sharedAccessAuthorizationRuleElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SharedAccessAuthorizationRule"); contentElement.appendChild(sharedAccessAuthorizationRuleElement); if (rule.getClaimType() != null) { Element claimTypeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimType"); claimTypeElement.appendChild(requestDoc.createTextNode(rule.getClaimType())); sharedAccessAuthorizationRuleElement.appendChild(claimTypeElement); } if (rule.getClaimValue() != null) { Element claimValueElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimValue"); claimValueElement.appendChild(requestDoc.createTextNode(rule.getClaimValue())); sharedAccessAuthorizationRuleElement.appendChild(claimValueElement); } if (rule.getRights() != null) { if (rule.getRights() instanceof LazyCollection == false || ((LazyCollection) rule.getRights()).isInitialized()) { Element rightsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Rights"); for (AccessRight rightsItem : rule.getRights()) { Element rightsItemElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights"); rightsItemElement.appendChild(requestDoc.createTextNode(rightsItem.toString())); rightsSequenceElement.appendChild(rightsItemElement); } sharedAccessAuthorizationRuleElement.appendChild(rightsSequenceElement); } } Element createdTimeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedTime"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); createdTimeElement .appendChild(requestDoc.createTextNode(simpleDateFormat.format(rule.getCreatedTime().getTime()))); sharedAccessAuthorizationRuleElement.appendChild(createdTimeElement); Element modifiedTimeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ModifiedTime"); SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC")); modifiedTimeElement .appendChild(requestDoc.createTextNode(simpleDateFormat2.format(rule.getModifiedTime().getTime()))); sharedAccessAuthorizationRuleElement.appendChild(modifiedTimeElement); Element revisionElement = requestDoc .createElementNS("http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Revision"); revisionElement.appendChild(requestDoc.createTextNode(Integer.toString(rule.getRevision()))); sharedAccessAuthorizationRuleElement.appendChild(revisionElement); if (rule.getKeyName() != null) { Element keyNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "KeyName"); keyNameElement.appendChild(requestDoc.createTextNode(rule.getKeyName())); sharedAccessAuthorizationRuleElement.appendChild(keyNameElement); } if (rule.getPrimaryKey() != null) { Element primaryKeyElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "PrimaryKey"); primaryKeyElement.appendChild(requestDoc.createTextNode(rule.getPrimaryKey())); sharedAccessAuthorizationRuleElement.appendChild(primaryKeyElement); } 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/atom+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_CREATED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ServiceBusAuthorizationRuleResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServiceBusAuthorizationRuleResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element entryElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom", "entry"); if (entryElement2 != null) { Element contentElement2 = XmlUtility.getElementByTagNameNS(entryElement2, "http://www.w3.org/2005/Atom", "content"); if (contentElement2 != null) { Element sharedAccessAuthorizationRuleElement2 = XmlUtility.getElementByTagNameNS( contentElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SharedAccessAuthorizationRule"); if (sharedAccessAuthorizationRuleElement2 != null) { ServiceBusSharedAccessAuthorizationRule sharedAccessAuthorizationRuleInstance = new ServiceBusSharedAccessAuthorizationRule(); result.setAuthorizationRule(sharedAccessAuthorizationRuleInstance); Element claimTypeElement2 = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimType"); if (claimTypeElement2 != null) { String claimTypeInstance; claimTypeInstance = claimTypeElement2.getTextContent(); sharedAccessAuthorizationRuleInstance.setClaimType(claimTypeInstance); } Element claimValueElement2 = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimValue"); if (claimValueElement2 != null) { String claimValueInstance; claimValueInstance = claimValueElement2.getTextContent(); sharedAccessAuthorizationRuleInstance.setClaimValue(claimValueInstance); } Element rightsSequenceElement2 = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Rights"); if (rightsSequenceElement2 != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(rightsSequenceElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights") .size(); i1 = i1 + 1) { org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(rightsSequenceElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights") .get(i1)); sharedAccessAuthorizationRuleInstance.getRights() .add(AccessRight.valueOf(rightsElement.getTextContent())); } } Element createdTimeElement2 = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedTime"); if (createdTimeElement2 != null) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter .parseDateTime(createdTimeElement2.getTextContent()); sharedAccessAuthorizationRuleInstance.setCreatedTime(createdTimeInstance); } Element modifiedTimeElement2 = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ModifiedTime"); if (modifiedTimeElement2 != null) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeElement2.getTextContent()); sharedAccessAuthorizationRuleInstance.setModifiedTime(modifiedTimeInstance); } Element keyNameElement2 = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "KeyName"); if (keyNameElement2 != null) { String keyNameInstance; keyNameInstance = keyNameElement2.getTextContent(); sharedAccessAuthorizationRuleInstance.setKeyName(keyNameInstance); } Element primaryKeyElement2 = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "PrimaryKey"); if (primaryKeyElement2 != null) { String primaryKeyInstance; primaryKeyInstance = primaryKeyElement2.getTextContent(); sharedAccessAuthorizationRuleInstance.setPrimaryKey(primaryKeyInstance); } Element secondaryKeyElement = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SecondaryKey"); if (secondaryKeyElement != null) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyElement.getTextContent(); sharedAccessAuthorizationRuleInstance.setSecondaryKey(secondaryKeyInstance); } Element revisionElement2 = XmlUtility.getElementByTagNameNS( sharedAccessAuthorizationRuleElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Revision"); if (revisionElement2 != null) { int revisionInstance; revisionInstance = DatatypeConverter.parseInt(revisionElement2.getTextContent()); sharedAccessAuthorizationRuleInstance.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(); } } }
From source file:com.microsoft.azure.management.network.NetworkSecurityGroupOperationsImpl.java
/** * The Put NetworkSecurityGroup operation creates/updates a network security * groupin the specified resource group.// ww w . j ava2s. c o m * * @param resourceGroupName Required. The name of the resource group. * @param networkSecurityGroupName Required. The name of the network * security group. * @param parameters Required. Parameters supplied to the create/update * Network Security Group operation * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return Response for PUT NetworkSecurityGroups Api servive call */ @Override public NetworkSecurityGroupPutResponse beginCreateOrUpdating(String resourceGroupName, String networkSecurityGroupName, NetworkSecurityGroup parameters) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (networkSecurityGroupName == null) { throw new NullPointerException("networkSecurityGroupName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getDefaultSecurityRules() != null) { for (SecurityRule defaultSecurityRulesParameterItem : parameters.getDefaultSecurityRules()) { if (defaultSecurityRulesParameterItem.getAccess() == null) { throw new NullPointerException("parameters.DefaultSecurityRules.Access"); } if (defaultSecurityRulesParameterItem.getDestinationAddressPrefix() == null) { throw new NullPointerException("parameters.DefaultSecurityRules.DestinationAddressPrefix"); } if (defaultSecurityRulesParameterItem.getDirection() == null) { throw new NullPointerException("parameters.DefaultSecurityRules.Direction"); } if (defaultSecurityRulesParameterItem.getProtocol() == null) { throw new NullPointerException("parameters.DefaultSecurityRules.Protocol"); } if (defaultSecurityRulesParameterItem.getSourceAddressPrefix() == null) { throw new NullPointerException("parameters.DefaultSecurityRules.SourceAddressPrefix"); } } } if (parameters.getLocation() == null) { throw new NullPointerException("parameters.Location"); } if (parameters.getSecurityRules() != null) { for (SecurityRule securityRulesParameterItem : parameters.getSecurityRules()) { if (securityRulesParameterItem.getAccess() == null) { throw new NullPointerException("parameters.SecurityRules.Access"); } if (securityRulesParameterItem.getDestinationAddressPrefix() == null) { throw new NullPointerException("parameters.SecurityRules.DestinationAddressPrefix"); } if (securityRulesParameterItem.getDirection() == null) { throw new NullPointerException("parameters.SecurityRules.Direction"); } if (securityRulesParameterItem.getProtocol() == null) { throw new NullPointerException("parameters.SecurityRules.Protocol"); } if (securityRulesParameterItem.getSourceAddressPrefix() == null) { throw new NullPointerException("parameters.SecurityRules.SourceAddressPrefix"); } } } // 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("networkSecurityGroupName", networkSecurityGroupName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCreateOrUpdatingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Network"; url = url + "/networkSecurityGroups/"; url = url + URLEncoder.encode(networkSecurityGroupName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-05-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json"); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode networkSecurityGroupJsonFormatValue = objectMapper.createObjectNode(); requestDoc = networkSecurityGroupJsonFormatValue; ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) networkSecurityGroupJsonFormatValue).put("properties", propertiesValue); if (parameters.getSecurityRules() != null) { if (parameters.getSecurityRules() instanceof LazyCollection == false || ((LazyCollection) parameters.getSecurityRules()).isInitialized()) { ArrayNode securityRulesArray = objectMapper.createArrayNode(); for (SecurityRule securityRulesItem : parameters.getSecurityRules()) { ObjectNode securityRuleJsonFormatValue = objectMapper.createObjectNode(); securityRulesArray.add(securityRuleJsonFormatValue); ObjectNode propertiesValue2 = objectMapper.createObjectNode(); ((ObjectNode) securityRuleJsonFormatValue).put("properties", propertiesValue2); if (securityRulesItem.getDescription() != null) { ((ObjectNode) propertiesValue2).put("description", securityRulesItem.getDescription()); } ((ObjectNode) propertiesValue2).put("protocol", securityRulesItem.getProtocol()); if (securityRulesItem.getSourcePortRange() != null) { ((ObjectNode) propertiesValue2).put("sourcePortRange", securityRulesItem.getSourcePortRange()); } if (securityRulesItem.getDestinationPortRange() != null) { ((ObjectNode) propertiesValue2).put("destinationPortRange", securityRulesItem.getDestinationPortRange()); } ((ObjectNode) propertiesValue2).put("sourceAddressPrefix", securityRulesItem.getSourceAddressPrefix()); ((ObjectNode) propertiesValue2).put("destinationAddressPrefix", securityRulesItem.getDestinationAddressPrefix()); ((ObjectNode) propertiesValue2).put("access", securityRulesItem.getAccess()); ((ObjectNode) propertiesValue2).put("priority", securityRulesItem.getPriority()); ((ObjectNode) propertiesValue2).put("direction", securityRulesItem.getDirection()); if (securityRulesItem.getProvisioningState() != null) { ((ObjectNode) propertiesValue2).put("provisioningState", securityRulesItem.getProvisioningState()); } if (securityRulesItem.getName() != null) { ((ObjectNode) securityRuleJsonFormatValue).put("name", securityRulesItem.getName()); } if (securityRulesItem.getEtag() != null) { ((ObjectNode) securityRuleJsonFormatValue).put("etag", securityRulesItem.getEtag()); } if (securityRulesItem.getId() != null) { ((ObjectNode) securityRuleJsonFormatValue).put("id", securityRulesItem.getId()); } } ((ObjectNode) propertiesValue).put("securityRules", securityRulesArray); } } if (parameters.getDefaultSecurityRules() != null) { if (parameters.getDefaultSecurityRules() instanceof LazyCollection == false || ((LazyCollection) parameters.getDefaultSecurityRules()).isInitialized()) { ArrayNode defaultSecurityRulesArray = objectMapper.createArrayNode(); for (SecurityRule defaultSecurityRulesItem : parameters.getDefaultSecurityRules()) { ObjectNode securityRuleJsonFormatValue2 = objectMapper.createObjectNode(); defaultSecurityRulesArray.add(securityRuleJsonFormatValue2); ObjectNode propertiesValue3 = objectMapper.createObjectNode(); ((ObjectNode) securityRuleJsonFormatValue2).put("properties", propertiesValue3); if (defaultSecurityRulesItem.getDescription() != null) { ((ObjectNode) propertiesValue3).put("description", defaultSecurityRulesItem.getDescription()); } ((ObjectNode) propertiesValue3).put("protocol", defaultSecurityRulesItem.getProtocol()); if (defaultSecurityRulesItem.getSourcePortRange() != null) { ((ObjectNode) propertiesValue3).put("sourcePortRange", defaultSecurityRulesItem.getSourcePortRange()); } if (defaultSecurityRulesItem.getDestinationPortRange() != null) { ((ObjectNode) propertiesValue3).put("destinationPortRange", defaultSecurityRulesItem.getDestinationPortRange()); } ((ObjectNode) propertiesValue3).put("sourceAddressPrefix", defaultSecurityRulesItem.getSourceAddressPrefix()); ((ObjectNode) propertiesValue3).put("destinationAddressPrefix", defaultSecurityRulesItem.getDestinationAddressPrefix()); ((ObjectNode) propertiesValue3).put("access", defaultSecurityRulesItem.getAccess()); ((ObjectNode) propertiesValue3).put("priority", defaultSecurityRulesItem.getPriority()); ((ObjectNode) propertiesValue3).put("direction", defaultSecurityRulesItem.getDirection()); if (defaultSecurityRulesItem.getProvisioningState() != null) { ((ObjectNode) propertiesValue3).put("provisioningState", defaultSecurityRulesItem.getProvisioningState()); } if (defaultSecurityRulesItem.getName() != null) { ((ObjectNode) securityRuleJsonFormatValue2).put("name", defaultSecurityRulesItem.getName()); } if (defaultSecurityRulesItem.getEtag() != null) { ((ObjectNode) securityRuleJsonFormatValue2).put("etag", defaultSecurityRulesItem.getEtag()); } if (defaultSecurityRulesItem.getId() != null) { ((ObjectNode) securityRuleJsonFormatValue2).put("id", defaultSecurityRulesItem.getId()); } } ((ObjectNode) propertiesValue).put("defaultSecurityRules", defaultSecurityRulesArray); } } if (parameters.getNetworkInterfaces() != null) { if (parameters.getNetworkInterfaces() instanceof LazyCollection == false || ((LazyCollection) parameters.getNetworkInterfaces()).isInitialized()) { ArrayNode networkInterfacesArray = objectMapper.createArrayNode(); for (ResourceId networkInterfacesItem : parameters.getNetworkInterfaces()) { ObjectNode resourceIdValue = objectMapper.createObjectNode(); networkInterfacesArray.add(resourceIdValue); if (networkInterfacesItem.getId() != null) { ((ObjectNode) resourceIdValue).put("id", networkInterfacesItem.getId()); } } ((ObjectNode) propertiesValue).put("networkInterfaces", networkInterfacesArray); } } if (parameters.getSubnets() != null) { if (parameters.getSubnets() instanceof LazyCollection == false || ((LazyCollection) parameters.getSubnets()).isInitialized()) { ArrayNode subnetsArray = objectMapper.createArrayNode(); for (ResourceId subnetsItem : parameters.getSubnets()) { ObjectNode resourceIdValue2 = objectMapper.createObjectNode(); subnetsArray.add(resourceIdValue2); if (subnetsItem.getId() != null) { ((ObjectNode) resourceIdValue2).put("id", subnetsItem.getId()); } } ((ObjectNode) propertiesValue).put("subnets", subnetsArray); } } if (parameters.getResourceGuid() != null) { ((ObjectNode) propertiesValue).put("resourceGuid", parameters.getResourceGuid()); } if (parameters.getProvisioningState() != null) { ((ObjectNode) propertiesValue).put("provisioningState", parameters.getProvisioningState()); } if (parameters.getEtag() != null) { ((ObjectNode) networkSecurityGroupJsonFormatValue).put("etag", parameters.getEtag()); } if (parameters.getId() != null) { ((ObjectNode) networkSecurityGroupJsonFormatValue).put("id", parameters.getId()); } if (parameters.getName() != null) { ((ObjectNode) networkSecurityGroupJsonFormatValue).put("name", parameters.getName()); } if (parameters.getType() != null) { ((ObjectNode) networkSecurityGroupJsonFormatValue).put("type", parameters.getType()); } ((ObjectNode) networkSecurityGroupJsonFormatValue).put("location", parameters.getLocation()); if (parameters.getTags() != null) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) networkSecurityGroupJsonFormatValue).put("tags", tagsDictionary); } StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, requestDoc); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/json"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result NetworkSecurityGroupPutResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new NetworkSecurityGroupPutResponse(); 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) { NetworkSecurityGroup networkSecurityGroupInstance = new NetworkSecurityGroup(); result.setNetworkSecurityGroup(networkSecurityGroupInstance); JsonNode propertiesValue4 = responseDoc.get("properties"); if (propertiesValue4 != null && propertiesValue4 instanceof NullNode == false) { JsonNode securityRulesArray2 = propertiesValue4.get("securityRules"); if (securityRulesArray2 != null && securityRulesArray2 instanceof NullNode == false) { for (JsonNode securityRulesValue : ((ArrayNode) securityRulesArray2)) { SecurityRule securityRuleJsonFormatInstance = new SecurityRule(); networkSecurityGroupInstance.getSecurityRules().add(securityRuleJsonFormatInstance); JsonNode propertiesValue5 = securityRulesValue.get("properties"); if (propertiesValue5 != null && propertiesValue5 instanceof NullNode == false) { JsonNode descriptionValue = propertiesValue5.get("description"); if (descriptionValue != null && descriptionValue instanceof NullNode == false) { String descriptionInstance; descriptionInstance = descriptionValue.getTextValue(); securityRuleJsonFormatInstance.setDescription(descriptionInstance); } JsonNode protocolValue = propertiesValue5.get("protocol"); if (protocolValue != null && protocolValue instanceof NullNode == false) { String protocolInstance; protocolInstance = protocolValue.getTextValue(); securityRuleJsonFormatInstance.setProtocol(protocolInstance); } JsonNode sourcePortRangeValue = propertiesValue5.get("sourcePortRange"); if (sourcePortRangeValue != null && sourcePortRangeValue instanceof NullNode == false) { String sourcePortRangeInstance; sourcePortRangeInstance = sourcePortRangeValue.getTextValue(); securityRuleJsonFormatInstance.setSourcePortRange(sourcePortRangeInstance); } JsonNode destinationPortRangeValue = propertiesValue5 .get("destinationPortRange"); if (destinationPortRangeValue != null && destinationPortRangeValue instanceof NullNode == false) { String destinationPortRangeInstance; destinationPortRangeInstance = destinationPortRangeValue.getTextValue(); securityRuleJsonFormatInstance .setDestinationPortRange(destinationPortRangeInstance); } JsonNode sourceAddressPrefixValue = propertiesValue5.get("sourceAddressPrefix"); if (sourceAddressPrefixValue != null && sourceAddressPrefixValue instanceof NullNode == false) { String sourceAddressPrefixInstance; sourceAddressPrefixInstance = sourceAddressPrefixValue.getTextValue(); securityRuleJsonFormatInstance .setSourceAddressPrefix(sourceAddressPrefixInstance); } JsonNode destinationAddressPrefixValue = propertiesValue5 .get("destinationAddressPrefix"); if (destinationAddressPrefixValue != null && destinationAddressPrefixValue instanceof NullNode == false) { String destinationAddressPrefixInstance; destinationAddressPrefixInstance = destinationAddressPrefixValue .getTextValue(); securityRuleJsonFormatInstance .setDestinationAddressPrefix(destinationAddressPrefixInstance); } JsonNode accessValue = propertiesValue5.get("access"); if (accessValue != null && accessValue instanceof NullNode == false) { String accessInstance; accessInstance = accessValue.getTextValue(); securityRuleJsonFormatInstance.setAccess(accessInstance); } JsonNode priorityValue = propertiesValue5.get("priority"); if (priorityValue != null && priorityValue instanceof NullNode == false) { int priorityInstance; priorityInstance = priorityValue.getIntValue(); securityRuleJsonFormatInstance.setPriority(priorityInstance); } JsonNode directionValue = propertiesValue5.get("direction"); if (directionValue != null && directionValue instanceof NullNode == false) { String directionInstance; directionInstance = directionValue.getTextValue(); securityRuleJsonFormatInstance.setDirection(directionInstance); } JsonNode provisioningStateValue = propertiesValue5.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); securityRuleJsonFormatInstance .setProvisioningState(provisioningStateInstance); } } JsonNode nameValue = securityRulesValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); securityRuleJsonFormatInstance.setName(nameInstance); } JsonNode etagValue = securityRulesValue.get("etag"); if (etagValue != null && etagValue instanceof NullNode == false) { String etagInstance; etagInstance = etagValue.getTextValue(); securityRuleJsonFormatInstance.setEtag(etagInstance); } JsonNode idValue = securityRulesValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); securityRuleJsonFormatInstance.setId(idInstance); } } } JsonNode defaultSecurityRulesArray2 = propertiesValue4.get("defaultSecurityRules"); if (defaultSecurityRulesArray2 != null && defaultSecurityRulesArray2 instanceof NullNode == false) { for (JsonNode defaultSecurityRulesValue : ((ArrayNode) defaultSecurityRulesArray2)) { SecurityRule securityRuleJsonFormatInstance2 = new SecurityRule(); networkSecurityGroupInstance.getDefaultSecurityRules() .add(securityRuleJsonFormatInstance2); JsonNode propertiesValue6 = defaultSecurityRulesValue.get("properties"); if (propertiesValue6 != null && propertiesValue6 instanceof NullNode == false) { JsonNode descriptionValue2 = propertiesValue6.get("description"); if (descriptionValue2 != null && descriptionValue2 instanceof NullNode == false) { String descriptionInstance2; descriptionInstance2 = descriptionValue2.getTextValue(); securityRuleJsonFormatInstance2.setDescription(descriptionInstance2); } JsonNode protocolValue2 = propertiesValue6.get("protocol"); if (protocolValue2 != null && protocolValue2 instanceof NullNode == false) { String protocolInstance2; protocolInstance2 = protocolValue2.getTextValue(); securityRuleJsonFormatInstance2.setProtocol(protocolInstance2); } JsonNode sourcePortRangeValue2 = propertiesValue6.get("sourcePortRange"); if (sourcePortRangeValue2 != null && sourcePortRangeValue2 instanceof NullNode == false) { String sourcePortRangeInstance2; sourcePortRangeInstance2 = sourcePortRangeValue2.getTextValue(); securityRuleJsonFormatInstance2 .setSourcePortRange(sourcePortRangeInstance2); } JsonNode destinationPortRangeValue2 = propertiesValue6 .get("destinationPortRange"); if (destinationPortRangeValue2 != null && destinationPortRangeValue2 instanceof NullNode == false) { String destinationPortRangeInstance2; destinationPortRangeInstance2 = destinationPortRangeValue2.getTextValue(); securityRuleJsonFormatInstance2 .setDestinationPortRange(destinationPortRangeInstance2); } JsonNode sourceAddressPrefixValue2 = propertiesValue6 .get("sourceAddressPrefix"); if (sourceAddressPrefixValue2 != null && sourceAddressPrefixValue2 instanceof NullNode == false) { String sourceAddressPrefixInstance2; sourceAddressPrefixInstance2 = sourceAddressPrefixValue2.getTextValue(); securityRuleJsonFormatInstance2 .setSourceAddressPrefix(sourceAddressPrefixInstance2); } JsonNode destinationAddressPrefixValue2 = propertiesValue6 .get("destinationAddressPrefix"); if (destinationAddressPrefixValue2 != null && destinationAddressPrefixValue2 instanceof NullNode == false) { String destinationAddressPrefixInstance2; destinationAddressPrefixInstance2 = destinationAddressPrefixValue2 .getTextValue(); securityRuleJsonFormatInstance2 .setDestinationAddressPrefix(destinationAddressPrefixInstance2); } JsonNode accessValue2 = propertiesValue6.get("access"); if (accessValue2 != null && accessValue2 instanceof NullNode == false) { String accessInstance2; accessInstance2 = accessValue2.getTextValue(); securityRuleJsonFormatInstance2.setAccess(accessInstance2); } JsonNode priorityValue2 = propertiesValue6.get("priority"); if (priorityValue2 != null && priorityValue2 instanceof NullNode == false) { int priorityInstance2; priorityInstance2 = priorityValue2.getIntValue(); securityRuleJsonFormatInstance2.setPriority(priorityInstance2); } JsonNode directionValue2 = propertiesValue6.get("direction"); if (directionValue2 != null && directionValue2 instanceof NullNode == false) { String directionInstance2; directionInstance2 = directionValue2.getTextValue(); securityRuleJsonFormatInstance2.setDirection(directionInstance2); } JsonNode provisioningStateValue2 = propertiesValue6.get("provisioningState"); if (provisioningStateValue2 != null && provisioningStateValue2 instanceof NullNode == false) { String provisioningStateInstance2; provisioningStateInstance2 = provisioningStateValue2.getTextValue(); securityRuleJsonFormatInstance2 .setProvisioningState(provisioningStateInstance2); } } JsonNode nameValue2 = defaultSecurityRulesValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); securityRuleJsonFormatInstance2.setName(nameInstance2); } JsonNode etagValue2 = defaultSecurityRulesValue.get("etag"); if (etagValue2 != null && etagValue2 instanceof NullNode == false) { String etagInstance2; etagInstance2 = etagValue2.getTextValue(); securityRuleJsonFormatInstance2.setEtag(etagInstance2); } JsonNode idValue2 = defaultSecurityRulesValue.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); securityRuleJsonFormatInstance2.setId(idInstance2); } } } JsonNode networkInterfacesArray2 = propertiesValue4.get("networkInterfaces"); if (networkInterfacesArray2 != null && networkInterfacesArray2 instanceof NullNode == false) { for (JsonNode networkInterfacesValue : ((ArrayNode) networkInterfacesArray2)) { ResourceId resourceIdInstance = new ResourceId(); networkSecurityGroupInstance.getNetworkInterfaces().add(resourceIdInstance); JsonNode idValue3 = networkInterfacesValue.get("id"); if (idValue3 != null && idValue3 instanceof NullNode == false) { String idInstance3; idInstance3 = idValue3.getTextValue(); resourceIdInstance.setId(idInstance3); } } } JsonNode subnetsArray2 = propertiesValue4.get("subnets"); if (subnetsArray2 != null && subnetsArray2 instanceof NullNode == false) { for (JsonNode subnetsValue : ((ArrayNode) subnetsArray2)) { ResourceId resourceIdInstance2 = new ResourceId(); networkSecurityGroupInstance.getSubnets().add(resourceIdInstance2); JsonNode idValue4 = subnetsValue.get("id"); if (idValue4 != null && idValue4 instanceof NullNode == false) { String idInstance4; idInstance4 = idValue4.getTextValue(); resourceIdInstance2.setId(idInstance4); } } } JsonNode resourceGuidValue = propertiesValue4.get("resourceGuid"); if (resourceGuidValue != null && resourceGuidValue instanceof NullNode == false) { String resourceGuidInstance; resourceGuidInstance = resourceGuidValue.getTextValue(); networkSecurityGroupInstance.setResourceGuid(resourceGuidInstance); } JsonNode provisioningStateValue3 = propertiesValue4.get("provisioningState"); if (provisioningStateValue3 != null && provisioningStateValue3 instanceof NullNode == false) { String provisioningStateInstance3; provisioningStateInstance3 = provisioningStateValue3.getTextValue(); networkSecurityGroupInstance.setProvisioningState(provisioningStateInstance3); } } JsonNode etagValue3 = responseDoc.get("etag"); if (etagValue3 != null && etagValue3 instanceof NullNode == false) { String etagInstance3; etagInstance3 = etagValue3.getTextValue(); networkSecurityGroupInstance.setEtag(etagInstance3); } JsonNode idValue5 = responseDoc.get("id"); if (idValue5 != null && idValue5 instanceof NullNode == false) { String idInstance5; idInstance5 = idValue5.getTextValue(); networkSecurityGroupInstance.setId(idInstance5); } JsonNode nameValue3 = responseDoc.get("name"); if (nameValue3 != null && nameValue3 instanceof NullNode == false) { String nameInstance3; nameInstance3 = nameValue3.getTextValue(); networkSecurityGroupInstance.setName(nameInstance3); } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); networkSecurityGroupInstance.setType(typeInstance); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); networkSecurityGroupInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey2 = property.getKey(); String tagsValue2 = property.getValue().getTextValue(); networkSecurityGroupInstance.getTags().put(tagsKey2, tagsValue2); } } JsonNode errorValue = responseDoc.get("error"); if (errorValue != null && errorValue instanceof NullNode == false) { Error errorInstance = new Error(); result.setError(errorInstance); JsonNode codeValue = errorValue.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); errorInstance.setCode(codeInstance); } JsonNode messageValue = errorValue.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); errorInstance.setMessage(messageInstance); } JsonNode targetValue = errorValue.get("target"); if (targetValue != null && targetValue instanceof NullNode == false) { String targetInstance; targetInstance = targetValue.getTextValue(); errorInstance.setTarget(targetInstance); } JsonNode detailsArray = errorValue.get("details"); if (detailsArray != null && detailsArray instanceof NullNode == false) { for (JsonNode detailsValue : ((ArrayNode) detailsArray)) { ErrorDetails errorDetailsInstance = new ErrorDetails(); errorInstance.getDetails().add(errorDetailsInstance); JsonNode codeValue2 = detailsValue.get("code"); if (codeValue2 != null && codeValue2 instanceof NullNode == false) { String codeInstance2; codeInstance2 = codeValue2.getTextValue(); errorDetailsInstance.setCode(codeInstance2); } JsonNode targetValue2 = detailsValue.get("target"); if (targetValue2 != null && targetValue2 instanceof NullNode == false) { String targetInstance2; targetInstance2 = targetValue2.getTextValue(); errorDetailsInstance.setTarget(targetInstance2); } JsonNode messageValue2 = detailsValue.get("message"); if (messageValue2 != null && messageValue2 instanceof NullNode == false) { String messageInstance2; messageInstance2 = messageValue2.getTextValue(); errorDetailsInstance.setMessage(messageInstance2); } } } JsonNode innerErrorValue = errorValue.get("innerError"); if (innerErrorValue != null && innerErrorValue instanceof NullNode == false) { String innerErrorInstance; innerErrorInstance = innerErrorValue.getTextValue(); errorInstance.setInnerError(innerErrorInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("Azure-AsyncOperation").length > 0) { result.setAzureAsyncOperation(httpResponse.getFirstHeader("Azure-AsyncOperation").getValue()); } if (httpResponse.getHeaders("Retry-After").length > 0) { result.setRetryAfter( DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue())); } if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.azure.management.network.NetworkInterfaceOperationsImpl.java
/** * The delete netwokInterface operation deletes the specified * netwokInterface./*from w ww . j a v a 2s .c o m*/ * * @param resourceGroupName Required. The name of the resource group. * @param networkInterfaceName Required. The name of the network interface. * @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 If the resource provide needs to return an error to any * operation, it should return the appropriate HTTP error code and a * message body as can be seen below.The message should be localized per * the Accept-Language header specified in the original request such thatit * could be directly be exposed to users */ @Override public UpdateOperationResponse beginDeleting(String resourceGroupName, String networkInterfaceName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (networkInterfaceName == null) { throw new NullPointerException("networkInterfaceName"); } // 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("networkInterfaceName", networkInterfaceName); CloudTracing.enter(invocationId, this, "beginDeletingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Network"; url = url + "/networkInterfaces/"; url = url + URLEncoder.encode(networkInterfaceName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-05-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects CustomHttpDelete httpRequest = new CustomHttpDelete(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 && statusCode != HttpStatus.SC_ACCEPTED && statusCode != HttpStatus.SC_NO_CONTENT) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result UpdateOperationResponse result = null; // Deserialize Response result = new UpdateOperationResponse(); result.setStatusCode(statusCode); if (httpResponse.getHeaders("Azure-AsyncOperation").length > 0) { result.setAzureAsyncOperation(httpResponse.getFirstHeader("Azure-AsyncOperation").getValue()); } if (httpResponse.getHeaders("Retry-After").length > 0) { result.setRetryAfter( DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue())); } if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.ServerFarmOperationsImpl.java
/** * You can create a server farm by issuing an HTTP POST request. Only one * server farm per webspace is permitted. You can retrieve server farm * details by using HTTP GET, change server farm properties by using HTTP * PUT, and delete a server farm by using HTTP DELETE. A request body is * required for server farm creation (HTTP POST) and server farm update * (HTTP PUT). Warning: Creating a server farm changes your webspace's * Compute Mode from Shared to Dedicated. You will be charged from the * moment the server farm is created, even if all your sites are still * running in Free mode. (see//from w w w. ja v a 2 s .co m * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param parameters Required. Parameters supplied to the Update Server Farm * operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Update Server Farm operation response. */ @Override public ServerFarmUpdateResponse update(String webSpaceName, ServerFarmUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (parameters == null) { throw new NullPointerException("parameters"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "updateAsync", tracingParameters); } // Construct URL String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/WebSpaces/" + webSpaceName.trim() + "/ServerFarms/DefaultServerFarm"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2013-08-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); requestDoc.appendChild(serverFarmElement); if (parameters.getCurrentNumberOfWorkers() != null) { Element currentNumberOfWorkersElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); currentNumberOfWorkersElement.appendChild( requestDoc.createTextNode(Integer.toString(parameters.getCurrentNumberOfWorkers()))); serverFarmElement.appendChild(currentNumberOfWorkersElement); } if (parameters.getCurrentWorkerSize() != null) { Element currentWorkerSizeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); currentWorkerSizeElement .appendChild(requestDoc.createTextNode(parameters.getCurrentWorkerSize().toString())); serverFarmElement.appendChild(currentWorkerSizeElement); } Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode("DefaultServerFarm")); serverFarmElement.appendChild(nameElement); Element numberOfWorkersElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); numberOfWorkersElement .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getNumberOfWorkers()))); serverFarmElement.appendChild(numberOfWorkersElement); Element workerSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "WorkerSize"); workerSizeElement.appendChild(requestDoc.createTextNode(parameters.getWorkerSize().toString())); serverFarmElement.appendChild(workerSizeElement); if (parameters.getStatus() != null) { Element statusElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Status"); statusElement.appendChild(requestDoc.createTextNode(parameters.getStatus().toString())); serverFarmElement.appendChild(statusElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ServerFarmUpdateResponse result = null; // Deserialize Response InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServerFarmUpdateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { Element currentNumberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); if (currentNumberOfWorkersElement2 != null) { int currentNumberOfWorkersInstance; currentNumberOfWorkersInstance = DatatypeConverter .parseInt(currentNumberOfWorkersElement2.getTextContent()); result.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance); } Element currentWorkerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); if (currentWorkerSizeElement2 != null) { ServerFarmWorkerSize currentWorkerSizeInstance; currentWorkerSizeInstance = ServerFarmWorkerSize .valueOf(currentWorkerSizeElement2.getTextContent()); result.setCurrentWorkerSize(currentWorkerSizeInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); result.setName(nameInstance); } Element numberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); if (numberOfWorkersElement2 != null) { int numberOfWorkersInstance; numberOfWorkersInstance = DatatypeConverter.parseInt(numberOfWorkersElement2.getTextContent()); result.setNumberOfWorkers(numberOfWorkersInstance); } Element workerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement2 != null) { ServerFarmWorkerSize workerSizeInstance; workerSizeInstance = ServerFarmWorkerSize.valueOf(workerSizeElement2.getTextContent()); result.setWorkerSize(workerSizeInstance); } Element statusElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement2 != null) { ServerFarmStatus statusInstance; statusInstance = ServerFarmStatus.valueOf(statusElement2.getTextContent()); result.setStatus(statusInstance); } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSpaceOperationsImpl.java
/** * Get the available geo regions for this web space. * * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations./*from w w w.j a va2 s .com*/ * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return The List Geo Regions operation response. */ @Override public WebSpacesListGeoRegionsResponse listGeoRegions() throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); CloudTracing.enter(invocationId, this, "listGeoRegionsAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("properties=georegions"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2014-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSpacesListGeoRegionsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesListGeoRegionsResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element geoRegionsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GeoRegions"); if (geoRegionsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(geoRegionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "GeoRegion") .size(); i1 = i1 + 1) { org.w3c.dom.Element geoRegionsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(geoRegionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "GeoRegion") .get(i1)); WebSpacesListGeoRegionsResponse.GeoRegion geoRegionInstance = new WebSpacesListGeoRegionsResponse.GeoRegion(); result.getGeoRegions().add(geoRegionInstance); Element descriptionElement = XmlUtility.getElementByTagNameNS(geoRegionsElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); geoRegionInstance.setDescription(descriptionInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(geoRegionsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); geoRegionInstance.setName(nameInstance); } Element sortOrderElement = XmlUtility.getElementByTagNameNS(geoRegionsElement, "http://schemas.microsoft.com/windowsazure", "SortOrder"); if (sortOrderElement != null && sortOrderElement.getTextContent() != null && !sortOrderElement.getTextContent().isEmpty()) { boolean isNil = false; Attr nilAttribute = sortOrderElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { int sortOrderInstance; sortOrderInstance = DatatypeConverter.parseInt(sortOrderElement.getTextContent()); geoRegionInstance.setSortOrder(sortOrderInstance); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.compute.VirtualMachineDiskOperationsImpl.java
/** * The Create Disk operation adds a disk to the user image repository. The * disk can be an operating system disk or a data disk. (see * http://msdn.microsoft.com/en-us/library/windowsazure/jj157178.aspx for * more information)/*from w ww .java 2 s . c o m*/ * * @param parameters Required. Parameters supplied to the Create Virtual * Machine Disk 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 A virtual machine disk associated with your subscription. */ @Override public VirtualMachineDiskCreateResponse createDisk(VirtualMachineDiskCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLabel() == null) { throw new NullPointerException("parameters.Label"); } if (parameters.getMediaLinkUri() == null) { throw new NullPointerException("parameters.MediaLinkUri"); } if (parameters.getName() == null) { throw new NullPointerException("parameters.Name"); } // 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("parameters", parameters); CloudTracing.enter(invocationId, this, "createDiskAsync", 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/disks"; 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", "2015-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element diskElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Disk"); requestDoc.appendChild(diskElement); if (parameters.getOperatingSystemType() != null) { Element osElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OS"); osElement.appendChild(requestDoc.createTextNode(parameters.getOperatingSystemType())); diskElement.appendChild(osElement); } Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label"); labelElement.appendChild(requestDoc.createTextNode(parameters.getLabel())); diskElement.appendChild(labelElement); Element mediaLinkElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLink"); mediaLinkElement.appendChild(requestDoc.createTextNode(parameters.getMediaLinkUri().toString())); diskElement.appendChild(mediaLinkElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); diskElement.appendChild(nameElement); DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result VirtualMachineDiskCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualMachineDiskCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element diskElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Disk"); if (diskElement2 != null) { Element osElement2 = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "OS"); if (osElement2 != null) { String osInstance; osInstance = osElement2.getTextContent(); result.setOperatingSystem(osInstance); } Element labelElement2 = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement2 != null) { String labelInstance; labelInstance = labelElement2.getTextContent(); result.setLabel(labelInstance); } Element affinityGroupElement = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "AffinityGroup"); if (affinityGroupElement != null) { String affinityGroupInstance; affinityGroupInstance = affinityGroupElement.getTextContent(); result.setAffinityGroup(affinityGroupInstance); } Element locationElement = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "Location"); if (locationElement != null) { String locationInstance; locationInstance = locationElement.getTextContent(); result.setLocation(locationInstance); } Element logicalDiskSizeInGBElement = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "LogicalDiskSizeInGB"); if (logicalDiskSizeInGBElement != null) { int logicalDiskSizeInGBInstance; logicalDiskSizeInGBInstance = DatatypeConverter .parseInt(logicalDiskSizeInGBElement.getTextContent()); result.setLogicalSizeInGB(logicalDiskSizeInGBInstance); } Element mediaLinkElement2 = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "MediaLink"); if (mediaLinkElement2 != null) { URI mediaLinkInstance; mediaLinkInstance = new URI(mediaLinkElement2.getTextContent()); result.setMediaLinkUri(mediaLinkInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); result.setName(nameInstance); } Element sourceImageNameElement = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "SourceImageName"); if (sourceImageNameElement != null) { String sourceImageNameInstance; sourceImageNameInstance = sourceImageNameElement.getTextContent(); result.setSourceImageName(sourceImageNameInstance); } Element attachedToElement = XmlUtility.getElementByTagNameNS(diskElement2, "http://schemas.microsoft.com/windowsazure", "AttachedTo"); if (attachedToElement != null) { VirtualMachineDiskCreateResponse.VirtualMachineDiskUsageDetails attachedToInstance = new VirtualMachineDiskCreateResponse.VirtualMachineDiskUsageDetails(); result.setUsageDetails(attachedToInstance); Element hostedServiceNameElement = XmlUtility.getElementByTagNameNS(attachedToElement, "http://schemas.microsoft.com/windowsazure", "HostedServiceName"); if (hostedServiceNameElement != null) { String hostedServiceNameInstance; hostedServiceNameInstance = hostedServiceNameElement.getTextContent(); attachedToInstance.setHostedServiceName(hostedServiceNameInstance); } Element deploymentNameElement = XmlUtility.getElementByTagNameNS(attachedToElement, "http://schemas.microsoft.com/windowsazure", "DeploymentName"); if (deploymentNameElement != null) { String deploymentNameInstance; deploymentNameInstance = deploymentNameElement.getTextContent(); attachedToInstance.setDeploymentName(deploymentNameInstance); } Element roleNameElement = XmlUtility.getElementByTagNameNS(attachedToElement, "http://schemas.microsoft.com/windowsazure", "RoleName"); if (roleNameElement != null) { String roleNameInstance; roleNameInstance = roleNameElement.getTextContent(); attachedToInstance.setRoleName(roleNameInstance); } } Element isPremiumElement = XmlUtility.getElementByTagNameNS(diskElement2, "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 iOTypeElement = XmlUtility.getElementByTagNameNS(diskElement2, "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.windowsazure.management.sql.DatabaseCopyOperationsImpl.java
/** * Retrieves the list of SQL Server database copies for a database. * * @param serverName Required. The name of the database server to be queried. * @param databaseName Required. The name of the database to be queried. * @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./*from w w w . ja v a2s . c om*/ * @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 Represents the response containing the list of database copies * for a given database. */ @Override public DatabaseCopyListResponse list(String serverName, String databaseName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("databaseName", databaseName); 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/"; url = url + URLEncoder.encode(databaseName, "UTF-8"); url = url + "/databasecopies"; 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 DatabaseCopyListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseCopyListResponse(); 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)); DatabaseCopy serviceResourceInstance = new DatabaseCopy(); result.getDatabaseCopies().add(serviceResourceInstance); Element sourceServerNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "SourceServerName"); if (sourceServerNameElement != null) { String sourceServerNameInstance; sourceServerNameInstance = sourceServerNameElement.getTextContent(); serviceResourceInstance.setSourceServerName(sourceServerNameInstance); } Element sourceDatabaseNameElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "SourceDatabaseName"); if (sourceDatabaseNameElement != null) { String sourceDatabaseNameInstance; sourceDatabaseNameInstance = sourceDatabaseNameElement.getTextContent(); serviceResourceInstance.setSourceDatabaseName(sourceDatabaseNameInstance); } Element destinationServerNameElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "DestinationServerName"); if (destinationServerNameElement != null) { String destinationServerNameInstance; destinationServerNameInstance = destinationServerNameElement.getTextContent(); serviceResourceInstance.setDestinationServerName(destinationServerNameInstance); } Element destinationDatabaseNameElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "DestinationDatabaseName"); if (destinationDatabaseNameElement != null) { String destinationDatabaseNameInstance; destinationDatabaseNameInstance = destinationDatabaseNameElement.getTextContent(); serviceResourceInstance.setDestinationDatabaseName(destinationDatabaseNameInstance); } Element isContinuousElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsContinuous"); if (isContinuousElement != null) { boolean isContinuousInstance; isContinuousInstance = DatatypeConverter .parseBoolean(isContinuousElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsContinuous(isContinuousInstance); } Element replicationStateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ReplicationState"); if (replicationStateElement != null) { byte replicationStateInstance; replicationStateInstance = DatatypeConverter .parseByte(replicationStateElement.getTextContent()); serviceResourceInstance.setReplicationState(replicationStateInstance); } Element replicationStateDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ReplicationStateDescription"); if (replicationStateDescriptionElement != null) { String replicationStateDescriptionInstance; replicationStateDescriptionInstance = replicationStateDescriptionElement .getTextContent(); serviceResourceInstance .setReplicationStateDescription(replicationStateDescriptionInstance); } Element localDatabaseIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "LocalDatabaseId"); if (localDatabaseIdElement != null) { int localDatabaseIdInstance; localDatabaseIdInstance = DatatypeConverter .parseInt(localDatabaseIdElement.getTextContent()); serviceResourceInstance.setLocalDatabaseId(localDatabaseIdInstance); } Element isLocalDatabaseReplicationTargetElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsLocalDatabaseReplicationTarget"); if (isLocalDatabaseReplicationTargetElement != null) { boolean isLocalDatabaseReplicationTargetInstance; isLocalDatabaseReplicationTargetInstance = DatatypeConverter.parseBoolean( isLocalDatabaseReplicationTargetElement.getTextContent().toLowerCase()); serviceResourceInstance .setIsLocalDatabaseReplicationTarget(isLocalDatabaseReplicationTargetInstance); } Element isInterlinkConnectedElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsInterlinkConnected"); if (isInterlinkConnectedElement != null) { boolean isInterlinkConnectedInstance; isInterlinkConnectedInstance = DatatypeConverter .parseBoolean(isInterlinkConnectedElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsInterlinkConnected(isInterlinkConnectedInstance); } Element startDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "StartDate"); if (startDateElement != null) { String startDateInstance; startDateInstance = startDateElement.getTextContent(); serviceResourceInstance.setStartDate(startDateInstance); } Element modifyDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ModifyDate"); if (modifyDateElement != null) { String modifyDateInstance; modifyDateInstance = modifyDateElement.getTextContent(); serviceResourceInstance.setModifyDate(modifyDateInstance); } Element percentCompleteElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "PercentComplete"); if (percentCompleteElement != null) { float percentCompleteInstance; percentCompleteInstance = DatatypeConverter .parseFloat(percentCompleteElement.getTextContent()); serviceResourceInstance.setPercentComplete(percentCompleteInstance); } Element isOfflineSecondaryElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsOfflineSecondary"); if (isOfflineSecondaryElement != null) { boolean isOfflineSecondaryInstance; isOfflineSecondaryInstance = DatatypeConverter .parseBoolean(isOfflineSecondaryElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsOfflineSecondary(isOfflineSecondaryInstance); } Element isTerminationAllowedElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsTerminationAllowed"); if (isTerminationAllowedElement != null) { boolean isTerminationAllowedInstance; isTerminationAllowedInstance = DatatypeConverter .parseBoolean(isTerminationAllowedElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsTerminationAllowed(isTerminationAllowedInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.azure.management.network.NetworkSecurityGroupOperationsImpl.java
/** * The Delete NetworkSecurityGroup operation deletes the specifed network * security group//w ww . j a va 2 s. co m * * @param resourceGroupName Required. The name of the resource group. * @param networkSecurityGroupName Required. The name of the network * security group. * @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 If the resource provide needs to return an error to any * operation, it should return the appropriate HTTP error code and a * message body as can be seen below.The message should be localized per * the Accept-Language header specified in the original request such thatit * could be directly be exposed to users */ @Override public UpdateOperationResponse beginDeleting(String resourceGroupName, String networkSecurityGroupName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (networkSecurityGroupName == null) { throw new NullPointerException("networkSecurityGroupName"); } // 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("networkSecurityGroupName", networkSecurityGroupName); CloudTracing.enter(invocationId, this, "beginDeletingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Network"; url = url + "/networkSecurityGroups/"; url = url + URLEncoder.encode(networkSecurityGroupName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-05-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects CustomHttpDelete httpRequest = new CustomHttpDelete(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 && statusCode != HttpStatus.SC_ACCEPTED && statusCode != HttpStatus.SC_NO_CONTENT) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result UpdateOperationResponse result = null; // Deserialize Response result = new UpdateOperationResponse(); result.setStatusCode(statusCode); if (httpResponse.getHeaders("Azure-AsyncOperation").length > 0) { result.setAzureAsyncOperation(httpResponse.getFirstHeader("Azure-AsyncOperation").getValue()); } if (httpResponse.getHeaders("Retry-After").length > 0) { result.setRetryAfter( DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue())); } if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationsImpl.java
/** * Returns information about an Azure SQL Database event logs. * * @param serverName Required. The name of the Azure SQL Database Server on * which the database is hosted.//from ww w.j a v a2s . c o m * @param databaseName Required. The name of the Azure SQL Database to be * retrieved. * @param parameters Required. The parameters for the Get Database Event * Logs operation. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return Contains the response to a Get Database Event Logs request. */ @Override public DatabaseGetEventLogsResponse getEventLogs(String serverName, String databaseName, DatabaseGetEventLogsParameters parameters) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getEventTypes() == null) { throw new NullPointerException("parameters.EventTypes"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("databaseName", databaseName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "getEventLogsAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases/"; url = url + URLEncoder.encode(databaseName, "UTF-8"); url = url + "/events"; ArrayList<String> queryParameters = new ArrayList<String>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); queryParameters.add("startDate=" + URLEncoder.encode(simpleDateFormat.format(parameters.getStartDate().getTime()), "UTF-8")); queryParameters.add("intervalSizeInMinutes=" + URLEncoder.encode(Integer.toString(parameters.getIntervalSizeInMinutes()), "UTF-8")); queryParameters.add("eventTypes=" + URLEncoder.encode(parameters.getEventTypes(), "UTF-8")); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseGetEventLogsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseGetEventLogsResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); DatabaseEventLog serviceResourceInstance = new DatabaseEventLog(); result.getEventLogs().add(serviceResourceInstance); Element databaseNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "DatabaseName"); if (databaseNameElement != null) { String databaseNameInstance; databaseNameInstance = databaseNameElement.getTextContent(); serviceResourceInstance.setDatabaseName(databaseNameInstance); } Element startTimeUtcElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "StartTimeUtc"); if (startTimeUtcElement != null) { Calendar startTimeUtcInstance; startTimeUtcInstance = DatatypeConverter .parseDateTime(startTimeUtcElement.getTextContent()); serviceResourceInstance.setStartTimeUtc(startTimeUtcInstance); } Element intervalSizeInMinutesElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IntervalSizeInMinutes"); if (intervalSizeInMinutesElement != null) { int intervalSizeInMinutesInstance; intervalSizeInMinutesInstance = DatatypeConverter .parseInt(intervalSizeInMinutesElement.getTextContent()); serviceResourceInstance.setIntervalSizeInMinutes(intervalSizeInMinutesInstance); } Element eventCategoryElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EventCategory"); if (eventCategoryElement != null) { String eventCategoryInstance; eventCategoryInstance = eventCategoryElement.getTextContent(); serviceResourceInstance.setEventCategory(eventCategoryInstance); } Element eventTypeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EventType"); if (eventTypeElement != null) { String eventTypeInstance; eventTypeInstance = eventTypeElement.getTextContent(); serviceResourceInstance.setEventType(eventTypeInstance); } Element eventSubtypeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EventSubtype"); if (eventSubtypeElement != null) { String eventSubtypeInstance; eventSubtypeInstance = eventSubtypeElement.getTextContent(); serviceResourceInstance.setEventSubtype(eventSubtypeInstance); } Element eventSubtypeDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EventSubtypeDescription"); if (eventSubtypeDescriptionElement != null) { String eventSubtypeDescriptionInstance; eventSubtypeDescriptionInstance = eventSubtypeDescriptionElement.getTextContent(); serviceResourceInstance.setEventSubtypeDescription(eventSubtypeDescriptionInstance); } Element numberOfEventsElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "NumberOfEvents"); if (numberOfEventsElement != null) { int numberOfEventsInstance; numberOfEventsInstance = DatatypeConverter .parseInt(numberOfEventsElement.getTextContent()); serviceResourceInstance.setNumberOfEvents(numberOfEventsInstance); } Element severityElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Severity"); if (severityElement != null) { int severityInstance; severityInstance = DatatypeConverter.parseInt(severityElement.getTextContent()); serviceResourceInstance.setSeverity(severityInstance); } Element descriptionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); serviceResourceInstance.setDescription(descriptionInstance); } Element additionalDataElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "AdditionalData"); if (additionalDataElement != null) { boolean isNil = false; Attr nilAttribute = additionalDataElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String additionalDataInstance; additionalDataInstance = additionalDataElement.getTextContent(); serviceResourceInstance.setAdditionalData(additionalDataInstance); } } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }