Example usage for javax.xml.bind DatatypeConverter parseInt

List of usage examples for javax.xml.bind DatatypeConverter parseInt

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter parseInt.

Prototype

public static int parseInt(String lexicalXSDInt) 

Source Link

Document

Convert the string argument into an int value.

Usage

From source file:com.microsoft.azure.management.notificationhubs.NamespaceOperationsImpl.java

/**
* The Get Operation Status operation returns the status of the specified
* operation. After calling an asynchronous operation, you can call Get
* Operation Status to determine whether the operation has succeeded,
* failed, or is still in progress.//  ww w. j  av a2 s  .  c  o m
*
* @param operationStatusLink Required. Location value returned by the Begin
* operation.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response for long running operations.
*/
@Override
public LongRunningOperationResponse getLongRunningOperationStatus(String operationStatusLink)
        throws IOException, ServiceException {
    // Validate
    if (operationStatusLink == null) {
        throw new NullPointerException("operationStatusLink");
    }

    // 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("operationStatusLink", operationStatusLink);
        CloudTracing.enter(invocationId, this, "getLongRunningOperationStatusAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + operationStatusLink;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2014-09-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 && statusCode != HttpStatus.SC_ACCEPTED
                && statusCode != HttpStatus.SC_NOT_FOUND) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        LongRunningOperationResponse result = null;
        // Deserialize Response
        result = new LongRunningOperationResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_BAD_REQUEST) {
            result.setStatus(OperationStatus.Failed);
        }
        if (statusCode == HttpStatus.SC_OK) {
            result.setStatus(OperationStatus.Succeeded);
        }
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            result.setStatus(OperationStatus.Succeeded);
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.network.ApplicationGatewayOperationsImpl.java

