List of usage examples for org.w3c.dom Document createTextNode
public Text createTextNode(String data);
Text
node given the specified string. From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java
private void saveGeneralParameters(final Element gaSettingsElement) { final Document document = gaSettingsElement.getOwnerDocument(); Element element = document.createElement(POPULATION_SIZE); element.appendChild(document.createTextNode(String.valueOf(populationSize))); gaSettingsElement.appendChild(element); element = document.createElement(POPULATION_RANDOM_SEED); element.appendChild(document.createTextNode(String.valueOf(populationGenerationSeed))); gaSettingsElement.appendChild(element); element = document.createElement(FIX_NUMBER_OF_GENERATIONS); element.appendChild(document.createTextNode(String.valueOf(fixNumberOfGenerations))); gaSettingsElement.appendChild(element); if (fixNumberOfGenerations) { element = document.createElement(NUMBER_OF_GENERATIONS); element.appendChild(document.createTextNode(String.valueOf(numberOfGenerations))); gaSettingsElement.appendChild(element); } else {/* ww w.ja v a2 s . c o m*/ element = document.createElement(FITNESS_LIMIT_CRITERION); element.appendChild(document.createTextNode(String.valueOf(fitnessLimitCriterion))); gaSettingsElement.appendChild(element); } element = document.createElement(OPTIMIZATION_DIRECTION); element.appendChild(document.createTextNode(optimizationDirection.name())); gaSettingsElement.appendChild(element); element = document.createElement(FITNESS_FUNCTION); element.setAttribute(WizardSettingsManager.ALIAS, selectedFunction.getName()); element.appendChild(document.createTextNode(selectedFunction.getAccessibleName())); gaSettingsElement.appendChild(element); }
From source file:com.microsoft.windowsazure.management.websites.ServerFarmOperationsImpl.java
/** * You can create a server farm by issuing an HTTP POST request. Only one * server farm per webspace is permitted. You can retrieve server farm * details by using HTTP GET, change server farm properties by using HTTP * PUT, and delete a server farm by using HTTP DELETE. A request body is * required for server farm creation (HTTP POST) and server farm update * (HTTP PUT). Warning: Creating a server farm changes your webspace's * Compute Mode from Shared to Dedicated. You will be charged from the * moment the server farm is created, even if all your sites are still * running in Free mode. (see/*w w w .j a v a 2s .com*/ * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param parameters Required. Parameters supplied to the Create Server Farm * operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Create Server Farm operation response. */ @Override public ServerFarmCreateResponse create(String webSpaceName, ServerFarmCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (parameters == null) { throw new NullPointerException("parameters"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createAsync", tracingParameters); } // Construct URL String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/WebSpaces/" + webSpaceName.trim() + "/ServerFarms"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2013-08-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); requestDoc.appendChild(serverFarmElement); if (parameters.getCurrentNumberOfWorkers() != null) { Element currentNumberOfWorkersElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); currentNumberOfWorkersElement.appendChild( requestDoc.createTextNode(Integer.toString(parameters.getCurrentNumberOfWorkers()))); serverFarmElement.appendChild(currentNumberOfWorkersElement); } if (parameters.getCurrentWorkerSize() != null) { Element currentWorkerSizeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); currentWorkerSizeElement .appendChild(requestDoc.createTextNode(parameters.getCurrentWorkerSize().toString())); serverFarmElement.appendChild(currentWorkerSizeElement); } Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode("DefaultServerFarm")); serverFarmElement.appendChild(nameElement); Element numberOfWorkersElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); numberOfWorkersElement .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getNumberOfWorkers()))); serverFarmElement.appendChild(numberOfWorkersElement); Element workerSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "WorkerSize"); workerSizeElement.appendChild(requestDoc.createTextNode(parameters.getWorkerSize().toString())); serverFarmElement.appendChild(workerSizeElement); if (parameters.getStatus() != null) { Element statusElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Status"); statusElement.appendChild(requestDoc.createTextNode(parameters.getStatus().toString())); serverFarmElement.appendChild(statusElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ServerFarmCreateResponse result = null; // Deserialize Response InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServerFarmCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { Element currentNumberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); if (currentNumberOfWorkersElement2 != null) { int currentNumberOfWorkersInstance; currentNumberOfWorkersInstance = DatatypeConverter .parseInt(currentNumberOfWorkersElement2.getTextContent()); result.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance); } Element currentWorkerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); if (currentWorkerSizeElement2 != null) { ServerFarmWorkerSize currentWorkerSizeInstance; currentWorkerSizeInstance = ServerFarmWorkerSize .valueOf(currentWorkerSizeElement2.getTextContent()); result.setCurrentWorkerSize(currentWorkerSizeInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); result.setName(nameInstance); } Element numberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); if (numberOfWorkersElement2 != null) { int numberOfWorkersInstance; numberOfWorkersInstance = DatatypeConverter.parseInt(numberOfWorkersElement2.getTextContent()); result.setNumberOfWorkers(numberOfWorkersInstance); } Element workerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement2 != null) { ServerFarmWorkerSize workerSizeInstance; workerSizeInstance = ServerFarmWorkerSize.valueOf(workerSizeElement2.getTextContent()); result.setWorkerSize(workerSizeInstance); } Element statusElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement2 != null) { ServerFarmStatus statusInstance; statusInstance = ServerFarmStatus.valueOf(statusElement2.getTextContent()); result.setStatus(statusInstance); } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.ServerFarmOperationsImpl.java
/** * You can create a server farm by issuing an HTTP POST request. Only one * server farm per webspace is permitted. You can retrieve server farm * details by using HTTP GET, change server farm properties by using HTTP * PUT, and delete a server farm by using HTTP DELETE. A request body is * required for server farm creation (HTTP POST) and server farm update * (HTTP PUT). Warning: Creating a server farm changes your webspace's * Compute Mode from Shared to Dedicated. You will be charged from the * moment the server farm is created, even if all your sites are still * running in Free mode. (see//from www . j a v a 2 s .com * http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param parameters Required. Parameters supplied to the Update Server Farm * operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Update Server Farm operation response. */ @Override public ServerFarmUpdateResponse update(String webSpaceName, ServerFarmUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (parameters == null) { throw new NullPointerException("parameters"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "updateAsync", tracingParameters); } // Construct URL String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/WebSpaces/" + webSpaceName.trim() + "/ServerFarms/DefaultServerFarm"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2013-08-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); requestDoc.appendChild(serverFarmElement); if (parameters.getCurrentNumberOfWorkers() != null) { Element currentNumberOfWorkersElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); currentNumberOfWorkersElement.appendChild( requestDoc.createTextNode(Integer.toString(parameters.getCurrentNumberOfWorkers()))); serverFarmElement.appendChild(currentNumberOfWorkersElement); } if (parameters.getCurrentWorkerSize() != null) { Element currentWorkerSizeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); currentWorkerSizeElement .appendChild(requestDoc.createTextNode(parameters.getCurrentWorkerSize().toString())); serverFarmElement.appendChild(currentWorkerSizeElement); } Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode("DefaultServerFarm")); serverFarmElement.appendChild(nameElement); Element numberOfWorkersElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); numberOfWorkersElement .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getNumberOfWorkers()))); serverFarmElement.appendChild(numberOfWorkersElement); Element workerSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "WorkerSize"); workerSizeElement.appendChild(requestDoc.createTextNode(parameters.getWorkerSize().toString())); serverFarmElement.appendChild(workerSizeElement); if (parameters.getStatus() != null) { Element statusElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Status"); statusElement.appendChild(requestDoc.createTextNode(parameters.getStatus().toString())); serverFarmElement.appendChild(statusElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ServerFarmUpdateResponse result = null; // Deserialize Response InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServerFarmUpdateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { Element currentNumberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); if (currentNumberOfWorkersElement2 != null) { int currentNumberOfWorkersInstance; currentNumberOfWorkersInstance = DatatypeConverter .parseInt(currentNumberOfWorkersElement2.getTextContent()); result.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance); } Element currentWorkerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); if (currentWorkerSizeElement2 != null) { ServerFarmWorkerSize currentWorkerSizeInstance; currentWorkerSizeInstance = ServerFarmWorkerSize .valueOf(currentWorkerSizeElement2.getTextContent()); result.setCurrentWorkerSize(currentWorkerSizeInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); result.setName(nameInstance); } Element numberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); if (numberOfWorkersElement2 != null) { int numberOfWorkersInstance; numberOfWorkersInstance = DatatypeConverter.parseInt(numberOfWorkersElement2.getTextContent()); result.setNumberOfWorkers(numberOfWorkersInstance); } Element workerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement2 != null) { ServerFarmWorkerSize workerSizeInstance; workerSizeInstance = ServerFarmWorkerSize.valueOf(workerSizeElement2.getTextContent()); result.setWorkerSize(workerSizeInstance); } Element statusElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement2 != null) { ServerFarmStatus statusInstance; statusInstance = ServerFarmStatus.valueOf(statusElement2.getTextContent()); result.setStatus(statusInstance); } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.twinsoft.convertigo.beans.transactions.HtmlTransaction.java
protected Document makeBlob(byte[] data) { Document document = XMLUtils.getDefaultDocumentBuilder().newDocument(); Element blob = document.createElement("blob"); document.appendChild(blob);/*from w w w . j a va 2 s .c om*/ Header[] heads = context.getResponseHeaders(); for (int i = 0; i < heads.length; i++) { if (HeaderName.ContentType.is(heads[i].getName()) || HeaderName.ContentLength.is(heads[i].getName())) { blob.setAttribute(heads[i].getName(), heads[i].getValue()); } } blob.setAttribute("Referer", ((HtmlConnector) context.getConnector()).getReferer()); blob.appendChild(document.createTextNode(Base64.encodeBase64String(data))); return document; }
From source file:com.marklogic.client.functionaltest.BasicJavaClientREST.java
/** * Returning a content of the document/* w ww .j a va2 s .c o m*/ * */ public Document getDocumentContent(String xmltype) throws IOException, ParserConfigurationException, SAXException { DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document content = docBuilder.newDocument(); Element rootElement = content.createElement("foo"); rootElement.appendChild(content.createTextNode(xmltype)); content.appendChild(rootElement); // content.createTextNode(xmltype); return content; }
From source file:com.microsoft.windowsazure.management.sql.DacOperationsImpl.java
/** * Gets the status of the import or export operation in the specified server * with the corresponding request ID. The request ID is provided in the * responses of the import or export operation. * * @param serverName Required. The name of the server in which the import or * export operation is taking place./*from w w w .java 2 s .c o m*/ * @param parameters Required. The parameters needed to get the status of an * import or export operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return Represents a list of import or export status values returned from * GetStatus. */ @Override public DacGetStatusResponse getStatusPost(String serverName, DacGetStatusParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getPassword() == null) { throw new NullPointerException("parameters.Password"); } if (parameters.getRequestId() == null) { throw new NullPointerException("parameters.RequestId"); } if (parameters.getServerName() == null) { throw new NullPointerException("parameters.ServerName"); } if (parameters.getUserName() == null) { throw new NullPointerException("parameters.UserName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "getStatusPostAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/DacOperations/Status"; 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", "2012-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element statusInputElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "StatusInput"); requestDoc.appendChild(statusInputElement); Element passwordElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "Password"); passwordElement.appendChild(requestDoc.createTextNode(parameters.getPassword())); statusInputElement.appendChild(passwordElement); Element requestIdElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "RequestId"); requestIdElement.appendChild(requestDoc.createTextNode(parameters.getRequestId())); statusInputElement.appendChild(requestIdElement); Element serverNameElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "ServerName"); serverNameElement.appendChild(requestDoc.createTextNode(parameters.getServerName())); statusInputElement.appendChild(serverNameElement); Element userNameElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "UserName"); userNameElement.appendChild(requestDoc.createTextNode(parameters.getUserName())); statusInputElement.appendChild(userNameElement); DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DacGetStatusResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DacGetStatusResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element arrayOfStatusInfoElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "ArrayOfStatusInfo"); if (arrayOfStatusInfoElement != null) { if (arrayOfStatusInfoElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(arrayOfStatusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "StatusInfo") .size(); i1 = i1 + 1) { org.w3c.dom.Element statusInfoElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(arrayOfStatusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "StatusInfo") .get(i1)); StatusInfo statusInfoInstance = new StatusInfo(); result.getStatusInfoList().add(statusInfoInstance); Element blobUriElement = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "BlobUri"); if (blobUriElement != null) { URI blobUriInstance; blobUriInstance = new URI(blobUriElement.getTextContent()); statusInfoInstance.setBlobUri(blobUriInstance); } Element databaseNameElement = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "DatabaseName"); if (databaseNameElement != null) { String databaseNameInstance; databaseNameInstance = databaseNameElement.getTextContent(); statusInfoInstance.setDatabaseName(databaseNameInstance); } Element errorMessageElement = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "ErrorMessage"); if (errorMessageElement != null) { boolean isNil = false; Attr nilAttribute = errorMessageElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String errorMessageInstance; errorMessageInstance = errorMessageElement.getTextContent(); statusInfoInstance.setErrorMessage(errorMessageInstance); } } Element lastModifiedTimeElement = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "LastModifiedTime"); if (lastModifiedTimeElement != null) { Calendar lastModifiedTimeInstance; lastModifiedTimeInstance = DatatypeConverter .parseDateTime(lastModifiedTimeElement.getTextContent()); statusInfoInstance.setLastModifiedTime(lastModifiedTimeInstance); } Element queuedTimeElement = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "QueuedTime"); if (queuedTimeElement != null) { Calendar queuedTimeInstance; queuedTimeInstance = DatatypeConverter .parseDateTime(queuedTimeElement.getTextContent()); statusInfoInstance.setQueuedTime(queuedTimeInstance); } Element requestIdElement2 = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "RequestId"); if (requestIdElement2 != null) { String requestIdInstance; requestIdInstance = requestIdElement2.getTextContent(); statusInfoInstance.setRequestId(requestIdInstance); } Element requestTypeElement = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "RequestType"); if (requestTypeElement != null) { String requestTypeInstance; requestTypeInstance = requestTypeElement.getTextContent(); statusInfoInstance.setRequestType(requestTypeInstance); } Element serverNameElement2 = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "ServerName"); if (serverNameElement2 != null) { String serverNameInstance; serverNameInstance = serverNameElement2.getTextContent(); statusInfoInstance.setServerName(serverNameInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(statusInfoElement, "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "Status"); if (statusElement != null) { String statusInstance; statusInstance = statusElement.getTextContent(); statusInfoInstance.setStatus(statusInstance); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebHostingPlanOperationsImpl.java
/** * Creates a new Web Hosting Plan. (see//w w w . j av a 2s. c om * http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/ * for more information) * * @param webSpaceName Required. The name of the web space. * @param parameters Required. Web Hosting Plan Parameters. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Create Web Web Hosting Plan operation response. */ @Override public WebHostingPlanCreateResponse create(String webSpaceName, WebHostingPlanCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getName() == null) { throw new NullPointerException("parameters.Name"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/ServerFarms"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2014-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); requestDoc.appendChild(serverFarmElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); serverFarmElement.appendChild(nameElement); if (parameters.getNumberOfWorkers() != null) { Element numberOfWorkersElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); numberOfWorkersElement .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getNumberOfWorkers()))); serverFarmElement.appendChild(numberOfWorkersElement); } if (parameters.getSKU() != null) { Element sKUElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SKU"); sKUElement.appendChild(requestDoc.createTextNode(parameters.getSKU().toString())); serverFarmElement.appendChild(sKUElement); } if (parameters.getWorkerSize() != null) { Element workerSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "WorkerSize"); workerSizeElement.appendChild(requestDoc.createTextNode(parameters.getWorkerSize().toString())); serverFarmElement.appendChild(workerSizeElement); } if (parameters.getAdminSiteName() != null) { Element adminSiteNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "AdminSiteName"); adminSiteNameElement.appendChild(requestDoc.createTextNode(parameters.getAdminSiteName())); serverFarmElement.appendChild(adminSiteNameElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebHostingPlanCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebHostingPlanCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { WebHostingPlan webHostingPlanInstance = new WebHostingPlan(); result.setWebHostingPlan(webHostingPlanInstance); Element nameElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); webHostingPlanInstance.setName(nameInstance); } Element numberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); if (numberOfWorkersElement2 != null && numberOfWorkersElement2.getTextContent() != null && !numberOfWorkersElement2.getTextContent().isEmpty()) { int numberOfWorkersInstance; numberOfWorkersInstance = DatatypeConverter .parseInt(numberOfWorkersElement2.getTextContent()); webHostingPlanInstance.setNumberOfWorkers(numberOfWorkersInstance); } Element sKUElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement2 != null && sKUElement2.getTextContent() != null && !sKUElement2.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement2.getTextContent()); webHostingPlanInstance.setSKU(sKUInstance); } Element workerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement2 != null && workerSizeElement2.getTextContent() != null && !workerSizeElement2.getTextContent().isEmpty()) { WorkerSizeOptions workerSizeInstance; workerSizeInstance = WorkerSizeOptions.valueOf(workerSizeElement2.getTextContent()); webHostingPlanInstance.setWorkerSize(workerSizeInstance); } Element adminSiteNameElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "AdminSiteName"); if (adminSiteNameElement2 != null) { String adminSiteNameInstance; adminSiteNameInstance = adminSiteNameElement2.getTextContent(); webHostingPlanInstance.setAdminSiteName(adminSiteNameInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.castlemock.web.mock.rest.converter.swagger.SwaggerRestDefinitionConverter.java
/** * The method creates a DOM {@link Element} based on a {@link Property}. * @param name The name of the element//from w w w . j a v a2 s.c o m * @param property The property that the element if based on. * @param definitions Models which may or may not be required * @param document The XML DOM document * @return An {@link Element} based on the provided {@link Property}. * @since 1.13 */ private Element getXmlElement(String name, final Property property, final Map<String, Model> definitions, final Document document) { Element element = null; if (name == null) { name = property.getType(); } if (property instanceof RefProperty) { final RefProperty refProperty = (RefProperty) property; final String simpleRef = refProperty.getSimpleRef(); final Model model = definitions.get(simpleRef); if (model == null) { LOGGER.warn("Unable to find the following definition in the Swagger file: " + simpleRef); return null; } element = getXmlElement(model, definitions, document); } else if (property instanceof ArrayProperty) { final ArrayProperty arrayProperty = (ArrayProperty) property; final Property item = arrayProperty.getItems(); final int maxItems = getMaxItems(arrayProperty.getMaxItems()); element = document.createElement(name); for (int index = 0; index < maxItems; index++) { Element child = getXmlElement(name, item, definitions, document); element.appendChild(child); } } else { String expression = getExpressionIdentifier(property); element = document.createElement(name); if (expression != null) { Text text = document.createTextNode(expression); element.appendChild(text); } else { } } return element; }
From source file:be.docarch.odt2braille.PEF.java
/** * maxPages: -1 = infinity// w w w. ja va 2 s .c om */ private int addPagesToSection(Document document, Element sectionElement, File brailleFile, int maxRows, int maxCols, int maxPages) throws IOException, Exception { int pageCount = 0; FileInputStream fileInputStream = new FileInputStream(brailleFile); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); Element pageElement; Element rowElement; Node textNode; String line; boolean nextPage = bufferedReader.ready() && (maxPages > pageCount || maxPages == -1); try { while (nextPage) { pageElement = document.createElementNS(pefNS, "page"); for (int i = 0; i < maxRows; i++) { line = bufferedReader.readLine(); if (line == null) { throw new Exception("number of rows < " + maxRows); } line = line.replaceAll("\u2800", "\u0020").replaceAll("\u00A0", "\u0020") .replaceAll("\uE00F", "\u002D").replaceAll("\uE000", "\u0020"); if (line.length() > maxCols) { throw new Exception("line length > " + maxCols); } rowElement = document.createElementNS(pefNS, "row"); textNode = document.createTextNode(liblouisTable.toBraille(line)); rowElement.appendChild(textNode); pageElement.appendChild(rowElement); if (IS_WINDOWS) { bufferedReader.readLine(); } } sectionElement.appendChild(pageElement); pageCount++; if (bufferedReader.read() != '\f') { throw new Exception("unexpected character, should be form feed"); } nextPage = nextPage = bufferedReader.ready() && (maxPages > pageCount || maxPages == -1); } } finally { if (bufferedReader != null) { bufferedReader.close(); inputStreamReader.close(); fileInputStream.close(); } } return pageCount; }
From source file:com.microsoft.windowsazure.management.sql.DacOperationsImpl.java
/** * Initiates an Import of a DACPAC file from Azure Blob Storage into a Azure * SQL Database.// w ww .jav a 2s .co m * * @param serverName Required. The name of the Azure SQL Database Server * into which the database is being imported. * @param parameters Optional. The parameters needed to initiated the Import * 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 Represents the response that the service returns once an import * or export operation has been initiated. */ @Override public DacImportExportResponse importMethod(String serverName, DacImportParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (parameters != null) { if (parameters.getBlobCredentials() != null) { if (parameters.getBlobCredentials().getStorageAccessKey() == null) { throw new NullPointerException("parameters.BlobCredentials.StorageAccessKey"); } if (parameters.getBlobCredentials().getUri() == null) { throw new NullPointerException("parameters.BlobCredentials.Uri"); } } if (parameters.getConnectionInfo() != null) { if (parameters.getConnectionInfo().getDatabaseName() == null) { throw new NullPointerException("parameters.ConnectionInfo.DatabaseName"); } if (parameters.getConnectionInfo().getPassword() == null) { throw new NullPointerException("parameters.ConnectionInfo.Password"); } if (parameters.getConnectionInfo().getServerName() == null) { throw new NullPointerException("parameters.ConnectionInfo.ServerName"); } if (parameters.getConnectionInfo().getUserName() == null) { throw new NullPointerException("parameters.ConnectionInfo.UserName"); } } } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "importMethodAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/DacOperations/Import"; 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", "2012-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); if (parameters != null) { Element importInputElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "ImportInput"); requestDoc.appendChild(importInputElement); if (parameters.getAzureEdition() != null) { Element azureEditionElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "AzureEdition"); azureEditionElement.appendChild(requestDoc.createTextNode(parameters.getAzureEdition())); importInputElement.appendChild(azureEditionElement); } if (parameters.getBlobCredentials() != null) { Element blobCredentialsElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "BlobCredentials"); importInputElement.appendChild(blobCredentialsElement); Attr typeAttribute = requestDoc.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"); typeAttribute.setValue("BlobStorageAccessKeyCredentials"); blobCredentialsElement.setAttributeNode(typeAttribute); Element uriElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "Uri"); uriElement.appendChild( requestDoc.createTextNode(parameters.getBlobCredentials().getUri().toString())); blobCredentialsElement.appendChild(uriElement); Element storageAccessKeyElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "StorageAccessKey"); storageAccessKeyElement.appendChild( requestDoc.createTextNode(parameters.getBlobCredentials().getStorageAccessKey())); blobCredentialsElement.appendChild(storageAccessKeyElement); } if (parameters.getConnectionInfo() != null) { Element connectionInfoElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "ConnectionInfo"); importInputElement.appendChild(connectionInfoElement); Element databaseNameElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "DatabaseName"); databaseNameElement .appendChild(requestDoc.createTextNode(parameters.getConnectionInfo().getDatabaseName())); connectionInfoElement.appendChild(databaseNameElement); Element passwordElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "Password"); passwordElement .appendChild(requestDoc.createTextNode(parameters.getConnectionInfo().getPassword())); connectionInfoElement.appendChild(passwordElement); Element serverNameElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "ServerName"); serverNameElement .appendChild(requestDoc.createTextNode(parameters.getConnectionInfo().getServerName())); connectionInfoElement.appendChild(serverNameElement); Element userNameElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "UserName"); userNameElement .appendChild(requestDoc.createTextNode(parameters.getConnectionInfo().getUserName())); connectionInfoElement.appendChild(userNameElement); } Element databaseSizeInGBElement = requestDoc.createElementNS( "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes", "DatabaseSizeInGB"); databaseSizeInGBElement .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getDatabaseSizeInGB()))); importInputElement.appendChild(databaseSizeInGBElement); } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DacImportExportResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DacImportExportResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element guidElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/2003/10/Serialization/", "guid"); if (guidElement != null) { result.setGuid(guidElement.getTextContent()); } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }