List of usage examples for javax.xml.bind DatatypeConverter parseLong
public static long parseLong(String lexicalXSDLong)
Converts the string argument into a long value.
From source file:com.microsoft.windowsazure.management.sql.RestorableDroppedDatabaseOperationsImpl.java
/** * Returns information about a dropped Azure SQL Database that can be * restored./*from w w w. jav a2s . c om*/ * * @param serverName Required. The name of the Azure SQL Database Server on * which the database was hosted. * @param entityId Required. The entity ID of the restorable dropped Azure * SQL Database to be obtained. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return Contains the response to the Get Restorable Dropped Database * request. */ @Override public RestorableDroppedDatabaseGetResponse get(String serverName, String entityId) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (entityId == null) { throw new NullPointerException("entityId"); } // 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("entityId", entityId); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/restorabledroppeddatabases/"; url = url + URLEncoder.encode(entityId, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result RestorableDroppedDatabaseGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new RestorableDroppedDatabaseGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement != null) { RestorableDroppedDatabase serviceResourceInstance = new RestorableDroppedDatabase(); result.setDatabase(serviceResourceInstance); Element entityIdElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "EntityId"); if (entityIdElement != null) { String entityIdInstance; entityIdInstance = entityIdElement.getTextContent(); serviceResourceInstance.setEntityId(entityIdInstance); } Element serverNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "ServerName"); if (serverNameElement != null) { String serverNameInstance; serverNameInstance = serverNameElement.getTextContent(); serviceResourceInstance.setServerName(serverNameInstance); } Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement != null) { String editionInstance; editionInstance = editionElement.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element maxSizeBytesElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); if (maxSizeBytesElement != null) { long maxSizeBytesInstance; maxSizeBytesInstance = DatatypeConverter.parseLong(maxSizeBytesElement.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance); } Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "CreationDate"); if (creationDateElement != null) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateElement.getTextContent()); serviceResourceInstance.setCreationDate(creationDateInstance); } Element deletionDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "DeletionDate"); if (deletionDateElement != null) { Calendar deletionDateInstance; deletionDateInstance = DatatypeConverter .parseDateTime(deletionDateElement.getTextContent()); serviceResourceInstance.setDeletionDate(deletionDateInstance); } Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "RecoveryPeriodStartDate"); if (recoveryPeriodStartDateElement != null && recoveryPeriodStartDateElement.getTextContent() != null && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) { Calendar recoveryPeriodStartDateInstance; recoveryPeriodStartDateInstance = DatatypeConverter .parseDateTime(recoveryPeriodStartDateElement.getTextContent()); serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationsImpl.java
/** * Creates a database in an Azure SQL Database Server. * * @param serverName Required. The name of the Azure SQL Database Server * where the database will be created./*from w w w . ja va 2 s . c o m*/ * @param parameters Required. The parameters for the create database * operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return Represents the response to a create database request from the * service. */ @Override public DatabaseCreateResponse create(String serverName, DatabaseCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } 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("serverName", serverName); 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/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases"; 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 serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceResource"); requestDoc.appendChild(serviceResourceElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); serviceResourceElement.appendChild(nameElement); if (parameters.getEdition() != null) { Element editionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Edition"); editionElement.appendChild(requestDoc.createTextNode(parameters.getEdition())); serviceResourceElement.appendChild(editionElement); } if (parameters.getMaximumDatabaseSizeInGB() != null) { Element maxSizeGBElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); maxSizeGBElement.appendChild( requestDoc.createTextNode(Integer.toString(parameters.getMaximumDatabaseSizeInGB()))); serviceResourceElement.appendChild(maxSizeGBElement); } if (parameters.getCollationName() != null) { Element collationNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "CollationName"); collationNameElement.appendChild(requestDoc.createTextNode(parameters.getCollationName())); serviceResourceElement.appendChild(collationNameElement); } if (parameters.getMaximumDatabaseSizeInBytes() != null) { Element maxSizeBytesElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); maxSizeBytesElement.appendChild( requestDoc.createTextNode(Long.toString(parameters.getMaximumDatabaseSizeInBytes()))); serviceResourceElement.appendChild(maxSizeBytesElement); } if (parameters.getServiceObjectiveId() != null) { Element serviceObjectiveIdElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); serviceObjectiveIdElement.appendChild(requestDoc.createTextNode(parameters.getServiceObjectiveId())); serviceResourceElement.appendChild(serviceObjectiveIdElement); } 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_CREATED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement2 != null) { Database serviceResourceInstance = new Database(); result.setDatabase(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { int idInstance; idInstance = DatatypeConverter.parseInt(idElement.getTextContent()); serviceResourceInstance.setId(idInstance); } Element editionElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement2 != null) { String editionInstance; editionInstance = editionElement2.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element maxSizeGBElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); if (maxSizeGBElement2 != null) { int maxSizeGBInstance; maxSizeGBInstance = DatatypeConverter.parseInt(maxSizeGBElement2.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInGB(maxSizeGBInstance); } Element maxSizeBytesElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); if (maxSizeBytesElement2 != null) { long maxSizeBytesInstance; maxSizeBytesInstance = DatatypeConverter.parseLong(maxSizeBytesElement2.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance); } Element collationNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "CollationName"); if (collationNameElement2 != null) { String collationNameInstance; collationNameInstance = collationNameElement2.getTextContent(); serviceResourceInstance.setCollationName(collationNameInstance); } Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "CreationDate"); if (creationDateElement != null) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateElement.getTextContent()); serviceResourceInstance.setCreationDate(creationDateInstance); } Element isFederationRootElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsFederationRoot"); if (isFederationRootElement != null) { boolean isFederationRootInstance; isFederationRootInstance = DatatypeConverter .parseBoolean(isFederationRootElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsFederationRoot(isFederationRootInstance); } Element isSystemObjectElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsSystemObject"); if (isSystemObjectElement != null) { boolean isSystemObjectInstance; isSystemObjectInstance = DatatypeConverter .parseBoolean(isSystemObjectElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsSystemObject(isSystemObjectInstance); } Element sizeMBElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SizeMB"); if (sizeMBElement != null) { String sizeMBInstance; sizeMBInstance = sizeMBElement.getTextContent(); serviceResourceInstance.setSizeMB(sizeMBInstance); } Element serviceObjectiveAssignmentErrorCodeElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorCode"); if (serviceObjectiveAssignmentErrorCodeElement != null) { String serviceObjectiveAssignmentErrorCodeInstance; serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorCode( serviceObjectiveAssignmentErrorCodeInstance); } Element serviceObjectiveAssignmentErrorDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorDescription"); if (serviceObjectiveAssignmentErrorDescriptionElement != null) { String serviceObjectiveAssignmentErrorDescriptionInstance; serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorDescription( serviceObjectiveAssignmentErrorDescriptionInstance); } Element serviceObjectiveAssignmentStateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentState"); if (serviceObjectiveAssignmentStateElement != null) { String serviceObjectiveAssignmentStateInstance; serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement .getTextContent(); serviceResourceInstance .setServiceObjectiveAssignmentState(serviceObjectiveAssignmentStateInstance); } Element serviceObjectiveAssignmentStateDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentStateDescription"); if (serviceObjectiveAssignmentStateDescriptionElement != null) { String serviceObjectiveAssignmentStateDescriptionInstance; serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentStateDescription( serviceObjectiveAssignmentStateDescriptionInstance); } Element serviceObjectiveAssignmentSuccessDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentSuccessDate"); if (serviceObjectiveAssignmentSuccessDateElement != null) { String serviceObjectiveAssignmentSuccessDateInstance; serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentSuccessDate( serviceObjectiveAssignmentSuccessDateInstance); } Element serviceObjectiveIdElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); if (serviceObjectiveIdElement2 != null) { String serviceObjectiveIdInstance; serviceObjectiveIdInstance = serviceObjectiveIdElement2.getTextContent(); serviceResourceInstance.setServiceObjectiveId(serviceObjectiveIdInstance); } Element assignedServiceObjectiveIdElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "AssignedServiceObjectiveId"); if (assignedServiceObjectiveIdElement != null) { String assignedServiceObjectiveIdInstance; assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement.getTextContent(); serviceResourceInstance.setAssignedServiceObjectiveId(assignedServiceObjectiveIdInstance); } Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "RecoveryPeriodStartDate"); if (recoveryPeriodStartDateElement != null && recoveryPeriodStartDateElement.getTextContent() != null && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) { Calendar recoveryPeriodStartDateInstance; recoveryPeriodStartDateInstance = DatatypeConverter .parseDateTime(recoveryPeriodStartDateElement.getTextContent()); serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.sql.RestorableDroppedDatabaseOperationsImpl.java
/** * Returns a collection of databases that has been dropped but can still be * restored from a specified server./* ww w . ja v a 2 s. c om*/ * * @param serverName Required. The name of the Azure SQL Database Server to * query for dropped databases that can still be restored. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return Contains the response to the List Restorable Dropped Databases * request. */ @Override public RestorableDroppedDatabaseListResponse list(String serverName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); CloudTracing.enter(invocationId, this, "listAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/restorabledroppeddatabases"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("contentview=generic"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result RestorableDroppedDatabaseListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new RestorableDroppedDatabaseListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); RestorableDroppedDatabase serviceResourceInstance = new RestorableDroppedDatabase(); result.getDatabases().add(serviceResourceInstance); Element entityIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EntityId"); if (entityIdElement != null) { String entityIdInstance; entityIdInstance = entityIdElement.getTextContent(); serviceResourceInstance.setEntityId(entityIdInstance); } Element serverNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServerName"); if (serverNameElement != null) { String serverNameInstance; serverNameInstance = serverNameElement.getTextContent(); serviceResourceInstance.setServerName(serverNameInstance); } Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement != null) { String editionInstance; editionInstance = editionElement.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element maxSizeBytesElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); if (maxSizeBytesElement != null) { long maxSizeBytesInstance; maxSizeBytesInstance = DatatypeConverter .parseLong(maxSizeBytesElement.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance); } Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "CreationDate"); if (creationDateElement != null) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateElement.getTextContent()); serviceResourceInstance.setCreationDate(creationDateInstance); } Element deletionDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "DeletionDate"); if (deletionDateElement != null) { Calendar deletionDateInstance; deletionDateInstance = DatatypeConverter .parseDateTime(deletionDateElement.getTextContent()); serviceResourceInstance.setDeletionDate(deletionDateInstance); } Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "RecoveryPeriodStartDate"); if (recoveryPeriodStartDateElement != null && recoveryPeriodStartDateElement.getTextContent() != null && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) { Calendar recoveryPeriodStartDateInstance; recoveryPeriodStartDateInstance = DatatypeConverter .parseDateTime(recoveryPeriodStartDateElement.getTextContent()); serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * Backups a site on-demand.// w w w .j a v a 2s.co m * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @param backupRequest Required. A backup specification. * @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 The backup record created based on the backup request. */ @Override public WebSiteBackupResponse backup(String webSpaceName, String webSiteName, BackupRequest backupRequest) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } if (backupRequest == null) { throw new NullPointerException("backupRequest"); } // 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("webSiteName", webSiteName); tracingParameters.put("backupRequest", backupRequest); CloudTracing.enter(invocationId, this, "backupAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); url = url + "/backup"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2014-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element backupRequestElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "BackupRequest"); requestDoc.appendChild(backupRequestElement); if (backupRequest.getBackupSchedule() != null) { Element backupScheduleElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "BackupSchedule"); backupRequestElement.appendChild(backupScheduleElement); Element frequencyIntervalElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "FrequencyInterval"); frequencyIntervalElement.appendChild(requestDoc .createTextNode(Integer.toString(backupRequest.getBackupSchedule().getFrequencyInterval()))); backupScheduleElement.appendChild(frequencyIntervalElement); if (backupRequest.getBackupSchedule().getFrequencyUnit() != null) { Element frequencyUnitElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "FrequencyUnit"); frequencyUnitElement.appendChild( requestDoc.createTextNode(backupRequest.getBackupSchedule().getFrequencyUnit().toString())); backupScheduleElement.appendChild(frequencyUnitElement); } Element keepAtLeastOneBackupElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "KeepAtLeastOneBackup"); keepAtLeastOneBackupElement.appendChild(requestDoc.createTextNode( Boolean.toString(backupRequest.getBackupSchedule().isKeepAtLeastOneBackup()).toLowerCase())); backupScheduleElement.appendChild(keepAtLeastOneBackupElement); if (backupRequest.getBackupSchedule().getLastExecutionTime() != null) { Element lastExecutionTimeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "LastExecutionTime"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); lastExecutionTimeElement.appendChild(requestDoc.createTextNode(simpleDateFormat .format(backupRequest.getBackupSchedule().getLastExecutionTime().getTime()))); backupScheduleElement.appendChild(lastExecutionTimeElement); } Element retentionPeriodInDaysElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "RetentionPeriodInDays"); retentionPeriodInDaysElement.appendChild(requestDoc.createTextNode( Integer.toString(backupRequest.getBackupSchedule().getRetentionPeriodInDays()))); backupScheduleElement.appendChild(retentionPeriodInDaysElement); if (backupRequest.getBackupSchedule().getStartTime() != null) { Element startTimeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "StartTime"); SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC")); startTimeElement.appendChild(requestDoc.createTextNode( simpleDateFormat2.format(backupRequest.getBackupSchedule().getStartTime().getTime()))); backupScheduleElement.appendChild(startTimeElement); } } if (backupRequest.getDatabases() != null) { if (backupRequest.getDatabases() instanceof LazyCollection == false || ((LazyCollection) backupRequest.getDatabases()).isInitialized()) { Element databasesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Databases"); for (DatabaseBackupSetting databasesItem : backupRequest.getDatabases()) { Element databaseBackupSettingElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DatabaseBackupSetting"); databasesSequenceElement.appendChild(databaseBackupSettingElement); if (databasesItem.getConnectionString() != null) { Element connectionStringElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ConnectionString"); connectionStringElement .appendChild(requestDoc.createTextNode(databasesItem.getConnectionString())); databaseBackupSettingElement.appendChild(connectionStringElement); } if (databasesItem.getConnectionStringName() != null) { Element connectionStringNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "ConnectionStringName"); connectionStringNameElement .appendChild(requestDoc.createTextNode(databasesItem.getConnectionStringName())); databaseBackupSettingElement.appendChild(connectionStringNameElement); } if (databasesItem.getDatabaseType() != null) { Element databaseTypeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "DatabaseType"); databaseTypeElement.appendChild(requestDoc.createTextNode(databasesItem.getDatabaseType())); databaseBackupSettingElement.appendChild(databaseTypeElement); } if (databasesItem.getName() != null) { Element nameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(databasesItem.getName())); databaseBackupSettingElement.appendChild(nameElement); } } backupRequestElement.appendChild(databasesSequenceElement); } } if (backupRequest.isEnabled() != null) { Element enabledElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Enabled"); enabledElement.appendChild( requestDoc.createTextNode(Boolean.toString(backupRequest.isEnabled()).toLowerCase())); backupRequestElement.appendChild(enabledElement); } if (backupRequest.getName() != null) { Element nameElement2 = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement2.appendChild(requestDoc.createTextNode(backupRequest.getName())); backupRequestElement.appendChild(nameElement2); } if (backupRequest.getStorageAccountUrl() != null) { Element storageAccountUrlElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "StorageAccountUrl"); storageAccountUrlElement.appendChild(requestDoc.createTextNode(backupRequest.getStorageAccountUrl())); backupRequestElement.appendChild(storageAccountUrlElement); } 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 WebSiteBackupResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteBackupResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element backupItemElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "BackupItem"); if (backupItemElement != null) { BackupItem backupItemInstance = new BackupItem(); result.setBackupItem(backupItemInstance); Element storageAccountUrlElement2 = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "StorageAccountUrl"); if (storageAccountUrlElement2 != null) { String storageAccountUrlInstance; storageAccountUrlInstance = storageAccountUrlElement2.getTextContent(); backupItemInstance.setStorageAccountUrl(storageAccountUrlInstance); } Element blobNameElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "BlobName"); if (blobNameElement != null) { String blobNameInstance; blobNameInstance = blobNameElement.getTextContent(); backupItemInstance.setBlobName(blobNameInstance); } Element nameElement3 = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement3 != null) { String nameInstance; nameInstance = nameElement3.getTextContent(); backupItemInstance.setName(nameInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { BackupItemStatus statusInstance; statusInstance = BackupItemStatus.valueOf(statusElement.getTextContent()); backupItemInstance.setStatus(statusInstance); } Element sizeInBytesElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "SizeInBytes"); if (sizeInBytesElement != null) { long sizeInBytesInstance; sizeInBytesInstance = DatatypeConverter.parseLong(sizeInBytesElement.getTextContent()); backupItemInstance.setSizeInBytes(sizeInBytesInstance); } Element createdElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "Created"); if (createdElement != null && createdElement.getTextContent() != null && !createdElement.getTextContent().isEmpty()) { Calendar createdInstance; createdInstance = DatatypeConverter.parseDateTime(createdElement.getTextContent()); backupItemInstance.setCreated(createdInstance); } Element logElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "Log"); if (logElement != null) { String logInstance; logInstance = logElement.getTextContent(); backupItemInstance.setLog(logInstance); } Element databasesSequenceElement2 = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "Databases"); if (databasesSequenceElement2 != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement2, "http://schemas.microsoft.com/windowsazure", "DatabaseBackupSetting") .size(); i1 = i1 + 1) { org.w3c.dom.Element databasesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement2, "http://schemas.microsoft.com/windowsazure", "DatabaseBackupSetting") .get(i1)); DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting(); backupItemInstance.getDatabases().add(databaseBackupSettingInstance); Element connectionStringElement2 = XmlUtility.getElementByTagNameNS(databasesElement, "http://schemas.microsoft.com/windowsazure", "ConnectionString"); if (connectionStringElement2 != null) { String connectionStringInstance; connectionStringInstance = connectionStringElement2.getTextContent(); databaseBackupSettingInstance.setConnectionString(connectionStringInstance); } Element connectionStringNameElement2 = XmlUtility.getElementByTagNameNS( databasesElement, "http://schemas.microsoft.com/windowsazure", "ConnectionStringName"); if (connectionStringNameElement2 != null) { String connectionStringNameInstance; connectionStringNameInstance = connectionStringNameElement2.getTextContent(); databaseBackupSettingInstance.setConnectionStringName(connectionStringNameInstance); } Element databaseTypeElement2 = XmlUtility.getElementByTagNameNS(databasesElement, "http://schemas.microsoft.com/windowsazure", "DatabaseType"); if (databaseTypeElement2 != null) { String databaseTypeInstance; databaseTypeInstance = databaseTypeElement2.getTextContent(); databaseBackupSettingInstance.setDatabaseType(databaseTypeInstance); } Element nameElement4 = XmlUtility.getElementByTagNameNS(databasesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement4 != null) { String nameInstance2; nameInstance2 = nameElement4.getTextContent(); databaseBackupSettingInstance.setName(nameInstance2); } } } Element scheduledElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "Scheduled"); if (scheduledElement != null) { boolean scheduledInstance; scheduledInstance = DatatypeConverter .parseBoolean(scheduledElement.getTextContent().toLowerCase()); backupItemInstance.setScheduled(scheduledInstance); } Element lastRestoreTimeStampElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "LastRestoreTimeStamp"); if (lastRestoreTimeStampElement != null && lastRestoreTimeStampElement.getTextContent() != null && !lastRestoreTimeStampElement.getTextContent().isEmpty()) { Calendar lastRestoreTimeStampInstance; lastRestoreTimeStampInstance = DatatypeConverter .parseDateTime(lastRestoreTimeStampElement.getTextContent()); backupItemInstance.setLastRestoreTimeStamp(lastRestoreTimeStampInstance); } Element finishedTimeStampElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "FinishedTimeStamp"); if (finishedTimeStampElement != null && finishedTimeStampElement.getTextContent() != null && !finishedTimeStampElement.getTextContent().isEmpty()) { Calendar finishedTimeStampInstance; finishedTimeStampInstance = DatatypeConverter .parseDateTime(finishedTimeStampElement.getTextContent()); backupItemInstance.setFinishedTimeStamp(finishedTimeStampInstance); } Element correlationIdElement = XmlUtility.getElementByTagNameNS(backupItemElement, "http://schemas.microsoft.com/windowsazure", "CorrelationId"); if (correlationIdElement != null) { String correlationIdInstance; correlationIdInstance = correlationIdElement.getTextContent(); backupItemInstance.setCorrelationId(correlationIdInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationsImpl.java
/** * Returns information about an Azure SQL Database. * * @param serverName Required. The name of the Azure SQL Database Server on * which the database is hosted.// w w w . j av a 2 s . com * @param databaseName Required. The name of the Azure SQL Database to be * retrieved. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return Contains the response to a Get Database request. */ @Override public DatabaseGetResponse get(String serverName, String databaseName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("databaseName", databaseName); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases/"; url = url + URLEncoder.encode(databaseName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement != null) { Database serviceResourceInstance = new Database(); result.setDatabase(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { int idInstance; idInstance = DatatypeConverter.parseInt(idElement.getTextContent()); serviceResourceInstance.setId(idInstance); } Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement != null) { String editionInstance; editionInstance = editionElement.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element maxSizeGBElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); if (maxSizeGBElement != null) { int maxSizeGBInstance; maxSizeGBInstance = DatatypeConverter.parseInt(maxSizeGBElement.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInGB(maxSizeGBInstance); } Element maxSizeBytesElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); if (maxSizeBytesElement != null) { long maxSizeBytesInstance; maxSizeBytesInstance = DatatypeConverter.parseLong(maxSizeBytesElement.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance); } Element collationNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "CollationName"); if (collationNameElement != null) { String collationNameInstance; collationNameInstance = collationNameElement.getTextContent(); serviceResourceInstance.setCollationName(collationNameInstance); } Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "CreationDate"); if (creationDateElement != null) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateElement.getTextContent()); serviceResourceInstance.setCreationDate(creationDateInstance); } Element isFederationRootElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "IsFederationRoot"); if (isFederationRootElement != null) { boolean isFederationRootInstance; isFederationRootInstance = DatatypeConverter .parseBoolean(isFederationRootElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsFederationRoot(isFederationRootInstance); } Element isSystemObjectElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "IsSystemObject"); if (isSystemObjectElement != null) { boolean isSystemObjectInstance; isSystemObjectInstance = DatatypeConverter .parseBoolean(isSystemObjectElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsSystemObject(isSystemObjectInstance); } Element sizeMBElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "SizeMB"); if (sizeMBElement != null) { String sizeMBInstance; sizeMBInstance = sizeMBElement.getTextContent(); serviceResourceInstance.setSizeMB(sizeMBInstance); } Element serviceObjectiveAssignmentErrorCodeElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorCode"); if (serviceObjectiveAssignmentErrorCodeElement != null) { String serviceObjectiveAssignmentErrorCodeInstance; serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorCode( serviceObjectiveAssignmentErrorCodeInstance); } Element serviceObjectiveAssignmentErrorDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorDescription"); if (serviceObjectiveAssignmentErrorDescriptionElement != null) { String serviceObjectiveAssignmentErrorDescriptionInstance; serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorDescription( serviceObjectiveAssignmentErrorDescriptionInstance); } Element serviceObjectiveAssignmentStateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentState"); if (serviceObjectiveAssignmentStateElement != null) { String serviceObjectiveAssignmentStateInstance; serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement .getTextContent(); serviceResourceInstance .setServiceObjectiveAssignmentState(serviceObjectiveAssignmentStateInstance); } Element serviceObjectiveAssignmentStateDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentStateDescription"); if (serviceObjectiveAssignmentStateDescriptionElement != null) { String serviceObjectiveAssignmentStateDescriptionInstance; serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentStateDescription( serviceObjectiveAssignmentStateDescriptionInstance); } Element serviceObjectiveAssignmentSuccessDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentSuccessDate"); if (serviceObjectiveAssignmentSuccessDateElement != null) { String serviceObjectiveAssignmentSuccessDateInstance; serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentSuccessDate( serviceObjectiveAssignmentSuccessDateInstance); } Element serviceObjectiveIdElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); if (serviceObjectiveIdElement != null) { String serviceObjectiveIdInstance; serviceObjectiveIdInstance = serviceObjectiveIdElement.getTextContent(); serviceResourceInstance.setServiceObjectiveId(serviceObjectiveIdInstance); } Element assignedServiceObjectiveIdElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "AssignedServiceObjectiveId"); if (assignedServiceObjectiveIdElement != null) { String assignedServiceObjectiveIdInstance; assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement.getTextContent(); serviceResourceInstance.setAssignedServiceObjectiveId(assignedServiceObjectiveIdInstance); } Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "RecoveryPeriodStartDate"); if (recoveryPeriodStartDateElement != null && recoveryPeriodStartDateElement.getTextContent() != null && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) { Calendar recoveryPeriodStartDateInstance; recoveryPeriodStartDateInstance = DatatypeConverter .parseDateTime(recoveryPeriodStartDateElement.getTextContent()); serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationsImpl.java
/** * Returns a collection of Azure SQL Databases. * * @param serverName Required. The name of the Azure SQL Database Server * from which to retrieve the database./*from ww w. ja va2s . co m*/ * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return Contains a collection of databases for a given Azure SQL Database * Server. */ @Override public DatabaseListResponse list(String serverName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); CloudTracing.enter(invocationId, this, "listAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("contentview=generic"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); Database serviceResourceInstance = new Database(); result.getDatabases().add(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { int idInstance; idInstance = DatatypeConverter.parseInt(idElement.getTextContent()); serviceResourceInstance.setId(idInstance); } Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement != null) { String editionInstance; editionInstance = editionElement.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element maxSizeGBElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); if (maxSizeGBElement != null) { int maxSizeGBInstance; maxSizeGBInstance = DatatypeConverter.parseInt(maxSizeGBElement.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInGB(maxSizeGBInstance); } Element maxSizeBytesElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); if (maxSizeBytesElement != null) { long maxSizeBytesInstance; maxSizeBytesInstance = DatatypeConverter .parseLong(maxSizeBytesElement.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance); } Element collationNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "CollationName"); if (collationNameElement != null) { String collationNameInstance; collationNameInstance = collationNameElement.getTextContent(); serviceResourceInstance.setCollationName(collationNameInstance); } Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "CreationDate"); if (creationDateElement != null) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateElement.getTextContent()); serviceResourceInstance.setCreationDate(creationDateInstance); } Element isFederationRootElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsFederationRoot"); if (isFederationRootElement != null) { boolean isFederationRootInstance; isFederationRootInstance = DatatypeConverter .parseBoolean(isFederationRootElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsFederationRoot(isFederationRootInstance); } Element isSystemObjectElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsSystemObject"); if (isSystemObjectElement != null) { boolean isSystemObjectInstance; isSystemObjectInstance = DatatypeConverter .parseBoolean(isSystemObjectElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsSystemObject(isSystemObjectInstance); } Element sizeMBElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "SizeMB"); if (sizeMBElement != null) { String sizeMBInstance; sizeMBInstance = sizeMBElement.getTextContent(); serviceResourceInstance.setSizeMB(sizeMBInstance); } Element serviceObjectiveAssignmentErrorCodeElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorCode"); if (serviceObjectiveAssignmentErrorCodeElement != null) { String serviceObjectiveAssignmentErrorCodeInstance; serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorCode( serviceObjectiveAssignmentErrorCodeInstance); } Element serviceObjectiveAssignmentErrorDescriptionElement = XmlUtility .getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorDescription"); if (serviceObjectiveAssignmentErrorDescriptionElement != null) { String serviceObjectiveAssignmentErrorDescriptionInstance; serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorDescription( serviceObjectiveAssignmentErrorDescriptionInstance); } Element serviceObjectiveAssignmentStateElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentState"); if (serviceObjectiveAssignmentStateElement != null) { String serviceObjectiveAssignmentStateInstance; serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement .getTextContent(); serviceResourceInstance .setServiceObjectiveAssignmentState(serviceObjectiveAssignmentStateInstance); } Element serviceObjectiveAssignmentStateDescriptionElement = XmlUtility .getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentStateDescription"); if (serviceObjectiveAssignmentStateDescriptionElement != null) { String serviceObjectiveAssignmentStateDescriptionInstance; serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentStateDescription( serviceObjectiveAssignmentStateDescriptionInstance); } Element serviceObjectiveAssignmentSuccessDateElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentSuccessDate"); if (serviceObjectiveAssignmentSuccessDateElement != null) { String serviceObjectiveAssignmentSuccessDateInstance; serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentSuccessDate( serviceObjectiveAssignmentSuccessDateInstance); } Element serviceObjectiveIdElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); if (serviceObjectiveIdElement != null) { String serviceObjectiveIdInstance; serviceObjectiveIdInstance = serviceObjectiveIdElement.getTextContent(); serviceResourceInstance.setServiceObjectiveId(serviceObjectiveIdInstance); } Element assignedServiceObjectiveIdElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "AssignedServiceObjectiveId"); if (assignedServiceObjectiveIdElement != null) { String assignedServiceObjectiveIdInstance; assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement.getTextContent(); serviceResourceInstance .setAssignedServiceObjectiveId(assignedServiceObjectiveIdInstance); } Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "RecoveryPeriodStartDate"); if (recoveryPeriodStartDateElement != null && recoveryPeriodStartDateElement.getTextContent() != null && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) { Calendar recoveryPeriodStartDateInstance; recoveryPeriodStartDateInstance = DatatypeConverter .parseDateTime(recoveryPeriodStartDateElement.getTextContent()); serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationsImpl.java
/** * Updates the properties of an Azure SQL Database. * * @param serverName Required. The name of the Azure SQL Database Server * where the database is hosted.//from ww w . jav a 2 s.c o m * @param databaseName Required. The name of the Azure SQL Database to be * updated. * @param parameters Required. The parameters for the Update Database * 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 Contains the response from a request to Update Database. */ @Override public DatabaseUpdateResponse update(String serverName, String databaseName, DatabaseUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getEdition() == null) { throw new NullPointerException("parameters.Edition"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("databaseName", databaseName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "updateAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases/"; url = url + URLEncoder.encode(databaseName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2012-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceResource"); requestDoc.appendChild(serviceResourceElement); if (parameters.getName() != null) { Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); serviceResourceElement.appendChild(nameElement); } Element editionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Edition"); editionElement.appendChild(requestDoc.createTextNode(parameters.getEdition())); serviceResourceElement.appendChild(editionElement); if (parameters.getMaximumDatabaseSizeInGB() != null) { Element maxSizeGBElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); maxSizeGBElement.appendChild( requestDoc.createTextNode(Integer.toString(parameters.getMaximumDatabaseSizeInGB()))); serviceResourceElement.appendChild(maxSizeGBElement); } if (parameters.getMaximumDatabaseSizeInBytes() != null) { Element maxSizeBytesElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); maxSizeBytesElement.appendChild( requestDoc.createTextNode(Long.toString(parameters.getMaximumDatabaseSizeInBytes()))); serviceResourceElement.appendChild(maxSizeBytesElement); } if (parameters.getServiceObjectiveId() != null) { Element serviceObjectiveIdElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); serviceObjectiveIdElement.appendChild(requestDoc.createTextNode(parameters.getServiceObjectiveId())); serviceResourceElement.appendChild(serviceObjectiveIdElement); } 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 DatabaseUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseUpdateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement2 != null) { Database serviceResourceInstance = new Database(); result.setDatabase(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { int idInstance; idInstance = DatatypeConverter.parseInt(idElement.getTextContent()); serviceResourceInstance.setId(idInstance); } Element editionElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement2 != null) { String editionInstance; editionInstance = editionElement2.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element maxSizeGBElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); if (maxSizeGBElement2 != null) { int maxSizeGBInstance; maxSizeGBInstance = DatatypeConverter.parseInt(maxSizeGBElement2.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInGB(maxSizeGBInstance); } Element maxSizeBytesElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); if (maxSizeBytesElement2 != null) { long maxSizeBytesInstance; maxSizeBytesInstance = DatatypeConverter.parseLong(maxSizeBytesElement2.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance); } Element collationNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "CollationName"); if (collationNameElement != null) { String collationNameInstance; collationNameInstance = collationNameElement.getTextContent(); serviceResourceInstance.setCollationName(collationNameInstance); } Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "CreationDate"); if (creationDateElement != null) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateElement.getTextContent()); serviceResourceInstance.setCreationDate(creationDateInstance); } Element isFederationRootElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsFederationRoot"); if (isFederationRootElement != null) { boolean isFederationRootInstance; isFederationRootInstance = DatatypeConverter .parseBoolean(isFederationRootElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsFederationRoot(isFederationRootInstance); } Element isSystemObjectElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsSystemObject"); if (isSystemObjectElement != null) { boolean isSystemObjectInstance; isSystemObjectInstance = DatatypeConverter .parseBoolean(isSystemObjectElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsSystemObject(isSystemObjectInstance); } Element sizeMBElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SizeMB"); if (sizeMBElement != null) { String sizeMBInstance; sizeMBInstance = sizeMBElement.getTextContent(); serviceResourceInstance.setSizeMB(sizeMBInstance); } Element serviceObjectiveAssignmentErrorCodeElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorCode"); if (serviceObjectiveAssignmentErrorCodeElement != null) { String serviceObjectiveAssignmentErrorCodeInstance; serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorCode( serviceObjectiveAssignmentErrorCodeInstance); } Element serviceObjectiveAssignmentErrorDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorDescription"); if (serviceObjectiveAssignmentErrorDescriptionElement != null) { String serviceObjectiveAssignmentErrorDescriptionInstance; serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorDescription( serviceObjectiveAssignmentErrorDescriptionInstance); } Element serviceObjectiveAssignmentStateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentState"); if (serviceObjectiveAssignmentStateElement != null) { String serviceObjectiveAssignmentStateInstance; serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement .getTextContent(); serviceResourceInstance .setServiceObjectiveAssignmentState(serviceObjectiveAssignmentStateInstance); } Element serviceObjectiveAssignmentStateDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentStateDescription"); if (serviceObjectiveAssignmentStateDescriptionElement != null) { String serviceObjectiveAssignmentStateDescriptionInstance; serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentStateDescription( serviceObjectiveAssignmentStateDescriptionInstance); } Element serviceObjectiveAssignmentSuccessDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentSuccessDate"); if (serviceObjectiveAssignmentSuccessDateElement != null) { String serviceObjectiveAssignmentSuccessDateInstance; serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentSuccessDate( serviceObjectiveAssignmentSuccessDateInstance); } Element serviceObjectiveIdElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); if (serviceObjectiveIdElement2 != null) { String serviceObjectiveIdInstance; serviceObjectiveIdInstance = serviceObjectiveIdElement2.getTextContent(); serviceResourceInstance.setServiceObjectiveId(serviceObjectiveIdInstance); } Element assignedServiceObjectiveIdElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "AssignedServiceObjectiveId"); if (assignedServiceObjectiveIdElement != null) { String assignedServiceObjectiveIdInstance; assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement.getTextContent(); serviceResourceInstance.setAssignedServiceObjectiveId(assignedServiceObjectiveIdInstance); } Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "RecoveryPeriodStartDate"); if (recoveryPeriodStartDateElement != null && recoveryPeriodStartDateElement.getTextContent() != null && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) { Calendar recoveryPeriodStartDateInstance; recoveryPeriodStartDateInstance = DatatypeConverter .parseDateTime(recoveryPeriodStartDateElement.getTextContent()); serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.network.ApplicationGatewayOperationsImpl.java
/** * The Get Application Gateway operation retrieves the application gateway * provisioned for the given subscription. (see * http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for * more information)// ww w .ja v a2 s . c o m * * @param gatewayName Required. The name of the gateway. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return The response body contains details of the application gateway. */ @Override public ApplicationGatewayGetResponse get(String gatewayName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (gatewayName == null) { throw new NullPointerException("gatewayName"); } // 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("gatewayName", gatewayName); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/ApplicationGateways/"; url = url + URLEncoder.encode(gatewayName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-04-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2015-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ApplicationGatewayGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ApplicationGatewayGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element applicationGatewayElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ApplicationGateway"); if (applicationGatewayElement != null) { Element descriptionElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); result.setDescription(descriptionInstance); } Element dnsNameElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "DnsName"); if (dnsNameElement != null) { String dnsNameInstance; dnsNameInstance = dnsNameElement.getTextContent(); result.setDnsName(dnsNameInstance); } Element gatewaySizeElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "GatewaySize"); if (gatewaySizeElement != null) { String gatewaySizeInstance; gatewaySizeInstance = gatewaySizeElement.getTextContent(); result.setGatewaySize(gatewaySizeInstance); } Element instanceCountElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "InstanceCount"); if (instanceCountElement != null) { long instanceCountInstance; instanceCountInstance = DatatypeConverter.parseLong(instanceCountElement.getTextContent()); result.setInstanceCount(instanceCountInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); result.setName(nameInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); result.setState(stateInstance); } Element subnetsSequenceElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "Subnets"); if (subnetsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(subnetsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Subnet") .size(); i1 = i1 + 1) { org.w3c.dom.Element subnetsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(subnetsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Subnet") .get(i1)); result.getSubnets().add(subnetsElement.getTextContent()); } } Element vnetNameElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "VnetName"); if (vnetNameElement != null) { String vnetNameInstance; vnetNameInstance = vnetNameElement.getTextContent(); result.setVnetName(vnetNameInstance); } Element virtualIPsSequenceElement = XmlUtility.getElementByTagNameNS(applicationGatewayElement, "http://schemas.microsoft.com/windowsazure", "VirtualIPs"); if (virtualIPsSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(virtualIPsSequenceElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP") .size(); i2 = i2 + 1) { org.w3c.dom.Element virtualIPsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(virtualIPsSequenceElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP") .get(i2)); result.getVirtualIPs().add(virtualIPsElement.getTextContent()); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.network.ApplicationGatewayOperationsImpl.java
/** * The List Application Gateway operation retrieves all application gateays * for the given subscription. (see//from w ww . j av a2 s. c om * http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for * more information) * * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return The response of ListApplicationGateways request. */ @Override public ApplicationGatewayListResponse list() throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); CloudTracing.enter(invocationId, this, "listAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/ApplicationGateways"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-04-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2015-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ApplicationGatewayListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ApplicationGatewayListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element applicationGatewaysSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ApplicationGateways"); if (applicationGatewaysSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(applicationGatewaysSequenceElement, "http://schemas.microsoft.com/windowsazure", "ApplicationGateway") .size(); i1 = i1 + 1) { org.w3c.dom.Element applicationGatewaysElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(applicationGatewaysSequenceElement, "http://schemas.microsoft.com/windowsazure", "ApplicationGateway") .get(i1)); ApplicationGatewayGetResponse applicationGatewayInstance = new ApplicationGatewayGetResponse(); result.getApplicationGateways().add(applicationGatewayInstance); Element descriptionElement = XmlUtility.getElementByTagNameNS(applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); applicationGatewayInstance.setDescription(descriptionInstance); } Element dnsNameElement = XmlUtility.getElementByTagNameNS(applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "DnsName"); if (dnsNameElement != null) { String dnsNameInstance; dnsNameInstance = dnsNameElement.getTextContent(); applicationGatewayInstance.setDnsName(dnsNameInstance); } Element gatewaySizeElement = XmlUtility.getElementByTagNameNS(applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "GatewaySize"); if (gatewaySizeElement != null) { String gatewaySizeInstance; gatewaySizeInstance = gatewaySizeElement.getTextContent(); applicationGatewayInstance.setGatewaySize(gatewaySizeInstance); } Element instanceCountElement = XmlUtility.getElementByTagNameNS(applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "InstanceCount"); if (instanceCountElement != null) { long instanceCountInstance; instanceCountInstance = DatatypeConverter .parseLong(instanceCountElement.getTextContent()); applicationGatewayInstance.setInstanceCount(instanceCountInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); applicationGatewayInstance.setName(nameInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); applicationGatewayInstance.setState(stateInstance); } Element subnetsSequenceElement = XmlUtility.getElementByTagNameNS( applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "Subnets"); if (subnetsSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(subnetsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Subnet") .size(); i2 = i2 + 1) { org.w3c.dom.Element subnetsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(subnetsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Subnet") .get(i2)); applicationGatewayInstance.getSubnets().add(subnetsElement.getTextContent()); } } Element vnetNameElement = XmlUtility.getElementByTagNameNS(applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "VnetName"); if (vnetNameElement != null) { String vnetNameInstance; vnetNameInstance = vnetNameElement.getTextContent(); applicationGatewayInstance.setVnetName(vnetNameInstance); } Element virtualIPsSequenceElement = XmlUtility.getElementByTagNameNS( applicationGatewaysElement, "http://schemas.microsoft.com/windowsazure", "VirtualIPs"); if (virtualIPsSequenceElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(virtualIPsSequenceElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP") .size(); i3 = i3 + 1) { org.w3c.dom.Element virtualIPsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(virtualIPsSequenceElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP") .get(i3)); applicationGatewayInstance.getVirtualIPs().add(virtualIPsElement.getTextContent()); } } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * Returns list of all backups which are tracked by the system. * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations.//from w ww.ja v a 2 s .c o m * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return List of backups for the website. */ @Override public WebSiteGetBackupsResponse listBackups(String webSpaceName, String webSiteName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } // 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("webSiteName", webSiteName); CloudTracing.enter(invocationId, this, "listBackupsAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); url = url + "/restore"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2014-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSiteGetBackupsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetBackupsResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element backupItemsElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "BackupItems"); if (backupItemsElement != null) { if (backupItemsElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(backupItemsElement, "http://schemas.microsoft.com/windowsazure", "BackupItem") .size(); i1 = i1 + 1) { org.w3c.dom.Element backupItemsElement2 = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(backupItemsElement, "http://schemas.microsoft.com/windowsazure", "BackupItem") .get(i1)); BackupItem backupItemInstance = new BackupItem(); result.getBackupItems().add(backupItemInstance); Element storageAccountUrlElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "StorageAccountUrl"); if (storageAccountUrlElement != null) { String storageAccountUrlInstance; storageAccountUrlInstance = storageAccountUrlElement.getTextContent(); backupItemInstance.setStorageAccountUrl(storageAccountUrlInstance); } Element blobNameElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "BlobName"); if (blobNameElement != null) { String blobNameInstance; blobNameInstance = blobNameElement.getTextContent(); backupItemInstance.setBlobName(blobNameInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); backupItemInstance.setName(nameInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { BackupItemStatus statusInstance; statusInstance = BackupItemStatus.valueOf(statusElement.getTextContent()); backupItemInstance.setStatus(statusInstance); } Element sizeInBytesElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "SizeInBytes"); if (sizeInBytesElement != null) { long sizeInBytesInstance; sizeInBytesInstance = DatatypeConverter .parseLong(sizeInBytesElement.getTextContent()); backupItemInstance.setSizeInBytes(sizeInBytesInstance); } Element createdElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "Created"); if (createdElement != null && createdElement.getTextContent() != null && !createdElement.getTextContent().isEmpty()) { Calendar createdInstance; createdInstance = DatatypeConverter.parseDateTime(createdElement.getTextContent()); backupItemInstance.setCreated(createdInstance); } Element logElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "Log"); if (logElement != null) { String logInstance; logInstance = logElement.getTextContent(); backupItemInstance.setLog(logInstance); } Element databasesSequenceElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "Databases"); if (databasesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement, "http://schemas.microsoft.com/windowsazure", "DatabaseBackupSetting") .size(); i2 = i2 + 1) { org.w3c.dom.Element databasesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement, "http://schemas.microsoft.com/windowsazure", "DatabaseBackupSetting") .get(i2)); DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting(); backupItemInstance.getDatabases().add(databaseBackupSettingInstance); Element connectionStringElement = XmlUtility.getElementByTagNameNS( databasesElement, "http://schemas.microsoft.com/windowsazure", "ConnectionString"); if (connectionStringElement != null) { String connectionStringInstance; connectionStringInstance = connectionStringElement.getTextContent(); databaseBackupSettingInstance.setConnectionString(connectionStringInstance); } Element connectionStringNameElement = XmlUtility.getElementByTagNameNS( databasesElement, "http://schemas.microsoft.com/windowsazure", "ConnectionStringName"); if (connectionStringNameElement != null) { String connectionStringNameInstance; connectionStringNameInstance = connectionStringNameElement.getTextContent(); databaseBackupSettingInstance .setConnectionStringName(connectionStringNameInstance); } Element databaseTypeElement = XmlUtility.getElementByTagNameNS(databasesElement, "http://schemas.microsoft.com/windowsazure", "DatabaseType"); if (databaseTypeElement != null) { String databaseTypeInstance; databaseTypeInstance = databaseTypeElement.getTextContent(); databaseBackupSettingInstance.setDatabaseType(databaseTypeInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(databasesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance2; nameInstance2 = nameElement2.getTextContent(); databaseBackupSettingInstance.setName(nameInstance2); } } } Element scheduledElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "Scheduled"); if (scheduledElement != null) { boolean scheduledInstance; scheduledInstance = DatatypeConverter .parseBoolean(scheduledElement.getTextContent().toLowerCase()); backupItemInstance.setScheduled(scheduledInstance); } Element lastRestoreTimeStampElement = XmlUtility.getElementByTagNameNS( backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "LastRestoreTimeStamp"); if (lastRestoreTimeStampElement != null && lastRestoreTimeStampElement.getTextContent() != null && !lastRestoreTimeStampElement.getTextContent().isEmpty()) { Calendar lastRestoreTimeStampInstance; lastRestoreTimeStampInstance = DatatypeConverter .parseDateTime(lastRestoreTimeStampElement.getTextContent()); backupItemInstance.setLastRestoreTimeStamp(lastRestoreTimeStampInstance); } Element finishedTimeStampElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "FinishedTimeStamp"); if (finishedTimeStampElement != null && finishedTimeStampElement.getTextContent() != null && !finishedTimeStampElement.getTextContent().isEmpty()) { Calendar finishedTimeStampInstance; finishedTimeStampInstance = DatatypeConverter .parseDateTime(finishedTimeStampElement.getTextContent()); backupItemInstance.setFinishedTimeStamp(finishedTimeStampInstance); } Element correlationIdElement = XmlUtility.getElementByTagNameNS(backupItemsElement2, "http://schemas.microsoft.com/windowsazure", "CorrelationId"); if (correlationIdElement != null) { String correlationIdInstance; correlationIdInstance = correlationIdElement.getTextContent(); backupItemInstance.setCorrelationId(correlationIdInstance); } } } } } 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(); } } }