/**
* The STOP ApplicationGateway operation stops application gatewayin the
* specified resource group through Network resource provider.
*
* @param resourceGroupName Required. The name of the resource group.
* @param applicationGatewayName Required. The name of the application
* gateway.//from   ww  w .  j  a  v  a 2 s  .  c  om
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return Response for PutVirtualNetworkGateway Api servive call
*/
@Override
public VirtualNetworkGatewayPutResponse beginStop(String resourceGroupName, String applicationGatewayName)
        throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (applicationGatewayName == null) {
        throw new NullPointerException("applicationGatewayName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("applicationGatewayName", applicationGatewayName);
        CloudTracing.enter(invocationId, this, "beginStopAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + "Microsoft.Network";
    url = url + "/applicationGateways/";
    url = url + URLEncoder.encode(applicationGatewayName, "UTF-8");
    url = url + "/stop";
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2015-05-01-preview");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPost httpRequest = new HttpPost(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_ACCEPTED) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        VirtualNetworkGatewayPutResponse result = null;
        // Deserialize Response
        result = new VirtualNetworkGatewayPutResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Azure-AsyncOperation").length > 0) {
            result.setAzureAsyncOperation(httpResponse.getFirstHeader("Azure-AsyncOperation").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.servicebus.QueueOperationsImpl.java

/**
* Enumerates the queues in the service namespace. The result is returned in
* pages, each containing up to 100 queues. If the namespace contains more
* than 100 queues, a feed is returned that contains the first page and a
* next link with the URI to view the next page of data.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/hh780759.asp for
* more information)//ww w .j a va  2  s .c  om
*
* @param namespaceName Required. The namespace name.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return A response to a request for a list of queues.
*/
@Override
public ServiceBusQueuesResponse list(String namespaceName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("namespaceName", namespaceName);
        CloudTracing.enter(invocationId, this, "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/servicebus/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    url = url + "/Queues";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml; charset=utf-8");
    httpRequest.setHeader("x-ms-version", "2013-08-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ServiceBusQueuesResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServiceBusQueuesResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element feedElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom",
                    "feed");
            if (feedElement != null) {
                if (feedElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(feedElement, "http://www.w3.org/2005/Atom", "entry")
                            .size(); i1 = i1 + 1) {
                        org.w3c.dom.Element entriesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(feedElement, "http://www.w3.org/2005/Atom", "entry")
                                .get(i1));
                        ServiceBusQueue entryInstance = new ServiceBusQueue();
                        result.getQueues().add(entryInstance);

                        Element titleElement = XmlUtility.getElementByTagNameNS(entriesElement,
                                "http://www.w3.org/2005/Atom", "title");
                        if (titleElement != null) {
                            String titleInstance;
                            titleInstance = titleElement.getTextContent();
                            entryInstance.setName(titleInstance);
                        }

                        Element contentElement = XmlUtility.getElementByTagNameNS(entriesElement,
                                "http://www.w3.org/2005/Atom", "content");
                        if (contentElement != null) {
                            Element queueDescriptionElement = XmlUtility.getElementByTagNameNS(contentElement,
                                    "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                    "QueueDescription");
                            if (queueDescriptionElement != null) {
                                Element lockDurationElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "LockDuration");
                                if (lockDurationElement != null) {
                                    String lockDurationInstance;
                                    lockDurationInstance = lockDurationElement.getTextContent();
                                    entryInstance.setLockDuration(lockDurationInstance);
                                }

                                Element maxSizeInMegabytesElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "MaxSizeInMegabytes");
                                if (maxSizeInMegabytesElement != null) {
                                    int maxSizeInMegabytesInstance;
                                    maxSizeInMegabytesInstance = DatatypeConverter
                                            .parseInt(maxSizeInMegabytesElement.getTextContent());
                                    entryInstance.setMaxSizeInMegabytes(maxSizeInMegabytesInstance);
                                }

                                Element requiresDuplicateDetectionElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "RequiresDuplicateDetection");
                                if (requiresDuplicateDetectionElement != null) {
                                    boolean requiresDuplicateDetectionInstance;
                                    requiresDuplicateDetectionInstance = DatatypeConverter.parseBoolean(
                                            requiresDuplicateDetectionElement.getTextContent().toLowerCase());
                                    entryInstance
                                            .setRequiresDuplicateDetection(requiresDuplicateDetectionInstance);
                                }

                                Element requiresSessionElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "RequiresSession");
                                if (requiresSessionElement != null) {
                                    boolean requiresSessionInstance;
                                    requiresSessionInstance = DatatypeConverter.parseBoolean(
                                            requiresSessionElement.getTextContent().toLowerCase());
                                    entryInstance.setRequiresSession(requiresSessionInstance);
                                }

                                Element defaultMessageTimeToLiveElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "DefaultMessageTimeToLive");
                                if (defaultMessageTimeToLiveElement != null) {
                                    String defaultMessageTimeToLiveInstance;
                                    defaultMessageTimeToLiveInstance = defaultMessageTimeToLiveElement
                                            .getTextContent();
                                    entryInstance.setDefaultMessageTimeToLive(defaultMessageTimeToLiveInstance);
                                }

                                Element deadLetteringOnMessageExpirationElement = XmlUtility
                                        .getElementByTagNameNS(queueDescriptionElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "DeadLetteringOnMessageExpiration");
                                if (deadLetteringOnMessageExpirationElement != null) {
                                    boolean deadLetteringOnMessageExpirationInstance;
                                    deadLetteringOnMessageExpirationInstance = DatatypeConverter
                                            .parseBoolean(deadLetteringOnMessageExpirationElement
                                                    .getTextContent().toLowerCase());
                                    entryInstance.setDeadLetteringOnMessageExpiration(
                                            deadLetteringOnMessageExpirationInstance);
                                }

                                Element duplicateDetectionHistoryTimeWindowElement = XmlUtility
                                        .getElementByTagNameNS(queueDescriptionElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "DuplicateDetectionHistoryTimeWindow");
                                if (duplicateDetectionHistoryTimeWindowElement != null) {
                                    String duplicateDetectionHistoryTimeWindowInstance;
                                    duplicateDetectionHistoryTimeWindowInstance = duplicateDetectionHistoryTimeWindowElement
                                            .getTextContent();
                                    entryInstance.setDuplicateDetectionHistoryTimeWindow(
                                            duplicateDetectionHistoryTimeWindowInstance);
                                }

                                Element maxDeliveryCountElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "MaxDeliveryCount");
                                if (maxDeliveryCountElement != null) {
                                    int maxDeliveryCountInstance;
                                    maxDeliveryCountInstance = DatatypeConverter
                                            .parseInt(maxDeliveryCountElement.getTextContent());
                                    entryInstance.setMaxDeliveryCount(maxDeliveryCountInstance);
                                }

                                Element enableBatchedOperationsElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "EnableBatchedOperations");
                                if (enableBatchedOperationsElement != null) {
                                    boolean enableBatchedOperationsInstance;
                                    enableBatchedOperationsInstance = DatatypeConverter.parseBoolean(
                                            enableBatchedOperationsElement.getTextContent().toLowerCase());
                                    entryInstance.setEnableBatchedOperations(enableBatchedOperationsInstance);
                                }

                                Element sizeInBytesElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "SizeInBytes");
                                if (sizeInBytesElement != null) {
                                    int sizeInBytesInstance;
                                    sizeInBytesInstance = DatatypeConverter
                                            .parseInt(sizeInBytesElement.getTextContent());
                                    entryInstance.setSizeInBytes(sizeInBytesInstance);
                                }

                                Element messageCountElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "MessageCount");
                                if (messageCountElement != null) {
                                    int messageCountInstance;
                                    messageCountInstance = DatatypeConverter
                                            .parseInt(messageCountElement.getTextContent());
                                    entryInstance.setMessageCount(messageCountInstance);
                                }

                                Element isAnonymousAccessibleElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "IsAnonymousAccessible");
                                if (isAnonymousAccessibleElement != null) {
                                    boolean isAnonymousAccessibleInstance;
                                    isAnonymousAccessibleInstance = DatatypeConverter.parseBoolean(
                                            isAnonymousAccessibleElement.getTextContent().toLowerCase());
                                    entryInstance.setIsAnonymousAccessible(isAnonymousAccessibleInstance);
                                }

                                Element authorizationRulesSequenceElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "AuthorizationRules");
                                if (authorizationRulesSequenceElement != null) {
                                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                            .getElementsByTagNameNS(authorizationRulesSequenceElement,
                                                    "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                    "AuthorizationRule")
                                            .size(); i2 = i2 + 1) {
                                        org.w3c.dom.Element authorizationRulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                .getElementsByTagNameNS(authorizationRulesSequenceElement,
                                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                        "AuthorizationRule")
                                                .get(i2));
                                        ServiceBusSharedAccessAuthorizationRule authorizationRuleInstance = new ServiceBusSharedAccessAuthorizationRule();
                                        entryInstance.getAuthorizationRules().add(authorizationRuleInstance);

                                        Element claimTypeElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "ClaimType");
                                        if (claimTypeElement != null) {
                                            String claimTypeInstance;
                                            claimTypeInstance = claimTypeElement.getTextContent();
                                            authorizationRuleInstance.setClaimType(claimTypeInstance);
                                        }

                                        Element claimValueElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "ClaimValue");
                                        if (claimValueElement != null) {
                                            String claimValueInstance;
                                            claimValueInstance = claimValueElement.getTextContent();
                                            authorizationRuleInstance.setClaimValue(claimValueInstance);
                                        }

                                        Element rightsSequenceElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "Rights");
                                        if (rightsSequenceElement != null) {
                                            for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility
                                                    .getElementsByTagNameNS(rightsSequenceElement,
                                                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                            "AccessRights")
                                                    .size(); i3 = i3 + 1) {
                                                org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                        .getElementsByTagNameNS(rightsSequenceElement,
                                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                                "AccessRights")
                                                        .get(i3));
                                                authorizationRuleInstance.getRights().add(
                                                        AccessRight.valueOf(rightsElement.getTextContent()));
                                            }
                                        }

                                        Element createdTimeElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "CreatedTime");
                                        if (createdTimeElement != null) {
                                            Calendar createdTimeInstance;
                                            createdTimeInstance = DatatypeConverter
                                                    .parseDateTime(createdTimeElement.getTextContent());
                                            authorizationRuleInstance.setCreatedTime(createdTimeInstance);
                                        }

                                        Element keyNameElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "KeyName");
                                        if (keyNameElement != null) {
                                            String keyNameInstance;
                                            keyNameInstance = keyNameElement.getTextContent();
                                            authorizationRuleInstance.setKeyName(keyNameInstance);
                                        }

                                        Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "ModifiedTime");
                                        if (modifiedTimeElement != null) {
                                            Calendar modifiedTimeInstance;
                                            modifiedTimeInstance = DatatypeConverter
                                                    .parseDateTime(modifiedTimeElement.getTextContent());
                                            authorizationRuleInstance.setModifiedTime(modifiedTimeInstance);
                                        }

                                        Element primaryKeyElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "PrimaryKey");
                                        if (primaryKeyElement != null) {
                                            String primaryKeyInstance;
                                            primaryKeyInstance = primaryKeyElement.getTextContent();
                                            authorizationRuleInstance.setPrimaryKey(primaryKeyInstance);
                                        }

                                        Element secondaryKeyElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "SecondaryKey");
                                        if (secondaryKeyElement != null) {
                                            String secondaryKeyInstance;
                                            secondaryKeyInstance = secondaryKeyElement.getTextContent();
                                            authorizationRuleInstance.setSecondaryKey(secondaryKeyInstance);
                                        }
                                    }
                                }

                                Element statusElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "Status");
                                if (statusElement != null) {
                                    String statusInstance;
                                    statusInstance = statusElement.getTextContent();
                                    entryInstance.setStatus(statusInstance);
                                }

                                Element createdAtElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "CreatedAt");
                                if (createdAtElement != null) {
                                    Calendar createdAtInstance;
                                    createdAtInstance = DatatypeConverter
                                            .parseDateTime(createdAtElement.getTextContent());
                                    entryInstance.setCreatedAt(createdAtInstance);
                                }

                                Element updatedAtElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "UpdatedAt");
                                if (updatedAtElement != null) {
                                    Calendar updatedAtInstance;
                                    updatedAtInstance = DatatypeConverter
                                            .parseDateTime(updatedAtElement.getTextContent());
                                    entryInstance.setUpdatedAt(updatedAtInstance);
                                }

                                Element accessedAtElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "AccessedAt");
                                if (accessedAtElement != null) {
                                    Calendar accessedAtInstance;
                                    accessedAtInstance = DatatypeConverter
                                            .parseDateTime(accessedAtElement.getTextContent());
                                    entryInstance.setAccessedAt(accessedAtInstance);
                                }

                                Element supportOrderingElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "SupportOrdering");
                                if (supportOrderingElement != null) {
                                    boolean supportOrderingInstance;
                                    supportOrderingInstance = DatatypeConverter.parseBoolean(
                                            supportOrderingElement.getTextContent().toLowerCase());
                                    entryInstance.setSupportOrdering(supportOrderingInstance);
                                }

                                Element countDetailsElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "CountDetails");
                                if (countDetailsElement != null) {
                                    CountDetails countDetailsInstance = new CountDetails();
                                    entryInstance.setCountDetails(countDetailsInstance);

                                    Element activeMessageCountElement = XmlUtility.getElementByTagNameNS(
                                            countDetailsElement,
                                            "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                            "ActiveMessageCount");
                                    if (activeMessageCountElement != null) {
                                        int activeMessageCountInstance;
                                        activeMessageCountInstance = DatatypeConverter
                                                .parseInt(activeMessageCountElement.getTextContent());
                                        countDetailsInstance.setActiveMessageCount(activeMessageCountInstance);
                                    }

                                    Element deadLetterMessageCountElement = XmlUtility.getElementByTagNameNS(
                                            countDetailsElement,
                                            "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                            "DeadLetterMessageCount");
                                    if (deadLetterMessageCountElement != null) {
                                        int deadLetterMessageCountInstance;
                                        deadLetterMessageCountInstance = DatatypeConverter
                                                .parseInt(deadLetterMessageCountElement.getTextContent());
                                        countDetailsInstance
                                                .setDeadLetterMessageCount(deadLetterMessageCountInstance);
                                    }

                                    Element scheduledMessageCountElement = XmlUtility.getElementByTagNameNS(
                                            countDetailsElement,
                                            "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                            "ScheduledMessageCount");
                                    if (scheduledMessageCountElement != null) {
                                        int scheduledMessageCountInstance;
                                        scheduledMessageCountInstance = DatatypeConverter
                                                .parseInt(scheduledMessageCountElement.getTextContent());
                                        countDetailsInstance
                                                .setScheduledMessageCount(scheduledMessageCountInstance);
                                    }

                                    Element transferDeadLetterMessageCountElement = XmlUtility
                                            .getElementByTagNameNS(countDetailsElement,
                                                    "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                                    "TransferDeadLetterMessageCount");
                                    if (transferDeadLetterMessageCountElement != null) {
                                        int transferDeadLetterMessageCountInstance;
                                        transferDeadLetterMessageCountInstance = DatatypeConverter.parseInt(
                                                transferDeadLetterMessageCountElement.getTextContent());
                                        countDetailsInstance.setTransferDeadLetterMessageCount(
                                                transferDeadLetterMessageCountInstance);
                                    }

                                    Element transferMessageCountElement = XmlUtility.getElementByTagNameNS(
                                            countDetailsElement,
                                            "http://schemas.microsoft.com/netservices/2011/06/servicebus",
                                            "TransferMessageCount");
                                    if (transferMessageCountElement != null) {
                                        int transferMessageCountInstance;
                                        transferMessageCountInstance = DatatypeConverter
                                                .parseInt(transferMessageCountElement.getTextContent());
                                        countDetailsInstance
                                                .setTransferMessageCount(transferMessageCountInstance);
                                    }
                                }

                                Element autoDeleteOnIdleElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "AutoDeleteOnIdle");
                                if (autoDeleteOnIdleElement != null) {
                                    String autoDeleteOnIdleInstance;
                                    autoDeleteOnIdleInstance = autoDeleteOnIdleElement.getTextContent();
                                    entryInstance.setAutoDeleteOnIdle(autoDeleteOnIdleInstance);
                                }

                                Element entityAvailabilityStatusElement = XmlUtility.getElementByTagNameNS(
                                        queueDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "EntityAvailabilityStatus");
                                if (entityAvailabilityStatusElement != null) {
                                    String entityAvailabilityStatusInstance;
                                    entityAvailabilityStatusInstance = entityAvailabilityStatusElement
                                            .getTextContent();
                                    entryInstance.setEntityAvailabilityStatus(entityAvailabilityStatusInstance);
                                }
                            }
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.network.LoadBalancerOperationsImpl.java

/**
* The delete loadbalancer operation deletes the specified loadbalancer.
*
* @param resourceGroupName Required. The name of the resource group.
* @param loadBalancerName Required. The name of the loadBalancer.
* @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 a2  s.  c om
* @throws ServiceException Thrown if an unexpected response is found.
* @return If the resource provide needs to return an error to any
* operation, it should return the appropriate HTTP error code and a
* message body as can be seen below.The message should be localized per
* the Accept-Language header specified in the original request such thatit
* could be directly be exposed to users
*/
@Override
public UpdateOperationResponse beginDeleting(String resourceGroupName, String loadBalancerName)
        throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (loadBalancerName == null) {
        throw new NullPointerException("loadBalancerName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("loadBalancerName", loadBalancerName);
        CloudTracing.enter(invocationId, this, "beginDeletingAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + "Microsoft.Network";
    url = url + "/loadBalancers/";
    url = url + URLEncoder.encode(loadBalancerName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2015-05-01-preview");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    CustomHttpDelete httpRequest = new CustomHttpDelete(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_ACCEPTED
                && statusCode != HttpStatus.SC_NO_CONTENT) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        UpdateOperationResponse result = null;
        // Deserialize Response
        result = new UpdateOperationResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Azure-AsyncOperation").length > 0) {
            result.setAzureAsyncOperation(httpResponse.getFirstHeader("Azure-AsyncOperation").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.network.RouteOperationsImpl.java

/**
* Get the specified route table for this subscription.
*
* @param routeTableName Required. The name of the route table in this
* subscription to retrieve.//from  w  w  w  .  j  av a 2s .co  m
* @param detailLevel Required. The amount of detail about the requested
* route table that will be returned.
* @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 A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GetRouteTableResponse getRouteTableWithDetails(String routeTableName, String detailLevel)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (routeTableName == null) {
        throw new NullPointerException("routeTableName");
    }
    if (detailLevel == null) {
        throw new NullPointerException("detailLevel");
    }

    // 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("routeTableName", routeTableName);
        tracingParameters.put("detailLevel", detailLevel);
        CloudTracing.enter(invocationId, this, "getRouteTableWithDetailsAsync", 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/routetables/";
    url = url + URLEncoder.encode(routeTableName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("detailLevel=" + URLEncoder.encode(detailLevel, "UTF-8"));
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    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
        GetRouteTableResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new GetRouteTableResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element routeTableElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "RouteTable");
            if (routeTableElement != null) {
                RouteTable routeTableInstance = new RouteTable();
                result.setRouteTable(routeTableInstance);

                Element nameElement = XmlUtility.getElementByTagNameNS(routeTableElement,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement != null) {
                    String nameInstance;
                    nameInstance = nameElement.getTextContent();
                    routeTableInstance.setName(nameInstance);
                }

                Element labelElement = XmlUtility.getElementByTagNameNS(routeTableElement,
                        "http://schemas.microsoft.com/windowsazure", "Label");
                if (labelElement != null) {
                    String labelInstance;
                    labelInstance = labelElement.getTextContent();
                    routeTableInstance.setLabel(labelInstance);
                }

                Element locationElement = XmlUtility.getElementByTagNameNS(routeTableElement,
                        "http://schemas.microsoft.com/windowsazure", "Location");
                if (locationElement != null) {
                    String locationInstance;
                    locationInstance = locationElement.getTextContent();
                    routeTableInstance.setLocation(locationInstance);
                }

                Element routeTableStateElement = XmlUtility.getElementByTagNameNS(routeTableElement,
                        "http://schemas.microsoft.com/windowsazure", "RouteTableState");
                if (routeTableStateElement != null && routeTableStateElement.getTextContent() != null
                        && !routeTableStateElement.getTextContent().isEmpty()) {
                    RouteTableState routeTableStateInstance;
                    routeTableStateInstance = RouteTableState.valueOf(routeTableStateElement.getTextContent());
                    routeTableInstance.setRouteTableState(routeTableStateInstance);
                }

                Element routeListSequenceElement = XmlUtility.getElementByTagNameNS(routeTableElement,
                        "http://schemas.microsoft.com/windowsazure", "RouteList");
                if (routeListSequenceElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(routeListSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "Route")
                            .size(); i1 = i1 + 1) {
                        org.w3c.dom.Element routeListElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(routeListSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "Route")
                                .get(i1));
                        Route routeInstance = new Route();
                        routeTableInstance.getRouteList().add(routeInstance);

                        Element nameElement2 = XmlUtility.getElementByTagNameNS(routeListElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement2 != null) {
                            String nameInstance2;
                            nameInstance2 = nameElement2.getTextContent();
                            routeInstance.setName(nameInstance2);
                        }

                        Element addressPrefixElement = XmlUtility.getElementByTagNameNS(routeListElement,
                                "http://schemas.microsoft.com/windowsazure", "AddressPrefix");
                        if (addressPrefixElement != null) {
                            String addressPrefixInstance;
                            addressPrefixInstance = addressPrefixElement.getTextContent();
                            routeInstance.setAddressPrefix(addressPrefixInstance);
                        }

                        Element nextHopTypeElement = XmlUtility.getElementByTagNameNS(routeListElement,
                                "http://schemas.microsoft.com/windowsazure", "NextHopType");
                        if (nextHopTypeElement != null) {
                            NextHop nextHopTypeInstance = new NextHop();
                            routeInstance.setNextHop(nextHopTypeInstance);

                            Element typeElement = XmlUtility.getElementByTagNameNS(nextHopTypeElement,
                                    "http://schemas.microsoft.com/windowsazure", "Type");
                            if (typeElement != null) {
                                String typeInstance;
                                typeInstance = typeElement.getTextContent();
                                nextHopTypeInstance.setType(typeInstance);
                            }

                            Element ipAddressElement = XmlUtility.getElementByTagNameNS(nextHopTypeElement,
                                    "http://schemas.microsoft.com/windowsazure", "IpAddress");
                            if (ipAddressElement != null) {
                                String ipAddressInstance;
                                ipAddressInstance = ipAddressElement.getTextContent();
                                nextHopTypeInstance.setIpAddress(ipAddressInstance);
                            }
                        }

                        Element metricElement = XmlUtility.getElementByTagNameNS(routeListElement,
                                "http://schemas.microsoft.com/windowsazure", "Metric");
                        if (metricElement != null) {
                            int metricInstance;
                            metricInstance = DatatypeConverter.parseInt(metricElement.getTextContent());
                            routeInstance.setMetric(metricInstance);
                        }

                        Element routeStateElement = XmlUtility.getElementByTagNameNS(routeListElement,
                                "http://schemas.microsoft.com/windowsazure", "RouteState");
                        if (routeStateElement != null && routeStateElement.getTextContent() != null
                                && !routeStateElement.getTextContent().isEmpty()) {
                            RouteState routeStateInstance;
                            routeStateInstance = RouteState.valueOf(routeStateElement.getTextContent());
                            routeInstance.setState(routeStateInstance);
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.compute.VirtualMachineDiskOperationsImpl.java

/**
* The Add Disk operation adds a disk to the user image repository. The disk
* can be an operating system disk or a data disk.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157178.aspx for
* more information)//from  w w w . j  a v a  2s.c  o  m
*
* @param name Required. The name of the disk being updated.
* @param parameters Required. Parameters supplied to the Update Virtual
* Machine Disk operation.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return A virtual machine disk associated with your subscription.
*/
@Override
public VirtualMachineDiskUpdateResponse updateDisk(String name, VirtualMachineDiskUpdateParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException,
        URISyntaxException {
    // Validate
    if (name == null) {
        throw new NullPointerException("name");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getLabel() == null) {
        throw new NullPointerException("parameters.Label");
    }
    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("name", name);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "updateDiskAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/disks/";
    url = url + URLEncoder.encode(name, "UTF-8");
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPut httpRequest = new HttpPut(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    httpRequest.setHeader("x-ms-version", "2015-04-01");

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element diskElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Disk");
    requestDoc.appendChild(diskElement);

    if (parameters.isHasOperatingSystem() != null) {
        Element hasOperatingSystemElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "HasOperatingSystem");
        hasOperatingSystemElement.appendChild(
                requestDoc.createTextNode(Boolean.toString(parameters.isHasOperatingSystem()).toLowerCase()));
        diskElement.appendChild(hasOperatingSystemElement);
    }

    if (parameters.getOperatingSystemType() != null) {
        Element osElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OS");
        osElement.appendChild(requestDoc.createTextNode(parameters.getOperatingSystemType()));
        diskElement.appendChild(osElement);
    }

    Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label");
    labelElement.appendChild(requestDoc.createTextNode(parameters.getLabel()));
    diskElement.appendChild(labelElement);

    if (parameters.getMediaLinkUri() != null) {
        Element mediaLinkElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "MediaLink");
        mediaLinkElement.appendChild(requestDoc.createTextNode(parameters.getMediaLinkUri().toString()));
        diskElement.appendChild(mediaLinkElement);
    }

    Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name");
    nameElement.appendChild(requestDoc.createTextNode(parameters.getName()));
    diskElement.appendChild(nameElement);

    if (parameters.getResizedSizeInGB() != null) {
        Element resizedSizeInGBElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "ResizedSizeInGB");
        resizedSizeInGBElement
                .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getResizedSizeInGB())));
        diskElement.appendChild(resizedSizeInGBElement);
    }

    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
        VirtualMachineDiskUpdateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new VirtualMachineDiskUpdateResponse();
            DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
            documentBuilderFactory2.setNamespaceAware(true);
            DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
            Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));

            Element diskElement2 = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Disk");
            if (diskElement2 != null) {
                Element osElement2 = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "OS");
                if (osElement2 != null) {
                    String osInstance;
                    osInstance = osElement2.getTextContent();
                    result.setOperatingSystem(osInstance);
                }

                Element labelElement2 = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "Label");
                if (labelElement2 != null) {
                    String labelInstance;
                    labelInstance = labelElement2.getTextContent();
                    result.setLabel(labelInstance);
                }

                Element affinityGroupElement = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "AffinityGroup");
                if (affinityGroupElement != null) {
                    String affinityGroupInstance;
                    affinityGroupInstance = affinityGroupElement.getTextContent();
                    result.setAffinityGroup(affinityGroupInstance);
                }

                Element locationElement = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "Location");
                if (locationElement != null) {
                    String locationInstance;
                    locationInstance = locationElement.getTextContent();
                    result.setLocation(locationInstance);
                }

                Element logicalDiskSizeInGBElement = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "LogicalDiskSizeInGB");
                if (logicalDiskSizeInGBElement != null) {
                    int logicalDiskSizeInGBInstance;
                    logicalDiskSizeInGBInstance = DatatypeConverter
                            .parseInt(logicalDiskSizeInGBElement.getTextContent());
                    result.setLogicalSizeInGB(logicalDiskSizeInGBInstance);
                }

                Element mediaLinkElement2 = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "MediaLink");
                if (mediaLinkElement2 != null) {
                    URI mediaLinkInstance;
                    mediaLinkInstance = new URI(mediaLinkElement2.getTextContent());
                    result.setMediaLinkUri(mediaLinkInstance);
                }

                Element nameElement2 = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement2 != null) {
                    String nameInstance;
                    nameInstance = nameElement2.getTextContent();
                    result.setName(nameInstance);
                }

                Element isPremiumElement = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "IsPremium");
                if (isPremiumElement != null && isPremiumElement.getTextContent() != null
                        && !isPremiumElement.getTextContent().isEmpty()) {
                    boolean isPremiumInstance;
                    isPremiumInstance = DatatypeConverter
                            .parseBoolean(isPremiumElement.getTextContent().toLowerCase());
                    result.setIsPremium(isPremiumInstance);
                }

                Element iOTypeElement = XmlUtility.getElementByTagNameNS(diskElement2,
                        "http://schemas.microsoft.com/windowsazure", "IOType");
                if (iOTypeElement != null) {
                    String iOTypeInstance;
                    iOTypeInstance = iOTypeElement.getTextContent();
                    result.setIOType(iOTypeInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.network.NetworkSecurityGroupOperationsImpl.java

/**
* Gets the details for the specified Network Security Group in the
* subscription./*from   w w w  . jav  a  2 s  .  co  m*/
*
* @param networkSecurityGroupName Required. The name of the Network
* Security Group to retrieve.
* @param detailLevel Optional. Use 'Full' to list rules.
* @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 A Network Security Group associated with your subscription.
*/
@Override
public NetworkSecurityGroupGetResponse get(String networkSecurityGroupName, String detailLevel)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (networkSecurityGroupName == null) {
        throw new NullPointerException("networkSecurityGroupName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("networkSecurityGroupName", networkSecurityGroupName);
        tracingParameters.put("detailLevel", detailLevel);
        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/networksecuritygroups/";
    url = url + URLEncoder.encode(networkSecurityGroupName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    if (detailLevel != null) {
        queryParameters.add("detaillevel=" + URLEncoder.encode(detailLevel, "UTF-8"));
    }
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "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
        NetworkSecurityGroupGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new NetworkSecurityGroupGetResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element networkSecurityGroupElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "NetworkSecurityGroup");
            if (networkSecurityGroupElement != null) {
                Element nameElement = XmlUtility.getElementByTagNameNS(networkSecurityGroupElement,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement != null) {
                    String nameInstance;
                    nameInstance = nameElement.getTextContent();
                    result.setName(nameInstance);
                }

                Element labelElement = XmlUtility.getElementByTagNameNS(networkSecurityGroupElement,
                        "http://schemas.microsoft.com/windowsazure", "Label");
                if (labelElement != null) {
                    String labelInstance;
                    labelInstance = labelElement.getTextContent();
                    result.setLabel(labelInstance);
                }

                Element locationElement = XmlUtility.getElementByTagNameNS(networkSecurityGroupElement,
                        "http://schemas.microsoft.com/windowsazure", "Location");
                if (locationElement != null) {
                    String locationInstance;
                    locationInstance = locationElement.getTextContent();
                    result.setLocation(locationInstance);
                }

                Element rulesSequenceElement = XmlUtility.getElementByTagNameNS(networkSecurityGroupElement,
                        "http://schemas.microsoft.com/windowsazure", "Rules");
                if (rulesSequenceElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(rulesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "Rule")
                            .size(); i1 = i1 + 1) {
                        org.w3c.dom.Element rulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(rulesSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "Rule")
                                .get(i1));
                        NetworkSecurityRule ruleInstance = new NetworkSecurityRule();
                        result.getRules().add(ruleInstance);

                        Element nameElement2 = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement2 != null) {
                            String nameInstance2;
                            nameInstance2 = nameElement2.getTextContent();
                            ruleInstance.setName(nameInstance2);
                        }

                        Element typeElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "Type");
                        if (typeElement != null) {
                            String typeInstance;
                            typeInstance = typeElement.getTextContent();
                            ruleInstance.setType(typeInstance);
                        }

                        Element priorityElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "Priority");
                        if (priorityElement != null) {
                            int priorityInstance;
                            priorityInstance = DatatypeConverter.parseInt(priorityElement.getTextContent());
                            ruleInstance.setPriority(priorityInstance);
                        }

                        Element actionElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "Action");
                        if (actionElement != null) {
                            String actionInstance;
                            actionInstance = actionElement.getTextContent();
                            ruleInstance.setAction(actionInstance);
                        }

                        Element sourceAddressPrefixElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "SourceAddressPrefix");
                        if (sourceAddressPrefixElement != null) {
                            String sourceAddressPrefixInstance;
                            sourceAddressPrefixInstance = sourceAddressPrefixElement.getTextContent();
                            ruleInstance.setSourceAddressPrefix(sourceAddressPrefixInstance);
                        }

                        Element sourcePortRangeElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "SourcePortRange");
                        if (sourcePortRangeElement != null) {
                            String sourcePortRangeInstance;
                            sourcePortRangeInstance = sourcePortRangeElement.getTextContent();
                            ruleInstance.setSourcePortRange(sourcePortRangeInstance);
                        }

                        Element destinationAddressPrefixElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "DestinationAddressPrefix");
                        if (destinationAddressPrefixElement != null) {
                            String destinationAddressPrefixInstance;
                            destinationAddressPrefixInstance = destinationAddressPrefixElement.getTextContent();
                            ruleInstance.setDestinationAddressPrefix(destinationAddressPrefixInstance);
                        }

                        Element destinationPortRangeElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "DestinationPortRange");
                        if (destinationPortRangeElement != null) {
                            String destinationPortRangeInstance;
                            destinationPortRangeInstance = destinationPortRangeElement.getTextContent();
                            ruleInstance.setDestinationPortRange(destinationPortRangeInstance);
                        }

                        Element protocolElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "Protocol");
                        if (protocolElement != null) {
                            String protocolInstance;
                            protocolInstance = protocolElement.getTextContent();
                            ruleInstance.setProtocol(protocolInstance);
                        }

                        Element stateElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "State");
                        if (stateElement != null) {
                            String stateInstance;
                            stateInstance = stateElement.getTextContent();
                            ruleInstance.setState(stateInstance);
                        }

                        Element isDefaultElement = XmlUtility.getElementByTagNameNS(rulesElement,
                                "http://schemas.microsoft.com/windowsazure", "IsDefault");
                        if (isDefaultElement != null) {
                            boolean isDefaultInstance;
                            isDefaultInstance = DatatypeConverter
                                    .parseBoolean(isDefaultElement.getTextContent().toLowerCase());
                            ruleInstance.setIsDefault(isDefaultInstance);
                        }
                    }
                }
            }

        }
        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.RouteOperationsImpl.java

