List of usage examples for org.w3c.dom Document createElementNS
public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException;
From source file:com.microsoft.windowsazure.management.compute.VirtualMachineOperationsImpl.java
/** * The Begin Updating Load Balanced Endpoint Set operation changes the * specified load-balanced InputEndpoints on all the roles of an * Infrastructure as a Service deployment. Non-load-balanced endpoints must * be changed using UpdateRole. (see/*from w ww. ja va 2 s . com*/ * http://msdn.microsoft.com/en-us/library/windowsazure/dn469417.aspx for * more information) * * @param serviceName Required. The name of your service. * @param deploymentName Required. The name of your deployment. * @param parameters Required. Parameters supplied to the Begin Updating * Load Balanced Endpoint Set operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return A standard service response including an HTTP status code and * request ID. */ @Override public OperationResponse beginUpdatingLoadBalancedEndpointSet(String serviceName, String deploymentName, VirtualMachineUpdateLoadBalancedSetParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLoadBalancedEndpoints() != null) { for (VirtualMachineUpdateLoadBalancedSetParameters.InputEndpoint loadBalancedEndpointsParameterItem : parameters .getLoadBalancedEndpoints()) { if (loadBalancedEndpointsParameterItem.getLoadBalancedEndpointSetName() == null) { throw new NullPointerException("parameters.LoadBalancedEndpoints.LoadBalancedEndpointSetName"); } } } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginUpdatingLoadBalancedEndpointSetAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("comp=UpdateLbSet"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); 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 loadBalancedEndpointListElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "LoadBalancedEndpointList"); requestDoc.appendChild(loadBalancedEndpointListElement); if (parameters.getLoadBalancedEndpoints() != null) { if (parameters.getLoadBalancedEndpoints() instanceof LazyCollection == false || ((LazyCollection) parameters.getLoadBalancedEndpoints()).isInitialized()) { for (VirtualMachineUpdateLoadBalancedSetParameters.InputEndpoint loadBalancedEndpointsItem : parameters .getLoadBalancedEndpoints()) { Element inputEndpointElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "InputEndpoint"); loadBalancedEndpointListElement.appendChild(inputEndpointElement); Element loadBalancedEndpointSetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancedEndpointSetName"); loadBalancedEndpointSetNameElement.appendChild( requestDoc.createTextNode(loadBalancedEndpointsItem.getLoadBalancedEndpointSetName())); inputEndpointElement.appendChild(loadBalancedEndpointSetNameElement); if (loadBalancedEndpointsItem.getLocalPort() != null) { Element localPortElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "LocalPort"); localPortElement.appendChild(requestDoc .createTextNode(Integer.toString(loadBalancedEndpointsItem.getLocalPort()))); inputEndpointElement.appendChild(localPortElement); } if (loadBalancedEndpointsItem.getName() != null) { Element nameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(loadBalancedEndpointsItem.getName())); inputEndpointElement.appendChild(nameElement); } if (loadBalancedEndpointsItem.getPort() != null) { Element portElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Port"); portElement.appendChild( requestDoc.createTextNode(Integer.toString(loadBalancedEndpointsItem.getPort()))); inputEndpointElement.appendChild(portElement); } if (loadBalancedEndpointsItem.getLoadBalancerProbe() != null) { Element loadBalancerProbeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "LoadBalancerProbe"); inputEndpointElement.appendChild(loadBalancerProbeElement); if (loadBalancedEndpointsItem.getLoadBalancerProbe().getPath() != null) { Element pathElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Path"); pathElement.appendChild(requestDoc .createTextNode(loadBalancedEndpointsItem.getLoadBalancerProbe().getPath())); loadBalancerProbeElement.appendChild(pathElement); } Element portElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Port"); portElement2.appendChild(requestDoc.createTextNode( Integer.toString(loadBalancedEndpointsItem.getLoadBalancerProbe().getPort()))); loadBalancerProbeElement.appendChild(portElement2); if (loadBalancedEndpointsItem.getLoadBalancerProbe().getProtocol() != null) { Element protocolElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement.appendChild(requestDoc.createTextNode( ComputeManagementClientImpl.loadBalancerProbeTransportProtocolToString( loadBalancedEndpointsItem.getLoadBalancerProbe().getProtocol()))); loadBalancerProbeElement.appendChild(protocolElement); } if (loadBalancedEndpointsItem.getLoadBalancerProbe().getIntervalInSeconds() != null) { Element intervalInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IntervalInSeconds"); intervalInSecondsElement.appendChild(requestDoc.createTextNode(Integer.toString( loadBalancedEndpointsItem.getLoadBalancerProbe().getIntervalInSeconds()))); loadBalancerProbeElement.appendChild(intervalInSecondsElement); } if (loadBalancedEndpointsItem.getLoadBalancerProbe().getTimeoutInSeconds() != null) { Element timeoutInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "TimeoutInSeconds"); timeoutInSecondsElement.appendChild(requestDoc.createTextNode(Integer.toString( loadBalancedEndpointsItem.getLoadBalancerProbe().getTimeoutInSeconds()))); loadBalancerProbeElement.appendChild(timeoutInSecondsElement); } } if (loadBalancedEndpointsItem.getProtocol() != null) { Element protocolElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement2 .appendChild(requestDoc.createTextNode(loadBalancedEndpointsItem.getProtocol())); inputEndpointElement.appendChild(protocolElement2); } if (loadBalancedEndpointsItem.getVirtualIPAddress() != null) { Element vipElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Vip"); vipElement.appendChild(requestDoc .createTextNode(loadBalancedEndpointsItem.getVirtualIPAddress().getHostAddress())); inputEndpointElement.appendChild(vipElement); } if (loadBalancedEndpointsItem.isEnableDirectServerReturn() != null) { Element enableDirectServerReturnElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EnableDirectServerReturn"); enableDirectServerReturnElement.appendChild(requestDoc.createTextNode(Boolean .toString(loadBalancedEndpointsItem.isEnableDirectServerReturn()).toLowerCase())); inputEndpointElement.appendChild(enableDirectServerReturnElement); } Element endpointAclElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "EndpointAcl"); inputEndpointElement.appendChild(endpointAclElement); if (loadBalancedEndpointsItem.getRules() != null) { if (loadBalancedEndpointsItem.getRules() instanceof LazyCollection == false || ((LazyCollection) loadBalancedEndpointsItem.getRules()).isInitialized()) { Element rulesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Rules"); for (AccessControlListRule rulesItem : loadBalancedEndpointsItem.getRules()) { Element ruleElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Rule"); rulesSequenceElement.appendChild(ruleElement); if (rulesItem.getOrder() != null) { Element orderElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Order"); orderElement.appendChild( requestDoc.createTextNode(Integer.toString(rulesItem.getOrder()))); ruleElement.appendChild(orderElement); } if (rulesItem.getAction() != null) { Element actionElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Action"); actionElement.appendChild(requestDoc.createTextNode(rulesItem.getAction())); ruleElement.appendChild(actionElement); } if (rulesItem.getRemoteSubnet() != null) { Element remoteSubnetElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "RemoteSubnet"); remoteSubnetElement .appendChild(requestDoc.createTextNode(rulesItem.getRemoteSubnet())); ruleElement.appendChild(remoteSubnetElement); } if (rulesItem.getDescription() != null) { Element descriptionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Description"); descriptionElement .appendChild(requestDoc.createTextNode(rulesItem.getDescription())); ruleElement.appendChild(descriptionElement); } } endpointAclElement.appendChild(rulesSequenceElement); } } if (loadBalancedEndpointsItem.getLoadBalancerName() != null) { Element loadBalancerNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "LoadBalancerName"); loadBalancerNameElement.appendChild( requestDoc.createTextNode(loadBalancedEndpointsItem.getLoadBalancerName())); inputEndpointElement.appendChild(loadBalancerNameElement); } if (loadBalancedEndpointsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement.appendChild(requestDoc.createTextNode( Integer.toString(loadBalancedEndpointsItem.getIdleTimeoutInMinutes()))); inputEndpointElement.appendChild(idleTimeoutInMinutesElement); } if (loadBalancedEndpointsItem.getLoadBalancerDistribution() != null) { Element loadBalancerDistributionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerDistribution"); loadBalancerDistributionElement.appendChild( requestDoc.createTextNode(loadBalancedEndpointsItem.getLoadBalancerDistribution())); inputEndpointElement.appendChild(loadBalancerDistributionElement); } if (loadBalancedEndpointsItem.getVirtualIPName() != null) { Element virtualIPNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "VirtualIPName"); virtualIPNameElement.appendChild( requestDoc.createTextNode(loadBalancedEndpointsItem.getVirtualIPName())); inputEndpointElement.appendChild(virtualIPNameElement); } } } } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; // Deserialize Response result = new OperationResponse(); 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.VirtualMachineOperationsImpl.java
/** * The Begin Capturing Role operation creates a copy of the operating system * virtual hard disk (VHD) that is deployed in the virtual machine, saves * the VHD copy in the same storage location as the operating system VHD, * and registers the copy as an image in your image gallery. From the * captured image, you can create additional customized virtual machines. * For more information about images and disks, see Manage Disks and Images * at http://msdn.microsoft.com/en-us/library/windowsazure/jj672979.aspx. * For more information about capturing images, see How to Capture an Image * of a Virtual Machine Running Windows Server 2008 R2 at * http://www.windowsazure.com/en-us/documentation/articles/virtual-machines-capture-image-windows-server/ * or How to Capture an Image of a Virtual Machine Running Linux at * http://www.windowsazure.com/en-us/documentation/articles/virtual-machines-linux-capture-image/. * (see http://msdn.microsoft.com/en-us/library/windowsazure/jj157201.aspx * for more information)/*from w w w . ja va2 s . c o m*/ * * @param serviceName Required. The name of your service. * @param deploymentName Required. The name of your deployment. * @param virtualMachineName Required. The name of the virtual machine to * restart. * @param parameters Required. Parameters supplied to the Begin Capturing * Virtual Machine operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return A standard service response including an HTTP status code and * request ID. */ @Override public OperationResponse beginCapturingOSImage(String serviceName, String deploymentName, String virtualMachineName, VirtualMachineCaptureOSImageParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (virtualMachineName == null) { throw new NullPointerException("virtualMachineName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getPostCaptureAction() == null) { throw new NullPointerException("parameters.PostCaptureAction"); } if (parameters.getProvisioningConfiguration() != null) { if (parameters.getProvisioningConfiguration().getAdditionalUnattendContent() != null) { if (parameters.getProvisioningConfiguration().getAdditionalUnattendContent() .getUnattendPasses() != null) { for (UnattendPassSettings unattendPassesParameterItem : parameters .getProvisioningConfiguration().getAdditionalUnattendContent().getUnattendPasses()) { if (unattendPassesParameterItem.getPassName() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.AdditionalUnattendContent.UnattendPasses.PassName"); } if (unattendPassesParameterItem.getUnattendComponents() != null) { for (UnattendComponent unattendComponentsParameterItem : unattendPassesParameterItem .getUnattendComponents()) { if (unattendComponentsParameterItem.getComponentName() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.AdditionalUnattendContent.UnattendPasses.UnattendComponents.ComponentName"); } if (unattendComponentsParameterItem.getUnattendComponentSettings() != null) { for (ComponentSetting unattendComponentSettingsParameterItem : unattendComponentsParameterItem .getUnattendComponentSettings()) { if (unattendComponentSettingsParameterItem.getSettingName() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.AdditionalUnattendContent.UnattendPasses.UnattendComponents.UnattendComponentSettings.SettingName"); } } } } } } } } if (parameters.getProvisioningConfiguration().getDomainJoin() != null) { if (parameters.getProvisioningConfiguration().getDomainJoin().getCredentials() != null) { if (parameters.getProvisioningConfiguration().getDomainJoin().getCredentials() .getPassword() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.DomainJoin.Credentials.Password"); } if (parameters.getProvisioningConfiguration().getDomainJoin().getCredentials() .getUserName() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.DomainJoin.Credentials.UserName"); } } } if (parameters.getProvisioningConfiguration().getHostName() != null && parameters.getProvisioningConfiguration().getHostName().length() < 1) { throw new IllegalArgumentException("parameters.ProvisioningConfiguration.HostName"); } if (parameters.getProvisioningConfiguration().getHostName() != null && parameters.getProvisioningConfiguration().getHostName().length() > 64) { throw new IllegalArgumentException("parameters.ProvisioningConfiguration.HostName"); } if (parameters.getProvisioningConfiguration().getSshSettings() != null) { if (parameters.getProvisioningConfiguration().getSshSettings().getKeyPairs() != null) { for (SshSettingKeyPair keyPairsParameterItem : parameters.getProvisioningConfiguration() .getSshSettings().getKeyPairs()) { if (keyPairsParameterItem.getFingerprint() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.SshSettings.KeyPairs.Fingerprint"); } if (keyPairsParameterItem.getPath() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.SshSettings.KeyPairs.Path"); } } } if (parameters.getProvisioningConfiguration().getSshSettings().getPublicKeys() != null) { for (SshSettingPublicKey publicKeysParameterItem : parameters.getProvisioningConfiguration() .getSshSettings().getPublicKeys()) { if (publicKeysParameterItem.getFingerprint() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.SshSettings.PublicKeys.Fingerprint"); } if (publicKeysParameterItem.getPath() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.SshSettings.PublicKeys.Path"); } } } } if (parameters.getProvisioningConfiguration().getStoredCertificateSettings() != null) { for (StoredCertificateSettings storedCertificateSettingsParameterItem : parameters .getProvisioningConfiguration().getStoredCertificateSettings()) { if (storedCertificateSettingsParameterItem.getStoreName() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.StoredCertificateSettings.StoreName"); } if (storedCertificateSettingsParameterItem.getThumbprint() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.StoredCertificateSettings.Thumbprint"); } } } if (parameters.getProvisioningConfiguration().getUserName() != null && parameters.getProvisioningConfiguration().getUserName().length() < 1) { throw new IllegalArgumentException("parameters.ProvisioningConfiguration.UserName"); } if (parameters.getProvisioningConfiguration().getUserName() != null && parameters.getProvisioningConfiguration().getUserName().length() > 32) { throw new IllegalArgumentException("parameters.ProvisioningConfiguration.UserName"); } if (parameters.getProvisioningConfiguration().getUserPassword() != null && parameters.getProvisioningConfiguration().getUserPassword().length() < 6) { throw new IllegalArgumentException("parameters.ProvisioningConfiguration.UserPassword"); } if (parameters.getProvisioningConfiguration().getUserPassword() != null && parameters.getProvisioningConfiguration().getUserPassword().length() > 72) { throw new IllegalArgumentException("parameters.ProvisioningConfiguration.UserPassword"); } if (parameters.getProvisioningConfiguration().getWindowsRemoteManagement() != null) { if (parameters.getProvisioningConfiguration().getWindowsRemoteManagement().getListeners() != null) { for (WindowsRemoteManagementListener listenersParameterItem : parameters .getProvisioningConfiguration().getWindowsRemoteManagement().getListeners()) { if (listenersParameterItem.getListenerType() == null) { throw new NullPointerException( "parameters.ProvisioningConfiguration.WindowsRemoteManagement.Listeners.ListenerType"); } } } } } if (parameters.getTargetImageLabel() == null) { throw new NullPointerException("parameters.TargetImageLabel"); } if (parameters.getTargetImageName() == null) { throw new NullPointerException("parameters.TargetImageName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("virtualMachineName", virtualMachineName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCapturingOSImageAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); url = url + "/roleinstances/"; url = url + URLEncoder.encode(virtualMachineName, "UTF-8"); url = url + "/Operations"; 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 captureRoleOperationElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CaptureRoleOperation"); requestDoc.appendChild(captureRoleOperationElement); Element operationTypeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OperationType"); operationTypeElement.appendChild(requestDoc.createTextNode("CaptureRoleOperation")); captureRoleOperationElement.appendChild(operationTypeElement); Element postCaptureActionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "PostCaptureAction"); postCaptureActionElement .appendChild(requestDoc.createTextNode(parameters.getPostCaptureAction().toString())); captureRoleOperationElement.appendChild(postCaptureActionElement); if (parameters.getProvisioningConfiguration() != null) { Element provisioningConfigurationElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ProvisioningConfiguration"); captureRoleOperationElement.appendChild(provisioningConfigurationElement); if (parameters.getProvisioningConfiguration().getConfigurationSetType() != null) { Element configurationSetTypeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ConfigurationSetType"); configurationSetTypeElement.appendChild(requestDoc .createTextNode(parameters.getProvisioningConfiguration().getConfigurationSetType())); provisioningConfigurationElement.appendChild(configurationSetTypeElement); } if (parameters.getProvisioningConfiguration().getInputEndpoints() != null) { if (parameters.getProvisioningConfiguration().getInputEndpoints() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration().getInputEndpoints()) .isInitialized()) { Element inputEndpointsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "InputEndpoints"); for (InputEndpoint inputEndpointsItem : parameters.getProvisioningConfiguration() .getInputEndpoints()) { Element inputEndpointElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "InputEndpoint"); inputEndpointsSequenceElement.appendChild(inputEndpointElement); if (inputEndpointsItem.getLoadBalancedEndpointSetName() != null) { Element loadBalancedEndpointSetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancedEndpointSetName"); loadBalancedEndpointSetNameElement.appendChild( requestDoc.createTextNode(inputEndpointsItem.getLoadBalancedEndpointSetName())); inputEndpointElement.appendChild(loadBalancedEndpointSetNameElement); } if (inputEndpointsItem.getLocalPort() != null) { Element localPortElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "LocalPort"); localPortElement.appendChild( requestDoc.createTextNode(Integer.toString(inputEndpointsItem.getLocalPort()))); inputEndpointElement.appendChild(localPortElement); } if (inputEndpointsItem.getName() != null) { Element nameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(inputEndpointsItem.getName())); inputEndpointElement.appendChild(nameElement); } if (inputEndpointsItem.getPort() != null) { Element portElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Port"); portElement.appendChild( requestDoc.createTextNode(Integer.toString(inputEndpointsItem.getPort()))); inputEndpointElement.appendChild(portElement); } if (inputEndpointsItem.getLoadBalancerProbe() != null) { Element loadBalancerProbeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerProbe"); inputEndpointElement.appendChild(loadBalancerProbeElement); if (inputEndpointsItem.getLoadBalancerProbe().getPath() != null) { Element pathElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Path"); pathElement.appendChild(requestDoc .createTextNode(inputEndpointsItem.getLoadBalancerProbe().getPath())); loadBalancerProbeElement.appendChild(pathElement); } Element portElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Port"); portElement2.appendChild(requestDoc.createTextNode( Integer.toString(inputEndpointsItem.getLoadBalancerProbe().getPort()))); loadBalancerProbeElement.appendChild(portElement2); if (inputEndpointsItem.getLoadBalancerProbe().getProtocol() != null) { Element protocolElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement.appendChild(requestDoc.createTextNode( ComputeManagementClientImpl.loadBalancerProbeTransportProtocolToString( inputEndpointsItem.getLoadBalancerProbe().getProtocol()))); loadBalancerProbeElement.appendChild(protocolElement); } if (inputEndpointsItem.getLoadBalancerProbe().getIntervalInSeconds() != null) { Element intervalInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IntervalInSeconds"); intervalInSecondsElement.appendChild(requestDoc.createTextNode(Integer.toString( inputEndpointsItem.getLoadBalancerProbe().getIntervalInSeconds()))); loadBalancerProbeElement.appendChild(intervalInSecondsElement); } if (inputEndpointsItem.getLoadBalancerProbe().getTimeoutInSeconds() != null) { Element timeoutInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "TimeoutInSeconds"); timeoutInSecondsElement.appendChild(requestDoc.createTextNode(Integer.toString( inputEndpointsItem.getLoadBalancerProbe().getTimeoutInSeconds()))); loadBalancerProbeElement.appendChild(timeoutInSecondsElement); } } if (inputEndpointsItem.getProtocol() != null) { Element protocolElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement2 .appendChild(requestDoc.createTextNode(inputEndpointsItem.getProtocol())); inputEndpointElement.appendChild(protocolElement2); } if (inputEndpointsItem.getVirtualIPAddress() != null) { Element vipElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Vip"); vipElement.appendChild(requestDoc .createTextNode(inputEndpointsItem.getVirtualIPAddress().getHostAddress())); inputEndpointElement.appendChild(vipElement); } if (inputEndpointsItem.isEnableDirectServerReturn() != null) { Element enableDirectServerReturnElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EnableDirectServerReturn"); enableDirectServerReturnElement.appendChild(requestDoc.createTextNode(Boolean .toString(inputEndpointsItem.isEnableDirectServerReturn()).toLowerCase())); inputEndpointElement.appendChild(enableDirectServerReturnElement); } if (inputEndpointsItem.getLoadBalancerName() != null) { Element loadBalancerNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerName"); loadBalancerNameElement.appendChild( requestDoc.createTextNode(inputEndpointsItem.getLoadBalancerName())); inputEndpointElement.appendChild(loadBalancerNameElement); } if (inputEndpointsItem.getEndpointAcl() != null) { Element endpointAclElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "EndpointAcl"); inputEndpointElement.appendChild(endpointAclElement); if (inputEndpointsItem.getEndpointAcl().getRules() != null) { if (inputEndpointsItem.getEndpointAcl() .getRules() instanceof LazyCollection == false || ((LazyCollection) inputEndpointsItem.getEndpointAcl().getRules()) .isInitialized()) { Element rulesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Rules"); for (AccessControlListRule rulesItem : inputEndpointsItem.getEndpointAcl() .getRules()) { Element ruleElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Rule"); rulesSequenceElement.appendChild(ruleElement); if (rulesItem.getOrder() != null) { Element orderElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Order"); orderElement.appendChild(requestDoc .createTextNode(Integer.toString(rulesItem.getOrder()))); ruleElement.appendChild(orderElement); } if (rulesItem.getAction() != null) { Element actionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Action"); actionElement .appendChild(requestDoc.createTextNode(rulesItem.getAction())); ruleElement.appendChild(actionElement); } if (rulesItem.getRemoteSubnet() != null) { Element remoteSubnetElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "RemoteSubnet"); remoteSubnetElement.appendChild( requestDoc.createTextNode(rulesItem.getRemoteSubnet())); ruleElement.appendChild(remoteSubnetElement); } if (rulesItem.getDescription() != null) { Element descriptionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Description"); descriptionElement.appendChild( requestDoc.createTextNode(rulesItem.getDescription())); ruleElement.appendChild(descriptionElement); } } endpointAclElement.appendChild(rulesSequenceElement); } } } if (inputEndpointsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement.appendChild(requestDoc.createTextNode( Integer.toString(inputEndpointsItem.getIdleTimeoutInMinutes()))); inputEndpointElement.appendChild(idleTimeoutInMinutesElement); } if (inputEndpointsItem.getLoadBalancerDistribution() != null) { Element loadBalancerDistributionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerDistribution"); loadBalancerDistributionElement.appendChild( requestDoc.createTextNode(inputEndpointsItem.getLoadBalancerDistribution())); inputEndpointElement.appendChild(loadBalancerDistributionElement); } if (inputEndpointsItem.getVirtualIPName() != null) { Element virtualIPNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "VirtualIPName"); virtualIPNameElement .appendChild(requestDoc.createTextNode(inputEndpointsItem.getVirtualIPName())); inputEndpointElement.appendChild(virtualIPNameElement); } } provisioningConfigurationElement.appendChild(inputEndpointsSequenceElement); } } if (parameters.getProvisioningConfiguration().getSubnetNames() != null) { if (parameters.getProvisioningConfiguration().getSubnetNames() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration().getSubnetNames()) .isInitialized()) { Element subnetNamesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetNames"); for (String subnetNamesItem : parameters.getProvisioningConfiguration().getSubnetNames()) { Element subnetNamesItemElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNamesItemElement.appendChild(requestDoc.createTextNode(subnetNamesItem)); subnetNamesSequenceElement.appendChild(subnetNamesItemElement); } provisioningConfigurationElement.appendChild(subnetNamesSequenceElement); } } if (parameters.getProvisioningConfiguration().getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement.appendChild(requestDoc.createTextNode( parameters.getProvisioningConfiguration().getStaticVirtualNetworkIPAddress())); provisioningConfigurationElement.appendChild(staticVirtualNetworkIPAddressElement); } if (parameters.getProvisioningConfiguration().getPublicIPs() != null) { if (parameters.getProvisioningConfiguration().getPublicIPs() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration().getPublicIPs()) .isInitialized()) { Element publicIPsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicIPs"); for (ConfigurationSet.PublicIP publicIPsItem : parameters.getProvisioningConfiguration() .getPublicIPs()) { Element publicIPElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicIP"); publicIPsSequenceElement.appendChild(publicIPElement); if (publicIPsItem.getName() != null) { Element nameElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement2.appendChild(requestDoc.createTextNode(publicIPsItem.getName())); publicIPElement.appendChild(nameElement2); } if (publicIPsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement2.appendChild(requestDoc .createTextNode(Integer.toString(publicIPsItem.getIdleTimeoutInMinutes()))); publicIPElement.appendChild(idleTimeoutInMinutesElement2); } if (publicIPsItem.getDomainNameLabel() != null) { Element domainNameLabelElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DomainNameLabel"); domainNameLabelElement .appendChild(requestDoc.createTextNode(publicIPsItem.getDomainNameLabel())); publicIPElement.appendChild(domainNameLabelElement); } } provisioningConfigurationElement.appendChild(publicIPsSequenceElement); } } if (parameters.getProvisioningConfiguration().getNetworkInterfaces() != null) { if (parameters.getProvisioningConfiguration() .getNetworkInterfaces() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration().getNetworkInterfaces()) .isInitialized()) { Element networkInterfacesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "NetworkInterfaces"); for (NetworkInterface networkInterfacesItem : parameters.getProvisioningConfiguration() .getNetworkInterfaces()) { Element networkInterfaceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "NetworkInterface"); networkInterfacesSequenceElement.appendChild(networkInterfaceElement); if (networkInterfacesItem.getName() != null) { Element nameElement3 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement3.appendChild(requestDoc.createTextNode(networkInterfacesItem.getName())); networkInterfaceElement.appendChild(nameElement3); } if (networkInterfacesItem.getIPConfigurations() != null) { if (networkInterfacesItem.getIPConfigurations() instanceof LazyCollection == false || ((LazyCollection) networkInterfacesItem.getIPConfigurations()) .isInitialized()) { Element iPConfigurationsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPConfigurations"); for (IPConfiguration iPConfigurationsItem : networkInterfacesItem .getIPConfigurations()) { Element iPConfigurationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPConfiguration"); iPConfigurationsSequenceElement.appendChild(iPConfigurationElement); if (iPConfigurationsItem.getSubnetName() != null) { Element subnetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNameElement.appendChild( requestDoc.createTextNode(iPConfigurationsItem.getSubnetName())); iPConfigurationElement.appendChild(subnetNameElement); } if (iPConfigurationsItem.getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement2.appendChild(requestDoc.createTextNode( iPConfigurationsItem.getStaticVirtualNetworkIPAddress())); iPConfigurationElement.appendChild(staticVirtualNetworkIPAddressElement2); } } networkInterfaceElement.appendChild(iPConfigurationsSequenceElement); } } if (networkInterfacesItem.getNetworkSecurityGroup() != null) { Element networkSecurityGroupElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup"); networkSecurityGroupElement.appendChild( requestDoc.createTextNode(networkInterfacesItem.getNetworkSecurityGroup())); networkInterfaceElement.appendChild(networkSecurityGroupElement); } if (networkInterfacesItem.getIPForwarding() != null) { Element iPForwardingElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IPForwarding"); iPForwardingElement.appendChild( requestDoc.createTextNode(networkInterfacesItem.getIPForwarding())); networkInterfaceElement.appendChild(iPForwardingElement); } } provisioningConfigurationElement.appendChild(networkInterfacesSequenceElement); } } if (parameters.getProvisioningConfiguration().getNetworkSecurityGroup() != null) { Element networkSecurityGroupElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup"); networkSecurityGroupElement2.appendChild(requestDoc .createTextNode(parameters.getProvisioningConfiguration().getNetworkSecurityGroup())); provisioningConfigurationElement.appendChild(networkSecurityGroupElement2); } if (parameters.getProvisioningConfiguration().getIPForwarding() != null) { Element iPForwardingElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IPForwarding"); iPForwardingElement2.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getIPForwarding())); provisioningConfigurationElement.appendChild(iPForwardingElement2); } if (parameters.getProvisioningConfiguration().getComputerName() != null) { Element computerNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ComputerName"); computerNameElement.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getComputerName())); provisioningConfigurationElement.appendChild(computerNameElement); } if (parameters.getProvisioningConfiguration().getAdminPassword() != null) { Element adminPasswordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AdminPassword"); adminPasswordElement.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getAdminPassword())); provisioningConfigurationElement.appendChild(adminPasswordElement); } if (parameters.getProvisioningConfiguration().isResetPasswordOnFirstLogon() != null) { Element resetPasswordOnFirstLogonElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ResetPasswordOnFirstLogon"); resetPasswordOnFirstLogonElement.appendChild(requestDoc.createTextNode( Boolean.toString(parameters.getProvisioningConfiguration().isResetPasswordOnFirstLogon()) .toLowerCase())); provisioningConfigurationElement.appendChild(resetPasswordOnFirstLogonElement); } if (parameters.getProvisioningConfiguration().isEnableAutomaticUpdates() != null) { Element enableAutomaticUpdatesElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "EnableAutomaticUpdates"); enableAutomaticUpdatesElement.appendChild(requestDoc.createTextNode( Boolean.toString(parameters.getProvisioningConfiguration().isEnableAutomaticUpdates()) .toLowerCase())); provisioningConfigurationElement.appendChild(enableAutomaticUpdatesElement); } if (parameters.getProvisioningConfiguration().getTimeZone() != null) { Element timeZoneElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "TimeZone"); timeZoneElement.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getTimeZone())); provisioningConfigurationElement.appendChild(timeZoneElement); } if (parameters.getProvisioningConfiguration().getDomainJoin() != null) { Element domainJoinElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "DomainJoin"); provisioningConfigurationElement.appendChild(domainJoinElement); if (parameters.getProvisioningConfiguration().getDomainJoin().getCredentials() != null) { Element credentialsElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Credentials"); domainJoinElement.appendChild(credentialsElement); if (parameters.getProvisioningConfiguration().getDomainJoin().getCredentials() .getDomain() != null) { Element domainElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Domain"); domainElement.appendChild(requestDoc.createTextNode(parameters .getProvisioningConfiguration().getDomainJoin().getCredentials().getDomain())); credentialsElement.appendChild(domainElement); } Element usernameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Username"); usernameElement.appendChild(requestDoc.createTextNode(parameters.getProvisioningConfiguration() .getDomainJoin().getCredentials().getUserName())); credentialsElement.appendChild(usernameElement); Element passwordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Password"); passwordElement.appendChild(requestDoc.createTextNode(parameters.getProvisioningConfiguration() .getDomainJoin().getCredentials().getPassword())); credentialsElement.appendChild(passwordElement); } if (parameters.getProvisioningConfiguration().getDomainJoin().getDomainToJoin() != null) { Element joinDomainElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "JoinDomain"); joinDomainElement.appendChild(requestDoc.createTextNode( parameters.getProvisioningConfiguration().getDomainJoin().getDomainToJoin())); domainJoinElement.appendChild(joinDomainElement); } if (parameters.getProvisioningConfiguration().getDomainJoin().getLdapMachineObjectOU() != null) { Element machineObjectOUElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MachineObjectOU"); machineObjectOUElement.appendChild(requestDoc.createTextNode( parameters.getProvisioningConfiguration().getDomainJoin().getLdapMachineObjectOU())); domainJoinElement.appendChild(machineObjectOUElement); } if (parameters.getProvisioningConfiguration().getDomainJoin().getProvisioning() != null) { Element provisioningElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Provisioning"); domainJoinElement.appendChild(provisioningElement); if (parameters.getProvisioningConfiguration().getDomainJoin().getProvisioning() .getAccountData() != null) { Element accountDataElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AccountData"); accountDataElement .appendChild(requestDoc.createTextNode(parameters.getProvisioningConfiguration() .getDomainJoin().getProvisioning().getAccountData())); provisioningElement.appendChild(accountDataElement); } } } if (parameters.getProvisioningConfiguration().getStoredCertificateSettings() != null) { if (parameters.getProvisioningConfiguration() .getStoredCertificateSettings() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration() .getStoredCertificateSettings()).isInitialized()) { Element storedCertificateSettingsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StoredCertificateSettings"); for (StoredCertificateSettings storedCertificateSettingsItem : parameters .getProvisioningConfiguration().getStoredCertificateSettings()) { Element certificateSettingElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CertificateSetting"); storedCertificateSettingsSequenceElement.appendChild(certificateSettingElement); Element storeLocationElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "StoreLocation"); storeLocationElement.appendChild(requestDoc.createTextNode("LocalMachine")); certificateSettingElement.appendChild(storeLocationElement); Element storeNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "StoreName"); storeNameElement.appendChild( requestDoc.createTextNode(storedCertificateSettingsItem.getStoreName())); certificateSettingElement.appendChild(storeNameElement); Element thumbprintElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Thumbprint"); thumbprintElement.appendChild( requestDoc.createTextNode(storedCertificateSettingsItem.getThumbprint())); certificateSettingElement.appendChild(thumbprintElement); } provisioningConfigurationElement.appendChild(storedCertificateSettingsSequenceElement); } } if (parameters.getProvisioningConfiguration().getWindowsRemoteManagement() != null) { Element winRMElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "WinRM"); provisioningConfigurationElement.appendChild(winRMElement); if (parameters.getProvisioningConfiguration().getWindowsRemoteManagement().getListeners() != null) { if (parameters.getProvisioningConfiguration().getWindowsRemoteManagement() .getListeners() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration() .getWindowsRemoteManagement().getListeners()).isInitialized()) { Element listenersSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Listeners"); for (WindowsRemoteManagementListener listenersItem : parameters .getProvisioningConfiguration().getWindowsRemoteManagement().getListeners()) { Element listenerElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Listener"); listenersSequenceElement.appendChild(listenerElement); if (listenersItem.getCertificateThumbprint() != null) { Element certificateThumbprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "CertificateThumbprint"); certificateThumbprintElement.appendChild( requestDoc.createTextNode(listenersItem.getCertificateThumbprint())); listenerElement.appendChild(certificateThumbprintElement); } Element protocolElement3 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement3.appendChild( requestDoc.createTextNode(listenersItem.getListenerType().toString())); listenerElement.appendChild(protocolElement3); } winRMElement.appendChild(listenersSequenceElement); } } } if (parameters.getProvisioningConfiguration().getAdminUserName() != null) { Element adminUsernameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AdminUsername"); adminUsernameElement.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getAdminUserName())); provisioningConfigurationElement.appendChild(adminUsernameElement); } if (parameters.getProvisioningConfiguration().getAdditionalUnattendContent() != null) { Element additionalUnattendContentElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AdditionalUnattendContent"); provisioningConfigurationElement.appendChild(additionalUnattendContentElement); if (parameters.getProvisioningConfiguration().getAdditionalUnattendContent() .getUnattendPasses() != null) { if (parameters.getProvisioningConfiguration().getAdditionalUnattendContent() .getUnattendPasses() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration() .getAdditionalUnattendContent().getUnattendPasses()).isInitialized()) { Element passesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Passes"); for (UnattendPassSettings passesItem : parameters.getProvisioningConfiguration() .getAdditionalUnattendContent().getUnattendPasses()) { Element unattendPassElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "UnattendPass"); passesSequenceElement.appendChild(unattendPassElement); Element passNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PassName"); passNameElement.appendChild(requestDoc.createTextNode(passesItem.getPassName())); unattendPassElement.appendChild(passNameElement); if (passesItem.getUnattendComponents() != null) { if (passesItem.getUnattendComponents() instanceof LazyCollection == false || ((LazyCollection) passesItem.getUnattendComponents()).isInitialized()) { Element componentsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Components"); for (UnattendComponent componentsItem : passesItem.getUnattendComponents()) { Element unattendComponentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "UnattendComponent"); componentsSequenceElement.appendChild(unattendComponentElement); Element componentNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentName"); componentNameElement.appendChild( requestDoc.createTextNode(componentsItem.getComponentName())); unattendComponentElement.appendChild(componentNameElement); if (componentsItem.getUnattendComponentSettings() != null) { if (componentsItem .getUnattendComponentSettings() instanceof LazyCollection == false || ((LazyCollection) componentsItem .getUnattendComponentSettings()).isInitialized()) { Element componentSettingsSequenceElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentSettings"); for (ComponentSetting componentSettingsItem : componentsItem .getUnattendComponentSettings()) { Element componentSettingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentSetting"); componentSettingsSequenceElement .appendChild(componentSettingElement); Element settingNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SettingName"); settingNameElement.appendChild(requestDoc.createTextNode( componentSettingsItem.getSettingName())); componentSettingElement.appendChild(settingNameElement); if (componentSettingsItem.getContent() != null) { Element contentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Content"); contentElement.appendChild(requestDoc .createTextNode(Base64.encode(componentSettingsItem .getContent().getBytes()))); componentSettingElement.appendChild(contentElement); } } unattendComponentElement .appendChild(componentSettingsSequenceElement); } } } unattendPassElement.appendChild(componentsSequenceElement); } } } additionalUnattendContentElement.appendChild(passesSequenceElement); } } } if (parameters.getProvisioningConfiguration().getHostName() != null) { Element hostNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "HostName"); hostNameElement.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getHostName())); provisioningConfigurationElement.appendChild(hostNameElement); } if (parameters.getProvisioningConfiguration().getUserName() != null) { Element userNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "UserName"); userNameElement.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getUserName())); provisioningConfigurationElement.appendChild(userNameElement); } if (parameters.getProvisioningConfiguration().getUserPassword() != null) { Element userPasswordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "UserPassword"); userPasswordElement.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getUserPassword())); provisioningConfigurationElement.appendChild(userPasswordElement); } if (parameters.getProvisioningConfiguration().isDisableSshPasswordAuthentication() != null) { Element disableSshPasswordAuthenticationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DisableSshPasswordAuthentication"); disableSshPasswordAuthenticationElement.appendChild(requestDoc.createTextNode(Boolean .toString(parameters.getProvisioningConfiguration().isDisableSshPasswordAuthentication()) .toLowerCase())); provisioningConfigurationElement.appendChild(disableSshPasswordAuthenticationElement); } if (parameters.getProvisioningConfiguration().getSshSettings() != null) { Element sSHElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SSH"); provisioningConfigurationElement.appendChild(sSHElement); if (parameters.getProvisioningConfiguration().getSshSettings().getPublicKeys() != null) { if (parameters.getProvisioningConfiguration().getSshSettings() .getPublicKeys() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration().getSshSettings() .getPublicKeys()).isInitialized()) { Element publicKeysSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicKeys"); for (SshSettingPublicKey publicKeysItem : parameters.getProvisioningConfiguration() .getSshSettings().getPublicKeys()) { Element publicKeyElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicKey"); publicKeysSequenceElement.appendChild(publicKeyElement); Element fingerprintElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Fingerprint"); fingerprintElement .appendChild(requestDoc.createTextNode(publicKeysItem.getFingerprint())); publicKeyElement.appendChild(fingerprintElement); Element pathElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Path"); pathElement2.appendChild(requestDoc.createTextNode(publicKeysItem.getPath())); publicKeyElement.appendChild(pathElement2); } sSHElement.appendChild(publicKeysSequenceElement); } } if (parameters.getProvisioningConfiguration().getSshSettings().getKeyPairs() != null) { if (parameters.getProvisioningConfiguration().getSshSettings() .getKeyPairs() instanceof LazyCollection == false || ((LazyCollection) parameters.getProvisioningConfiguration().getSshSettings() .getKeyPairs()).isInitialized()) { Element keyPairsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "KeyPairs"); for (SshSettingKeyPair keyPairsItem : parameters.getProvisioningConfiguration() .getSshSettings().getKeyPairs()) { Element keyPairElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "KeyPair"); keyPairsSequenceElement.appendChild(keyPairElement); Element fingerprintElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Fingerprint"); fingerprintElement2 .appendChild(requestDoc.createTextNode(keyPairsItem.getFingerprint())); keyPairElement.appendChild(fingerprintElement2); Element pathElement3 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Path"); pathElement3.appendChild(requestDoc.createTextNode(keyPairsItem.getPath())); keyPairElement.appendChild(pathElement3); } sSHElement.appendChild(keyPairsSequenceElement); } } } if (parameters.getProvisioningConfiguration().getCustomData() != null) { Element customDataElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "CustomData"); customDataElement.appendChild( requestDoc.createTextNode(parameters.getProvisioningConfiguration().getCustomData())); provisioningConfigurationElement.appendChild(customDataElement); } } Element targetImageLabelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "TargetImageLabel"); targetImageLabelElement.appendChild(requestDoc.createTextNode(parameters.getTargetImageLabel())); captureRoleOperationElement.appendChild(targetImageLabelElement); Element targetImageNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "TargetImageName"); targetImageNameElement.appendChild(requestDoc.createTextNode(parameters.getTargetImageName())); captureRoleOperationElement.appendChild(targetImageNameElement); 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; // Deserialize Response result = new OperationResponse(); 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.VirtualMachineOperationsImpl.java
/** * The Begin Updating Role operation adds a virtual machine to an existing * deployment. (see// ww w . j a v a2s. c o m * http://msdn.microsoft.com/en-us/library/windowsazure/jj157187.aspx for * more information) * * @param serviceName Required. The name of your service. * @param deploymentName Required. The name of your deployment. * @param virtualMachineName Required. The name of your virtual machine. * @param parameters Required. Parameters supplied to the Begin Updating * Virtual Machine operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return A standard service response including an HTTP status code and * request ID. */ @Override public OperationResponse beginUpdating(String serviceName, String deploymentName, String virtualMachineName, VirtualMachineUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (virtualMachineName == null) { throw new NullPointerException("virtualMachineName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getConfigurationSets() != null) { for (ConfigurationSet configurationSetsParameterItem : parameters.getConfigurationSets()) { if (configurationSetsParameterItem.getAdditionalUnattendContent() != null) { if (configurationSetsParameterItem.getAdditionalUnattendContent().getUnattendPasses() != null) { for (UnattendPassSettings unattendPassesParameterItem : configurationSetsParameterItem .getAdditionalUnattendContent().getUnattendPasses()) { if (unattendPassesParameterItem.getPassName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.PassName"); } if (unattendPassesParameterItem.getUnattendComponents() != null) { for (UnattendComponent unattendComponentsParameterItem : unattendPassesParameterItem .getUnattendComponents()) { if (unattendComponentsParameterItem.getComponentName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.UnattendComponents.ComponentName"); } if (unattendComponentsParameterItem.getUnattendComponentSettings() != null) { for (ComponentSetting unattendComponentSettingsParameterItem : unattendComponentsParameterItem .getUnattendComponentSettings()) { if (unattendComponentSettingsParameterItem.getSettingName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.UnattendComponents.UnattendComponentSettings.SettingName"); } } } } } } } } if (configurationSetsParameterItem.getDomainJoin() != null) { if (configurationSetsParameterItem.getDomainJoin().getCredentials() != null) { if (configurationSetsParameterItem.getDomainJoin().getCredentials().getPassword() == null) { throw new NullPointerException( "parameters.ConfigurationSets.DomainJoin.Credentials.Password"); } if (configurationSetsParameterItem.getDomainJoin().getCredentials().getUserName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.DomainJoin.Credentials.UserName"); } } } if (configurationSetsParameterItem.getHostName() != null && configurationSetsParameterItem.getHostName().length() < 1) { throw new IllegalArgumentException("parameters.ConfigurationSets.HostName"); } if (configurationSetsParameterItem.getHostName() != null && configurationSetsParameterItem.getHostName().length() > 64) { throw new IllegalArgumentException("parameters.ConfigurationSets.HostName"); } if (configurationSetsParameterItem.getSshSettings() != null) { if (configurationSetsParameterItem.getSshSettings().getKeyPairs() != null) { for (SshSettingKeyPair keyPairsParameterItem : configurationSetsParameterItem .getSshSettings().getKeyPairs()) { if (keyPairsParameterItem.getFingerprint() == null) { throw new NullPointerException( "parameters.ConfigurationSets.SshSettings.KeyPairs.Fingerprint"); } if (keyPairsParameterItem.getPath() == null) { throw new NullPointerException( "parameters.ConfigurationSets.SshSettings.KeyPairs.Path"); } } } if (configurationSetsParameterItem.getSshSettings().getPublicKeys() != null) { for (SshSettingPublicKey publicKeysParameterItem : configurationSetsParameterItem .getSshSettings().getPublicKeys()) { if (publicKeysParameterItem.getFingerprint() == null) { throw new NullPointerException( "parameters.ConfigurationSets.SshSettings.PublicKeys.Fingerprint"); } if (publicKeysParameterItem.getPath() == null) { throw new NullPointerException( "parameters.ConfigurationSets.SshSettings.PublicKeys.Path"); } } } } if (configurationSetsParameterItem.getStoredCertificateSettings() != null) { for (StoredCertificateSettings storedCertificateSettingsParameterItem : configurationSetsParameterItem .getStoredCertificateSettings()) { if (storedCertificateSettingsParameterItem.getStoreName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.StoredCertificateSettings.StoreName"); } if (storedCertificateSettingsParameterItem.getThumbprint() == null) { throw new NullPointerException( "parameters.ConfigurationSets.StoredCertificateSettings.Thumbprint"); } } } if (configurationSetsParameterItem.getUserName() != null && configurationSetsParameterItem.getUserName().length() < 1) { throw new IllegalArgumentException("parameters.ConfigurationSets.UserName"); } if (configurationSetsParameterItem.getUserName() != null && configurationSetsParameterItem.getUserName().length() > 32) { throw new IllegalArgumentException("parameters.ConfigurationSets.UserName"); } if (configurationSetsParameterItem.getUserPassword() != null && configurationSetsParameterItem.getUserPassword().length() < 6) { throw new IllegalArgumentException("parameters.ConfigurationSets.UserPassword"); } if (configurationSetsParameterItem.getUserPassword() != null && configurationSetsParameterItem.getUserPassword().length() > 72) { throw new IllegalArgumentException("parameters.ConfigurationSets.UserPassword"); } if (configurationSetsParameterItem.getWindowsRemoteManagement() != null) { if (configurationSetsParameterItem.getWindowsRemoteManagement().getListeners() != null) { for (WindowsRemoteManagementListener listenersParameterItem : configurationSetsParameterItem .getWindowsRemoteManagement().getListeners()) { if (listenersParameterItem.getListenerType() == null) { throw new NullPointerException( "parameters.ConfigurationSets.WindowsRemoteManagement.Listeners.ListenerType"); } } } } } } if (parameters.getOSVirtualHardDisk() == null) { throw new NullPointerException("parameters.OSVirtualHardDisk"); } if (parameters.getRoleName() == null) { throw new NullPointerException("parameters.RoleName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("virtualMachineName", virtualMachineName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginUpdatingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); url = url + "/roles/"; url = url + URLEncoder.encode(virtualMachineName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2015-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element persistentVMRoleElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "PersistentVMRole"); requestDoc.appendChild(persistentVMRoleElement); Element roleNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "RoleName"); roleNameElement.appendChild(requestDoc.createTextNode(parameters.getRoleName())); persistentVMRoleElement.appendChild(roleNameElement); Element roleTypeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "RoleType"); roleTypeElement.appendChild(requestDoc.createTextNode("PersistentVMRole")); persistentVMRoleElement.appendChild(roleTypeElement); if (parameters.getConfigurationSets() != null) { if (parameters.getConfigurationSets() instanceof LazyCollection == false || ((LazyCollection) parameters.getConfigurationSets()).isInitialized()) { Element configurationSetsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ConfigurationSets"); for (ConfigurationSet configurationSetsItem : parameters.getConfigurationSets()) { Element configurationSetElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ConfigurationSet"); configurationSetsSequenceElement.appendChild(configurationSetElement); if (configurationSetsItem.getConfigurationSetType() != null) { Element configurationSetTypeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ConfigurationSetType"); configurationSetTypeElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getConfigurationSetType())); configurationSetElement.appendChild(configurationSetTypeElement); } if (configurationSetsItem.getInputEndpoints() != null) { if (configurationSetsItem.getInputEndpoints() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getInputEndpoints()).isInitialized()) { Element inputEndpointsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "InputEndpoints"); for (InputEndpoint inputEndpointsItem : configurationSetsItem.getInputEndpoints()) { Element inputEndpointElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "InputEndpoint"); inputEndpointsSequenceElement.appendChild(inputEndpointElement); if (inputEndpointsItem.getLoadBalancedEndpointSetName() != null) { Element loadBalancedEndpointSetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancedEndpointSetName"); loadBalancedEndpointSetNameElement.appendChild(requestDoc .createTextNode(inputEndpointsItem.getLoadBalancedEndpointSetName())); inputEndpointElement.appendChild(loadBalancedEndpointSetNameElement); } if (inputEndpointsItem.getLocalPort() != null) { Element localPortElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LocalPort"); localPortElement.appendChild(requestDoc .createTextNode(Integer.toString(inputEndpointsItem.getLocalPort()))); inputEndpointElement.appendChild(localPortElement); } if (inputEndpointsItem.getName() != null) { Element nameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement .appendChild(requestDoc.createTextNode(inputEndpointsItem.getName())); inputEndpointElement.appendChild(nameElement); } if (inputEndpointsItem.getPort() != null) { Element portElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Port"); portElement.appendChild(requestDoc .createTextNode(Integer.toString(inputEndpointsItem.getPort()))); inputEndpointElement.appendChild(portElement); } if (inputEndpointsItem.getLoadBalancerProbe() != null) { Element loadBalancerProbeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerProbe"); inputEndpointElement.appendChild(loadBalancerProbeElement); if (inputEndpointsItem.getLoadBalancerProbe().getPath() != null) { Element pathElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Path"); pathElement.appendChild(requestDoc.createTextNode( inputEndpointsItem.getLoadBalancerProbe().getPath())); loadBalancerProbeElement.appendChild(pathElement); } Element portElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Port"); portElement2.appendChild(requestDoc.createTextNode( Integer.toString(inputEndpointsItem.getLoadBalancerProbe().getPort()))); loadBalancerProbeElement.appendChild(portElement2); if (inputEndpointsItem.getLoadBalancerProbe().getProtocol() != null) { Element protocolElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement .appendChild(requestDoc.createTextNode(ComputeManagementClientImpl .loadBalancerProbeTransportProtocolToString( inputEndpointsItem.getLoadBalancerProbe() .getProtocol()))); loadBalancerProbeElement.appendChild(protocolElement); } if (inputEndpointsItem.getLoadBalancerProbe().getIntervalInSeconds() != null) { Element intervalInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IntervalInSeconds"); intervalInSecondsElement.appendChild( requestDoc.createTextNode(Integer.toString(inputEndpointsItem .getLoadBalancerProbe().getIntervalInSeconds()))); loadBalancerProbeElement.appendChild(intervalInSecondsElement); } if (inputEndpointsItem.getLoadBalancerProbe().getTimeoutInSeconds() != null) { Element timeoutInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "TimeoutInSeconds"); timeoutInSecondsElement.appendChild( requestDoc.createTextNode(Integer.toString(inputEndpointsItem .getLoadBalancerProbe().getTimeoutInSeconds()))); loadBalancerProbeElement.appendChild(timeoutInSecondsElement); } } if (inputEndpointsItem.getProtocol() != null) { Element protocolElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement2.appendChild( requestDoc.createTextNode(inputEndpointsItem.getProtocol())); inputEndpointElement.appendChild(protocolElement2); } if (inputEndpointsItem.getVirtualIPAddress() != null) { Element vipElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Vip"); vipElement.appendChild(requestDoc.createTextNode( inputEndpointsItem.getVirtualIPAddress().getHostAddress())); inputEndpointElement.appendChild(vipElement); } if (inputEndpointsItem.isEnableDirectServerReturn() != null) { Element enableDirectServerReturnElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EnableDirectServerReturn"); enableDirectServerReturnElement.appendChild(requestDoc.createTextNode( Boolean.toString(inputEndpointsItem.isEnableDirectServerReturn()) .toLowerCase())); inputEndpointElement.appendChild(enableDirectServerReturnElement); } if (inputEndpointsItem.getLoadBalancerName() != null) { Element loadBalancerNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerName"); loadBalancerNameElement.appendChild( requestDoc.createTextNode(inputEndpointsItem.getLoadBalancerName())); inputEndpointElement.appendChild(loadBalancerNameElement); } if (inputEndpointsItem.getEndpointAcl() != null) { Element endpointAclElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EndpointAcl"); inputEndpointElement.appendChild(endpointAclElement); if (inputEndpointsItem.getEndpointAcl().getRules() != null) { if (inputEndpointsItem.getEndpointAcl() .getRules() instanceof LazyCollection == false || ((LazyCollection) inputEndpointsItem.getEndpointAcl().getRules()) .isInitialized()) { Element rulesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Rules"); for (AccessControlListRule rulesItem : inputEndpointsItem .getEndpointAcl().getRules()) { Element ruleElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Rule"); rulesSequenceElement.appendChild(ruleElement); if (rulesItem.getOrder() != null) { Element orderElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Order"); orderElement.appendChild(requestDoc.createTextNode( Integer.toString(rulesItem.getOrder()))); ruleElement.appendChild(orderElement); } if (rulesItem.getAction() != null) { Element actionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Action"); actionElement.appendChild( requestDoc.createTextNode(rulesItem.getAction())); ruleElement.appendChild(actionElement); } if (rulesItem.getRemoteSubnet() != null) { Element remoteSubnetElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "RemoteSubnet"); remoteSubnetElement.appendChild( requestDoc.createTextNode(rulesItem.getRemoteSubnet())); ruleElement.appendChild(remoteSubnetElement); } if (rulesItem.getDescription() != null) { Element descriptionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Description"); descriptionElement.appendChild( requestDoc.createTextNode(rulesItem.getDescription())); ruleElement.appendChild(descriptionElement); } } endpointAclElement.appendChild(rulesSequenceElement); } } } if (inputEndpointsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement.appendChild(requestDoc.createTextNode( Integer.toString(inputEndpointsItem.getIdleTimeoutInMinutes()))); inputEndpointElement.appendChild(idleTimeoutInMinutesElement); } if (inputEndpointsItem.getLoadBalancerDistribution() != null) { Element loadBalancerDistributionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerDistribution"); loadBalancerDistributionElement.appendChild(requestDoc .createTextNode(inputEndpointsItem.getLoadBalancerDistribution())); inputEndpointElement.appendChild(loadBalancerDistributionElement); } if (inputEndpointsItem.getVirtualIPName() != null) { Element virtualIPNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "VirtualIPName"); virtualIPNameElement.appendChild( requestDoc.createTextNode(inputEndpointsItem.getVirtualIPName())); inputEndpointElement.appendChild(virtualIPNameElement); } } configurationSetElement.appendChild(inputEndpointsSequenceElement); } } if (configurationSetsItem.getSubnetNames() != null) { if (configurationSetsItem.getSubnetNames() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSubnetNames()).isInitialized()) { Element subnetNamesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetNames"); for (String subnetNamesItem : configurationSetsItem.getSubnetNames()) { Element subnetNamesItemElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNamesItemElement.appendChild(requestDoc.createTextNode(subnetNamesItem)); subnetNamesSequenceElement.appendChild(subnetNamesItemElement); } configurationSetElement.appendChild(subnetNamesSequenceElement); } } if (configurationSetsItem.getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement.appendChild(requestDoc .createTextNode(configurationSetsItem.getStaticVirtualNetworkIPAddress())); configurationSetElement.appendChild(staticVirtualNetworkIPAddressElement); } if (configurationSetsItem.getPublicIPs() != null) { if (configurationSetsItem.getPublicIPs() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getPublicIPs()).isInitialized()) { Element publicIPsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicIPs"); for (ConfigurationSet.PublicIP publicIPsItem : configurationSetsItem.getPublicIPs()) { Element publicIPElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicIP"); publicIPsSequenceElement.appendChild(publicIPElement); if (publicIPsItem.getName() != null) { Element nameElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement2.appendChild(requestDoc.createTextNode(publicIPsItem.getName())); publicIPElement.appendChild(nameElement2); } if (publicIPsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement2.appendChild(requestDoc.createTextNode( Integer.toString(publicIPsItem.getIdleTimeoutInMinutes()))); publicIPElement.appendChild(idleTimeoutInMinutesElement2); } if (publicIPsItem.getDomainNameLabel() != null) { Element domainNameLabelElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DomainNameLabel"); domainNameLabelElement.appendChild( requestDoc.createTextNode(publicIPsItem.getDomainNameLabel())); publicIPElement.appendChild(domainNameLabelElement); } } configurationSetElement.appendChild(publicIPsSequenceElement); } } if (configurationSetsItem.getNetworkInterfaces() != null) { if (configurationSetsItem.getNetworkInterfaces() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getNetworkInterfaces()) .isInitialized()) { Element networkInterfacesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkInterfaces"); for (NetworkInterface networkInterfacesItem : configurationSetsItem .getNetworkInterfaces()) { Element networkInterfaceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkInterface"); networkInterfacesSequenceElement.appendChild(networkInterfaceElement); if (networkInterfacesItem.getName() != null) { Element nameElement3 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement3.appendChild( requestDoc.createTextNode(networkInterfacesItem.getName())); networkInterfaceElement.appendChild(nameElement3); } if (networkInterfacesItem.getIPConfigurations() != null) { if (networkInterfacesItem .getIPConfigurations() instanceof LazyCollection == false || ((LazyCollection) networkInterfacesItem.getIPConfigurations()) .isInitialized()) { Element iPConfigurationsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPConfigurations"); for (IPConfiguration iPConfigurationsItem : networkInterfacesItem .getIPConfigurations()) { Element iPConfigurationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPConfiguration"); iPConfigurationsSequenceElement.appendChild(iPConfigurationElement); if (iPConfigurationsItem.getSubnetName() != null) { Element subnetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNameElement.appendChild(requestDoc .createTextNode(iPConfigurationsItem.getSubnetName())); iPConfigurationElement.appendChild(subnetNameElement); } if (iPConfigurationsItem.getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement2 = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement2 .appendChild(requestDoc.createTextNode(iPConfigurationsItem .getStaticVirtualNetworkIPAddress())); iPConfigurationElement .appendChild(staticVirtualNetworkIPAddressElement2); } } networkInterfaceElement.appendChild(iPConfigurationsSequenceElement); } } if (networkInterfacesItem.getNetworkSecurityGroup() != null) { Element networkSecurityGroupElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup"); networkSecurityGroupElement.appendChild(requestDoc .createTextNode(networkInterfacesItem.getNetworkSecurityGroup())); networkInterfaceElement.appendChild(networkSecurityGroupElement); } if (networkInterfacesItem.getIPForwarding() != null) { Element iPForwardingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPForwarding"); iPForwardingElement.appendChild( requestDoc.createTextNode(networkInterfacesItem.getIPForwarding())); networkInterfaceElement.appendChild(iPForwardingElement); } } configurationSetElement.appendChild(networkInterfacesSequenceElement); } } if (configurationSetsItem.getNetworkSecurityGroup() != null) { Element networkSecurityGroupElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup"); networkSecurityGroupElement2.appendChild( requestDoc.createTextNode(configurationSetsItem.getNetworkSecurityGroup())); configurationSetElement.appendChild(networkSecurityGroupElement2); } if (configurationSetsItem.getIPForwarding() != null) { Element iPForwardingElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IPForwarding"); iPForwardingElement2 .appendChild(requestDoc.createTextNode(configurationSetsItem.getIPForwarding())); configurationSetElement.appendChild(iPForwardingElement2); } if (configurationSetsItem.getComputerName() != null) { Element computerNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ComputerName"); computerNameElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getComputerName())); configurationSetElement.appendChild(computerNameElement); } if (configurationSetsItem.getAdminPassword() != null) { Element adminPasswordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AdminPassword"); adminPasswordElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getAdminPassword())); configurationSetElement.appendChild(adminPasswordElement); } if (configurationSetsItem.isResetPasswordOnFirstLogon() != null) { Element resetPasswordOnFirstLogonElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResetPasswordOnFirstLogon"); resetPasswordOnFirstLogonElement.appendChild(requestDoc.createTextNode(Boolean .toString(configurationSetsItem.isResetPasswordOnFirstLogon()).toLowerCase())); configurationSetElement.appendChild(resetPasswordOnFirstLogonElement); } if (configurationSetsItem.isEnableAutomaticUpdates() != null) { Element enableAutomaticUpdatesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EnableAutomaticUpdates"); enableAutomaticUpdatesElement.appendChild(requestDoc.createTextNode( Boolean.toString(configurationSetsItem.isEnableAutomaticUpdates()).toLowerCase())); configurationSetElement.appendChild(enableAutomaticUpdatesElement); } if (configurationSetsItem.getTimeZone() != null) { Element timeZoneElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "TimeZone"); timeZoneElement.appendChild(requestDoc.createTextNode(configurationSetsItem.getTimeZone())); configurationSetElement.appendChild(timeZoneElement); } if (configurationSetsItem.getDomainJoin() != null) { Element domainJoinElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DomainJoin"); configurationSetElement.appendChild(domainJoinElement); if (configurationSetsItem.getDomainJoin().getCredentials() != null) { Element credentialsElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Credentials"); domainJoinElement.appendChild(credentialsElement); if (configurationSetsItem.getDomainJoin().getCredentials().getDomain() != null) { Element domainElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Domain"); domainElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getCredentials().getDomain())); credentialsElement.appendChild(domainElement); } Element usernameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Username"); usernameElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getCredentials().getUserName())); credentialsElement.appendChild(usernameElement); Element passwordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Password"); passwordElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getCredentials().getPassword())); credentialsElement.appendChild(passwordElement); } if (configurationSetsItem.getDomainJoin().getDomainToJoin() != null) { Element joinDomainElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "JoinDomain"); joinDomainElement.appendChild(requestDoc .createTextNode(configurationSetsItem.getDomainJoin().getDomainToJoin())); domainJoinElement.appendChild(joinDomainElement); } if (configurationSetsItem.getDomainJoin().getLdapMachineObjectOU() != null) { Element machineObjectOUElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "MachineObjectOU"); machineObjectOUElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getLdapMachineObjectOU())); domainJoinElement.appendChild(machineObjectOUElement); } if (configurationSetsItem.getDomainJoin().getProvisioning() != null) { Element provisioningElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Provisioning"); domainJoinElement.appendChild(provisioningElement); if (configurationSetsItem.getDomainJoin().getProvisioning().getAccountData() != null) { Element accountDataElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "AccountData"); accountDataElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getProvisioning().getAccountData())); provisioningElement.appendChild(accountDataElement); } } } if (configurationSetsItem.getStoredCertificateSettings() != null) { if (configurationSetsItem.getStoredCertificateSettings() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getStoredCertificateSettings()) .isInitialized()) { Element storedCertificateSettingsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StoredCertificateSettings"); for (StoredCertificateSettings storedCertificateSettingsItem : configurationSetsItem .getStoredCertificateSettings()) { Element certificateSettingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "CertificateSetting"); storedCertificateSettingsSequenceElement.appendChild(certificateSettingElement); Element storeLocationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StoreLocation"); storeLocationElement.appendChild(requestDoc.createTextNode("LocalMachine")); certificateSettingElement.appendChild(storeLocationElement); Element storeNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "StoreName"); storeNameElement.appendChild( requestDoc.createTextNode(storedCertificateSettingsItem.getStoreName())); certificateSettingElement.appendChild(storeNameElement); Element thumbprintElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Thumbprint"); thumbprintElement.appendChild( requestDoc.createTextNode(storedCertificateSettingsItem.getThumbprint())); certificateSettingElement.appendChild(thumbprintElement); } configurationSetElement.appendChild(storedCertificateSettingsSequenceElement); } } if (configurationSetsItem.getWindowsRemoteManagement() != null) { Element winRMElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "WinRM"); configurationSetElement.appendChild(winRMElement); if (configurationSetsItem.getWindowsRemoteManagement().getListeners() != null) { if (configurationSetsItem.getWindowsRemoteManagement() .getListeners() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getWindowsRemoteManagement() .getListeners()).isInitialized()) { Element listenersSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Listeners"); for (WindowsRemoteManagementListener listenersItem : configurationSetsItem .getWindowsRemoteManagement().getListeners()) { Element listenerElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Listener"); listenersSequenceElement.appendChild(listenerElement); if (listenersItem.getCertificateThumbprint() != null) { Element certificateThumbprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "CertificateThumbprint"); certificateThumbprintElement.appendChild(requestDoc .createTextNode(listenersItem.getCertificateThumbprint())); listenerElement.appendChild(certificateThumbprintElement); } Element protocolElement3 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement3.appendChild( requestDoc.createTextNode(listenersItem.getListenerType().toString())); listenerElement.appendChild(protocolElement3); } winRMElement.appendChild(listenersSequenceElement); } } } if (configurationSetsItem.getAdminUserName() != null) { Element adminUsernameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AdminUsername"); adminUsernameElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getAdminUserName())); configurationSetElement.appendChild(adminUsernameElement); } if (configurationSetsItem.getAdditionalUnattendContent() != null) { Element additionalUnattendContentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "AdditionalUnattendContent"); configurationSetElement.appendChild(additionalUnattendContentElement); if (configurationSetsItem.getAdditionalUnattendContent().getUnattendPasses() != null) { if (configurationSetsItem.getAdditionalUnattendContent() .getUnattendPasses() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getAdditionalUnattendContent() .getUnattendPasses()).isInitialized()) { Element passesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Passes"); for (UnattendPassSettings passesItem : configurationSetsItem .getAdditionalUnattendContent().getUnattendPasses()) { Element unattendPassElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "UnattendPass"); passesSequenceElement.appendChild(unattendPassElement); Element passNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PassName"); passNameElement .appendChild(requestDoc.createTextNode(passesItem.getPassName())); unattendPassElement.appendChild(passNameElement); if (passesItem.getUnattendComponents() != null) { if (passesItem.getUnattendComponents() instanceof LazyCollection == false || ((LazyCollection) passesItem.getUnattendComponents()) .isInitialized()) { Element componentsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Components"); for (UnattendComponent componentsItem : passesItem .getUnattendComponents()) { Element unattendComponentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "UnattendComponent"); componentsSequenceElement.appendChild(unattendComponentElement); Element componentNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentName"); componentNameElement.appendChild(requestDoc .createTextNode(componentsItem.getComponentName())); unattendComponentElement.appendChild(componentNameElement); if (componentsItem.getUnattendComponentSettings() != null) { if (componentsItem .getUnattendComponentSettings() instanceof LazyCollection == false || ((LazyCollection) componentsItem .getUnattendComponentSettings()) .isInitialized()) { Element componentSettingsSequenceElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentSettings"); for (ComponentSetting componentSettingsItem : componentsItem .getUnattendComponentSettings()) { Element componentSettingElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentSetting"); componentSettingsSequenceElement .appendChild(componentSettingElement); Element settingNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SettingName"); settingNameElement.appendChild( requestDoc.createTextNode(componentSettingsItem .getSettingName())); componentSettingElement.appendChild(settingNameElement); if (componentSettingsItem.getContent() != null) { Element contentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Content"); contentElement .appendChild(requestDoc.createTextNode( Base64.encode(componentSettingsItem .getContent().getBytes()))); componentSettingElement.appendChild(contentElement); } } unattendComponentElement .appendChild(componentSettingsSequenceElement); } } } unattendPassElement.appendChild(componentsSequenceElement); } } } additionalUnattendContentElement.appendChild(passesSequenceElement); } } } if (configurationSetsItem.getHostName() != null) { Element hostNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostName"); hostNameElement.appendChild(requestDoc.createTextNode(configurationSetsItem.getHostName())); configurationSetElement.appendChild(hostNameElement); } if (configurationSetsItem.getUserName() != null) { Element userNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "UserName"); userNameElement.appendChild(requestDoc.createTextNode(configurationSetsItem.getUserName())); configurationSetElement.appendChild(userNameElement); } if (configurationSetsItem.getUserPassword() != null) { Element userPasswordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "UserPassword"); userPasswordElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getUserPassword())); configurationSetElement.appendChild(userPasswordElement); } if (configurationSetsItem.isDisableSshPasswordAuthentication() != null) { Element disableSshPasswordAuthenticationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DisableSshPasswordAuthentication"); disableSshPasswordAuthenticationElement.appendChild(requestDoc.createTextNode( Boolean.toString(configurationSetsItem.isDisableSshPasswordAuthentication()) .toLowerCase())); configurationSetElement.appendChild(disableSshPasswordAuthenticationElement); } if (configurationSetsItem.getSshSettings() != null) { Element sSHElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SSH"); configurationSetElement.appendChild(sSHElement); if (configurationSetsItem.getSshSettings().getPublicKeys() != null) { if (configurationSetsItem.getSshSettings() .getPublicKeys() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSshSettings().getPublicKeys()) .isInitialized()) { Element publicKeysSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicKeys"); for (SshSettingPublicKey publicKeysItem : configurationSetsItem.getSshSettings() .getPublicKeys()) { Element publicKeyElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PublicKey"); publicKeysSequenceElement.appendChild(publicKeyElement); Element fingerprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Fingerprint"); fingerprintElement.appendChild( requestDoc.createTextNode(publicKeysItem.getFingerprint())); publicKeyElement.appendChild(fingerprintElement); Element pathElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Path"); pathElement2.appendChild(requestDoc.createTextNode(publicKeysItem.getPath())); publicKeyElement.appendChild(pathElement2); } sSHElement.appendChild(publicKeysSequenceElement); } } if (configurationSetsItem.getSshSettings().getKeyPairs() != null) { if (configurationSetsItem.getSshSettings() .getKeyPairs() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSshSettings().getKeyPairs()) .isInitialized()) { Element keyPairsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "KeyPairs"); for (SshSettingKeyPair keyPairsItem : configurationSetsItem.getSshSettings() .getKeyPairs()) { Element keyPairElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "KeyPair"); keyPairsSequenceElement.appendChild(keyPairElement); Element fingerprintElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Fingerprint"); fingerprintElement2 .appendChild(requestDoc.createTextNode(keyPairsItem.getFingerprint())); keyPairElement.appendChild(fingerprintElement2); Element pathElement3 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Path"); pathElement3.appendChild(requestDoc.createTextNode(keyPairsItem.getPath())); keyPairElement.appendChild(pathElement3); } sSHElement.appendChild(keyPairsSequenceElement); } } } if (configurationSetsItem.getCustomData() != null) { Element customDataElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CustomData"); customDataElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getCustomData())); configurationSetElement.appendChild(customDataElement); } } persistentVMRoleElement.appendChild(configurationSetsSequenceElement); } } if (parameters.getResourceExtensionReferences() != null) { if (parameters.getResourceExtensionReferences() instanceof LazyCollection == false || ((LazyCollection) parameters.getResourceExtensionReferences()).isInitialized()) { Element resourceExtensionReferencesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionReferences"); for (ResourceExtensionReference resourceExtensionReferencesItem : parameters .getResourceExtensionReferences()) { Element resourceExtensionReferenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionReference"); resourceExtensionReferencesSequenceElement.appendChild(resourceExtensionReferenceElement); if (resourceExtensionReferencesItem.getReferenceName() != null) { Element referenceNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ReferenceName"); referenceNameElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getReferenceName())); resourceExtensionReferenceElement.appendChild(referenceNameElement); } if (resourceExtensionReferencesItem.getPublisher() != null) { Element publisherElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Publisher"); publisherElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getPublisher())); resourceExtensionReferenceElement.appendChild(publisherElement); } if (resourceExtensionReferencesItem.getName() != null) { Element nameElement4 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement4 .appendChild(requestDoc.createTextNode(resourceExtensionReferencesItem.getName())); resourceExtensionReferenceElement.appendChild(nameElement4); } if (resourceExtensionReferencesItem.getVersion() != null) { Element versionElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Version"); versionElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getVersion())); resourceExtensionReferenceElement.appendChild(versionElement); } if (resourceExtensionReferencesItem.getResourceExtensionParameterValues() != null) { if (resourceExtensionReferencesItem .getResourceExtensionParameterValues() instanceof LazyCollection == false || ((LazyCollection) resourceExtensionReferencesItem .getResourceExtensionParameterValues()).isInitialized()) { Element resourceExtensionParameterValuesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionParameterValues"); for (ResourceExtensionParameterValue resourceExtensionParameterValuesItem : resourceExtensionReferencesItem .getResourceExtensionParameterValues()) { Element resourceExtensionParameterValueElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionParameterValue"); resourceExtensionParameterValuesSequenceElement .appendChild(resourceExtensionParameterValueElement); if (resourceExtensionParameterValuesItem.getKey() != null) { Element keyElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Key"); keyElement.appendChild(requestDoc .createTextNode(resourceExtensionParameterValuesItem.getKey())); resourceExtensionParameterValueElement.appendChild(keyElement); } if (resourceExtensionParameterValuesItem.getValue() != null) { Element valueElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Value"); valueElement.appendChild(requestDoc.createTextNode(Base64 .encode(resourceExtensionParameterValuesItem.getValue().getBytes()))); resourceExtensionParameterValueElement.appendChild(valueElement); } if (resourceExtensionParameterValuesItem.getType() != null) { Element typeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Type"); typeElement.appendChild(requestDoc .createTextNode(resourceExtensionParameterValuesItem.getType())); resourceExtensionParameterValueElement.appendChild(typeElement); } } resourceExtensionReferenceElement .appendChild(resourceExtensionParameterValuesSequenceElement); } } if (resourceExtensionReferencesItem.getState() != null) { Element stateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "State"); stateElement .appendChild(requestDoc.createTextNode(resourceExtensionReferencesItem.getState())); resourceExtensionReferenceElement.appendChild(stateElement); } if (resourceExtensionReferencesItem.isForceUpdate() != null) { Element forceUpdateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ForceUpdate"); forceUpdateElement.appendChild(requestDoc.createTextNode( Boolean.toString(resourceExtensionReferencesItem.isForceUpdate()).toLowerCase())); resourceExtensionReferenceElement.appendChild(forceUpdateElement); } } persistentVMRoleElement.appendChild(resourceExtensionReferencesSequenceElement); } } if (parameters.getAvailabilitySetName() != null) { Element availabilitySetNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AvailabilitySetName"); availabilitySetNameElement.appendChild(requestDoc.createTextNode(parameters.getAvailabilitySetName())); persistentVMRoleElement.appendChild(availabilitySetNameElement); } if (parameters.getDataVirtualHardDisks() != null) { if (parameters.getDataVirtualHardDisks() instanceof LazyCollection == false || ((LazyCollection) parameters.getDataVirtualHardDisks()).isInitialized()) { Element dataVirtualHardDisksSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DataVirtualHardDisks"); for (DataVirtualHardDisk dataVirtualHardDisksItem : parameters.getDataVirtualHardDisks()) { Element dataVirtualHardDiskElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DataVirtualHardDisk"); dataVirtualHardDisksSequenceElement.appendChild(dataVirtualHardDiskElement); if (dataVirtualHardDisksItem.getHostCaching() != null) { Element hostCachingElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostCaching"); hostCachingElement .appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getHostCaching())); dataVirtualHardDiskElement.appendChild(hostCachingElement); } if (dataVirtualHardDisksItem.getLabel() != null) { Element diskLabelElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DiskLabel"); diskLabelElement .appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getLabel())); dataVirtualHardDiskElement.appendChild(diskLabelElement); } if (dataVirtualHardDisksItem.getName() != null) { Element diskNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DiskName"); diskNameElement.appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getName())); dataVirtualHardDiskElement.appendChild(diskNameElement); } if (dataVirtualHardDisksItem.getLogicalUnitNumber() != null) { Element lunElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Lun"); lunElement.appendChild(requestDoc .createTextNode(Integer.toString(dataVirtualHardDisksItem.getLogicalUnitNumber()))); dataVirtualHardDiskElement.appendChild(lunElement); } if (dataVirtualHardDisksItem.getLogicalDiskSizeInGB() != null) { Element logicalDiskSizeInGBElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LogicalDiskSizeInGB"); logicalDiskSizeInGBElement.appendChild(requestDoc.createTextNode( Integer.toString(dataVirtualHardDisksItem.getLogicalDiskSizeInGB()))); dataVirtualHardDiskElement.appendChild(logicalDiskSizeInGBElement); } if (dataVirtualHardDisksItem.getMediaLink() != null) { Element mediaLinkElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLink"); mediaLinkElement.appendChild( requestDoc.createTextNode(dataVirtualHardDisksItem.getMediaLink().toString())); dataVirtualHardDiskElement.appendChild(mediaLinkElement); } if (dataVirtualHardDisksItem.getSourceMediaLink() != null) { Element sourceMediaLinkElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SourceMediaLink"); sourceMediaLinkElement.appendChild(requestDoc .createTextNode(dataVirtualHardDisksItem.getSourceMediaLink().toString())); dataVirtualHardDiskElement.appendChild(sourceMediaLinkElement); } if (dataVirtualHardDisksItem.getIOType() != null) { Element iOTypeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IOType"); iOTypeElement.appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getIOType())); dataVirtualHardDiskElement.appendChild(iOTypeElement); } } persistentVMRoleElement.appendChild(dataVirtualHardDisksSequenceElement); } } Element oSVirtualHardDiskElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OSVirtualHardDisk"); persistentVMRoleElement.appendChild(oSVirtualHardDiskElement); if (parameters.getOSVirtualHardDisk().getHostCaching() != null) { Element hostCachingElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "HostCaching"); hostCachingElement2 .appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getHostCaching())); oSVirtualHardDiskElement.appendChild(hostCachingElement2); } if (parameters.getOSVirtualHardDisk().getLabel() != null) { Element diskLabelElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "DiskLabel"); diskLabelElement2.appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getLabel())); oSVirtualHardDiskElement.appendChild(diskLabelElement2); } if (parameters.getOSVirtualHardDisk().getName() != null) { Element diskNameElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "DiskName"); diskNameElement2.appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getName())); oSVirtualHardDiskElement.appendChild(diskNameElement2); } if (parameters.getOSVirtualHardDisk().getMediaLink() != null) { Element mediaLinkElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLink"); mediaLinkElement2.appendChild( requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getMediaLink().toString())); oSVirtualHardDiskElement.appendChild(mediaLinkElement2); } if (parameters.getOSVirtualHardDisk().getSourceImageName() != null) { Element sourceImageNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SourceImageName"); sourceImageNameElement .appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getSourceImageName())); oSVirtualHardDiskElement.appendChild(sourceImageNameElement); } if (parameters.getOSVirtualHardDisk().getOperatingSystem() != null) { Element osElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OS"); osElement .appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getOperatingSystem())); oSVirtualHardDiskElement.appendChild(osElement); } if (parameters.getOSVirtualHardDisk().getRemoteSourceImageLink() != null) { Element remoteSourceImageLinkElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "RemoteSourceImageLink"); remoteSourceImageLinkElement.appendChild(requestDoc .createTextNode(parameters.getOSVirtualHardDisk().getRemoteSourceImageLink().toString())); oSVirtualHardDiskElement.appendChild(remoteSourceImageLinkElement); } if (parameters.getOSVirtualHardDisk().getIOType() != null) { Element iOTypeElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "IOType"); iOTypeElement2.appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getIOType())); oSVirtualHardDiskElement.appendChild(iOTypeElement2); } if (parameters.getOSVirtualHardDisk().getResizedSizeInGB() != null) { Element resizedSizeInGBElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ResizedSizeInGB"); resizedSizeInGBElement.appendChild(requestDoc .createTextNode(Integer.toString(parameters.getOSVirtualHardDisk().getResizedSizeInGB()))); oSVirtualHardDiskElement.appendChild(resizedSizeInGBElement); } if (parameters.getRoleSize() != null) { Element roleSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "RoleSize"); roleSizeElement.appendChild(requestDoc.createTextNode(parameters.getRoleSize())); persistentVMRoleElement.appendChild(roleSizeElement); } if (parameters.isProvisionGuestAgent() != null) { Element provisionGuestAgentElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ProvisionGuestAgent"); provisionGuestAgentElement.appendChild( requestDoc.createTextNode(Boolean.toString(parameters.isProvisionGuestAgent()).toLowerCase())); persistentVMRoleElement.appendChild(provisionGuestAgentElement); } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; // Deserialize Response result = new OperationResponse(); 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.VirtualMachineOperationsImpl.java
/** * The Begin Creating Role operation adds a virtual machine to an existing * deployment. You can refer to the OSDisk in the Add Role operation in the * following ways: Platform/User Image - Set the SourceImageName to a * platform or user image. You can optionally specify the DiskName and * MediaLink values as part the operation to control the name and location * of target disk. When DiskName and MediaLink are specified in this mode, * they must not already exist in the system, otherwise a conflict fault is * returned; UserDisk - Set DiskName to a user supplied image in image * repository. SourceImageName must be set to NULL. All other properties * are ignored; or Blob in a Storage Account - Set MediaLink to a blob * containing the image. SourceImageName and DiskName are set to NULL. * (see http://msdn.microsoft.com/en-us/library/windowsazure/jj157186.aspx * for more information)//from w w w . j ava2s.com * * @param serviceName Required. The name of your service. * @param deploymentName Required. The name of your deployment. * @param parameters Required. Parameters supplied to the Begin Creating * Virtual Machine operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return A standard service response including an HTTP status code and * request ID. */ @Override public OperationResponse beginCreating(String serviceName, String deploymentName, VirtualMachineCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getConfigurationSets() != null) { for (ConfigurationSet configurationSetsParameterItem : parameters.getConfigurationSets()) { if (configurationSetsParameterItem.getAdditionalUnattendContent() != null) { if (configurationSetsParameterItem.getAdditionalUnattendContent().getUnattendPasses() != null) { for (UnattendPassSettings unattendPassesParameterItem : configurationSetsParameterItem .getAdditionalUnattendContent().getUnattendPasses()) { if (unattendPassesParameterItem.getPassName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.PassName"); } if (unattendPassesParameterItem.getUnattendComponents() != null) { for (UnattendComponent unattendComponentsParameterItem : unattendPassesParameterItem .getUnattendComponents()) { if (unattendComponentsParameterItem.getComponentName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.UnattendComponents.ComponentName"); } if (unattendComponentsParameterItem.getUnattendComponentSettings() != null) { for (ComponentSetting unattendComponentSettingsParameterItem : unattendComponentsParameterItem .getUnattendComponentSettings()) { if (unattendComponentSettingsParameterItem.getSettingName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.UnattendComponents.UnattendComponentSettings.SettingName"); } } } } } } } } if (configurationSetsParameterItem.getDomainJoin() != null) { if (configurationSetsParameterItem.getDomainJoin().getCredentials() != null) { if (configurationSetsParameterItem.getDomainJoin().getCredentials().getPassword() == null) { throw new NullPointerException( "parameters.ConfigurationSets.DomainJoin.Credentials.Password"); } if (configurationSetsParameterItem.getDomainJoin().getCredentials().getUserName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.DomainJoin.Credentials.UserName"); } } } if (configurationSetsParameterItem.getHostName() != null && configurationSetsParameterItem.getHostName().length() < 1) { throw new IllegalArgumentException("parameters.ConfigurationSets.HostName"); } if (configurationSetsParameterItem.getHostName() != null && configurationSetsParameterItem.getHostName().length() > 64) { throw new IllegalArgumentException("parameters.ConfigurationSets.HostName"); } if (configurationSetsParameterItem.getSshSettings() != null) { if (configurationSetsParameterItem.getSshSettings().getKeyPairs() != null) { for (SshSettingKeyPair keyPairsParameterItem : configurationSetsParameterItem .getSshSettings().getKeyPairs()) { if (keyPairsParameterItem.getFingerprint() == null) { throw new NullPointerException( "parameters.ConfigurationSets.SshSettings.KeyPairs.Fingerprint"); } if (keyPairsParameterItem.getPath() == null) { throw new NullPointerException( "parameters.ConfigurationSets.SshSettings.KeyPairs.Path"); } } } if (configurationSetsParameterItem.getSshSettings().getPublicKeys() != null) { for (SshSettingPublicKey publicKeysParameterItem : configurationSetsParameterItem .getSshSettings().getPublicKeys()) { if (publicKeysParameterItem.getFingerprint() == null) { throw new NullPointerException( "parameters.ConfigurationSets.SshSettings.PublicKeys.Fingerprint"); } if (publicKeysParameterItem.getPath() == null) { throw new NullPointerException( "parameters.ConfigurationSets.SshSettings.PublicKeys.Path"); } } } } if (configurationSetsParameterItem.getStoredCertificateSettings() != null) { for (StoredCertificateSettings storedCertificateSettingsParameterItem : configurationSetsParameterItem .getStoredCertificateSettings()) { if (storedCertificateSettingsParameterItem.getStoreName() == null) { throw new NullPointerException( "parameters.ConfigurationSets.StoredCertificateSettings.StoreName"); } if (storedCertificateSettingsParameterItem.getThumbprint() == null) { throw new NullPointerException( "parameters.ConfigurationSets.StoredCertificateSettings.Thumbprint"); } } } if (configurationSetsParameterItem.getUserName() != null && configurationSetsParameterItem.getUserName().length() < 1) { throw new IllegalArgumentException("parameters.ConfigurationSets.UserName"); } if (configurationSetsParameterItem.getUserName() != null && configurationSetsParameterItem.getUserName().length() > 32) { throw new IllegalArgumentException("parameters.ConfigurationSets.UserName"); } if (configurationSetsParameterItem.getUserPassword() != null && configurationSetsParameterItem.getUserPassword().length() < 6) { throw new IllegalArgumentException("parameters.ConfigurationSets.UserPassword"); } if (configurationSetsParameterItem.getUserPassword() != null && configurationSetsParameterItem.getUserPassword().length() > 72) { throw new IllegalArgumentException("parameters.ConfigurationSets.UserPassword"); } if (configurationSetsParameterItem.getWindowsRemoteManagement() != null) { if (configurationSetsParameterItem.getWindowsRemoteManagement().getListeners() != null) { for (WindowsRemoteManagementListener listenersParameterItem : configurationSetsParameterItem .getWindowsRemoteManagement().getListeners()) { if (listenersParameterItem.getListenerType() == null) { throw new NullPointerException( "parameters.ConfigurationSets.WindowsRemoteManagement.Listeners.ListenerType"); } } } } } } if (parameters.getRoleName() == null) { throw new NullPointerException("parameters.RoleName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCreatingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); url = url + "/roles"; 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 persistentVMRoleElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "PersistentVMRole"); requestDoc.appendChild(persistentVMRoleElement); Element roleNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "RoleName"); roleNameElement.appendChild(requestDoc.createTextNode(parameters.getRoleName())); persistentVMRoleElement.appendChild(roleNameElement); Element roleTypeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "RoleType"); roleTypeElement.appendChild(requestDoc.createTextNode("PersistentVMRole")); persistentVMRoleElement.appendChild(roleTypeElement); if (parameters.getConfigurationSets() != null) { if (parameters.getConfigurationSets() instanceof LazyCollection == false || ((LazyCollection) parameters.getConfigurationSets()).isInitialized()) { Element configurationSetsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ConfigurationSets"); for (ConfigurationSet configurationSetsItem : parameters.getConfigurationSets()) { Element configurationSetElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ConfigurationSet"); configurationSetsSequenceElement.appendChild(configurationSetElement); if (configurationSetsItem.getConfigurationSetType() != null) { Element configurationSetTypeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ConfigurationSetType"); configurationSetTypeElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getConfigurationSetType())); configurationSetElement.appendChild(configurationSetTypeElement); } if (configurationSetsItem.getInputEndpoints() != null) { if (configurationSetsItem.getInputEndpoints() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getInputEndpoints()).isInitialized()) { Element inputEndpointsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "InputEndpoints"); for (InputEndpoint inputEndpointsItem : configurationSetsItem.getInputEndpoints()) { Element inputEndpointElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "InputEndpoint"); inputEndpointsSequenceElement.appendChild(inputEndpointElement); if (inputEndpointsItem.getLoadBalancedEndpointSetName() != null) { Element loadBalancedEndpointSetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancedEndpointSetName"); loadBalancedEndpointSetNameElement.appendChild(requestDoc .createTextNode(inputEndpointsItem.getLoadBalancedEndpointSetName())); inputEndpointElement.appendChild(loadBalancedEndpointSetNameElement); } if (inputEndpointsItem.getLocalPort() != null) { Element localPortElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LocalPort"); localPortElement.appendChild(requestDoc .createTextNode(Integer.toString(inputEndpointsItem.getLocalPort()))); inputEndpointElement.appendChild(localPortElement); } if (inputEndpointsItem.getName() != null) { Element nameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement .appendChild(requestDoc.createTextNode(inputEndpointsItem.getName())); inputEndpointElement.appendChild(nameElement); } if (inputEndpointsItem.getPort() != null) { Element portElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Port"); portElement.appendChild(requestDoc .createTextNode(Integer.toString(inputEndpointsItem.getPort()))); inputEndpointElement.appendChild(portElement); } if (inputEndpointsItem.getLoadBalancerProbe() != null) { Element loadBalancerProbeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerProbe"); inputEndpointElement.appendChild(loadBalancerProbeElement); if (inputEndpointsItem.getLoadBalancerProbe().getPath() != null) { Element pathElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Path"); pathElement.appendChild(requestDoc.createTextNode( inputEndpointsItem.getLoadBalancerProbe().getPath())); loadBalancerProbeElement.appendChild(pathElement); } Element portElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Port"); portElement2.appendChild(requestDoc.createTextNode( Integer.toString(inputEndpointsItem.getLoadBalancerProbe().getPort()))); loadBalancerProbeElement.appendChild(portElement2); if (inputEndpointsItem.getLoadBalancerProbe().getProtocol() != null) { Element protocolElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement .appendChild(requestDoc.createTextNode(ComputeManagementClientImpl .loadBalancerProbeTransportProtocolToString( inputEndpointsItem.getLoadBalancerProbe() .getProtocol()))); loadBalancerProbeElement.appendChild(protocolElement); } if (inputEndpointsItem.getLoadBalancerProbe().getIntervalInSeconds() != null) { Element intervalInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IntervalInSeconds"); intervalInSecondsElement.appendChild( requestDoc.createTextNode(Integer.toString(inputEndpointsItem .getLoadBalancerProbe().getIntervalInSeconds()))); loadBalancerProbeElement.appendChild(intervalInSecondsElement); } if (inputEndpointsItem.getLoadBalancerProbe().getTimeoutInSeconds() != null) { Element timeoutInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "TimeoutInSeconds"); timeoutInSecondsElement.appendChild( requestDoc.createTextNode(Integer.toString(inputEndpointsItem .getLoadBalancerProbe().getTimeoutInSeconds()))); loadBalancerProbeElement.appendChild(timeoutInSecondsElement); } } if (inputEndpointsItem.getProtocol() != null) { Element protocolElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement2.appendChild( requestDoc.createTextNode(inputEndpointsItem.getProtocol())); inputEndpointElement.appendChild(protocolElement2); } if (inputEndpointsItem.getVirtualIPAddress() != null) { Element vipElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Vip"); vipElement.appendChild(requestDoc.createTextNode( inputEndpointsItem.getVirtualIPAddress().getHostAddress())); inputEndpointElement.appendChild(vipElement); } if (inputEndpointsItem.isEnableDirectServerReturn() != null) { Element enableDirectServerReturnElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EnableDirectServerReturn"); enableDirectServerReturnElement.appendChild(requestDoc.createTextNode( Boolean.toString(inputEndpointsItem.isEnableDirectServerReturn()) .toLowerCase())); inputEndpointElement.appendChild(enableDirectServerReturnElement); } if (inputEndpointsItem.getLoadBalancerName() != null) { Element loadBalancerNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerName"); loadBalancerNameElement.appendChild( requestDoc.createTextNode(inputEndpointsItem.getLoadBalancerName())); inputEndpointElement.appendChild(loadBalancerNameElement); } if (inputEndpointsItem.getEndpointAcl() != null) { Element endpointAclElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EndpointAcl"); inputEndpointElement.appendChild(endpointAclElement); if (inputEndpointsItem.getEndpointAcl().getRules() != null) { if (inputEndpointsItem.getEndpointAcl() .getRules() instanceof LazyCollection == false || ((LazyCollection) inputEndpointsItem.getEndpointAcl().getRules()) .isInitialized()) { Element rulesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Rules"); for (AccessControlListRule rulesItem : inputEndpointsItem .getEndpointAcl().getRules()) { Element ruleElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Rule"); rulesSequenceElement.appendChild(ruleElement); if (rulesItem.getOrder() != null) { Element orderElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Order"); orderElement.appendChild(requestDoc.createTextNode( Integer.toString(rulesItem.getOrder()))); ruleElement.appendChild(orderElement); } if (rulesItem.getAction() != null) { Element actionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Action"); actionElement.appendChild( requestDoc.createTextNode(rulesItem.getAction())); ruleElement.appendChild(actionElement); } if (rulesItem.getRemoteSubnet() != null) { Element remoteSubnetElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "RemoteSubnet"); remoteSubnetElement.appendChild( requestDoc.createTextNode(rulesItem.getRemoteSubnet())); ruleElement.appendChild(remoteSubnetElement); } if (rulesItem.getDescription() != null) { Element descriptionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Description"); descriptionElement.appendChild( requestDoc.createTextNode(rulesItem.getDescription())); ruleElement.appendChild(descriptionElement); } } endpointAclElement.appendChild(rulesSequenceElement); } } } if (inputEndpointsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement.appendChild(requestDoc.createTextNode( Integer.toString(inputEndpointsItem.getIdleTimeoutInMinutes()))); inputEndpointElement.appendChild(idleTimeoutInMinutesElement); } if (inputEndpointsItem.getLoadBalancerDistribution() != null) { Element loadBalancerDistributionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerDistribution"); loadBalancerDistributionElement.appendChild(requestDoc .createTextNode(inputEndpointsItem.getLoadBalancerDistribution())); inputEndpointElement.appendChild(loadBalancerDistributionElement); } if (inputEndpointsItem.getVirtualIPName() != null) { Element virtualIPNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "VirtualIPName"); virtualIPNameElement.appendChild( requestDoc.createTextNode(inputEndpointsItem.getVirtualIPName())); inputEndpointElement.appendChild(virtualIPNameElement); } } configurationSetElement.appendChild(inputEndpointsSequenceElement); } } if (configurationSetsItem.getSubnetNames() != null) { if (configurationSetsItem.getSubnetNames() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSubnetNames()).isInitialized()) { Element subnetNamesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetNames"); for (String subnetNamesItem : configurationSetsItem.getSubnetNames()) { Element subnetNamesItemElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNamesItemElement.appendChild(requestDoc.createTextNode(subnetNamesItem)); subnetNamesSequenceElement.appendChild(subnetNamesItemElement); } configurationSetElement.appendChild(subnetNamesSequenceElement); } } if (configurationSetsItem.getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement.appendChild(requestDoc .createTextNode(configurationSetsItem.getStaticVirtualNetworkIPAddress())); configurationSetElement.appendChild(staticVirtualNetworkIPAddressElement); } if (configurationSetsItem.getPublicIPs() != null) { if (configurationSetsItem.getPublicIPs() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getPublicIPs()).isInitialized()) { Element publicIPsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicIPs"); for (ConfigurationSet.PublicIP publicIPsItem : configurationSetsItem.getPublicIPs()) { Element publicIPElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicIP"); publicIPsSequenceElement.appendChild(publicIPElement); if (publicIPsItem.getName() != null) { Element nameElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement2.appendChild(requestDoc.createTextNode(publicIPsItem.getName())); publicIPElement.appendChild(nameElement2); } if (publicIPsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement2.appendChild(requestDoc.createTextNode( Integer.toString(publicIPsItem.getIdleTimeoutInMinutes()))); publicIPElement.appendChild(idleTimeoutInMinutesElement2); } if (publicIPsItem.getDomainNameLabel() != null) { Element domainNameLabelElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DomainNameLabel"); domainNameLabelElement.appendChild( requestDoc.createTextNode(publicIPsItem.getDomainNameLabel())); publicIPElement.appendChild(domainNameLabelElement); } } configurationSetElement.appendChild(publicIPsSequenceElement); } } if (configurationSetsItem.getNetworkInterfaces() != null) { if (configurationSetsItem.getNetworkInterfaces() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getNetworkInterfaces()) .isInitialized()) { Element networkInterfacesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkInterfaces"); for (NetworkInterface networkInterfacesItem : configurationSetsItem .getNetworkInterfaces()) { Element networkInterfaceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkInterface"); networkInterfacesSequenceElement.appendChild(networkInterfaceElement); if (networkInterfacesItem.getName() != null) { Element nameElement3 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement3.appendChild( requestDoc.createTextNode(networkInterfacesItem.getName())); networkInterfaceElement.appendChild(nameElement3); } if (networkInterfacesItem.getIPConfigurations() != null) { if (networkInterfacesItem .getIPConfigurations() instanceof LazyCollection == false || ((LazyCollection) networkInterfacesItem.getIPConfigurations()) .isInitialized()) { Element iPConfigurationsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPConfigurations"); for (IPConfiguration iPConfigurationsItem : networkInterfacesItem .getIPConfigurations()) { Element iPConfigurationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPConfiguration"); iPConfigurationsSequenceElement.appendChild(iPConfigurationElement); if (iPConfigurationsItem.getSubnetName() != null) { Element subnetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNameElement.appendChild(requestDoc .createTextNode(iPConfigurationsItem.getSubnetName())); iPConfigurationElement.appendChild(subnetNameElement); } if (iPConfigurationsItem.getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement2 = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement2 .appendChild(requestDoc.createTextNode(iPConfigurationsItem .getStaticVirtualNetworkIPAddress())); iPConfigurationElement .appendChild(staticVirtualNetworkIPAddressElement2); } } networkInterfaceElement.appendChild(iPConfigurationsSequenceElement); } } if (networkInterfacesItem.getNetworkSecurityGroup() != null) { Element networkSecurityGroupElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup"); networkSecurityGroupElement.appendChild(requestDoc .createTextNode(networkInterfacesItem.getNetworkSecurityGroup())); networkInterfaceElement.appendChild(networkSecurityGroupElement); } if (networkInterfacesItem.getIPForwarding() != null) { Element iPForwardingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPForwarding"); iPForwardingElement.appendChild( requestDoc.createTextNode(networkInterfacesItem.getIPForwarding())); networkInterfaceElement.appendChild(iPForwardingElement); } } configurationSetElement.appendChild(networkInterfacesSequenceElement); } } if (configurationSetsItem.getNetworkSecurityGroup() != null) { Element networkSecurityGroupElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup"); networkSecurityGroupElement2.appendChild( requestDoc.createTextNode(configurationSetsItem.getNetworkSecurityGroup())); configurationSetElement.appendChild(networkSecurityGroupElement2); } if (configurationSetsItem.getIPForwarding() != null) { Element iPForwardingElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IPForwarding"); iPForwardingElement2 .appendChild(requestDoc.createTextNode(configurationSetsItem.getIPForwarding())); configurationSetElement.appendChild(iPForwardingElement2); } if (configurationSetsItem.getComputerName() != null) { Element computerNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ComputerName"); computerNameElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getComputerName())); configurationSetElement.appendChild(computerNameElement); } if (configurationSetsItem.getAdminPassword() != null) { Element adminPasswordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AdminPassword"); adminPasswordElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getAdminPassword())); configurationSetElement.appendChild(adminPasswordElement); } if (configurationSetsItem.isResetPasswordOnFirstLogon() != null) { Element resetPasswordOnFirstLogonElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResetPasswordOnFirstLogon"); resetPasswordOnFirstLogonElement.appendChild(requestDoc.createTextNode(Boolean .toString(configurationSetsItem.isResetPasswordOnFirstLogon()).toLowerCase())); configurationSetElement.appendChild(resetPasswordOnFirstLogonElement); } if (configurationSetsItem.isEnableAutomaticUpdates() != null) { Element enableAutomaticUpdatesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EnableAutomaticUpdates"); enableAutomaticUpdatesElement.appendChild(requestDoc.createTextNode( Boolean.toString(configurationSetsItem.isEnableAutomaticUpdates()).toLowerCase())); configurationSetElement.appendChild(enableAutomaticUpdatesElement); } if (configurationSetsItem.getTimeZone() != null) { Element timeZoneElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "TimeZone"); timeZoneElement.appendChild(requestDoc.createTextNode(configurationSetsItem.getTimeZone())); configurationSetElement.appendChild(timeZoneElement); } if (configurationSetsItem.getDomainJoin() != null) { Element domainJoinElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DomainJoin"); configurationSetElement.appendChild(domainJoinElement); if (configurationSetsItem.getDomainJoin().getCredentials() != null) { Element credentialsElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Credentials"); domainJoinElement.appendChild(credentialsElement); if (configurationSetsItem.getDomainJoin().getCredentials().getDomain() != null) { Element domainElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Domain"); domainElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getCredentials().getDomain())); credentialsElement.appendChild(domainElement); } Element usernameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Username"); usernameElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getCredentials().getUserName())); credentialsElement.appendChild(usernameElement); Element passwordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Password"); passwordElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getCredentials().getPassword())); credentialsElement.appendChild(passwordElement); } if (configurationSetsItem.getDomainJoin().getDomainToJoin() != null) { Element joinDomainElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "JoinDomain"); joinDomainElement.appendChild(requestDoc .createTextNode(configurationSetsItem.getDomainJoin().getDomainToJoin())); domainJoinElement.appendChild(joinDomainElement); } if (configurationSetsItem.getDomainJoin().getLdapMachineObjectOU() != null) { Element machineObjectOUElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "MachineObjectOU"); machineObjectOUElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getLdapMachineObjectOU())); domainJoinElement.appendChild(machineObjectOUElement); } if (configurationSetsItem.getDomainJoin().getProvisioning() != null) { Element provisioningElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Provisioning"); domainJoinElement.appendChild(provisioningElement); if (configurationSetsItem.getDomainJoin().getProvisioning().getAccountData() != null) { Element accountDataElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "AccountData"); accountDataElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getProvisioning().getAccountData())); provisioningElement.appendChild(accountDataElement); } } } if (configurationSetsItem.getStoredCertificateSettings() != null) { if (configurationSetsItem.getStoredCertificateSettings() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getStoredCertificateSettings()) .isInitialized()) { Element storedCertificateSettingsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StoredCertificateSettings"); for (StoredCertificateSettings storedCertificateSettingsItem : configurationSetsItem .getStoredCertificateSettings()) { Element certificateSettingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "CertificateSetting"); storedCertificateSettingsSequenceElement.appendChild(certificateSettingElement); Element storeLocationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StoreLocation"); storeLocationElement.appendChild(requestDoc.createTextNode("LocalMachine")); certificateSettingElement.appendChild(storeLocationElement); Element storeNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "StoreName"); storeNameElement.appendChild( requestDoc.createTextNode(storedCertificateSettingsItem.getStoreName())); certificateSettingElement.appendChild(storeNameElement); Element thumbprintElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Thumbprint"); thumbprintElement.appendChild( requestDoc.createTextNode(storedCertificateSettingsItem.getThumbprint())); certificateSettingElement.appendChild(thumbprintElement); } configurationSetElement.appendChild(storedCertificateSettingsSequenceElement); } } if (configurationSetsItem.getWindowsRemoteManagement() != null) { Element winRMElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "WinRM"); configurationSetElement.appendChild(winRMElement); if (configurationSetsItem.getWindowsRemoteManagement().getListeners() != null) { if (configurationSetsItem.getWindowsRemoteManagement() .getListeners() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getWindowsRemoteManagement() .getListeners()).isInitialized()) { Element listenersSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Listeners"); for (WindowsRemoteManagementListener listenersItem : configurationSetsItem .getWindowsRemoteManagement().getListeners()) { Element listenerElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Listener"); listenersSequenceElement.appendChild(listenerElement); if (listenersItem.getCertificateThumbprint() != null) { Element certificateThumbprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "CertificateThumbprint"); certificateThumbprintElement.appendChild(requestDoc .createTextNode(listenersItem.getCertificateThumbprint())); listenerElement.appendChild(certificateThumbprintElement); } Element protocolElement3 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement3.appendChild( requestDoc.createTextNode(listenersItem.getListenerType().toString())); listenerElement.appendChild(protocolElement3); } winRMElement.appendChild(listenersSequenceElement); } } } if (configurationSetsItem.getAdminUserName() != null) { Element adminUsernameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AdminUsername"); adminUsernameElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getAdminUserName())); configurationSetElement.appendChild(adminUsernameElement); } if (configurationSetsItem.getAdditionalUnattendContent() != null) { Element additionalUnattendContentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "AdditionalUnattendContent"); configurationSetElement.appendChild(additionalUnattendContentElement); if (configurationSetsItem.getAdditionalUnattendContent().getUnattendPasses() != null) { if (configurationSetsItem.getAdditionalUnattendContent() .getUnattendPasses() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getAdditionalUnattendContent() .getUnattendPasses()).isInitialized()) { Element passesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Passes"); for (UnattendPassSettings passesItem : configurationSetsItem .getAdditionalUnattendContent().getUnattendPasses()) { Element unattendPassElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "UnattendPass"); passesSequenceElement.appendChild(unattendPassElement); Element passNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PassName"); passNameElement .appendChild(requestDoc.createTextNode(passesItem.getPassName())); unattendPassElement.appendChild(passNameElement); if (passesItem.getUnattendComponents() != null) { if (passesItem.getUnattendComponents() instanceof LazyCollection == false || ((LazyCollection) passesItem.getUnattendComponents()) .isInitialized()) { Element componentsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Components"); for (UnattendComponent componentsItem : passesItem .getUnattendComponents()) { Element unattendComponentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "UnattendComponent"); componentsSequenceElement.appendChild(unattendComponentElement); Element componentNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentName"); componentNameElement.appendChild(requestDoc .createTextNode(componentsItem.getComponentName())); unattendComponentElement.appendChild(componentNameElement); if (componentsItem.getUnattendComponentSettings() != null) { if (componentsItem .getUnattendComponentSettings() instanceof LazyCollection == false || ((LazyCollection) componentsItem .getUnattendComponentSettings()) .isInitialized()) { Element componentSettingsSequenceElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentSettings"); for (ComponentSetting componentSettingsItem : componentsItem .getUnattendComponentSettings()) { Element componentSettingElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentSetting"); componentSettingsSequenceElement .appendChild(componentSettingElement); Element settingNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SettingName"); settingNameElement.appendChild( requestDoc.createTextNode(componentSettingsItem .getSettingName())); componentSettingElement.appendChild(settingNameElement); if (componentSettingsItem.getContent() != null) { Element contentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Content"); contentElement .appendChild(requestDoc.createTextNode( Base64.encode(componentSettingsItem .getContent().getBytes()))); componentSettingElement.appendChild(contentElement); } } unattendComponentElement .appendChild(componentSettingsSequenceElement); } } } unattendPassElement.appendChild(componentsSequenceElement); } } } additionalUnattendContentElement.appendChild(passesSequenceElement); } } } if (configurationSetsItem.getHostName() != null) { Element hostNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostName"); hostNameElement.appendChild(requestDoc.createTextNode(configurationSetsItem.getHostName())); configurationSetElement.appendChild(hostNameElement); } if (configurationSetsItem.getUserName() != null) { Element userNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "UserName"); userNameElement.appendChild(requestDoc.createTextNode(configurationSetsItem.getUserName())); configurationSetElement.appendChild(userNameElement); } if (configurationSetsItem.getUserPassword() != null) { Element userPasswordElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "UserPassword"); userPasswordElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getUserPassword())); configurationSetElement.appendChild(userPasswordElement); } if (configurationSetsItem.isDisableSshPasswordAuthentication() != null) { Element disableSshPasswordAuthenticationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DisableSshPasswordAuthentication"); disableSshPasswordAuthenticationElement.appendChild(requestDoc.createTextNode( Boolean.toString(configurationSetsItem.isDisableSshPasswordAuthentication()) .toLowerCase())); configurationSetElement.appendChild(disableSshPasswordAuthenticationElement); } if (configurationSetsItem.getSshSettings() != null) { Element sSHElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SSH"); configurationSetElement.appendChild(sSHElement); if (configurationSetsItem.getSshSettings().getPublicKeys() != null) { if (configurationSetsItem.getSshSettings() .getPublicKeys() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSshSettings().getPublicKeys()) .isInitialized()) { Element publicKeysSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "PublicKeys"); for (SshSettingPublicKey publicKeysItem : configurationSetsItem.getSshSettings() .getPublicKeys()) { Element publicKeyElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PublicKey"); publicKeysSequenceElement.appendChild(publicKeyElement); Element fingerprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Fingerprint"); fingerprintElement.appendChild( requestDoc.createTextNode(publicKeysItem.getFingerprint())); publicKeyElement.appendChild(fingerprintElement); Element pathElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Path"); pathElement2.appendChild(requestDoc.createTextNode(publicKeysItem.getPath())); publicKeyElement.appendChild(pathElement2); } sSHElement.appendChild(publicKeysSequenceElement); } } if (configurationSetsItem.getSshSettings().getKeyPairs() != null) { if (configurationSetsItem.getSshSettings() .getKeyPairs() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSshSettings().getKeyPairs()) .isInitialized()) { Element keyPairsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "KeyPairs"); for (SshSettingKeyPair keyPairsItem : configurationSetsItem.getSshSettings() .getKeyPairs()) { Element keyPairElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "KeyPair"); keyPairsSequenceElement.appendChild(keyPairElement); Element fingerprintElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Fingerprint"); fingerprintElement2 .appendChild(requestDoc.createTextNode(keyPairsItem.getFingerprint())); keyPairElement.appendChild(fingerprintElement2); Element pathElement3 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Path"); pathElement3.appendChild(requestDoc.createTextNode(keyPairsItem.getPath())); keyPairElement.appendChild(pathElement3); } sSHElement.appendChild(keyPairsSequenceElement); } } } if (configurationSetsItem.getCustomData() != null) { Element customDataElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CustomData"); customDataElement .appendChild(requestDoc.createTextNode(configurationSetsItem.getCustomData())); configurationSetElement.appendChild(customDataElement); } } persistentVMRoleElement.appendChild(configurationSetsSequenceElement); } } if (parameters.getResourceExtensionReferences() != null) { if (parameters.getResourceExtensionReferences() instanceof LazyCollection == false || ((LazyCollection) parameters.getResourceExtensionReferences()).isInitialized()) { Element resourceExtensionReferencesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionReferences"); for (ResourceExtensionReference resourceExtensionReferencesItem : parameters .getResourceExtensionReferences()) { Element resourceExtensionReferenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionReference"); resourceExtensionReferencesSequenceElement.appendChild(resourceExtensionReferenceElement); if (resourceExtensionReferencesItem.getReferenceName() != null) { Element referenceNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ReferenceName"); referenceNameElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getReferenceName())); resourceExtensionReferenceElement.appendChild(referenceNameElement); } if (resourceExtensionReferencesItem.getPublisher() != null) { Element publisherElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Publisher"); publisherElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getPublisher())); resourceExtensionReferenceElement.appendChild(publisherElement); } if (resourceExtensionReferencesItem.getName() != null) { Element nameElement4 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement4 .appendChild(requestDoc.createTextNode(resourceExtensionReferencesItem.getName())); resourceExtensionReferenceElement.appendChild(nameElement4); } if (resourceExtensionReferencesItem.getVersion() != null) { Element versionElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Version"); versionElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getVersion())); resourceExtensionReferenceElement.appendChild(versionElement); } if (resourceExtensionReferencesItem.getResourceExtensionParameterValues() != null) { if (resourceExtensionReferencesItem .getResourceExtensionParameterValues() instanceof LazyCollection == false || ((LazyCollection) resourceExtensionReferencesItem .getResourceExtensionParameterValues()).isInitialized()) { Element resourceExtensionParameterValuesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionParameterValues"); for (ResourceExtensionParameterValue resourceExtensionParameterValuesItem : resourceExtensionReferencesItem .getResourceExtensionParameterValues()) { Element resourceExtensionParameterValueElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionParameterValue"); resourceExtensionParameterValuesSequenceElement .appendChild(resourceExtensionParameterValueElement); if (resourceExtensionParameterValuesItem.getKey() != null) { Element keyElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Key"); keyElement.appendChild(requestDoc .createTextNode(resourceExtensionParameterValuesItem.getKey())); resourceExtensionParameterValueElement.appendChild(keyElement); } if (resourceExtensionParameterValuesItem.getValue() != null) { Element valueElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Value"); valueElement.appendChild(requestDoc.createTextNode(Base64 .encode(resourceExtensionParameterValuesItem.getValue().getBytes()))); resourceExtensionParameterValueElement.appendChild(valueElement); } if (resourceExtensionParameterValuesItem.getType() != null) { Element typeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Type"); typeElement.appendChild(requestDoc .createTextNode(resourceExtensionParameterValuesItem.getType())); resourceExtensionParameterValueElement.appendChild(typeElement); } } resourceExtensionReferenceElement .appendChild(resourceExtensionParameterValuesSequenceElement); } } if (resourceExtensionReferencesItem.getState() != null) { Element stateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "State"); stateElement .appendChild(requestDoc.createTextNode(resourceExtensionReferencesItem.getState())); resourceExtensionReferenceElement.appendChild(stateElement); } if (resourceExtensionReferencesItem.isForceUpdate() != null) { Element forceUpdateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ForceUpdate"); forceUpdateElement.appendChild(requestDoc.createTextNode( Boolean.toString(resourceExtensionReferencesItem.isForceUpdate()).toLowerCase())); resourceExtensionReferenceElement.appendChild(forceUpdateElement); } } persistentVMRoleElement.appendChild(resourceExtensionReferencesSequenceElement); } } if (parameters.getVMImageName() != null) { Element vMImageNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "VMImageName"); vMImageNameElement.appendChild(requestDoc.createTextNode(parameters.getVMImageName())); persistentVMRoleElement.appendChild(vMImageNameElement); } if (parameters.getMediaLocation() != null) { Element mediaLocationElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLocation"); mediaLocationElement.appendChild(requestDoc.createTextNode(parameters.getMediaLocation().toString())); persistentVMRoleElement.appendChild(mediaLocationElement); } if (parameters.getAvailabilitySetName() != null) { Element availabilitySetNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AvailabilitySetName"); availabilitySetNameElement.appendChild(requestDoc.createTextNode(parameters.getAvailabilitySetName())); persistentVMRoleElement.appendChild(availabilitySetNameElement); } if (parameters.getDataVirtualHardDisks() != null) { if (parameters.getDataVirtualHardDisks() instanceof LazyCollection == false || ((LazyCollection) parameters.getDataVirtualHardDisks()).isInitialized()) { Element dataVirtualHardDisksSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DataVirtualHardDisks"); for (DataVirtualHardDisk dataVirtualHardDisksItem : parameters.getDataVirtualHardDisks()) { Element dataVirtualHardDiskElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DataVirtualHardDisk"); dataVirtualHardDisksSequenceElement.appendChild(dataVirtualHardDiskElement); if (dataVirtualHardDisksItem.getHostCaching() != null) { Element hostCachingElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostCaching"); hostCachingElement .appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getHostCaching())); dataVirtualHardDiskElement.appendChild(hostCachingElement); } if (dataVirtualHardDisksItem.getLabel() != null) { Element diskLabelElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DiskLabel"); diskLabelElement .appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getLabel())); dataVirtualHardDiskElement.appendChild(diskLabelElement); } if (dataVirtualHardDisksItem.getName() != null) { Element diskNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DiskName"); diskNameElement.appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getName())); dataVirtualHardDiskElement.appendChild(diskNameElement); } if (dataVirtualHardDisksItem.getLogicalUnitNumber() != null) { Element lunElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Lun"); lunElement.appendChild(requestDoc .createTextNode(Integer.toString(dataVirtualHardDisksItem.getLogicalUnitNumber()))); dataVirtualHardDiskElement.appendChild(lunElement); } if (dataVirtualHardDisksItem.getLogicalDiskSizeInGB() != null) { Element logicalDiskSizeInGBElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LogicalDiskSizeInGB"); logicalDiskSizeInGBElement.appendChild(requestDoc.createTextNode( Integer.toString(dataVirtualHardDisksItem.getLogicalDiskSizeInGB()))); dataVirtualHardDiskElement.appendChild(logicalDiskSizeInGBElement); } if (dataVirtualHardDisksItem.getMediaLink() != null) { Element mediaLinkElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLink"); mediaLinkElement.appendChild( requestDoc.createTextNode(dataVirtualHardDisksItem.getMediaLink().toString())); dataVirtualHardDiskElement.appendChild(mediaLinkElement); } if (dataVirtualHardDisksItem.getSourceMediaLink() != null) { Element sourceMediaLinkElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SourceMediaLink"); sourceMediaLinkElement.appendChild(requestDoc .createTextNode(dataVirtualHardDisksItem.getSourceMediaLink().toString())); dataVirtualHardDiskElement.appendChild(sourceMediaLinkElement); } if (dataVirtualHardDisksItem.getIOType() != null) { Element iOTypeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IOType"); iOTypeElement.appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getIOType())); dataVirtualHardDiskElement.appendChild(iOTypeElement); } } persistentVMRoleElement.appendChild(dataVirtualHardDisksSequenceElement); } } if (parameters.getOSVirtualHardDisk() != null) { Element oSVirtualHardDiskElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "OSVirtualHardDisk"); persistentVMRoleElement.appendChild(oSVirtualHardDiskElement); if (parameters.getOSVirtualHardDisk().getHostCaching() != null) { Element hostCachingElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostCaching"); hostCachingElement2 .appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getHostCaching())); oSVirtualHardDiskElement.appendChild(hostCachingElement2); } if (parameters.getOSVirtualHardDisk().getLabel() != null) { Element diskLabelElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "DiskLabel"); diskLabelElement2 .appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getLabel())); oSVirtualHardDiskElement.appendChild(diskLabelElement2); } if (parameters.getOSVirtualHardDisk().getName() != null) { Element diskNameElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "DiskName"); diskNameElement2 .appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getName())); oSVirtualHardDiskElement.appendChild(diskNameElement2); } if (parameters.getOSVirtualHardDisk().getMediaLink() != null) { Element mediaLinkElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLink"); mediaLinkElement2.appendChild( requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getMediaLink().toString())); oSVirtualHardDiskElement.appendChild(mediaLinkElement2); } if (parameters.getOSVirtualHardDisk().getSourceImageName() != null) { Element sourceImageNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SourceImageName"); sourceImageNameElement.appendChild( requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getSourceImageName())); oSVirtualHardDiskElement.appendChild(sourceImageNameElement); } if (parameters.getOSVirtualHardDisk().getOperatingSystem() != null) { Element osElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OS"); osElement.appendChild( requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getOperatingSystem())); oSVirtualHardDiskElement.appendChild(osElement); } if (parameters.getOSVirtualHardDisk().getRemoteSourceImageLink() != null) { Element remoteSourceImageLinkElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "RemoteSourceImageLink"); remoteSourceImageLinkElement.appendChild(requestDoc .createTextNode(parameters.getOSVirtualHardDisk().getRemoteSourceImageLink().toString())); oSVirtualHardDiskElement.appendChild(remoteSourceImageLinkElement); } if (parameters.getOSVirtualHardDisk().getIOType() != null) { Element iOTypeElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "IOType"); iOTypeElement2 .appendChild(requestDoc.createTextNode(parameters.getOSVirtualHardDisk().getIOType())); oSVirtualHardDiskElement.appendChild(iOTypeElement2); } if (parameters.getOSVirtualHardDisk().getResizedSizeInGB() != null) { Element resizedSizeInGBElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ResizedSizeInGB"); resizedSizeInGBElement.appendChild(requestDoc .createTextNode(Integer.toString(parameters.getOSVirtualHardDisk().getResizedSizeInGB()))); oSVirtualHardDiskElement.appendChild(resizedSizeInGBElement); } } if (parameters.getRoleSize() != null) { Element roleSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "RoleSize"); roleSizeElement.appendChild(requestDoc.createTextNode(parameters.getRoleSize())); persistentVMRoleElement.appendChild(roleSizeElement); } if (parameters.isProvisionGuestAgent() != null) { Element provisionGuestAgentElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ProvisionGuestAgent"); provisionGuestAgentElement.appendChild( requestDoc.createTextNode(Boolean.toString(parameters.isProvisionGuestAgent()).toLowerCase())); persistentVMRoleElement.appendChild(provisionGuestAgentElement); } if (parameters.getVMImageInput() != null) { Element vMImageInputElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "VMImageInput"); persistentVMRoleElement.appendChild(vMImageInputElement); } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; // Deserialize Response result = new OperationResponse(); 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.VirtualMachineOperationsImpl.java
/** * The Begin Creating Virtual Machine Deployment operation provisions a * virtual machine based on the supplied configuration. When you create a * deployment of a virtual machine, you should make sure that the cloud * service and the disk or image that you use are located in the same * region. For example, if the cloud service was created in the West US * region, the disk or image that you use should also be located in a * storage account in the West US region. (see * http://msdn.microsoft.com/en-us/library/windowsazure/jj157194.aspx for * more information)//from w ww.j a va 2 s .c o m * * @param serviceName Required. The name of your service. * @param parameters Required. Parameters supplied to the Begin Creating * Virtual Machine Deployment operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return A standard service response including an HTTP status code and * request ID. */ @Override public OperationResponse beginCreatingDeployment(String serviceName, VirtualMachineCreateDeploymentParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getDeploymentSlot() == null) { throw new NullPointerException("parameters.DeploymentSlot"); } if (parameters.getLabel() == null) { throw new NullPointerException("parameters.Label"); } if (parameters.getLabel().length() > 100) { throw new IllegalArgumentException("parameters.Label"); } if (parameters.getName() == null) { throw new NullPointerException("parameters.Name"); } if (parameters.getRoles() == null) { throw new NullPointerException("parameters.Roles"); } if (parameters.getRoles() != null) { for (Role rolesParameterItem : parameters.getRoles()) { if (rolesParameterItem.getConfigurationSets() != null) { for (ConfigurationSet configurationSetsParameterItem : rolesParameterItem .getConfigurationSets()) { if (configurationSetsParameterItem.getAdditionalUnattendContent() != null) { if (configurationSetsParameterItem.getAdditionalUnattendContent() .getUnattendPasses() != null) { for (UnattendPassSettings unattendPassesParameterItem : configurationSetsParameterItem .getAdditionalUnattendContent().getUnattendPasses()) { if (unattendPassesParameterItem.getPassName() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.PassName"); } if (unattendPassesParameterItem.getUnattendComponents() != null) { for (UnattendComponent unattendComponentsParameterItem : unattendPassesParameterItem .getUnattendComponents()) { if (unattendComponentsParameterItem.getComponentName() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.UnattendComponents.ComponentName"); } if (unattendComponentsParameterItem .getUnattendComponentSettings() != null) { for (ComponentSetting unattendComponentSettingsParameterItem : unattendComponentsParameterItem .getUnattendComponentSettings()) { if (unattendComponentSettingsParameterItem .getSettingName() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.AdditionalUnattendContent.UnattendPasses.UnattendComponents.UnattendComponentSettings.SettingName"); } } } } } } } } if (configurationSetsParameterItem.getDomainJoin() != null) { if (configurationSetsParameterItem.getDomainJoin().getCredentials() != null) { if (configurationSetsParameterItem.getDomainJoin().getCredentials() .getPassword() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.DomainJoin.Credentials.Password"); } if (configurationSetsParameterItem.getDomainJoin().getCredentials() .getUserName() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.DomainJoin.Credentials.UserName"); } } } if (configurationSetsParameterItem.getHostName() != null && configurationSetsParameterItem.getHostName().length() < 1) { throw new IllegalArgumentException("parameters.Roles.ConfigurationSets.HostName"); } if (configurationSetsParameterItem.getHostName() != null && configurationSetsParameterItem.getHostName().length() > 64) { throw new IllegalArgumentException("parameters.Roles.ConfigurationSets.HostName"); } if (configurationSetsParameterItem.getSshSettings() != null) { if (configurationSetsParameterItem.getSshSettings().getKeyPairs() != null) { for (SshSettingKeyPair keyPairsParameterItem : configurationSetsParameterItem .getSshSettings().getKeyPairs()) { if (keyPairsParameterItem.getFingerprint() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.SshSettings.KeyPairs.Fingerprint"); } if (keyPairsParameterItem.getPath() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.SshSettings.KeyPairs.Path"); } } } if (configurationSetsParameterItem.getSshSettings().getPublicKeys() != null) { for (SshSettingPublicKey publicKeysParameterItem : configurationSetsParameterItem .getSshSettings().getPublicKeys()) { if (publicKeysParameterItem.getFingerprint() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.SshSettings.PublicKeys.Fingerprint"); } if (publicKeysParameterItem.getPath() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.SshSettings.PublicKeys.Path"); } } } } if (configurationSetsParameterItem.getStoredCertificateSettings() != null) { for (StoredCertificateSettings storedCertificateSettingsParameterItem : configurationSetsParameterItem .getStoredCertificateSettings()) { if (storedCertificateSettingsParameterItem.getStoreName() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.StoredCertificateSettings.StoreName"); } if (storedCertificateSettingsParameterItem.getThumbprint() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.StoredCertificateSettings.Thumbprint"); } } } if (configurationSetsParameterItem.getUserName() != null && configurationSetsParameterItem.getUserName().length() < 1) { throw new IllegalArgumentException("parameters.Roles.ConfigurationSets.UserName"); } if (configurationSetsParameterItem.getUserName() != null && configurationSetsParameterItem.getUserName().length() > 32) { throw new IllegalArgumentException("parameters.Roles.ConfigurationSets.UserName"); } if (configurationSetsParameterItem.getUserPassword() != null && configurationSetsParameterItem.getUserPassword().length() < 6) { throw new IllegalArgumentException("parameters.Roles.ConfigurationSets.UserPassword"); } if (configurationSetsParameterItem.getUserPassword() != null && configurationSetsParameterItem.getUserPassword().length() > 72) { throw new IllegalArgumentException("parameters.Roles.ConfigurationSets.UserPassword"); } if (configurationSetsParameterItem.getWindowsRemoteManagement() != null) { if (configurationSetsParameterItem.getWindowsRemoteManagement() .getListeners() != null) { for (WindowsRemoteManagementListener listenersParameterItem : configurationSetsParameterItem .getWindowsRemoteManagement().getListeners()) { if (listenersParameterItem.getListenerType() == null) { throw new NullPointerException( "parameters.Roles.ConfigurationSets.WindowsRemoteManagement.Listeners.ListenerType"); } } } } } } } } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCreatingDeploymentAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments"; 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 deploymentElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Deployment"); requestDoc.appendChild(deploymentElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); deploymentElement.appendChild(nameElement); Element deploymentSlotElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "DeploymentSlot"); deploymentSlotElement.appendChild(requestDoc.createTextNode(parameters.getDeploymentSlot().toString())); deploymentElement.appendChild(deploymentSlotElement); Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label"); labelElement.appendChild(requestDoc.createTextNode(parameters.getLabel())); deploymentElement.appendChild(labelElement); if (parameters.getRoles() instanceof LazyCollection == false || ((LazyCollection) parameters.getRoles()).isInitialized()) { Element roleListSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "RoleList"); for (Role roleListItem : parameters.getRoles()) { Element roleElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Role"); roleListSequenceElement.appendChild(roleElement); if (roleListItem.getRoleName() != null) { Element roleNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "RoleName"); roleNameElement.appendChild(requestDoc.createTextNode(roleListItem.getRoleName())); roleElement.appendChild(roleNameElement); } if (roleListItem.getOSVersion() != null) { Element osVersionElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "OsVersion"); osVersionElement.appendChild(requestDoc.createTextNode(roleListItem.getOSVersion())); roleElement.appendChild(osVersionElement); } if (roleListItem.getRoleType() != null) { Element roleTypeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "RoleType"); roleTypeElement.appendChild(requestDoc.createTextNode(roleListItem.getRoleType())); roleElement.appendChild(roleTypeElement); } if (roleListItem.getConfigurationSets() != null) { if (roleListItem.getConfigurationSets() instanceof LazyCollection == false || ((LazyCollection) roleListItem.getConfigurationSets()).isInitialized()) { Element configurationSetsSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ConfigurationSets"); for (ConfigurationSet configurationSetsItem : roleListItem.getConfigurationSets()) { Element configurationSetElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ConfigurationSet"); configurationSetsSequenceElement.appendChild(configurationSetElement); if (configurationSetsItem.getConfigurationSetType() != null) { Element configurationSetTypeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ConfigurationSetType"); configurationSetTypeElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getConfigurationSetType())); configurationSetElement.appendChild(configurationSetTypeElement); } if (configurationSetsItem.getInputEndpoints() != null) { if (configurationSetsItem.getInputEndpoints() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getInputEndpoints()) .isInitialized()) { Element inputEndpointsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "InputEndpoints"); for (InputEndpoint inputEndpointsItem : configurationSetsItem .getInputEndpoints()) { Element inputEndpointElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "InputEndpoint"); inputEndpointsSequenceElement.appendChild(inputEndpointElement); if (inputEndpointsItem.getLoadBalancedEndpointSetName() != null) { Element loadBalancedEndpointSetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancedEndpointSetName"); loadBalancedEndpointSetNameElement .appendChild(requestDoc.createTextNode( inputEndpointsItem.getLoadBalancedEndpointSetName())); inputEndpointElement.appendChild(loadBalancedEndpointSetNameElement); } if (inputEndpointsItem.getLocalPort() != null) { Element localPortElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LocalPort"); localPortElement.appendChild(requestDoc.createTextNode( Integer.toString(inputEndpointsItem.getLocalPort()))); inputEndpointElement.appendChild(localPortElement); } if (inputEndpointsItem.getName() != null) { Element nameElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Name"); nameElement2.appendChild( requestDoc.createTextNode(inputEndpointsItem.getName())); inputEndpointElement.appendChild(nameElement2); } if (inputEndpointsItem.getPort() != null) { Element portElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Port"); portElement.appendChild(requestDoc.createTextNode( Integer.toString(inputEndpointsItem.getPort()))); inputEndpointElement.appendChild(portElement); } if (inputEndpointsItem.getLoadBalancerProbe() != null) { Element loadBalancerProbeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerProbe"); inputEndpointElement.appendChild(loadBalancerProbeElement); if (inputEndpointsItem.getLoadBalancerProbe().getPath() != null) { Element pathElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Path"); pathElement.appendChild(requestDoc.createTextNode( inputEndpointsItem.getLoadBalancerProbe().getPath())); loadBalancerProbeElement.appendChild(pathElement); } Element portElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Port"); portElement2.appendChild(requestDoc.createTextNode(Integer.toString( inputEndpointsItem.getLoadBalancerProbe().getPort()))); loadBalancerProbeElement.appendChild(portElement2); if (inputEndpointsItem.getLoadBalancerProbe().getProtocol() != null) { Element protocolElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement.appendChild( requestDoc.createTextNode(ComputeManagementClientImpl .loadBalancerProbeTransportProtocolToString( inputEndpointsItem.getLoadBalancerProbe() .getProtocol()))); loadBalancerProbeElement.appendChild(protocolElement); } if (inputEndpointsItem.getLoadBalancerProbe() .getIntervalInSeconds() != null) { Element intervalInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IntervalInSeconds"); intervalInSecondsElement.appendChild(requestDoc .createTextNode(Integer.toString(inputEndpointsItem .getLoadBalancerProbe().getIntervalInSeconds()))); loadBalancerProbeElement.appendChild(intervalInSecondsElement); } if (inputEndpointsItem.getLoadBalancerProbe() .getTimeoutInSeconds() != null) { Element timeoutInSecondsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "TimeoutInSeconds"); timeoutInSecondsElement.appendChild(requestDoc .createTextNode(Integer.toString(inputEndpointsItem .getLoadBalancerProbe().getTimeoutInSeconds()))); loadBalancerProbeElement.appendChild(timeoutInSecondsElement); } } if (inputEndpointsItem.getProtocol() != null) { Element protocolElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement2.appendChild( requestDoc.createTextNode(inputEndpointsItem.getProtocol())); inputEndpointElement.appendChild(protocolElement2); } if (inputEndpointsItem.getVirtualIPAddress() != null) { Element vipElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Vip"); vipElement.appendChild(requestDoc.createTextNode( inputEndpointsItem.getVirtualIPAddress().getHostAddress())); inputEndpointElement.appendChild(vipElement); } if (inputEndpointsItem.isEnableDirectServerReturn() != null) { Element enableDirectServerReturnElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EnableDirectServerReturn"); enableDirectServerReturnElement .appendChild(requestDoc.createTextNode(Boolean .toString( inputEndpointsItem.isEnableDirectServerReturn()) .toLowerCase())); inputEndpointElement.appendChild(enableDirectServerReturnElement); } if (inputEndpointsItem.getLoadBalancerName() != null) { Element loadBalancerNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerName"); loadBalancerNameElement.appendChild(requestDoc .createTextNode(inputEndpointsItem.getLoadBalancerName())); inputEndpointElement.appendChild(loadBalancerNameElement); } if (inputEndpointsItem.getEndpointAcl() != null) { Element endpointAclElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EndpointAcl"); inputEndpointElement.appendChild(endpointAclElement); if (inputEndpointsItem.getEndpointAcl().getRules() != null) { if (inputEndpointsItem.getEndpointAcl() .getRules() instanceof LazyCollection == false || ((LazyCollection) inputEndpointsItem.getEndpointAcl() .getRules()).isInitialized()) { Element rulesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Rules"); for (AccessControlListRule rulesItem : inputEndpointsItem .getEndpointAcl().getRules()) { Element ruleElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Rule"); rulesSequenceElement.appendChild(ruleElement); if (rulesItem.getOrder() != null) { Element orderElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Order"); orderElement.appendChild(requestDoc.createTextNode( Integer.toString(rulesItem.getOrder()))); ruleElement.appendChild(orderElement); } if (rulesItem.getAction() != null) { Element actionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Action"); actionElement.appendChild(requestDoc .createTextNode(rulesItem.getAction())); ruleElement.appendChild(actionElement); } if (rulesItem.getRemoteSubnet() != null) { Element remoteSubnetElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "RemoteSubnet"); remoteSubnetElement.appendChild(requestDoc .createTextNode(rulesItem.getRemoteSubnet())); ruleElement.appendChild(remoteSubnetElement); } if (rulesItem.getDescription() != null) { Element descriptionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Description"); descriptionElement.appendChild(requestDoc .createTextNode(rulesItem.getDescription())); ruleElement.appendChild(descriptionElement); } } endpointAclElement.appendChild(rulesSequenceElement); } } } if (inputEndpointsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement .appendChild(requestDoc.createTextNode(Integer.toString( inputEndpointsItem.getIdleTimeoutInMinutes()))); inputEndpointElement.appendChild(idleTimeoutInMinutesElement); } if (inputEndpointsItem.getLoadBalancerDistribution() != null) { Element loadBalancerDistributionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LoadBalancerDistribution"); loadBalancerDistributionElement.appendChild(requestDoc.createTextNode( inputEndpointsItem.getLoadBalancerDistribution())); inputEndpointElement.appendChild(loadBalancerDistributionElement); } if (inputEndpointsItem.getVirtualIPName() != null) { Element virtualIPNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "VirtualIPName"); virtualIPNameElement.appendChild(requestDoc .createTextNode(inputEndpointsItem.getVirtualIPName())); inputEndpointElement.appendChild(virtualIPNameElement); } } configurationSetElement.appendChild(inputEndpointsSequenceElement); } } if (configurationSetsItem.getSubnetNames() != null) { if (configurationSetsItem.getSubnetNames() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSubnetNames()) .isInitialized()) { Element subnetNamesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SubnetNames"); for (String subnetNamesItem : configurationSetsItem.getSubnetNames()) { Element subnetNamesItemElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNamesItemElement .appendChild(requestDoc.createTextNode(subnetNamesItem)); subnetNamesSequenceElement.appendChild(subnetNamesItemElement); } configurationSetElement.appendChild(subnetNamesSequenceElement); } } if (configurationSetsItem.getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement.appendChild(requestDoc .createTextNode(configurationSetsItem.getStaticVirtualNetworkIPAddress())); configurationSetElement.appendChild(staticVirtualNetworkIPAddressElement); } if (configurationSetsItem.getPublicIPs() != null) { if (configurationSetsItem.getPublicIPs() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getPublicIPs()) .isInitialized()) { Element publicIPsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PublicIPs"); for (ConfigurationSet.PublicIP publicIPsItem : configurationSetsItem .getPublicIPs()) { Element publicIPElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PublicIP"); publicIPsSequenceElement.appendChild(publicIPElement); if (publicIPsItem.getName() != null) { Element nameElement3 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Name"); nameElement3.appendChild( requestDoc.createTextNode(publicIPsItem.getName())); publicIPElement.appendChild(nameElement3); } if (publicIPsItem.getIdleTimeoutInMinutes() != null) { Element idleTimeoutInMinutesElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IdleTimeoutInMinutes"); idleTimeoutInMinutesElement2.appendChild(requestDoc.createTextNode( Integer.toString(publicIPsItem.getIdleTimeoutInMinutes()))); publicIPElement.appendChild(idleTimeoutInMinutesElement2); } if (publicIPsItem.getDomainNameLabel() != null) { Element domainNameLabelElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DomainNameLabel"); domainNameLabelElement.appendChild( requestDoc.createTextNode(publicIPsItem.getDomainNameLabel())); publicIPElement.appendChild(domainNameLabelElement); } } configurationSetElement.appendChild(publicIPsSequenceElement); } } if (configurationSetsItem.getNetworkInterfaces() != null) { if (configurationSetsItem.getNetworkInterfaces() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getNetworkInterfaces()) .isInitialized()) { Element networkInterfacesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkInterfaces"); for (NetworkInterface networkInterfacesItem : configurationSetsItem .getNetworkInterfaces()) { Element networkInterfaceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkInterface"); networkInterfacesSequenceElement.appendChild(networkInterfaceElement); if (networkInterfacesItem.getName() != null) { Element nameElement4 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Name"); nameElement4.appendChild( requestDoc.createTextNode(networkInterfacesItem.getName())); networkInterfaceElement.appendChild(nameElement4); } if (networkInterfacesItem.getIPConfigurations() != null) { if (networkInterfacesItem .getIPConfigurations() instanceof LazyCollection == false || ((LazyCollection) networkInterfacesItem .getIPConfigurations()).isInitialized()) { Element iPConfigurationsSequenceElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "IPConfigurations"); for (IPConfiguration iPConfigurationsItem : networkInterfacesItem .getIPConfigurations()) { Element iPConfigurationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPConfiguration"); iPConfigurationsSequenceElement .appendChild(iPConfigurationElement); if (iPConfigurationsItem.getSubnetName() != null) { Element subnetNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNameElement.appendChild(requestDoc.createTextNode( iPConfigurationsItem.getSubnetName())); iPConfigurationElement.appendChild(subnetNameElement); } if (iPConfigurationsItem .getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement2 = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement2.appendChild( requestDoc.createTextNode(iPConfigurationsItem .getStaticVirtualNetworkIPAddress())); iPConfigurationElement .appendChild(staticVirtualNetworkIPAddressElement2); } } networkInterfaceElement .appendChild(iPConfigurationsSequenceElement); } } if (networkInterfacesItem.getNetworkSecurityGroup() != null) { Element networkSecurityGroupElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup"); networkSecurityGroupElement.appendChild(requestDoc.createTextNode( networkInterfacesItem.getNetworkSecurityGroup())); networkInterfaceElement.appendChild(networkSecurityGroupElement); } if (networkInterfacesItem.getIPForwarding() != null) { Element iPForwardingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPForwarding"); iPForwardingElement.appendChild(requestDoc .createTextNode(networkInterfacesItem.getIPForwarding())); networkInterfaceElement.appendChild(iPForwardingElement); } } configurationSetElement.appendChild(networkInterfacesSequenceElement); } } if (configurationSetsItem.getNetworkSecurityGroup() != null) { Element networkSecurityGroupElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup"); networkSecurityGroupElement2.appendChild( requestDoc.createTextNode(configurationSetsItem.getNetworkSecurityGroup())); configurationSetElement.appendChild(networkSecurityGroupElement2); } if (configurationSetsItem.getIPForwarding() != null) { Element iPForwardingElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "IPForwarding"); iPForwardingElement2.appendChild( requestDoc.createTextNode(configurationSetsItem.getIPForwarding())); configurationSetElement.appendChild(iPForwardingElement2); } if (configurationSetsItem.getComputerName() != null) { Element computerNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ComputerName"); computerNameElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getComputerName())); configurationSetElement.appendChild(computerNameElement); } if (configurationSetsItem.getAdminPassword() != null) { Element adminPasswordElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "AdminPassword"); adminPasswordElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getAdminPassword())); configurationSetElement.appendChild(adminPasswordElement); } if (configurationSetsItem.isResetPasswordOnFirstLogon() != null) { Element resetPasswordOnFirstLogonElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResetPasswordOnFirstLogon"); resetPasswordOnFirstLogonElement.appendChild(requestDoc.createTextNode( Boolean.toString(configurationSetsItem.isResetPasswordOnFirstLogon()) .toLowerCase())); configurationSetElement.appendChild(resetPasswordOnFirstLogonElement); } if (configurationSetsItem.isEnableAutomaticUpdates() != null) { Element enableAutomaticUpdatesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "EnableAutomaticUpdates"); enableAutomaticUpdatesElement.appendChild(requestDoc.createTextNode(Boolean .toString(configurationSetsItem.isEnableAutomaticUpdates()).toLowerCase())); configurationSetElement.appendChild(enableAutomaticUpdatesElement); } if (configurationSetsItem.getTimeZone() != null) { Element timeZoneElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "TimeZone"); timeZoneElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getTimeZone())); configurationSetElement.appendChild(timeZoneElement); } if (configurationSetsItem.getDomainJoin() != null) { Element domainJoinElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DomainJoin"); configurationSetElement.appendChild(domainJoinElement); if (configurationSetsItem.getDomainJoin().getCredentials() != null) { Element credentialsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Credentials"); domainJoinElement.appendChild(credentialsElement); if (configurationSetsItem.getDomainJoin().getCredentials() .getDomain() != null) { Element domainElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Domain"); domainElement.appendChild(requestDoc.createTextNode(configurationSetsItem .getDomainJoin().getCredentials().getDomain())); credentialsElement.appendChild(domainElement); } Element usernameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Username"); usernameElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getCredentials().getUserName())); credentialsElement.appendChild(usernameElement); Element passwordElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Password"); passwordElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getCredentials().getPassword())); credentialsElement.appendChild(passwordElement); } if (configurationSetsItem.getDomainJoin().getDomainToJoin() != null) { Element joinDomainElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "JoinDomain"); joinDomainElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getDomainToJoin())); domainJoinElement.appendChild(joinDomainElement); } if (configurationSetsItem.getDomainJoin().getLdapMachineObjectOU() != null) { Element machineObjectOUElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "MachineObjectOU"); machineObjectOUElement.appendChild(requestDoc.createTextNode( configurationSetsItem.getDomainJoin().getLdapMachineObjectOU())); domainJoinElement.appendChild(machineObjectOUElement); } if (configurationSetsItem.getDomainJoin().getProvisioning() != null) { Element provisioningElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Provisioning"); domainJoinElement.appendChild(provisioningElement); if (configurationSetsItem.getDomainJoin().getProvisioning() .getAccountData() != null) { Element accountDataElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "AccountData"); accountDataElement .appendChild(requestDoc.createTextNode(configurationSetsItem .getDomainJoin().getProvisioning().getAccountData())); provisioningElement.appendChild(accountDataElement); } } } if (configurationSetsItem.getStoredCertificateSettings() != null) { if (configurationSetsItem .getStoredCertificateSettings() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getStoredCertificateSettings()) .isInitialized()) { Element storedCertificateSettingsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StoredCertificateSettings"); for (StoredCertificateSettings storedCertificateSettingsItem : configurationSetsItem .getStoredCertificateSettings()) { Element certificateSettingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "CertificateSetting"); storedCertificateSettingsSequenceElement .appendChild(certificateSettingElement); Element storeLocationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StoreLocation"); storeLocationElement.appendChild(requestDoc.createTextNode("LocalMachine")); certificateSettingElement.appendChild(storeLocationElement); Element storeNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StoreName"); storeNameElement.appendChild(requestDoc .createTextNode(storedCertificateSettingsItem.getStoreName())); certificateSettingElement.appendChild(storeNameElement); Element thumbprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Thumbprint"); thumbprintElement.appendChild(requestDoc .createTextNode(storedCertificateSettingsItem.getThumbprint())); certificateSettingElement.appendChild(thumbprintElement); } configurationSetElement.appendChild(storedCertificateSettingsSequenceElement); } } if (configurationSetsItem.getWindowsRemoteManagement() != null) { Element winRMElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "WinRM"); configurationSetElement.appendChild(winRMElement); if (configurationSetsItem.getWindowsRemoteManagement().getListeners() != null) { if (configurationSetsItem.getWindowsRemoteManagement() .getListeners() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getWindowsRemoteManagement() .getListeners()).isInitialized()) { Element listenersSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Listeners"); for (WindowsRemoteManagementListener listenersItem : configurationSetsItem .getWindowsRemoteManagement().getListeners()) { Element listenerElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Listener"); listenersSequenceElement.appendChild(listenerElement); if (listenersItem.getCertificateThumbprint() != null) { Element certificateThumbprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "CertificateThumbprint"); certificateThumbprintElement.appendChild(requestDoc .createTextNode(listenersItem.getCertificateThumbprint())); listenerElement.appendChild(certificateThumbprintElement); } Element protocolElement3 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Protocol"); protocolElement3.appendChild(requestDoc .createTextNode(listenersItem.getListenerType().toString())); listenerElement.appendChild(protocolElement3); } winRMElement.appendChild(listenersSequenceElement); } } } if (configurationSetsItem.getAdminUserName() != null) { Element adminUsernameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "AdminUsername"); adminUsernameElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getAdminUserName())); configurationSetElement.appendChild(adminUsernameElement); } if (configurationSetsItem.getAdditionalUnattendContent() != null) { Element additionalUnattendContentElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "AdditionalUnattendContent"); configurationSetElement.appendChild(additionalUnattendContentElement); if (configurationSetsItem.getAdditionalUnattendContent() .getUnattendPasses() != null) { if (configurationSetsItem.getAdditionalUnattendContent() .getUnattendPasses() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem .getAdditionalUnattendContent().getUnattendPasses()) .isInitialized()) { Element passesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Passes"); for (UnattendPassSettings passesItem : configurationSetsItem .getAdditionalUnattendContent().getUnattendPasses()) { Element unattendPassElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "UnattendPass"); passesSequenceElement.appendChild(unattendPassElement); Element passNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PassName"); passNameElement.appendChild( requestDoc.createTextNode(passesItem.getPassName())); unattendPassElement.appendChild(passNameElement); if (passesItem.getUnattendComponents() != null) { if (passesItem .getUnattendComponents() instanceof LazyCollection == false || ((LazyCollection) passesItem.getUnattendComponents()) .isInitialized()) { Element componentsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Components"); for (UnattendComponent componentsItem : passesItem .getUnattendComponents()) { Element unattendComponentElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "UnattendComponent"); componentsSequenceElement .appendChild(unattendComponentElement); Element componentNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentName"); componentNameElement.appendChild(requestDoc .createTextNode(componentsItem.getComponentName())); unattendComponentElement.appendChild(componentNameElement); if (componentsItem.getUnattendComponentSettings() != null) { if (componentsItem .getUnattendComponentSettings() instanceof LazyCollection == false || ((LazyCollection) componentsItem .getUnattendComponentSettings()) .isInitialized()) { Element componentSettingsSequenceElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentSettings"); for (ComponentSetting componentSettingsItem : componentsItem .getUnattendComponentSettings()) { Element componentSettingElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "ComponentSetting"); componentSettingsSequenceElement .appendChild(componentSettingElement); Element settingNameElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "SettingName"); settingNameElement.appendChild(requestDoc .createTextNode(componentSettingsItem .getSettingName())); componentSettingElement .appendChild(settingNameElement); if (componentSettingsItem .getContent() != null) { Element contentElement = requestDoc .createElementNS( "http://schemas.microsoft.com/windowsazure", "Content"); contentElement.appendChild(requestDoc .createTextNode(Base64.encode( componentSettingsItem .getContent() .getBytes()))); componentSettingElement .appendChild(contentElement); } } unattendComponentElement.appendChild( componentSettingsSequenceElement); } } } unattendPassElement.appendChild(componentsSequenceElement); } } } additionalUnattendContentElement.appendChild(passesSequenceElement); } } } if (configurationSetsItem.getHostName() != null) { Element hostNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostName"); hostNameElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getHostName())); configurationSetElement.appendChild(hostNameElement); } if (configurationSetsItem.getUserName() != null) { Element userNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "UserName"); userNameElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getUserName())); configurationSetElement.appendChild(userNameElement); } if (configurationSetsItem.getUserPassword() != null) { Element userPasswordElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "UserPassword"); userPasswordElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getUserPassword())); configurationSetElement.appendChild(userPasswordElement); } if (configurationSetsItem.isDisableSshPasswordAuthentication() != null) { Element disableSshPasswordAuthenticationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DisableSshPasswordAuthentication"); disableSshPasswordAuthenticationElement.appendChild(requestDoc.createTextNode( Boolean.toString(configurationSetsItem.isDisableSshPasswordAuthentication()) .toLowerCase())); configurationSetElement.appendChild(disableSshPasswordAuthenticationElement); } if (configurationSetsItem.getSshSettings() != null) { Element sSHElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SSH"); configurationSetElement.appendChild(sSHElement); if (configurationSetsItem.getSshSettings().getPublicKeys() != null) { if (configurationSetsItem.getSshSettings() .getPublicKeys() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSshSettings() .getPublicKeys()).isInitialized()) { Element publicKeysSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PublicKeys"); for (SshSettingPublicKey publicKeysItem : configurationSetsItem .getSshSettings().getPublicKeys()) { Element publicKeyElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "PublicKey"); publicKeysSequenceElement.appendChild(publicKeyElement); Element fingerprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Fingerprint"); fingerprintElement.appendChild( requestDoc.createTextNode(publicKeysItem.getFingerprint())); publicKeyElement.appendChild(fingerprintElement); Element pathElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Path"); pathElement2.appendChild( requestDoc.createTextNode(publicKeysItem.getPath())); publicKeyElement.appendChild(pathElement2); } sSHElement.appendChild(publicKeysSequenceElement); } } if (configurationSetsItem.getSshSettings().getKeyPairs() != null) { if (configurationSetsItem.getSshSettings() .getKeyPairs() instanceof LazyCollection == false || ((LazyCollection) configurationSetsItem.getSshSettings() .getKeyPairs()).isInitialized()) { Element keyPairsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "KeyPairs"); for (SshSettingKeyPair keyPairsItem : configurationSetsItem.getSshSettings() .getKeyPairs()) { Element keyPairElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "KeyPair"); keyPairsSequenceElement.appendChild(keyPairElement); Element fingerprintElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Fingerprint"); fingerprintElement2.appendChild( requestDoc.createTextNode(keyPairsItem.getFingerprint())); keyPairElement.appendChild(fingerprintElement2); Element pathElement3 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Path"); pathElement3 .appendChild(requestDoc.createTextNode(keyPairsItem.getPath())); keyPairElement.appendChild(pathElement3); } sSHElement.appendChild(keyPairsSequenceElement); } } } if (configurationSetsItem.getCustomData() != null) { Element customDataElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CustomData"); customDataElement.appendChild( requestDoc.createTextNode(configurationSetsItem.getCustomData())); configurationSetElement.appendChild(customDataElement); } } roleElement.appendChild(configurationSetsSequenceElement); } } if (roleListItem.getResourceExtensionReferences() != null) { if (roleListItem.getResourceExtensionReferences() instanceof LazyCollection == false || ((LazyCollection) roleListItem.getResourceExtensionReferences()).isInitialized()) { Element resourceExtensionReferencesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionReferences"); for (ResourceExtensionReference resourceExtensionReferencesItem : roleListItem .getResourceExtensionReferences()) { Element resourceExtensionReferenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionReference"); resourceExtensionReferencesSequenceElement .appendChild(resourceExtensionReferenceElement); if (resourceExtensionReferencesItem.getReferenceName() != null) { Element referenceNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ReferenceName"); referenceNameElement.appendChild(requestDoc .createTextNode(resourceExtensionReferencesItem.getReferenceName())); resourceExtensionReferenceElement.appendChild(referenceNameElement); } if (resourceExtensionReferencesItem.getPublisher() != null) { Element publisherElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Publisher"); publisherElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getPublisher())); resourceExtensionReferenceElement.appendChild(publisherElement); } if (resourceExtensionReferencesItem.getName() != null) { Element nameElement5 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement5.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getName())); resourceExtensionReferenceElement.appendChild(nameElement5); } if (resourceExtensionReferencesItem.getVersion() != null) { Element versionElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Version"); versionElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getVersion())); resourceExtensionReferenceElement.appendChild(versionElement); } if (resourceExtensionReferencesItem.getResourceExtensionParameterValues() != null) { if (resourceExtensionReferencesItem .getResourceExtensionParameterValues() instanceof LazyCollection == false || ((LazyCollection) resourceExtensionReferencesItem .getResourceExtensionParameterValues()).isInitialized()) { Element resourceExtensionParameterValuesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ResourceExtensionParameterValues"); for (ResourceExtensionParameterValue resourceExtensionParameterValuesItem : resourceExtensionReferencesItem .getResourceExtensionParameterValues()) { Element resourceExtensionParameterValueElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResourceExtensionParameterValue"); resourceExtensionParameterValuesSequenceElement .appendChild(resourceExtensionParameterValueElement); if (resourceExtensionParameterValuesItem.getKey() != null) { Element keyElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Key"); keyElement.appendChild(requestDoc .createTextNode(resourceExtensionParameterValuesItem.getKey())); resourceExtensionParameterValueElement.appendChild(keyElement); } if (resourceExtensionParameterValuesItem.getValue() != null) { Element valueElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Value"); valueElement.appendChild(requestDoc.createTextNode(Base64.encode( resourceExtensionParameterValuesItem.getValue().getBytes()))); resourceExtensionParameterValueElement.appendChild(valueElement); } if (resourceExtensionParameterValuesItem.getType() != null) { Element typeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "Type"); typeElement.appendChild(requestDoc.createTextNode( resourceExtensionParameterValuesItem.getType())); resourceExtensionParameterValueElement.appendChild(typeElement); } } resourceExtensionReferenceElement .appendChild(resourceExtensionParameterValuesSequenceElement); } } if (resourceExtensionReferencesItem.getState() != null) { Element stateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "State"); stateElement.appendChild( requestDoc.createTextNode(resourceExtensionReferencesItem.getState())); resourceExtensionReferenceElement.appendChild(stateElement); } if (resourceExtensionReferencesItem.isForceUpdate() != null) { Element forceUpdateElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ForceUpdate"); forceUpdateElement.appendChild(requestDoc.createTextNode(Boolean .toString(resourceExtensionReferencesItem.isForceUpdate()).toLowerCase())); resourceExtensionReferenceElement.appendChild(forceUpdateElement); } } roleElement.appendChild(resourceExtensionReferencesSequenceElement); } } if (roleListItem.getVMImageName() != null) { Element vMImageNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "VMImageName"); vMImageNameElement.appendChild(requestDoc.createTextNode(roleListItem.getVMImageName())); roleElement.appendChild(vMImageNameElement); } if (roleListItem.getMediaLocation() != null) { Element mediaLocationElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLocation"); mediaLocationElement .appendChild(requestDoc.createTextNode(roleListItem.getMediaLocation().toString())); roleElement.appendChild(mediaLocationElement); } if (roleListItem.getAvailabilitySetName() != null) { Element availabilitySetNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "AvailabilitySetName"); availabilitySetNameElement .appendChild(requestDoc.createTextNode(roleListItem.getAvailabilitySetName())); roleElement.appendChild(availabilitySetNameElement); } if (roleListItem.getDataVirtualHardDisks() != null) { if (roleListItem.getDataVirtualHardDisks() instanceof LazyCollection == false || ((LazyCollection) roleListItem.getDataVirtualHardDisks()).isInitialized()) { Element dataVirtualHardDisksSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DataVirtualHardDisks"); for (DataVirtualHardDisk dataVirtualHardDisksItem : roleListItem .getDataVirtualHardDisks()) { Element dataVirtualHardDiskElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DataVirtualHardDisk"); dataVirtualHardDisksSequenceElement.appendChild(dataVirtualHardDiskElement); if (dataVirtualHardDisksItem.getHostCaching() != null) { Element hostCachingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "HostCaching"); hostCachingElement.appendChild( requestDoc.createTextNode(dataVirtualHardDisksItem.getHostCaching())); dataVirtualHardDiskElement.appendChild(hostCachingElement); } if (dataVirtualHardDisksItem.getLabel() != null) { Element diskLabelElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DiskLabel"); diskLabelElement.appendChild( requestDoc.createTextNode(dataVirtualHardDisksItem.getLabel())); dataVirtualHardDiskElement.appendChild(diskLabelElement); } if (dataVirtualHardDisksItem.getName() != null) { Element diskNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DiskName"); diskNameElement .appendChild(requestDoc.createTextNode(dataVirtualHardDisksItem.getName())); dataVirtualHardDiskElement.appendChild(diskNameElement); } if (dataVirtualHardDisksItem.getLogicalUnitNumber() != null) { Element lunElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Lun"); lunElement.appendChild(requestDoc.createTextNode( Integer.toString(dataVirtualHardDisksItem.getLogicalUnitNumber()))); dataVirtualHardDiskElement.appendChild(lunElement); } if (dataVirtualHardDisksItem.getLogicalDiskSizeInGB() != null) { Element logicalDiskSizeInGBElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "LogicalDiskSizeInGB"); logicalDiskSizeInGBElement.appendChild(requestDoc.createTextNode( Integer.toString(dataVirtualHardDisksItem.getLogicalDiskSizeInGB()))); dataVirtualHardDiskElement.appendChild(logicalDiskSizeInGBElement); } if (dataVirtualHardDisksItem.getMediaLink() != null) { Element mediaLinkElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLink"); mediaLinkElement.appendChild(requestDoc .createTextNode(dataVirtualHardDisksItem.getMediaLink().toString())); dataVirtualHardDiskElement.appendChild(mediaLinkElement); } if (dataVirtualHardDisksItem.getSourceMediaLink() != null) { Element sourceMediaLinkElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "SourceMediaLink"); sourceMediaLinkElement.appendChild(requestDoc .createTextNode(dataVirtualHardDisksItem.getSourceMediaLink().toString())); dataVirtualHardDiskElement.appendChild(sourceMediaLinkElement); } if (dataVirtualHardDisksItem.getIOType() != null) { Element iOTypeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IOType"); iOTypeElement.appendChild( requestDoc.createTextNode(dataVirtualHardDisksItem.getIOType())); dataVirtualHardDiskElement.appendChild(iOTypeElement); } } roleElement.appendChild(dataVirtualHardDisksSequenceElement); } } if (roleListItem.getLabel() != null) { Element labelElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label"); labelElement2.appendChild(requestDoc.createTextNode(roleListItem.getLabel())); roleElement.appendChild(labelElement2); } if (roleListItem.getOSVirtualHardDisk() != null) { Element oSVirtualHardDiskElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "OSVirtualHardDisk"); roleElement.appendChild(oSVirtualHardDiskElement); if (roleListItem.getOSVirtualHardDisk().getHostCaching() != null) { Element hostCachingElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostCaching"); hostCachingElement2.appendChild( requestDoc.createTextNode(roleListItem.getOSVirtualHardDisk().getHostCaching())); oSVirtualHardDiskElement.appendChild(hostCachingElement2); } if (roleListItem.getOSVirtualHardDisk().getLabel() != null) { Element diskLabelElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DiskLabel"); diskLabelElement2.appendChild( requestDoc.createTextNode(roleListItem.getOSVirtualHardDisk().getLabel())); oSVirtualHardDiskElement.appendChild(diskLabelElement2); } if (roleListItem.getOSVirtualHardDisk().getName() != null) { Element diskNameElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DiskName"); diskNameElement2.appendChild( requestDoc.createTextNode(roleListItem.getOSVirtualHardDisk().getName())); oSVirtualHardDiskElement.appendChild(diskNameElement2); } if (roleListItem.getOSVirtualHardDisk().getMediaLink() != null) { Element mediaLinkElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MediaLink"); mediaLinkElement2.appendChild(requestDoc .createTextNode(roleListItem.getOSVirtualHardDisk().getMediaLink().toString())); oSVirtualHardDiskElement.appendChild(mediaLinkElement2); } if (roleListItem.getOSVirtualHardDisk().getSourceImageName() != null) { Element sourceImageNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SourceImageName"); sourceImageNameElement.appendChild(requestDoc .createTextNode(roleListItem.getOSVirtualHardDisk().getSourceImageName())); oSVirtualHardDiskElement.appendChild(sourceImageNameElement); } if (roleListItem.getOSVirtualHardDisk().getOperatingSystem() != null) { Element osElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OS"); osElement.appendChild(requestDoc .createTextNode(roleListItem.getOSVirtualHardDisk().getOperatingSystem())); oSVirtualHardDiskElement.appendChild(osElement); } if (roleListItem.getOSVirtualHardDisk().getRemoteSourceImageLink() != null) { Element remoteSourceImageLinkElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "RemoteSourceImageLink"); remoteSourceImageLinkElement.appendChild(requestDoc.createTextNode( roleListItem.getOSVirtualHardDisk().getRemoteSourceImageLink().toString())); oSVirtualHardDiskElement.appendChild(remoteSourceImageLinkElement); } if (roleListItem.getOSVirtualHardDisk().getIOType() != null) { Element iOTypeElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IOType"); iOTypeElement2.appendChild( requestDoc.createTextNode(roleListItem.getOSVirtualHardDisk().getIOType())); oSVirtualHardDiskElement.appendChild(iOTypeElement2); } if (roleListItem.getOSVirtualHardDisk().getResizedSizeInGB() != null) { Element resizedSizeInGBElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ResizedSizeInGB"); resizedSizeInGBElement.appendChild(requestDoc.createTextNode( Integer.toString(roleListItem.getOSVirtualHardDisk().getResizedSizeInGB()))); oSVirtualHardDiskElement.appendChild(resizedSizeInGBElement); } } if (roleListItem.getRoleSize() != null) { Element roleSizeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "RoleSize"); roleSizeElement.appendChild(requestDoc.createTextNode(roleListItem.getRoleSize())); roleElement.appendChild(roleSizeElement); } if (roleListItem.getDefaultWinRmCertificateThumbprint() != null) { Element defaultWinRmCertificateThumbprintElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DefaultWinRmCertificateThumbprint"); defaultWinRmCertificateThumbprintElement.appendChild( requestDoc.createTextNode(roleListItem.getDefaultWinRmCertificateThumbprint())); roleElement.appendChild(defaultWinRmCertificateThumbprintElement); } if (roleListItem.isProvisionGuestAgent() != null) { Element provisionGuestAgentElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ProvisionGuestAgent"); provisionGuestAgentElement.appendChild(requestDoc .createTextNode(Boolean.toString(roleListItem.isProvisionGuestAgent()).toLowerCase())); roleElement.appendChild(provisionGuestAgentElement); } if (roleListItem.getVMImageInput() != null) { Element vMImageInputElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "VMImageInput"); roleElement.appendChild(vMImageInputElement); if (roleListItem.getVMImageInput().getOSDiskConfiguration() != null) { Element oSDiskConfigurationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "OSDiskConfiguration"); vMImageInputElement.appendChild(oSDiskConfigurationElement); if (roleListItem.getVMImageInput().getOSDiskConfiguration().getResizedSizeInGB() != null) { Element resizedSizeInGBElement2 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResizedSizeInGB"); resizedSizeInGBElement2.appendChild(requestDoc.createTextNode(Integer.toString( roleListItem.getVMImageInput().getOSDiskConfiguration().getResizedSizeInGB()))); oSDiskConfigurationElement.appendChild(resizedSizeInGBElement2); } } if (roleListItem.getVMImageInput().getDataDiskConfigurations() != null) { if (roleListItem.getVMImageInput() .getDataDiskConfigurations() instanceof LazyCollection == false || ((LazyCollection) roleListItem.getVMImageInput().getDataDiskConfigurations()) .isInitialized()) { Element dataDiskConfigurationsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DataDiskConfigurations"); for (DataDiskConfiguration dataDiskConfigurationsItem : roleListItem.getVMImageInput() .getDataDiskConfigurations()) { Element dataDiskConfigurationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "DataDiskConfiguration"); dataDiskConfigurationsSequenceElement.appendChild(dataDiskConfigurationElement); if (dataDiskConfigurationsItem.getDiskName() != null) { Element nameElement6 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement6.appendChild( requestDoc.createTextNode(dataDiskConfigurationsItem.getDiskName())); dataDiskConfigurationElement.appendChild(nameElement6); } if (dataDiskConfigurationsItem.getResizedSizeInGB() != null) { Element resizedSizeInGBElement3 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ResizedSizeInGB"); resizedSizeInGBElement3.appendChild(requestDoc.createTextNode( Integer.toString(dataDiskConfigurationsItem.getResizedSizeInGB()))); dataDiskConfigurationElement.appendChild(resizedSizeInGBElement3); } } vMImageInputElement.appendChild(dataDiskConfigurationsSequenceElement); } } } } deploymentElement.appendChild(roleListSequenceElement); } if (parameters.getVirtualNetworkName() != null) { Element virtualNetworkNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "VirtualNetworkName"); virtualNetworkNameElement.appendChild(requestDoc.createTextNode(parameters.getVirtualNetworkName())); deploymentElement.appendChild(virtualNetworkNameElement); } if (parameters.getDnsSettings() != null) { Element dnsElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Dns"); deploymentElement.appendChild(dnsElement); if (parameters.getDnsSettings().getDnsServers() != null) { if (parameters.getDnsSettings().getDnsServers() instanceof LazyCollection == false || ((LazyCollection) parameters.getDnsSettings().getDnsServers()).isInitialized()) { Element dnsServersSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DnsServers"); for (DnsServer dnsServersItem : parameters.getDnsSettings().getDnsServers()) { Element dnsServerElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DnsServer"); dnsServersSequenceElement.appendChild(dnsServerElement); if (dnsServersItem.getName() != null) { Element nameElement7 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement7.appendChild(requestDoc.createTextNode(dnsServersItem.getName())); dnsServerElement.appendChild(nameElement7); } if (dnsServersItem.getAddress() != null) { Element addressElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Address"); addressElement.appendChild( requestDoc.createTextNode(dnsServersItem.getAddress().getHostAddress())); dnsServerElement.appendChild(addressElement); } } dnsElement.appendChild(dnsServersSequenceElement); } } } if (parameters.getReservedIPName() != null) { Element reservedIPNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ReservedIPName"); reservedIPNameElement.appendChild(requestDoc.createTextNode(parameters.getReservedIPName())); deploymentElement.appendChild(reservedIPNameElement); } if (parameters.getLoadBalancers() != null) { if (parameters.getLoadBalancers() instanceof LazyCollection == false || ((LazyCollection) parameters.getLoadBalancers()).isInitialized()) { Element loadBalancersSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "LoadBalancers"); for (LoadBalancer loadBalancersItem : parameters.getLoadBalancers()) { Element loadBalancerElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "LoadBalancer"); loadBalancersSequenceElement.appendChild(loadBalancerElement); if (loadBalancersItem.getName() != null) { Element nameElement8 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement8.appendChild(requestDoc.createTextNode(loadBalancersItem.getName())); loadBalancerElement.appendChild(nameElement8); } if (loadBalancersItem.getFrontendIPConfiguration() != null) { Element frontendIpConfigurationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "FrontendIpConfiguration"); loadBalancerElement.appendChild(frontendIpConfigurationElement); if (loadBalancersItem.getFrontendIPConfiguration().getType() != null) { Element typeElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Type"); typeElement2.appendChild(requestDoc .createTextNode(loadBalancersItem.getFrontendIPConfiguration().getType())); frontendIpConfigurationElement.appendChild(typeElement2); } if (loadBalancersItem.getFrontendIPConfiguration().getSubnetName() != null) { Element subnetNameElement2 = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNameElement2.appendChild(requestDoc.createTextNode( loadBalancersItem.getFrontendIPConfiguration().getSubnetName())); frontendIpConfigurationElement.appendChild(subnetNameElement2); } if (loadBalancersItem.getFrontendIPConfiguration() .getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement3 = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement3.appendChild( requestDoc.createTextNode(loadBalancersItem.getFrontendIPConfiguration() .getStaticVirtualNetworkIPAddress().getHostAddress())); frontendIpConfigurationElement.appendChild(staticVirtualNetworkIPAddressElement3); } } } deploymentElement.appendChild(loadBalancersSequenceElement); } } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; // Deserialize Response result = new OperationResponse(); result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.network.GatewayOperationsImpl.java
/** * The Begin Set Virtual Network Gateway Shared Key operation sets the * shared key on the virtual network gateway for the specified virtual * network connection to the specified local network in Azure. (see * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for * more information)/*w ww. ja va 2s . c om*/ * * @param networkName Required. The name of the virtual network for this * gateway. * @param localNetworkName Required. The name of the local network. * @param parameters Required. Parameters supplied to the Begin Virtual * Network Gateway Set Shared Key request. * @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 standard service response including an HTTP status code and * request ID. */ @Override public GatewayOperationResponse beginSetSharedKey(String networkName, String localNetworkName, GatewaySetSharedKeyParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (networkName == null) { throw new NullPointerException("networkName"); } if (localNetworkName == null) { throw new NullPointerException("localNetworkName"); } 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("networkName", networkName); tracingParameters.put("localNetworkName", localNetworkName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginSetSharedKeyAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/"; url = url + URLEncoder.encode(networkName, "UTF-8"); url = url + "/gateway/connection/"; url = url + URLEncoder.encode(localNetworkName, "UTF-8"); url = url + "/sharedkey"; 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 sharedKeyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SharedKey"); requestDoc.appendChild(sharedKeyElement); if (parameters.getValue() != null) { Element valueElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Value"); valueElement.appendChild(requestDoc.createTextNode(parameters.getValue())); sharedKeyElement.appendChild(valueElement); } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result GatewayOperationResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new GatewayOperationResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse"); if (gatewayOperationAsyncResponseElement != null) { Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID"); if (idElement != null) { String idInstance; idInstance = idElement.getTextContent(); result.setOperationId(idInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.network.GatewayOperationsImpl.java
/** * The Begin Set Virtual Network Gateway Shared Key V2 operation sets the * shared key used between the gateway and customer vpn for the specified * site.//ww w. ja va 2s. co m * * @param gatewayId Required. The virtual network for this gateway Id. * @param connectedentityId Required. The connected entity Id. * @param parameters Required. Parameters supplied to the Begin Virtual * Network Gateway Set Shared Key V2 request. * @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 standard service response including an HTTP status code and * request ID. */ @Override public GatewayOperationResponse beginSetSharedKeyV2(String gatewayId, String connectedentityId, GatewaySetSharedKeyParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (gatewayId == null) { throw new NullPointerException("gatewayId"); } if (connectedentityId == null) { throw new NullPointerException("connectedentityId"); } 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("gatewayId", gatewayId); tracingParameters.put("connectedentityId", connectedentityId); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginSetSharedKeyV2Async", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/virtualnetworkgateways/"; url = url + URLEncoder.encode(gatewayId, "UTF-8"); url = url + "/connectedentity/"; url = url + URLEncoder.encode(connectedentityId, "UTF-8"); url = url + "/sharedkey"; 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 sharedKeyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SharedKey"); requestDoc.appendChild(sharedKeyElement); if (parameters.getValue() != null) { Element valueElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Value"); valueElement.appendChild(requestDoc.createTextNode(parameters.getValue())); sharedKeyElement.appendChild(valueElement); } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result GatewayOperationResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new GatewayOperationResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse"); if (gatewayOperationAsyncResponseElement != null) { Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID"); if (idElement != null) { String idInstance; idInstance = idElement.getTextContent(); result.setOperationId(idInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.network.GatewayOperationsImpl.java
/** * The Begin Set Virtual Network Gateway Shared Key operation sets the * default sites on the virtual network gateway for the specified virtual * network.//from w w w.jav a2 s . c om * * @param networkName Required. The name of the virtual network for this * gateway. * @param parameters Required. Parameters supplied to the Begin Virtual * Network Gateway Set Default Sites request. * @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 standard service response including an HTTP status code and * request ID. */ @Override public GatewayOperationResponse beginSetDefaultSites(String networkName, GatewaySetDefaultSiteListParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (networkName == null) { throw new NullPointerException("networkName"); } 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("networkName", networkName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginSetDefaultSitesAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/"; url = url + URLEncoder.encode(networkName, "UTF-8"); url = url + "/gateway/defaultsites"; 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 defaultSiteListElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "DefaultSiteList"); requestDoc.appendChild(defaultSiteListElement); if (parameters.getDefaultSite() != null) { Element stringElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "string"); stringElement.appendChild(requestDoc.createTextNode(parameters.getDefaultSite())); defaultSiteListElement.appendChild(stringElement); } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result GatewayOperationResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new GatewayOperationResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse"); if (gatewayOperationAsyncResponseElement != null) { Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID"); if (idElement != null) { String idInstance; idInstance = idElement.getTextContent(); result.setOperationId(idInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.network.GatewayOperationsImpl.java
/** * The Begin Reset Virtual Network Gateway Shared Key operation resets the * shared key on the virtual network gateway for the specified virtual * network connection to the specified local network in Azure. (see * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for * more information)/* w w w . j a v a2 s .c o m*/ * * @param networkName Required. The name of the virtual network for this * gateway. * @param localNetworkName Required. The name of the local network. * @param parameters Required. Parameters supplied to the Begin Virtual * Network Gateway Reset Shared Key request. * @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 standard service response including an HTTP status code and * request ID. */ @Override public GatewayOperationResponse beginResetSharedKey(String networkName, String localNetworkName, GatewayResetSharedKeyParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (networkName == null) { throw new NullPointerException("networkName"); } if (localNetworkName == null) { throw new NullPointerException("localNetworkName"); } 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("networkName", networkName); tracingParameters.put("localNetworkName", localNetworkName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginResetSharedKeyAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/"; url = url + URLEncoder.encode(networkName, "UTF-8"); url = url + "/gateway/connection/"; url = url + URLEncoder.encode(localNetworkName, "UTF-8"); url = url + "/sharedkey"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2015-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element resetSharedKeyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ResetSharedKey"); requestDoc.appendChild(resetSharedKeyElement); Element keyLengthElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "KeyLength"); keyLengthElement.appendChild(requestDoc.createTextNode(Integer.toString(parameters.getKeyLength()))); resetSharedKeyElement.appendChild(keyLengthElement); 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result GatewayOperationResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new GatewayOperationResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse"); if (gatewayOperationAsyncResponseElement != null) { Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID"); if (idElement != null) { String idInstance; idInstance = idElement.getTextContent(); result.setOperationId(idInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.network.GatewayOperationsImpl.java
/** * The Begin Reset Virtual Network Gateway Shared Key V2 operation resets * the shared key used between the gateway and customer vpn. * * @param gatewayId Required. The virtual network for this gateway Id. * @param connectedentityId Required. The connected entity Id. * @param parameters Required. Parameters supplied to the Begin Virtual * Network Gateway Reset Shared Key V2 request. * @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.// w w w . j a va 2 s .c o m * @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 standard service response including an HTTP status code and * request ID. */ @Override public GatewayOperationResponse beginResetSharedKeyV2(String gatewayId, String connectedentityId, GatewayResetSharedKeyParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (gatewayId == null) { throw new NullPointerException("gatewayId"); } if (connectedentityId == null) { throw new NullPointerException("connectedentityId"); } 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("gatewayId", gatewayId); tracingParameters.put("connectedentityId", connectedentityId); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginResetSharedKeyV2Async", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/virtualnetworkgateways/"; url = url + URLEncoder.encode(gatewayId, "UTF-8"); url = url + "/connectedentity/"; url = url + URLEncoder.encode(connectedentityId, "UTF-8"); url = url + "/sharedkey"; 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 HttpPatch httpRequest = new HttpPatch(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 resetSharedKeyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ResetSharedKey"); requestDoc.appendChild(resetSharedKeyElement); Element keyLengthElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "KeyLength"); keyLengthElement.appendChild(requestDoc.createTextNode(Integer.toString(parameters.getKeyLength()))); resetSharedKeyElement.appendChild(keyLengthElement); 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result GatewayOperationResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new GatewayOperationResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse"); if (gatewayOperationAsyncResponseElement != null) { Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID"); if (idElement != null) { String idInstance; idInstance = idElement.getTextContent(); result.setOperationId(idInstance); } } } 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(); } } }