/**
* List the existing route tables for this subscription.
*
* @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.// w  w  w. jav  a2 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 A standard service response including an HTTP status code and
* request ID.
*/
@Override
public ListRouteTablesResponse listRouteTables()
        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, "listRouteTablesAsync", 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/routetables";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    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
        ListRouteTablesResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ListRouteTablesResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element routeTablesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "RouteTables");
            if (routeTablesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(routeTablesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "RouteTable")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element routeTablesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(routeTablesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "RouteTable")
                            .get(i1));
                    RouteTable routeTableInstance = new RouteTable();
                    result.getRouteTables().add(routeTableInstance);

                    Element nameElement = XmlUtility.getElementByTagNameNS(routeTablesElement,
                            "http://schemas.microsoft.com/windowsazure", "Name");
                    if (nameElement != null) {
                        String nameInstance;
                        nameInstance = nameElement.getTextContent();
                        routeTableInstance.setName(nameInstance);
                    }

                    Element labelElement = XmlUtility.getElementByTagNameNS(routeTablesElement,
                            "http://schemas.microsoft.com/windowsazure", "Label");
                    if (labelElement != null) {
                        String labelInstance;
                        labelInstance = labelElement.getTextContent();
                        routeTableInstance.setLabel(labelInstance);
                    }

                    Element locationElement = XmlUtility.getElementByTagNameNS(routeTablesElement,
                            "http://schemas.microsoft.com/windowsazure", "Location");
                    if (locationElement != null) {
                        String locationInstance;
                        locationInstance = locationElement.getTextContent();
                        routeTableInstance.setLocation(locationInstance);
                    }

                    Element routeTableStateElement = XmlUtility.getElementByTagNameNS(routeTablesElement,
                            "http://schemas.microsoft.com/windowsazure", "RouteTableState");
                    if (routeTableStateElement != null && routeTableStateElement.getTextContent() != null
                            && !routeTableStateElement.getTextContent().isEmpty()) {
                        RouteTableState routeTableStateInstance;
                        routeTableStateInstance = RouteTableState
                                .valueOf(routeTableStateElement.getTextContent());
                        routeTableInstance.setRouteTableState(routeTableStateInstance);
                    }

                    Element routeListSequenceElement = XmlUtility.getElementByTagNameNS(routeTablesElement,
                            "http://schemas.microsoft.com/windowsazure", "RouteList");
                    if (routeListSequenceElement != null) {
                        for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(routeListSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "Route")
                                .size(); i2 = i2 + 1) {
                            org.w3c.dom.Element routeListElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(routeListSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "Route")
                                    .get(i2));
                            Route routeInstance = new Route();
                            routeTableInstance.getRouteList().add(routeInstance);

                            Element nameElement2 = XmlUtility.getElementByTagNameNS(routeListElement,
                                    "http://schemas.microsoft.com/windowsazure", "Name");
                            if (nameElement2 != null) {
                                String nameInstance2;
                                nameInstance2 = nameElement2.getTextContent();
                                routeInstance.setName(nameInstance2);
                            }

                            Element addressPrefixElement = XmlUtility.getElementByTagNameNS(routeListElement,
                                    "http://schemas.microsoft.com/windowsazure", "AddressPrefix");
                            if (addressPrefixElement != null) {
                                String addressPrefixInstance;
                                addressPrefixInstance = addressPrefixElement.getTextContent();
                                routeInstance.setAddressPrefix(addressPrefixInstance);
                            }

                            Element nextHopTypeElement = XmlUtility.getElementByTagNameNS(routeListElement,
                                    "http://schemas.microsoft.com/windowsazure", "NextHopType");
                            if (nextHopTypeElement != null) {
                                NextHop nextHopTypeInstance = new NextHop();
                                routeInstance.setNextHop(nextHopTypeInstance);

                                Element typeElement = XmlUtility.getElementByTagNameNS(nextHopTypeElement,
                                        "http://schemas.microsoft.com/windowsazure", "Type");
                                if (typeElement != null) {
                                    String typeInstance;
                                    typeInstance = typeElement.getTextContent();
                                    nextHopTypeInstance.setType(typeInstance);
                                }

                                Element ipAddressElement = XmlUtility.getElementByTagNameNS(nextHopTypeElement,
                                        "http://schemas.microsoft.com/windowsazure", "IpAddress");
                                if (ipAddressElement != null) {
                                    String ipAddressInstance;
                                    ipAddressInstance = ipAddressElement.getTextContent();
                                    nextHopTypeInstance.setIpAddress(ipAddressInstance);
                                }
                            }

                            Element metricElement = XmlUtility.getElementByTagNameNS(routeListElement,
                                    "http://schemas.microsoft.com/windowsazure", "Metric");
                            if (metricElement != null) {
                                int metricInstance;
                                metricInstance = DatatypeConverter.parseInt(metricElement.getTextContent());
                                routeInstance.setMetric(metricInstance);
                            }

                            Element routeStateElement = XmlUtility.getElementByTagNameNS(routeListElement,
                                    "http://schemas.microsoft.com/windowsazure", "RouteState");
                            if (routeStateElement != null && routeStateElement.getTextContent() != null
                                    && !routeStateElement.getTextContent().isEmpty()) {
                                RouteState routeStateInstance;
                                routeStateInstance = RouteState.valueOf(routeStateElement.getTextContent());
                                routeInstance.setState(routeStateInstance);
                            }
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.servicebus.NamespaceOperationsImpl.java

/**
* The get authorization rules operation gets the authorization rules for a
* namespace./*from ww w.  jav a  2s. com*/
*
* @param namespaceName Required. The namespace to get the authorization
* rule for.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @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 A response to a request for a list of authorization rules.
*/
@Override
public ServiceBusAuthorizationRulesResponse listAuthorizationRules(String namespaceName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("namespaceName", namespaceName);
        CloudTracing.enter(invocationId, this, "listAuthorizationRulesAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/servicebus/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    url = url + "/AuthorizationRules";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Accept", "application/atom+xml");
    httpRequest.setHeader("Content-Type", "application/xml");
    httpRequest.setHeader("x-ms-version", "2013-08-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ServiceBusAuthorizationRulesResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServiceBusAuthorizationRulesResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element feedElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom",
                    "feed");
            if (feedElement != null) {
                if (feedElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(feedElement, "http://www.w3.org/2005/Atom", "entry")
                            .size(); i1 = i1 + 1) {
                        org.w3c.dom.Element entriesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(feedElement, "http://www.w3.org/2005/Atom", "entry")
                                .get(i1));
                        ServiceBusSharedAccessAuthorizationRule entryInstance = new ServiceBusSharedAccessAuthorizationRule();
                        result.getAuthorizationRules().add(entryInstance);

                        Element contentElement = XmlUtility.getElementByTagNameNS(entriesElement,
                                "http://www.w3.org/2005/Atom", "content");
                        if (contentElement != null) {
                            Element sharedAccessAuthorizationRuleElement = XmlUtility.getElementByTagNameNS(
                                    contentElement,
                                    "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                    "SharedAccessAuthorizationRule");
                            if (sharedAccessAuthorizationRuleElement != null) {
                                Element claimTypeElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ClaimType");
                                if (claimTypeElement != null) {
                                    String claimTypeInstance;
                                    claimTypeInstance = claimTypeElement.getTextContent();
                                    entryInstance.setClaimType(claimTypeInstance);
                                }

                                Element claimValueElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ClaimValue");
                                if (claimValueElement != null) {
                                    String claimValueInstance;
                                    claimValueInstance = claimValueElement.getTextContent();
                                    entryInstance.setClaimValue(claimValueInstance);
                                }

                                Element rightsSequenceElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "Rights");
                                if (rightsSequenceElement != null) {
                                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                            .getElementsByTagNameNS(rightsSequenceElement,
                                                    "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                    "AccessRights")
                                            .size(); i2 = i2 + 1) {
                                        org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                .getElementsByTagNameNS(rightsSequenceElement,
                                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                        "AccessRights")
                                                .get(i2));
                                        entryInstance.getRights()
                                                .add(AccessRight.valueOf(rightsElement.getTextContent()));
                                    }
                                }

                                Element createdTimeElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "CreatedTime");
                                if (createdTimeElement != null) {
                                    Calendar createdTimeInstance;
                                    createdTimeInstance = DatatypeConverter
                                            .parseDateTime(createdTimeElement.getTextContent());
                                    entryInstance.setCreatedTime(createdTimeInstance);
                                }

                                Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ModifiedTime");
                                if (modifiedTimeElement != null) {
                                    Calendar modifiedTimeInstance;
                                    modifiedTimeInstance = DatatypeConverter
                                            .parseDateTime(modifiedTimeElement.getTextContent());
                                    entryInstance.setModifiedTime(modifiedTimeInstance);
                                }

                                Element keyNameElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "KeyName");
                                if (keyNameElement != null) {
                                    String keyNameInstance;
                                    keyNameInstance = keyNameElement.getTextContent();
                                    entryInstance.setKeyName(keyNameInstance);
                                }

                                Element primaryKeyElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "PrimaryKey");
                                if (primaryKeyElement != null) {
                                    String primaryKeyInstance;
                                    primaryKeyInstance = primaryKeyElement.getTextContent();
                                    entryInstance.setPrimaryKey(primaryKeyInstance);
                                }

                                Element secondaryKeyElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "SecondaryKey");
                                if (secondaryKeyElement != null) {
                                    String secondaryKeyInstance;
                                    secondaryKeyInstance = secondaryKeyElement.getTextContent();
                                    entryInstance.setSecondaryKey(secondaryKeyInstance);
                                }

                                Element revisionElement = XmlUtility.getElementByTagNameNS(
                                        sharedAccessAuthorizationRuleElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "Revision");
                                if (revisionElement != null) {
                                    int revisionInstance;
                                    revisionInstance = DatatypeConverter
                                            .parseInt(revisionElement.getTextContent());
                                    entryInstance.setRevision(revisionInstance);
                                }
                            }
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.network.ApplicationGatewayOperationsImpl.java

/**
* The Get Application Gateway Configuration operation retrieves the
* configuration of the gateway.  (see// w  w  w .  j a v a2 s. c o m
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for
* more information)
*
* @param gatewayName Required. The id  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 to a GetApplicationGatewayConfiguation  request.
*/
@Override
public ApplicationGatewayGetConfiguration getConfig(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, "getConfigAsync", 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");
    url = url + "/configuration";
    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
        ApplicationGatewayGetConfiguration result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ApplicationGatewayGetConfiguration();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element applicationGatewayConfigurationElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ApplicationGatewayConfiguration");
            if (applicationGatewayConfigurationElement != null) {
                Element frontendIPConfigurationsSequenceElement = XmlUtility.getElementByTagNameNS(
                        applicationGatewayConfigurationElement, "http://schemas.microsoft.com/windowsazure",
                        "FrontendIPConfigurations");
                if (frontendIPConfigurationsSequenceElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(frontendIPConfigurationsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "FrontendIPConfiguration")
                            .size(); i1 = i1 + 1) {
                        org.w3c.dom.Element frontendIPConfigurationsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(frontendIPConfigurationsSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "FrontendIPConfiguration")
                                .get(i1));
                        FrontendIPConfiguration frontendIPConfigurationInstance = new FrontendIPConfiguration();
                        result.getFrontendIPConfigurations().add(frontendIPConfigurationInstance);

                        Element nameElement = XmlUtility.getElementByTagNameNS(frontendIPConfigurationsElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement != null) {
                            String nameInstance;
                            nameInstance = nameElement.getTextContent();
                            frontendIPConfigurationInstance.setName(nameInstance);
                        }

                        Element typeElement = XmlUtility.getElementByTagNameNS(frontendIPConfigurationsElement,
                                "http://schemas.microsoft.com/windowsazure", "Type");
                        if (typeElement != null) {
                            String typeInstance;
                            typeInstance = typeElement.getTextContent();
                            frontendIPConfigurationInstance.setType(typeInstance);
                        }

                        Element staticIPAddressElement = XmlUtility.getElementByTagNameNS(
                                frontendIPConfigurationsElement, "http://schemas.microsoft.com/windowsazure",
                                "StaticIPAddress");
                        if (staticIPAddressElement != null) {
                            String staticIPAddressInstance;
                            staticIPAddressInstance = staticIPAddressElement.getTextContent();
                            frontendIPConfigurationInstance.setStaticIPAddress(staticIPAddressInstance);
                        }
                    }
                }

                Element frontendPortsSequenceElement = XmlUtility.getElementByTagNameNS(
                        applicationGatewayConfigurationElement, "http://schemas.microsoft.com/windowsazure",
                        "FrontendPorts");
                if (frontendPortsSequenceElement != null) {
                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(frontendPortsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "FrontendPort")
                            .size(); i2 = i2 + 1) {
                        org.w3c.dom.Element frontendPortsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(frontendPortsSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "FrontendPort")
                                .get(i2));
                        FrontendPort frontendPortInstance = new FrontendPort();
                        result.getFrontendPorts().add(frontendPortInstance);

                        Element nameElement2 = XmlUtility.getElementByTagNameNS(frontendPortsElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement2 != null) {
                            String nameInstance2;
                            nameInstance2 = nameElement2.getTextContent();
                            frontendPortInstance.setName(nameInstance2);
                        }

                        Element portElement = XmlUtility.getElementByTagNameNS(frontendPortsElement,
                                "http://schemas.microsoft.com/windowsazure", "Port");
                        if (portElement != null) {
                            int portInstance;
                            portInstance = DatatypeConverter.parseInt(portElement.getTextContent());
                            frontendPortInstance.setPort(portInstance);
                        }
                    }
                }

                Element backendAddressPoolsSequenceElement = XmlUtility.getElementByTagNameNS(
                        applicationGatewayConfigurationElement, "http://schemas.microsoft.com/windowsazure",
                        "BackendAddressPools");
                if (backendAddressPoolsSequenceElement != null) {
                    for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(backendAddressPoolsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "BackendAddressPool")
                            .size(); i3 = i3 + 1) {
                        org.w3c.dom.Element backendAddressPoolsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(backendAddressPoolsSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "BackendAddressPool")
                                .get(i3));
                        BackendAddressPool backendAddressPoolInstance = new BackendAddressPool();
                        result.getBackendAddressPools().add(backendAddressPoolInstance);

                        Element nameElement3 = XmlUtility.getElementByTagNameNS(backendAddressPoolsElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement3 != null) {
                            String nameInstance3;
                            nameInstance3 = nameElement3.getTextContent();
                            backendAddressPoolInstance.setName(nameInstance3);
                        }

                        Element iPAddressesSequenceElement = XmlUtility.getElementByTagNameNS(
                                backendAddressPoolsElement, "http://schemas.microsoft.com/windowsazure",
                                "IPAddresses");
                        if (iPAddressesSequenceElement != null) {
                            for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(iPAddressesSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "IPAddress")
                                    .size(); i4 = i4 + 1) {
                                org.w3c.dom.Element iPAddressesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(iPAddressesSequenceElement,
                                                "http://schemas.microsoft.com/windowsazure", "IPAddress")
                                        .get(i4));
                                BackendServer iPAddressInstance = new BackendServer();
                                backendAddressPoolInstance.getBackendServers().add(iPAddressInstance);

                                String iPAddressInstance2;
                                iPAddressInstance2 = iPAddressesElement.getTextContent();
                                iPAddressInstance.setIPAddress(iPAddressInstance2);
                            }
                        }
                    }
                }

                Element backendHttpSettingsListSequenceElement = XmlUtility.getElementByTagNameNS(
                        applicationGatewayConfigurationElement, "http://schemas.microsoft.com/windowsazure",
                        "BackendHttpSettingsList");
                if (backendHttpSettingsListSequenceElement != null) {
                    for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(backendHttpSettingsListSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "BackendHttpSettings")
                            .size(); i5 = i5 + 1) {
                        org.w3c.dom.Element backendHttpSettingsListElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(backendHttpSettingsListSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "BackendHttpSettings")
                                .get(i5));
                        BackendHttpSettings backendHttpSettingsInstance = new BackendHttpSettings();
                        result.getBackendHttpSettingsList().add(backendHttpSettingsInstance);

                        Element nameElement4 = XmlUtility.getElementByTagNameNS(backendHttpSettingsListElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement4 != null) {
                            String nameInstance4;
                            nameInstance4 = nameElement4.getTextContent();
                            backendHttpSettingsInstance.setName(nameInstance4);
                        }

                        Element portElement2 = XmlUtility.getElementByTagNameNS(backendHttpSettingsListElement,
                                "http://schemas.microsoft.com/windowsazure", "Port");
                        if (portElement2 != null) {
                            int portInstance2;
                            portInstance2 = DatatypeConverter.parseInt(portElement2.getTextContent());
                            backendHttpSettingsInstance.setPort(portInstance2);
                        }

                        Element protocolElement = XmlUtility.getElementByTagNameNS(
                                backendHttpSettingsListElement, "http://schemas.microsoft.com/windowsazure",
                                "Protocol");
                        if (protocolElement != null && protocolElement.getTextContent() != null
                                && !protocolElement.getTextContent().isEmpty()) {
                            Protocol protocolInstance;
                            protocolInstance = Protocol.valueOf(protocolElement.getTextContent());
                            backendHttpSettingsInstance.setProtocol(protocolInstance);
                        }

                        Element cookieBasedAffinityElement = XmlUtility.getElementByTagNameNS(
                                backendHttpSettingsListElement, "http://schemas.microsoft.com/windowsazure",
                                "CookieBasedAffinity");
                        if (cookieBasedAffinityElement != null) {
                            String cookieBasedAffinityInstance;
                            cookieBasedAffinityInstance = cookieBasedAffinityElement.getTextContent();
                            backendHttpSettingsInstance.setCookieBasedAffinity(cookieBasedAffinityInstance);
                        }
                    }
                }

                Element httpListenersSequenceElement = XmlUtility.getElementByTagNameNS(
                        applicationGatewayConfigurationElement, "http://schemas.microsoft.com/windowsazure",
                        "HttpListeners");
                if (httpListenersSequenceElement != null) {
                    for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(httpListenersSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "HttpListener")
                            .size(); i6 = i6 + 1) {
                        org.w3c.dom.Element httpListenersElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(httpListenersSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "HttpListener")
                                .get(i6));
                        AGHttpListener httpListenerInstance = new AGHttpListener();
                        result.getHttpListeners().add(httpListenerInstance);

                        Element nameElement5 = XmlUtility.getElementByTagNameNS(httpListenersElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement5 != null) {
                            String nameInstance5;
                            nameInstance5 = nameElement5.getTextContent();
                            httpListenerInstance.setName(nameInstance5);
                        }

                        Element frontendIPElement = XmlUtility.getElementByTagNameNS(httpListenersElement,
                                "http://schemas.microsoft.com/windowsazure", "FrontendIP");
                        if (frontendIPElement != null) {
                            String frontendIPInstance;
                            frontendIPInstance = frontendIPElement.getTextContent();
                            httpListenerInstance.setFrontendIP(frontendIPInstance);
                        }

                        Element frontendPortElement = XmlUtility.getElementByTagNameNS(httpListenersElement,
                                "http://schemas.microsoft.com/windowsazure", "FrontendPort");
                        if (frontendPortElement != null) {
                            String frontendPortInstance2;
                            frontendPortInstance2 = frontendPortElement.getTextContent();
                            httpListenerInstance.setFrontendPort(frontendPortInstance2);
                        }

                        Element protocolElement2 = XmlUtility.getElementByTagNameNS(httpListenersElement,
                                "http://schemas.microsoft.com/windowsazure", "Protocol");
                        if (protocolElement2 != null && protocolElement2.getTextContent() != null
                                && !protocolElement2.getTextContent().isEmpty()) {
                            Protocol protocolInstance2;
                            protocolInstance2 = Protocol.valueOf(protocolElement2.getTextContent());
                            httpListenerInstance.setProtocol(protocolInstance2);
                        }

                        Element sslCertElement = XmlUtility.getElementByTagNameNS(httpListenersElement,
                                "http://schemas.microsoft.com/windowsazure", "SslCert");
                        if (sslCertElement != null) {
                            String sslCertInstance;
                            sslCertInstance = sslCertElement.getTextContent();
                            httpListenerInstance.setSslCert(sslCertInstance);
                        }
                    }
                }

                Element httpLoadBalancingRulesSequenceElement = XmlUtility.getElementByTagNameNS(
                        applicationGatewayConfigurationElement, "http://schemas.microsoft.com/windowsazure",
                        "HttpLoadBalancingRules");
                if (httpLoadBalancingRulesSequenceElement != null) {
                    for (int i7 = 0; i7 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(httpLoadBalancingRulesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "HttpLoadBalancingRule")
                            .size(); i7 = i7 + 1) {
                        org.w3c.dom.Element httpLoadBalancingRulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(httpLoadBalancingRulesSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "HttpLoadBalancingRule")
                                .get(i7));
                        HttpLoadBalancingRule httpLoadBalancingRuleInstance = new HttpLoadBalancingRule();
                        result.getHttpLoadBalancingRules().add(httpLoadBalancingRuleInstance);

                        Element nameElement6 = XmlUtility.getElementByTagNameNS(httpLoadBalancingRulesElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement6 != null) {
                            String nameInstance6;
                            nameInstance6 = nameElement6.getTextContent();
                            httpLoadBalancingRuleInstance.setName(nameInstance6);
                        }

                        Element typeElement2 = XmlUtility.getElementByTagNameNS(httpLoadBalancingRulesElement,
                                "http://schemas.microsoft.com/windowsazure", "Type");
                        if (typeElement2 != null) {
                            String typeInstance2;
                            typeInstance2 = typeElement2.getTextContent();
                            httpLoadBalancingRuleInstance.setType(typeInstance2);
                        }

                        Element backendHttpSettingsElement = XmlUtility.getElementByTagNameNS(
                                httpLoadBalancingRulesElement, "http://schemas.microsoft.com/windowsazure",
                                "BackendHttpSettings");
                        if (backendHttpSettingsElement != null) {
                            String backendHttpSettingsInstance2;
                            backendHttpSettingsInstance2 = backendHttpSettingsElement.getTextContent();
                            httpLoadBalancingRuleInstance.setBackendHttpSettings(backendHttpSettingsInstance2);
                        }

                        Element listenerElement = XmlUtility.getElementByTagNameNS(
                                httpLoadBalancingRulesElement, "http://schemas.microsoft.com/windowsazure",
                                "Listener");
                        if (listenerElement != null) {
                            String listenerInstance;
                            listenerInstance = listenerElement.getTextContent();
                            httpLoadBalancingRuleInstance.setListener(listenerInstance);
                        }

                        Element backendAddressPoolElement = XmlUtility.getElementByTagNameNS(
                                httpLoadBalancingRulesElement, "http://schemas.microsoft.com/windowsazure",
                                "BackendAddressPool");
                        if (backendAddressPoolElement != null) {
                            String backendAddressPoolInstance2;
                            backendAddressPoolInstance2 = backendAddressPoolElement.getTextContent();
                            httpLoadBalancingRuleInstance.setBackendAddressPool(backendAddressPoolInstance2);
                        }
                    }
                }
            }

        }
        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();
        }
    }
}