List of usage examples for java.lang Enum valueOf
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
From source file:com.microsoft.azure.management.notificationhubs.NamespaceOperationsImpl.java
/** * Lists all the available namespaces within the subscription irrespective * of the resourceGroups. (see/*from w w w . ja va 2s . c o m*/ * http://msdn.microsoft.com/en-us/library/azure/hh780759.aspx for more * information) * * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The response of the List Namespace operation. */ @Override public NamespaceListResponse listAll() throws IOException, ServiceException, URISyntaxException { // 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, "listAllAsync", 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 + "/providers/"; url = url + "Microsoft.NotificationHubs"; url = url + "/namespaces"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-09-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("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) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result NamespaceListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new NamespaceListResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { JsonNode valueArray = responseDoc.get("value"); if (valueArray != null && valueArray instanceof NullNode == false) { for (JsonNode valueValue : ((ArrayNode) valueArray)) { NamespaceResource namespaceResourceInstance = new NamespaceResource(); result.getValue().add(namespaceResourceInstance); JsonNode idValue = valueValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); namespaceResourceInstance.setId(idInstance); } JsonNode locationValue = valueValue.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); namespaceResourceInstance.setLocation(locationInstance); } JsonNode nameValue = valueValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); namespaceResourceInstance.setName(nameInstance); } JsonNode typeValue = valueValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); namespaceResourceInstance.setType(typeInstance); } JsonNode tagsSequenceElement = ((JsonNode) valueValue.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); namespaceResourceInstance.getTags().put(tagsKey, tagsValue); } } JsonNode propertiesValue = valueValue.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { NamespaceProperties propertiesInstance = new NamespaceProperties(); namespaceResourceInstance.setProperties(propertiesInstance); JsonNode nameValue2 = propertiesValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); propertiesInstance.setName(nameInstance2); } JsonNode provisioningStateValue = propertiesValue.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); propertiesInstance.setProvisioningState(provisioningStateInstance); } JsonNode regionValue = propertiesValue.get("region"); if (regionValue != null && regionValue instanceof NullNode == false) { String regionInstance; regionInstance = regionValue.getTextValue(); propertiesInstance.setRegion(regionInstance); } JsonNode statusValue = propertiesValue.get("status"); if (statusValue != null && statusValue instanceof NullNode == false) { String statusInstance; statusInstance = statusValue.getTextValue(); propertiesInstance.setStatus(statusInstance); } JsonNode createdAtValue = propertiesValue.get("createdAt"); if (createdAtValue != null && createdAtValue instanceof NullNode == false) { Calendar createdAtInstance; createdAtInstance = DatatypeConverter .parseDateTime(createdAtValue.getTextValue()); propertiesInstance.setCreatedAt(createdAtInstance); } JsonNode serviceBusEndpointValue = propertiesValue.get("serviceBusEndpoint"); if (serviceBusEndpointValue != null && serviceBusEndpointValue instanceof NullNode == false) { URI serviceBusEndpointInstance; serviceBusEndpointInstance = new URI(serviceBusEndpointValue.getTextValue()); propertiesInstance.setServiceBusEndpoint(serviceBusEndpointInstance); } JsonNode subscriptionIdValue = propertiesValue.get("subscriptionId"); if (subscriptionIdValue != null && subscriptionIdValue instanceof NullNode == false) { String subscriptionIdInstance; subscriptionIdInstance = subscriptionIdValue.getTextValue(); propertiesInstance.setSubscriptionId(subscriptionIdInstance); } JsonNode scaleUnitValue = propertiesValue.get("scaleUnit"); if (scaleUnitValue != null && scaleUnitValue instanceof NullNode == false) { String scaleUnitInstance; scaleUnitInstance = scaleUnitValue.getTextValue(); propertiesInstance.setScaleUnit(scaleUnitInstance); } JsonNode enabledValue = propertiesValue.get("enabled"); if (enabledValue != null && enabledValue instanceof NullNode == false) { boolean enabledInstance; enabledInstance = enabledValue.getBooleanValue(); propertiesInstance.setEnabled(enabledInstance); } JsonNode criticalValue = propertiesValue.get("critical"); if (criticalValue != null && criticalValue instanceof NullNode == false) { boolean criticalInstance; criticalInstance = criticalValue.getBooleanValue(); propertiesInstance.setCritical(criticalInstance); } JsonNode namespaceTypeValue = propertiesValue.get("namespaceType"); if (namespaceTypeValue != null && namespaceTypeValue instanceof NullNode == false) { NamespaceType namespaceTypeInstance; namespaceTypeInstance = Enum.valueOf(NamespaceType.class, namespaceTypeValue.getTextValue()); propertiesInstance.setNamespaceType(namespaceTypeInstance); } } } } JsonNode nextLinkValue = responseDoc.get("nextLink"); if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) { String nextLinkInstance; nextLinkInstance = nextLinkValue.getTextValue(); result.setNextLink(nextLinkInstance); } } } 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.notificationhubs.NotificationHubOperationsImpl.java
/** * Lists the PNS Credentials associated with a notification hub . * * @param resourceGroupName Required. The name of the resource group. * @param namespaceName Required. The namespace name. * @param notificationHubName Required. The notification hub 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./*from w ww.ja v a 2s .c o m*/ * @throws ServiceException Thrown if an unexpected response is found. * @return The response of the Get NotificationHub operation. */ @Override public NotificationHubGetResponse getPnsCredentials(String resourceGroupName, String namespaceName, String notificationHubName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (namespaceName == null) { throw new NullPointerException("namespaceName"); } if (notificationHubName == null) { throw new NullPointerException("notificationHubName"); } // 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("namespaceName", namespaceName); tracingParameters.put("notificationHubName", notificationHubName); CloudTracing.enter(invocationId, this, "getPnsCredentialsAsync", 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.NotificationHubs"; url = url + "/namespaces/"; url = url + URLEncoder.encode(namespaceName, "UTF-8"); url = url + "/notificationHubs/"; url = url + URLEncoder.encode(notificationHubName, "UTF-8"); url = url + "/pnsCredentials"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-09-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 HttpPost httpRequest = new HttpPost(url); // Set Headers // 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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result NotificationHubGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new NotificationHubGetResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { NotificationHubResource valueInstance = new NotificationHubResource(); result.setValue(valueInstance); JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); valueInstance.setId(idInstance); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); valueInstance.setLocation(locationInstance); } JsonNode nameValue = responseDoc.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); valueInstance.setName(nameInstance); } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); valueInstance.setType(typeInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); valueInstance.getTags().put(tagsKey, tagsValue); } } JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { NotificationHubProperties propertiesInstance = new NotificationHubProperties(); valueInstance.setProperties(propertiesInstance); JsonNode nameValue2 = propertiesValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); propertiesInstance.setName(nameInstance2); } JsonNode registrationTtlValue = propertiesValue.get("registrationTtl"); if (registrationTtlValue != null && registrationTtlValue instanceof NullNode == false) { String registrationTtlInstance; registrationTtlInstance = registrationTtlValue.getTextValue(); propertiesInstance.setRegistrationTtl(registrationTtlInstance); } JsonNode authorizationRulesArray = propertiesValue.get("authorizationRules"); if (authorizationRulesArray != null && authorizationRulesArray instanceof NullNode == false) { for (JsonNode authorizationRulesValue : ((ArrayNode) authorizationRulesArray)) { SharedAccessAuthorizationRuleProperties sharedAccessAuthorizationRulePropertiesInstance = new SharedAccessAuthorizationRuleProperties(); propertiesInstance.getAuthorizationRules() .add(sharedAccessAuthorizationRulePropertiesInstance); JsonNode primaryKeyValue = authorizationRulesValue.get("primaryKey"); if (primaryKeyValue != null && primaryKeyValue instanceof NullNode == false) { String primaryKeyInstance; primaryKeyInstance = primaryKeyValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance .setPrimaryKey(primaryKeyInstance); } JsonNode secondaryKeyValue = authorizationRulesValue.get("secondaryKey"); if (secondaryKeyValue != null && secondaryKeyValue instanceof NullNode == false) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance .setSecondaryKey(secondaryKeyInstance); } JsonNode keyNameValue = authorizationRulesValue.get("keyName"); if (keyNameValue != null && keyNameValue instanceof NullNode == false) { String keyNameInstance; keyNameInstance = keyNameValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance.setKeyName(keyNameInstance); } JsonNode claimTypeValue = authorizationRulesValue.get("claimType"); if (claimTypeValue != null && claimTypeValue instanceof NullNode == false) { String claimTypeInstance; claimTypeInstance = claimTypeValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance.setClaimType(claimTypeInstance); } JsonNode claimValueValue = authorizationRulesValue.get("claimValue"); if (claimValueValue != null && claimValueValue instanceof NullNode == false) { String claimValueInstance; claimValueInstance = claimValueValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance .setClaimValue(claimValueInstance); } JsonNode rightsArray = authorizationRulesValue.get("rights"); if (rightsArray != null && rightsArray instanceof NullNode == false) { for (JsonNode rightsValue : ((ArrayNode) rightsArray)) { sharedAccessAuthorizationRulePropertiesInstance.getRights() .add(Enum.valueOf(AccessRights.class, rightsValue.getTextValue())); } } JsonNode createdTimeValue = authorizationRulesValue.get("createdTime"); if (createdTimeValue != null && createdTimeValue instanceof NullNode == false) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter .parseDateTime(createdTimeValue.getTextValue()); sharedAccessAuthorizationRulePropertiesInstance .setCreatedTime(createdTimeInstance); } JsonNode modifiedTimeValue = authorizationRulesValue.get("modifiedTime"); if (modifiedTimeValue != null && modifiedTimeValue instanceof NullNode == false) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeValue.getTextValue()); sharedAccessAuthorizationRulePropertiesInstance .setModifiedTime(modifiedTimeInstance); } JsonNode revisionValue = authorizationRulesValue.get("revision"); if (revisionValue != null && revisionValue instanceof NullNode == false) { int revisionInstance; revisionInstance = revisionValue.getIntValue(); sharedAccessAuthorizationRulePropertiesInstance.setRevision(revisionInstance); } } } JsonNode apnsCredentialValue = propertiesValue.get("apnsCredential"); if (apnsCredentialValue != null && apnsCredentialValue instanceof NullNode == false) { ApnsCredential apnsCredentialInstance = new ApnsCredential(); propertiesInstance.setApnsCredential(apnsCredentialInstance); JsonNode propertiesValue2 = apnsCredentialValue.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { ApnsCredentialProperties propertiesInstance2 = new ApnsCredentialProperties(); apnsCredentialInstance.setProperties(propertiesInstance2); JsonNode apnsCertificateValue = propertiesValue2.get("apnsCertificate"); if (apnsCertificateValue != null && apnsCertificateValue instanceof NullNode == false) { String apnsCertificateInstance; apnsCertificateInstance = apnsCertificateValue.getTextValue(); propertiesInstance2.setApnsCertificate(apnsCertificateInstance); } JsonNode certificateKeyValue = propertiesValue2.get("certificateKey"); if (certificateKeyValue != null && certificateKeyValue instanceof NullNode == false) { String certificateKeyInstance; certificateKeyInstance = certificateKeyValue.getTextValue(); propertiesInstance2.setCertificateKey(certificateKeyInstance); } JsonNode endpointValue = propertiesValue2.get("endpoint"); if (endpointValue != null && endpointValue instanceof NullNode == false) { String endpointInstance; endpointInstance = endpointValue.getTextValue(); propertiesInstance2.setEndpoint(endpointInstance); } JsonNode thumbprintValue = propertiesValue2.get("thumbprint"); if (thumbprintValue != null && thumbprintValue instanceof NullNode == false) { String thumbprintInstance; thumbprintInstance = thumbprintValue.getTextValue(); propertiesInstance2.setThumbprint(thumbprintInstance); } } } JsonNode wnsCredentialValue = propertiesValue.get("wnsCredential"); if (wnsCredentialValue != null && wnsCredentialValue instanceof NullNode == false) { WnsCredential wnsCredentialInstance = new WnsCredential(); propertiesInstance.setWnsCredential(wnsCredentialInstance); JsonNode propertiesValue3 = wnsCredentialValue.get("properties"); if (propertiesValue3 != null && propertiesValue3 instanceof NullNode == false) { WnsCredentialProperties propertiesInstance3 = new WnsCredentialProperties(); wnsCredentialInstance.setProperties(propertiesInstance3); JsonNode packageSidValue = propertiesValue3.get("packageSid"); if (packageSidValue != null && packageSidValue instanceof NullNode == false) { String packageSidInstance; packageSidInstance = packageSidValue.getTextValue(); propertiesInstance3.setPackageSid(packageSidInstance); } JsonNode secretKeyValue = propertiesValue3.get("secretKey"); if (secretKeyValue != null && secretKeyValue instanceof NullNode == false) { String secretKeyInstance; secretKeyInstance = secretKeyValue.getTextValue(); propertiesInstance3.setSecretKey(secretKeyInstance); } JsonNode windowsLiveEndpointValue = propertiesValue3.get("windowsLiveEndpoint"); if (windowsLiveEndpointValue != null && windowsLiveEndpointValue instanceof NullNode == false) { String windowsLiveEndpointInstance; windowsLiveEndpointInstance = windowsLiveEndpointValue.getTextValue(); propertiesInstance3.setWindowsLiveEndpoint(windowsLiveEndpointInstance); } } } JsonNode gcmCredentialValue = propertiesValue.get("gcmCredential"); if (gcmCredentialValue != null && gcmCredentialValue instanceof NullNode == false) { GcmCredential gcmCredentialInstance = new GcmCredential(); propertiesInstance.setGcmCredential(gcmCredentialInstance); JsonNode propertiesValue4 = gcmCredentialValue.get("properties"); if (propertiesValue4 != null && propertiesValue4 instanceof NullNode == false) { GcmCredentialProperties propertiesInstance4 = new GcmCredentialProperties(); gcmCredentialInstance.setProperties(propertiesInstance4); JsonNode gcmEndpointValue = propertiesValue4.get("gcmEndpoint"); if (gcmEndpointValue != null && gcmEndpointValue instanceof NullNode == false) { String gcmEndpointInstance; gcmEndpointInstance = gcmEndpointValue.getTextValue(); propertiesInstance4.setGcmEndpoint(gcmEndpointInstance); } JsonNode googleApiKeyValue = propertiesValue4.get("googleApiKey"); if (googleApiKeyValue != null && googleApiKeyValue instanceof NullNode == false) { String googleApiKeyInstance; googleApiKeyInstance = googleApiKeyValue.getTextValue(); propertiesInstance4.setGoogleApiKey(googleApiKeyInstance); } } } JsonNode mpnsCredentialValue = propertiesValue.get("mpnsCredential"); if (mpnsCredentialValue != null && mpnsCredentialValue instanceof NullNode == false) { MpnsCredential mpnsCredentialInstance = new MpnsCredential(); propertiesInstance.setMpnsCredential(mpnsCredentialInstance); JsonNode propertiesValue5 = mpnsCredentialValue.get("properties"); if (propertiesValue5 != null && propertiesValue5 instanceof NullNode == false) { MpnsCredentialProperties propertiesInstance5 = new MpnsCredentialProperties(); mpnsCredentialInstance.setProperties(propertiesInstance5); JsonNode mpnsCertificateValue = propertiesValue5.get("mpnsCertificate"); if (mpnsCertificateValue != null && mpnsCertificateValue instanceof NullNode == false) { String mpnsCertificateInstance; mpnsCertificateInstance = mpnsCertificateValue.getTextValue(); propertiesInstance5.setMpnsCertificate(mpnsCertificateInstance); } JsonNode certificateKeyValue2 = propertiesValue5.get("certificateKey"); if (certificateKeyValue2 != null && certificateKeyValue2 instanceof NullNode == false) { String certificateKeyInstance2; certificateKeyInstance2 = certificateKeyValue2.getTextValue(); propertiesInstance5.setCertificateKey(certificateKeyInstance2); } JsonNode thumbprintValue2 = propertiesValue5.get("thumbprint"); if (thumbprintValue2 != null && thumbprintValue2 instanceof NullNode == false) { String thumbprintInstance2; thumbprintInstance2 = thumbprintValue2.getTextValue(); propertiesInstance5.setThumbprint(thumbprintInstance2); } } } JsonNode admCredentialValue = propertiesValue.get("admCredential"); if (admCredentialValue != null && admCredentialValue instanceof NullNode == false) { AdmCredential admCredentialInstance = new AdmCredential(); propertiesInstance.setAdmCredential(admCredentialInstance); JsonNode propertiesValue6 = admCredentialValue.get("properties"); if (propertiesValue6 != null && propertiesValue6 instanceof NullNode == false) { AdmCredentialProperties propertiesInstance6 = new AdmCredentialProperties(); admCredentialInstance.setProperties(propertiesInstance6); JsonNode clientIdValue = propertiesValue6.get("clientId"); if (clientIdValue != null && clientIdValue instanceof NullNode == false) { String clientIdInstance; clientIdInstance = clientIdValue.getTextValue(); propertiesInstance6.setClientId(clientIdInstance); } JsonNode clientSecretValue = propertiesValue6.get("clientSecret"); if (clientSecretValue != null && clientSecretValue instanceof NullNode == false) { String clientSecretInstance; clientSecretInstance = clientSecretValue.getTextValue(); propertiesInstance6.setClientSecret(clientSecretInstance); } JsonNode authTokenUrlValue = propertiesValue6.get("authTokenUrl"); if (authTokenUrlValue != null && authTokenUrlValue instanceof NullNode == false) { String authTokenUrlInstance; authTokenUrlInstance = authTokenUrlValue.getTextValue(); propertiesInstance6.setAuthTokenUrl(authTokenUrlInstance); } } } JsonNode baiduCredentialValue = propertiesValue.get("baiduCredential"); if (baiduCredentialValue != null && baiduCredentialValue instanceof NullNode == false) { BaiduCredential baiduCredentialInstance = new BaiduCredential(); propertiesInstance.setBaiduCredential(baiduCredentialInstance); JsonNode propertiesValue7 = baiduCredentialValue.get("properties"); if (propertiesValue7 != null && propertiesValue7 instanceof NullNode == false) { BaiduCredentialProperties propertiesInstance7 = new BaiduCredentialProperties(); baiduCredentialInstance.setProperties(propertiesInstance7); JsonNode baiduApiKeyValue = propertiesValue7.get("baiduApiKey"); if (baiduApiKeyValue != null && baiduApiKeyValue instanceof NullNode == false) { String baiduApiKeyInstance; baiduApiKeyInstance = baiduApiKeyValue.getTextValue(); propertiesInstance7.setBaiduApiKey(baiduApiKeyInstance); } JsonNode baiduEndPointValue = propertiesValue7.get("baiduEndPoint"); if (baiduEndPointValue != null && baiduEndPointValue instanceof NullNode == false) { String baiduEndPointInstance; baiduEndPointInstance = baiduEndPointValue.getTextValue(); propertiesInstance7.setBaiduEndPoint(baiduEndPointInstance); } JsonNode baiduSecretKeyValue = propertiesValue7.get("baiduSecretKey"); if (baiduSecretKeyValue != null && baiduSecretKeyValue instanceof NullNode == false) { String baiduSecretKeyInstance; baiduSecretKeyInstance = baiduSecretKeyValue.getTextValue(); propertiesInstance7.setBaiduSecretKey(baiduSecretKeyInstance); } } } } } } 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:org.openTwoFactor.client.util.TwoFactorClientCommonUtils.java
/** * If necessary, convert an object to another type. if type is Object.class, just return the input * @param <T> is the type to return * @param value/*www .j a v a 2s . c o m*/ * @param theClass * @param convertNullToDefaultPrimitive if the value is null, and theClass is primitive, should we * convert the null to a primitive default value * @param useNewInstanceHooks if theClass is not recognized, then honor the string "null", "newInstance", * or get a constructor with one param, and call it * @return the object of that instance converted into something else */ @SuppressWarnings({ "unchecked", "cast" }) public static <T> T typeCast(Object value, Class<T> theClass, boolean convertNullToDefaultPrimitive, boolean useNewInstanceHooks) { if (Object.class.equals(theClass)) { return (T) value; } if (value == null) { if (convertNullToDefaultPrimitive && theClass.isPrimitive()) { if (theClass == boolean.class) { return (T) Boolean.FALSE; } if (theClass == char.class) { return (T) (Object) 0; } //convert 0 to the type return typeCast(0, theClass, false, false); } return null; } if (theClass.isInstance(value)) { return (T) value; } //if array, get the base class if (theClass.isArray() && theClass.getComponentType() != null) { theClass = (Class<T>) theClass.getComponentType(); } Object resultValue = null; //loop through and see the primitive types etc if (theClass.equals(Date.class)) { resultValue = dateValue(value); } else if (theClass.equals(String.class)) { resultValue = stringValue(value); } else if (theClass.equals(Timestamp.class)) { resultValue = toTimestamp(value); } else if (theClass.equals(Boolean.class) || theClass.equals(boolean.class)) { resultValue = booleanObjectValue(value); } else if (theClass.equals(Integer.class) || theClass.equals(int.class)) { resultValue = intObjectValue(value, true); } else if (theClass.equals(Double.class) || theClass.equals(double.class)) { resultValue = doubleObjectValue(value, true); } else if (theClass.equals(Float.class) || theClass.equals(float.class)) { resultValue = floatObjectValue(value, true); } else if (theClass.equals(Long.class) || theClass.equals(long.class)) { resultValue = longObjectValue(value, true); } else if (theClass.equals(Byte.class) || theClass.equals(byte.class)) { resultValue = byteObjectValue(value); } else if (theClass.equals(Character.class) || theClass.equals(char.class)) { resultValue = charObjectValue(value); } else if (theClass.equals(Short.class) || theClass.equals(short.class)) { resultValue = shortObjectValue(value); } else if (theClass.isEnum() && (value instanceof String)) { resultValue = Enum.valueOf((Class) theClass, (String) value); } else if (theClass.equals(Class.class) && (value instanceof String)) { resultValue = forName((String) value); } else if (useNewInstanceHooks && value instanceof String) { String stringValue = (String) value; if (equals("null", stringValue)) { resultValue = null; } else if (equals("newInstance", stringValue)) { resultValue = newInstance(theClass); } else { // instantiate using string //note, we could typecast this to fit whatever is there... right now this is used for annotation try { Constructor constructor = theClass.getConstructor(new Class[] { String.class }); resultValue = constructor.newInstance(new Object[] { stringValue }); } catch (Exception e) { throw new RuntimeException("Cant find constructor with string for class: " + theClass); } } } else { throw new RuntimeException("Cannot convert from type: " + value.getClass() + " to type: " + theClass); } return (T) resultValue; }
From source file:com.microsoft.azure.management.resources.DeploymentOperationsImpl.java
/** * Validate a deployment template.//w w w . j av a 2 s . c o m * * @param resourceGroupName Required. The name of the resource group. The * name is case insensitive. * @param deploymentName Required. The name of the deployment. * @param parameters Required. Deployment to validate. * @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 Information from validate template deployment response. */ @Override public DeploymentValidateResponse validate(String resourceGroupName, String deploymentName, Deployment parameters) throws IOException, ServiceException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (resourceGroupName != null && resourceGroupName.length() > 1000) { throw new IllegalArgumentException("resourceGroupName"); } if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) { throw new IllegalArgumentException("resourceGroupName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getProperties() != null) { if (parameters.getProperties().getParametersLink() != null) { if (parameters.getProperties().getParametersLink().getUri() == null) { throw new NullPointerException("parameters.Properties.ParametersLink.Uri"); } } if (parameters.getProperties().getTemplateLink() != null) { if (parameters.getProperties().getTemplateLink().getUri() == null) { throw new NullPointerException("parameters.Properties.TemplateLink.Uri"); } } } // 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("deploymentName", deploymentName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "validateAsync", 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/microsoft.resources/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); url = url + "/validate"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-04-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; charset=utf-8"); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode deploymentValue = objectMapper.createObjectNode(); requestDoc = deploymentValue; if (parameters.getProperties() != null) { ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) deploymentValue).put("properties", propertiesValue); if (parameters.getProperties().getTemplate() != null) { ((ObjectNode) propertiesValue).put("template", objectMapper.readTree(parameters.getProperties().getTemplate())); } if (parameters.getProperties().getTemplateLink() != null) { ObjectNode templateLinkValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("templateLink", templateLinkValue); ((ObjectNode) templateLinkValue).put("uri", parameters.getProperties().getTemplateLink().getUri().toString()); if (parameters.getProperties().getTemplateLink().getContentVersion() != null) { ((ObjectNode) templateLinkValue).put("contentVersion", parameters.getProperties().getTemplateLink().getContentVersion()); } } if (parameters.getProperties().getParameters() != null) { ((ObjectNode) propertiesValue).put("parameters", objectMapper.readTree(parameters.getProperties().getParameters())); } if (parameters.getProperties().getParametersLink() != null) { ObjectNode parametersLinkValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("parametersLink", parametersLinkValue); ((ObjectNode) parametersLinkValue).put("uri", parameters.getProperties().getParametersLink().getUri().toString()); if (parameters.getProperties().getParametersLink().getContentVersion() != null) { ((ObjectNode) parametersLinkValue).put("contentVersion", parameters.getProperties().getParametersLink().getContentVersion()); } } if (parameters.getProperties().getMode() != null) { ((ObjectNode) propertiesValue).put("mode", parameters.getProperties().getMode().toString()); } } StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, requestDoc); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/json; charset=utf-8"); // 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_BAD_REQUEST) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DeploymentValidateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_BAD_REQUEST) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DeploymentValidateResponse(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { JsonNode errorValue = responseDoc.get("error"); if (errorValue != null && errorValue instanceof NullNode == false) { ResourceManagementErrorWithDetails errorInstance = new ResourceManagementErrorWithDetails(); result.setError(errorInstance); JsonNode detailsArray = errorValue.get("details"); if (detailsArray != null && detailsArray instanceof NullNode == false) { for (JsonNode detailsValue : ((ArrayNode) detailsArray)) { ResourceManagementError resourceManagementErrorInstance = new ResourceManagementError(); errorInstance.getDetails().add(resourceManagementErrorInstance); JsonNode codeValue = detailsValue.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); resourceManagementErrorInstance.setCode(codeInstance); } JsonNode messageValue = detailsValue.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); resourceManagementErrorInstance.setMessage(messageInstance); } JsonNode targetValue = detailsValue.get("target"); if (targetValue != null && targetValue instanceof NullNode == false) { String targetInstance; targetInstance = targetValue.getTextValue(); resourceManagementErrorInstance.setTarget(targetInstance); } } } JsonNode codeValue2 = errorValue.get("code"); if (codeValue2 != null && codeValue2 instanceof NullNode == false) { String codeInstance2; codeInstance2 = codeValue2.getTextValue(); errorInstance.setCode(codeInstance2); } JsonNode messageValue2 = errorValue.get("message"); if (messageValue2 != null && messageValue2 instanceof NullNode == false) { String messageInstance2; messageInstance2 = messageValue2.getTextValue(); errorInstance.setMessage(messageInstance2); } JsonNode targetValue2 = errorValue.get("target"); if (targetValue2 != null && targetValue2 instanceof NullNode == false) { String targetInstance2; targetInstance2 = targetValue2.getTextValue(); errorInstance.setTarget(targetInstance2); } } JsonNode propertiesValue2 = responseDoc.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { DeploymentPropertiesExtended propertiesInstance = new DeploymentPropertiesExtended(); result.setProperties(propertiesInstance); JsonNode provisioningStateValue = propertiesValue2.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); propertiesInstance.setProvisioningState(provisioningStateInstance); } JsonNode correlationIdValue = propertiesValue2.get("correlationId"); if (correlationIdValue != null && correlationIdValue instanceof NullNode == false) { String correlationIdInstance; correlationIdInstance = correlationIdValue.getTextValue(); propertiesInstance.setCorrelationId(correlationIdInstance); } JsonNode timestampValue = propertiesValue2.get("timestamp"); if (timestampValue != null && timestampValue instanceof NullNode == false) { Calendar timestampInstance; timestampInstance = DatatypeConverter.parseDateTime(timestampValue.getTextValue()); propertiesInstance.setTimestamp(timestampInstance); } JsonNode outputsValue = propertiesValue2.get("outputs"); if (outputsValue != null && outputsValue instanceof NullNode == false) { String outputsInstance; outputsInstance = outputsValue.getTextValue(); propertiesInstance.setOutputs(outputsInstance); } JsonNode providersArray = propertiesValue2.get("providers"); if (providersArray != null && providersArray instanceof NullNode == false) { for (JsonNode providersValue : ((ArrayNode) providersArray)) { Provider providerInstance = new Provider(); propertiesInstance.getProviders().add(providerInstance); JsonNode idValue = providersValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); providerInstance.setId(idInstance); } JsonNode namespaceValue = providersValue.get("namespace"); if (namespaceValue != null && namespaceValue instanceof NullNode == false) { String namespaceInstance; namespaceInstance = namespaceValue.getTextValue(); providerInstance.setNamespace(namespaceInstance); } JsonNode registrationStateValue = providersValue.get("registrationState"); if (registrationStateValue != null && registrationStateValue instanceof NullNode == false) { String registrationStateInstance; registrationStateInstance = registrationStateValue.getTextValue(); providerInstance.setRegistrationState(registrationStateInstance); } JsonNode resourceTypesArray = providersValue.get("resourceTypes"); if (resourceTypesArray != null && resourceTypesArray instanceof NullNode == false) { for (JsonNode resourceTypesValue : ((ArrayNode) resourceTypesArray)) { ProviderResourceType providerResourceTypeInstance = new ProviderResourceType(); providerInstance.getResourceTypes().add(providerResourceTypeInstance); JsonNode resourceTypeValue = resourceTypesValue.get("resourceType"); if (resourceTypeValue != null && resourceTypeValue instanceof NullNode == false) { String resourceTypeInstance; resourceTypeInstance = resourceTypeValue.getTextValue(); providerResourceTypeInstance.setName(resourceTypeInstance); } JsonNode locationsArray = resourceTypesValue.get("locations"); if (locationsArray != null && locationsArray instanceof NullNode == false) { for (JsonNode locationsValue : ((ArrayNode) locationsArray)) { providerResourceTypeInstance.getLocations() .add(locationsValue.getTextValue()); } } JsonNode apiVersionsArray = resourceTypesValue.get("apiVersions"); if (apiVersionsArray != null && apiVersionsArray instanceof NullNode == false) { for (JsonNode apiVersionsValue : ((ArrayNode) apiVersionsArray)) { providerResourceTypeInstance.getApiVersions() .add(apiVersionsValue.getTextValue()); } } JsonNode propertiesSequenceElement = ((JsonNode) resourceTypesValue .get("properties")); if (propertiesSequenceElement != null && propertiesSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = propertiesSequenceElement .getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String propertiesKey = property.getKey(); String propertiesValue3 = property.getValue().getTextValue(); providerResourceTypeInstance.getProperties().put(propertiesKey, propertiesValue3); } } } } } } JsonNode dependenciesArray = propertiesValue2.get("dependencies"); if (dependenciesArray != null && dependenciesArray instanceof NullNode == false) { for (JsonNode dependenciesValue : ((ArrayNode) dependenciesArray)) { Dependency dependencyInstance = new Dependency(); propertiesInstance.getDependencies().add(dependencyInstance); JsonNode dependsOnArray = dependenciesValue.get("dependsOn"); if (dependsOnArray != null && dependsOnArray instanceof NullNode == false) { for (JsonNode dependsOnValue : ((ArrayNode) dependsOnArray)) { BasicDependency basicDependencyInstance = new BasicDependency(); dependencyInstance.getDependsOn().add(basicDependencyInstance); JsonNode idValue2 = dependsOnValue.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); basicDependencyInstance.setId(idInstance2); } JsonNode resourceTypeValue2 = dependsOnValue.get("resourceType"); if (resourceTypeValue2 != null && resourceTypeValue2 instanceof NullNode == false) { String resourceTypeInstance2; resourceTypeInstance2 = resourceTypeValue2.getTextValue(); basicDependencyInstance.setResourceType(resourceTypeInstance2); } JsonNode resourceNameValue = dependsOnValue.get("resourceName"); if (resourceNameValue != null && resourceNameValue instanceof NullNode == false) { String resourceNameInstance; resourceNameInstance = resourceNameValue.getTextValue(); basicDependencyInstance.setResourceName(resourceNameInstance); } } } JsonNode idValue3 = dependenciesValue.get("id"); if (idValue3 != null && idValue3 instanceof NullNode == false) { String idInstance3; idInstance3 = idValue3.getTextValue(); dependencyInstance.setId(idInstance3); } JsonNode resourceTypeValue3 = dependenciesValue.get("resourceType"); if (resourceTypeValue3 != null && resourceTypeValue3 instanceof NullNode == false) { String resourceTypeInstance3; resourceTypeInstance3 = resourceTypeValue3.getTextValue(); dependencyInstance.setResourceType(resourceTypeInstance3); } JsonNode resourceNameValue2 = dependenciesValue.get("resourceName"); if (resourceNameValue2 != null && resourceNameValue2 instanceof NullNode == false) { String resourceNameInstance2; resourceNameInstance2 = resourceNameValue2.getTextValue(); dependencyInstance.setResourceName(resourceNameInstance2); } } } JsonNode templateValue = propertiesValue2.get("template"); if (templateValue != null && templateValue instanceof NullNode == false) { String templateInstance; templateInstance = templateValue.getTextValue(); propertiesInstance.setTemplate(templateInstance); } JsonNode templateLinkValue2 = propertiesValue2.get("templateLink"); if (templateLinkValue2 != null && templateLinkValue2 instanceof NullNode == false) { TemplateLink templateLinkInstance = new TemplateLink(); propertiesInstance.setTemplateLink(templateLinkInstance); JsonNode uriValue = templateLinkValue2.get("uri"); if (uriValue != null && uriValue instanceof NullNode == false) { URI uriInstance; uriInstance = new URI(uriValue.getTextValue()); templateLinkInstance.setUri(uriInstance); } JsonNode contentVersionValue = templateLinkValue2.get("contentVersion"); if (contentVersionValue != null && contentVersionValue instanceof NullNode == false) { String contentVersionInstance; contentVersionInstance = contentVersionValue.getTextValue(); templateLinkInstance.setContentVersion(contentVersionInstance); } } JsonNode parametersValue = propertiesValue2.get("parameters"); if (parametersValue != null && parametersValue instanceof NullNode == false) { String parametersInstance; parametersInstance = parametersValue.getTextValue(); propertiesInstance.setParameters(parametersInstance); } JsonNode parametersLinkValue2 = propertiesValue2.get("parametersLink"); if (parametersLinkValue2 != null && parametersLinkValue2 instanceof NullNode == false) { ParametersLink parametersLinkInstance = new ParametersLink(); propertiesInstance.setParametersLink(parametersLinkInstance); JsonNode uriValue2 = parametersLinkValue2.get("uri"); if (uriValue2 != null && uriValue2 instanceof NullNode == false) { URI uriInstance2; uriInstance2 = new URI(uriValue2.getTextValue()); parametersLinkInstance.setUri(uriInstance2); } JsonNode contentVersionValue2 = parametersLinkValue2.get("contentVersion"); if (contentVersionValue2 != null && contentVersionValue2 instanceof NullNode == false) { String contentVersionInstance2; contentVersionInstance2 = contentVersionValue2.getTextValue(); parametersLinkInstance.setContentVersion(contentVersionInstance2); } } JsonNode modeValue = propertiesValue2.get("mode"); if (modeValue != null && modeValue instanceof NullNode == false) { DeploymentMode modeInstance; modeInstance = Enum.valueOf(DeploymentMode.class, modeValue.getTextValue()); propertiesInstance.setMode(modeInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (statusCode == HttpStatus.SC_OK) { result.setIsValid(true); } 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.notificationhubs.NamespaceOperationsImpl.java
/** * The get authorization rules operation gets the authorization rules for a * namespace.// ww w. ja v a 2s . c om * * @param resourceGroupName Required. The name of the resource group. * @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. * @return The response of the List Namespace operation. */ @Override public SharedAccessAuthorizationRuleListResponse listAuthorizationRules(String resourceGroupName, String namespaceName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } 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("resourceGroupName", resourceGroupName); tracingParameters.put("namespaceName", namespaceName); CloudTracing.enter(invocationId, this, "listAuthorizationRulesAsync", 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.NotificationHubs"; url = url + "/namespaces/"; url = url + URLEncoder.encode(namespaceName, "UTF-8"); url = url + "/AuthorizationRules"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-09-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 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) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result SharedAccessAuthorizationRuleListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new SharedAccessAuthorizationRuleListResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { JsonNode valueArray = responseDoc.get("value"); if (valueArray != null && valueArray instanceof NullNode == false) { for (JsonNode valueValue : ((ArrayNode) valueArray)) { SharedAccessAuthorizationRuleResource sharedAccessAuthorizationRuleResourceInstance = new SharedAccessAuthorizationRuleResource(); result.getValue().add(sharedAccessAuthorizationRuleResourceInstance); JsonNode idValue = valueValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); sharedAccessAuthorizationRuleResourceInstance.setId(idInstance); } JsonNode locationValue = valueValue.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); sharedAccessAuthorizationRuleResourceInstance.setLocation(locationInstance); } JsonNode nameValue = valueValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); sharedAccessAuthorizationRuleResourceInstance.setName(nameInstance); } JsonNode typeValue = valueValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); sharedAccessAuthorizationRuleResourceInstance.setType(typeInstance); } JsonNode tagsSequenceElement = ((JsonNode) valueValue.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); sharedAccessAuthorizationRuleResourceInstance.getTags().put(tagsKey, tagsValue); } } JsonNode propertiesValue = valueValue.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { SharedAccessAuthorizationRuleProperties propertiesInstance = new SharedAccessAuthorizationRuleProperties(); sharedAccessAuthorizationRuleResourceInstance.setProperties(propertiesInstance); JsonNode primaryKeyValue = propertiesValue.get("primaryKey"); if (primaryKeyValue != null && primaryKeyValue instanceof NullNode == false) { String primaryKeyInstance; primaryKeyInstance = primaryKeyValue.getTextValue(); propertiesInstance.setPrimaryKey(primaryKeyInstance); } JsonNode secondaryKeyValue = propertiesValue.get("secondaryKey"); if (secondaryKeyValue != null && secondaryKeyValue instanceof NullNode == false) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyValue.getTextValue(); propertiesInstance.setSecondaryKey(secondaryKeyInstance); } JsonNode keyNameValue = propertiesValue.get("keyName"); if (keyNameValue != null && keyNameValue instanceof NullNode == false) { String keyNameInstance; keyNameInstance = keyNameValue.getTextValue(); propertiesInstance.setKeyName(keyNameInstance); } JsonNode claimTypeValue = propertiesValue.get("claimType"); if (claimTypeValue != null && claimTypeValue instanceof NullNode == false) { String claimTypeInstance; claimTypeInstance = claimTypeValue.getTextValue(); propertiesInstance.setClaimType(claimTypeInstance); } JsonNode claimValueValue = propertiesValue.get("claimValue"); if (claimValueValue != null && claimValueValue instanceof NullNode == false) { String claimValueInstance; claimValueInstance = claimValueValue.getTextValue(); propertiesInstance.setClaimValue(claimValueInstance); } JsonNode rightsArray = propertiesValue.get("rights"); if (rightsArray != null && rightsArray instanceof NullNode == false) { for (JsonNode rightsValue : ((ArrayNode) rightsArray)) { propertiesInstance.getRights() .add(Enum.valueOf(AccessRights.class, rightsValue.getTextValue())); } } JsonNode createdTimeValue = propertiesValue.get("createdTime"); if (createdTimeValue != null && createdTimeValue instanceof NullNode == false) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter .parseDateTime(createdTimeValue.getTextValue()); propertiesInstance.setCreatedTime(createdTimeInstance); } JsonNode modifiedTimeValue = propertiesValue.get("modifiedTime"); if (modifiedTimeValue != null && modifiedTimeValue instanceof NullNode == false) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeValue.getTextValue()); propertiesInstance.setModifiedTime(modifiedTimeInstance); } JsonNode revisionValue = propertiesValue.get("revision"); if (revisionValue != null && revisionValue instanceof NullNode == false) { int revisionInstance; revisionInstance = revisionValue.getIntValue(); propertiesInstance.setRevision(revisionInstance); } } } } JsonNode nextLinkValue = responseDoc.get("nextLink"); if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) { String nextLinkInstance; nextLinkInstance = nextLinkValue.getTextValue(); result.setNextLink(nextLinkInstance); } } } 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.websites.WebSiteOperationsImpl.java
/** * You can retrieve details for a web site by issuing an HTTP GET request. * (see http://msdn.microsoft.com/en-us/library/windowsazure/dn167007.aspx * for more information)//w w w . j av a 2s.co m * * @param resourceGroupName Required. The name of the resource group. * @param webSiteName Required. The name of the web site. * @param slotName Optional. The name of the slot. * @param parameters Optional. Additional parameters. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Get Web Site Details operation response. */ @Override public WebSiteGetResponse get(String resourceGroupName, String webSiteName, String slotName, WebSiteGetParameters parameters) throws IOException, ServiceException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("resourceGroupName", resourceGroupName); tracingParameters.put("webSiteName", webSiteName); tracingParameters.put("slotName", slotName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "getAsync", 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.Web"; url = url + "/"; url = url + "sites"; url = url + "/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); if (slotName != null) { url = url + "/slots/" + URLEncoder.encode(slotName, "UTF-8"); } ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-06-01"); if (parameters != null && parameters.getPropertiesToInclude() != null && parameters.getPropertiesToInclude().size() > 0) { queryParameters.add("propertiesToInclude=" + URLEncoder .encode(CollectionStringBuilder.join(parameters.getPropertiesToInclude(), ","), "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 // 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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSiteGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { WebSite webSiteInstance = new WebSite(); result.setWebSite(webSiteInstance); JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { WebSiteProperties propertiesInstance = new WebSiteProperties(); webSiteInstance.setProperties(propertiesInstance); JsonNode adminEnabledValue = propertiesValue.get("adminEnabled"); if (adminEnabledValue != null && adminEnabledValue instanceof NullNode == false) { boolean adminEnabledInstance; adminEnabledInstance = adminEnabledValue.getBooleanValue(); propertiesInstance.setAdminEnabled(adminEnabledInstance); } JsonNode availabilityStateValue = propertiesValue.get("availabilityState"); if (availabilityStateValue != null && availabilityStateValue instanceof NullNode == false) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = Enum.valueOf(WebSpaceAvailabilityState.class, availabilityStateValue.getTextValue()); propertiesInstance.setAvailabilityState(availabilityStateInstance); } JsonNode enabledValue = propertiesValue.get("enabled"); if (enabledValue != null && enabledValue instanceof NullNode == false) { boolean enabledInstance; enabledInstance = enabledValue.getBooleanValue(); propertiesInstance.setEnabled(enabledInstance); } JsonNode enabledHostNamesArray = propertiesValue.get("enabledHostNames"); if (enabledHostNamesArray != null && enabledHostNamesArray instanceof NullNode == false) { for (JsonNode enabledHostNamesValue : ((ArrayNode) enabledHostNamesArray)) { propertiesInstance.getEnabledHostNames().add(enabledHostNamesValue.getTextValue()); } } JsonNode hostNameSslStatesArray = propertiesValue.get("hostNameSslStates"); if (hostNameSslStatesArray != null && hostNameSslStatesArray instanceof NullNode == false) { for (JsonNode hostNameSslStatesValue : ((ArrayNode) hostNameSslStatesArray)) { WebSiteProperties.WebSiteHostNameSslState webSiteHostNameSslStateInstance = new WebSiteProperties.WebSiteHostNameSslState(); propertiesInstance.getHostNameSslStates().add(webSiteHostNameSslStateInstance); JsonNode nameValue = hostNameSslStatesValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); webSiteHostNameSslStateInstance.setName(nameInstance); } JsonNode sslStateValue = hostNameSslStatesValue.get("sslState"); if (sslStateValue != null && sslStateValue instanceof NullNode == false) { WebSiteSslState sslStateInstance; sslStateInstance = Enum.valueOf(WebSiteSslState.class, sslStateValue.getTextValue()); webSiteHostNameSslStateInstance.setSslState(sslStateInstance); } JsonNode thumbprintValue = hostNameSslStatesValue.get("thumbprint"); if (thumbprintValue != null && thumbprintValue instanceof NullNode == false) { String thumbprintInstance; thumbprintInstance = thumbprintValue.getTextValue(); webSiteHostNameSslStateInstance.setThumbprint(thumbprintInstance); } JsonNode virtualIPValue = hostNameSslStatesValue.get("virtualIP"); if (virtualIPValue != null && virtualIPValue instanceof NullNode == false) { InetAddress virtualIPInstance; virtualIPInstance = InetAddress.getByName(virtualIPValue.getTextValue()); webSiteHostNameSslStateInstance.setVirtualIP(virtualIPInstance); } JsonNode ipBasedSslResultValue = hostNameSslStatesValue.get("ipBasedSslResult"); if (ipBasedSslResultValue != null && ipBasedSslResultValue instanceof NullNode == false) { String ipBasedSslResultInstance; ipBasedSslResultInstance = ipBasedSslResultValue.getTextValue(); webSiteHostNameSslStateInstance.setIpBasedSslResult(ipBasedSslResultInstance); } JsonNode toUpdateValue = hostNameSslStatesValue.get("toUpdate"); if (toUpdateValue != null && toUpdateValue instanceof NullNode == false) { boolean toUpdateInstance; toUpdateInstance = toUpdateValue.getBooleanValue(); webSiteHostNameSslStateInstance.setToUpdate(toUpdateInstance); } JsonNode toUpdateIpBasedSslValue = hostNameSslStatesValue.get("toUpdateIpBasedSsl"); if (toUpdateIpBasedSslValue != null && toUpdateIpBasedSslValue instanceof NullNode == false) { boolean toUpdateIpBasedSslInstance; toUpdateIpBasedSslInstance = toUpdateIpBasedSslValue.getBooleanValue(); webSiteHostNameSslStateInstance .setToUpdateIpBasedSsl(toUpdateIpBasedSslInstance); } JsonNode hostTypeValue = hostNameSslStatesValue.get("hostType"); if (hostTypeValue != null && hostTypeValue instanceof NullNode == false) { HostType hostTypeInstance; hostTypeInstance = Enum.valueOf(HostType.class, hostTypeValue.getTextValue()); webSiteHostNameSslStateInstance.setHostType(hostTypeInstance); } } } JsonNode hostNamesArray = propertiesValue.get("hostNames"); if (hostNamesArray != null && hostNamesArray instanceof NullNode == false) { for (JsonNode hostNamesValue : ((ArrayNode) hostNamesArray)) { propertiesInstance.getHostNames().add(hostNamesValue.getTextValue()); } } JsonNode lastModifiedTimeUtcValue = propertiesValue.get("lastModifiedTimeUtc"); if (lastModifiedTimeUtcValue != null && lastModifiedTimeUtcValue instanceof NullNode == false) { Calendar lastModifiedTimeUtcInstance; lastModifiedTimeUtcInstance = DatatypeConverter .parseDateTime(lastModifiedTimeUtcValue.getTextValue()); propertiesInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance); } JsonNode repositorySiteNameValue = propertiesValue.get("repositorySiteName"); if (repositorySiteNameValue != null && repositorySiteNameValue instanceof NullNode == false) { String repositorySiteNameInstance; repositorySiteNameInstance = repositorySiteNameValue.getTextValue(); propertiesInstance.setRepositorySiteName(repositorySiteNameInstance); } JsonNode runtimeAvailabilityStateValue = propertiesValue.get("runtimeAvailabilityState"); if (runtimeAvailabilityStateValue != null && runtimeAvailabilityStateValue instanceof NullNode == false) { WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance; runtimeAvailabilityStateInstance = Enum.valueOf(WebSiteRuntimeAvailabilityState.class, runtimeAvailabilityStateValue.getTextValue()); propertiesInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance); } JsonNode trafficManagerHostNamesArray = propertiesValue.get("trafficManagerHostNames"); if (trafficManagerHostNamesArray != null && trafficManagerHostNamesArray instanceof NullNode == false) { for (JsonNode trafficManagerHostNamesValue : ((ArrayNode) trafficManagerHostNamesArray)) { propertiesInstance.getTrafficManagerHostNames() .add(trafficManagerHostNamesValue.getTextValue()); } } JsonNode selfLinkValue = propertiesValue.get("selfLink"); if (selfLinkValue != null && selfLinkValue instanceof NullNode == false) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkValue.getTextValue()); propertiesInstance.setUri(selfLinkInstance); } JsonNode serverFarmValue = propertiesValue.get("serverFarm"); if (serverFarmValue != null && serverFarmValue instanceof NullNode == false) { String serverFarmInstance; serverFarmInstance = serverFarmValue.getTextValue(); propertiesInstance.setServerFarm(serverFarmInstance); } JsonNode serverFarmIdValue = propertiesValue.get("serverFarmId"); if (serverFarmIdValue != null && serverFarmIdValue instanceof NullNode == false) { String serverFarmIdInstance; serverFarmIdInstance = serverFarmIdValue.getTextValue(); propertiesInstance.setServerFarmId(serverFarmIdInstance); } JsonNode skuValue = propertiesValue.get("sku"); if (skuValue != null && skuValue instanceof NullNode == false) { SkuOptions skuInstance; skuInstance = Enum.valueOf(SkuOptions.class, skuValue.getTextValue()); propertiesInstance.setSku(skuInstance); } JsonNode sitePropertiesValue = propertiesValue.get("siteProperties"); if (sitePropertiesValue != null && sitePropertiesValue instanceof NullNode == false) { WebSiteProperties.SiteProperties sitePropertiesInstance = new WebSiteProperties.SiteProperties(); propertiesInstance.setProperties(sitePropertiesInstance); JsonNode appSettingsSequenceElement = ((JsonNode) sitePropertiesValue .get("appSettings")); if (appSettingsSequenceElement != null && appSettingsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = appSettingsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String appSettingsKey = property.getKey(); String appSettingsValue = property.getValue().getTextValue(); sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } JsonNode metadataSequenceElement = ((JsonNode) sitePropertiesValue.get("metadata")); if (metadataSequenceElement != null && metadataSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr2 = metadataSequenceElement.getFields(); while (itr2.hasNext()) { Map.Entry<String, JsonNode> property2 = itr2.next(); String metadataKey = property2.getKey(); String metadataValue = property2.getValue().getTextValue(); sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue); } } JsonNode propertiesSequenceElement = ((JsonNode) sitePropertiesValue.get("properties")); if (propertiesSequenceElement != null && propertiesSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr3 = propertiesSequenceElement.getFields(); while (itr3.hasNext()) { Map.Entry<String, JsonNode> property3 = itr3.next(); String propertiesKey = property3.getKey(); String propertiesValue2 = property3.getValue().getTextValue(); sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue2); } } } JsonNode siteConfigValue = propertiesValue.get("siteConfig"); if (siteConfigValue != null && siteConfigValue instanceof NullNode == false) { WebSiteConfiguration siteConfigInstance = new WebSiteConfiguration(); propertiesInstance.setSiteConfig(siteConfigInstance); JsonNode appSettingsSequenceElement2 = ((JsonNode) siteConfigValue.get("appSettings")); if (appSettingsSequenceElement2 != null && appSettingsSequenceElement2 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr4 = appSettingsSequenceElement2 .getFields(); while (itr4.hasNext()) { Map.Entry<String, JsonNode> property4 = itr4.next(); String appSettingsKey2 = property4.getKey(); String appSettingsValue2 = property4.getValue().getTextValue(); siteConfigInstance.getAppSettings().put(appSettingsKey2, appSettingsValue2); } } JsonNode connectionStringsArray = siteConfigValue.get("connectionStrings"); if (connectionStringsArray != null && connectionStringsArray instanceof NullNode == false) { for (JsonNode connectionStringsValue : ((ArrayNode) connectionStringsArray)) { ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo(); siteConfigInstance.getConnectionStrings().add(connStringInfoInstance); JsonNode connectionStringValue = connectionStringsValue.get("connectionString"); if (connectionStringValue != null && connectionStringValue instanceof NullNode == false) { String connectionStringInstance; connectionStringInstance = connectionStringValue.getTextValue(); connStringInfoInstance.setConnectionString(connectionStringInstance); } JsonNode nameValue2 = connectionStringsValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); connStringInfoInstance.setName(nameInstance2); } JsonNode typeValue = connectionStringsValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { DatabaseServerType typeInstance; typeInstance = Enum.valueOf(DatabaseServerType.class, typeValue.getTextValue()); connStringInfoInstance.setType(typeInstance); } } } JsonNode defaultDocumentsArray = siteConfigValue.get("defaultDocuments"); if (defaultDocumentsArray != null && defaultDocumentsArray instanceof NullNode == false) { for (JsonNode defaultDocumentsValue : ((ArrayNode) defaultDocumentsArray)) { siteConfigInstance.getDefaultDocuments() .add(defaultDocumentsValue.getTextValue()); } } JsonNode detailedErrorLoggingEnabledValue = siteConfigValue .get("detailedErrorLoggingEnabled"); if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue instanceof NullNode == false) { boolean detailedErrorLoggingEnabledInstance; detailedErrorLoggingEnabledInstance = detailedErrorLoggingEnabledValue .getBooleanValue(); siteConfigInstance .setDetailedErrorLoggingEnabled(detailedErrorLoggingEnabledInstance); } JsonNode documentRootValue = siteConfigValue.get("documentRoot"); if (documentRootValue != null && documentRootValue instanceof NullNode == false) { String documentRootInstance; documentRootInstance = documentRootValue.getTextValue(); siteConfigInstance.setDocumentRoot(documentRootInstance); } JsonNode handlerMappingsArray = siteConfigValue.get("handlerMappings"); if (handlerMappingsArray != null && handlerMappingsArray instanceof NullNode == false) { for (JsonNode handlerMappingsValue : ((ArrayNode) handlerMappingsArray)) { WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping(); siteConfigInstance.getHandlerMappings().add(handlerMappingInstance); JsonNode argumentsValue = handlerMappingsValue.get("arguments"); if (argumentsValue != null && argumentsValue instanceof NullNode == false) { String argumentsInstance; argumentsInstance = argumentsValue.getTextValue(); handlerMappingInstance.setArguments(argumentsInstance); } JsonNode extensionValue = handlerMappingsValue.get("extension"); if (extensionValue != null && extensionValue instanceof NullNode == false) { String extensionInstance; extensionInstance = extensionValue.getTextValue(); handlerMappingInstance.setExtension(extensionInstance); } JsonNode scriptProcessorValue = handlerMappingsValue.get("scriptProcessor"); if (scriptProcessorValue != null && scriptProcessorValue instanceof NullNode == false) { String scriptProcessorInstance; scriptProcessorInstance = scriptProcessorValue.getTextValue(); handlerMappingInstance.setScriptProcessor(scriptProcessorInstance); } } } JsonNode httpLoggingEnabledValue = siteConfigValue.get("httpLoggingEnabled"); if (httpLoggingEnabledValue != null && httpLoggingEnabledValue instanceof NullNode == false) { boolean httpLoggingEnabledInstance; httpLoggingEnabledInstance = httpLoggingEnabledValue.getBooleanValue(); siteConfigInstance.setHttpLoggingEnabled(httpLoggingEnabledInstance); } JsonNode logsDirectorySizeLimitValue = siteConfigValue.get("logsDirectorySizeLimit"); if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue instanceof NullNode == false) { int logsDirectorySizeLimitInstance; logsDirectorySizeLimitInstance = logsDirectorySizeLimitValue.getIntValue(); siteConfigInstance.setLogsDirectorySizeLimit(logsDirectorySizeLimitInstance); } JsonNode managedPipelineModeValue = siteConfigValue.get("managedPipelineMode"); if (managedPipelineModeValue != null && managedPipelineModeValue instanceof NullNode == false) { ManagedPipelineMode managedPipelineModeInstance; managedPipelineModeInstance = Enum.valueOf(ManagedPipelineMode.class, managedPipelineModeValue.getTextValue()); siteConfigInstance.setManagedPipelineMode(managedPipelineModeInstance); } JsonNode metadataSequenceElement2 = ((JsonNode) siteConfigValue.get("metadata")); if (metadataSequenceElement2 != null && metadataSequenceElement2 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr5 = metadataSequenceElement2.getFields(); while (itr5.hasNext()) { Map.Entry<String, JsonNode> property5 = itr5.next(); String metadataKey2 = property5.getKey(); String metadataValue2 = property5.getValue().getTextValue(); siteConfigInstance.getMetadata().put(metadataKey2, metadataValue2); } } JsonNode netFrameworkVersionValue = siteConfigValue.get("netFrameworkVersion"); if (netFrameworkVersionValue != null && netFrameworkVersionValue instanceof NullNode == false) { String netFrameworkVersionInstance; netFrameworkVersionInstance = netFrameworkVersionValue.getTextValue(); siteConfigInstance.setNetFrameworkVersion(netFrameworkVersionInstance); } JsonNode numberOfWorkersValue = siteConfigValue.get("numberOfWorkers"); if (numberOfWorkersValue != null && numberOfWorkersValue instanceof NullNode == false) { int numberOfWorkersInstance; numberOfWorkersInstance = numberOfWorkersValue.getIntValue(); siteConfigInstance.setNumberOfWorkers(numberOfWorkersInstance); } JsonNode phpVersionValue = siteConfigValue.get("phpVersion"); if (phpVersionValue != null && phpVersionValue instanceof NullNode == false) { String phpVersionInstance; phpVersionInstance = phpVersionValue.getTextValue(); siteConfigInstance.setPhpVersion(phpVersionInstance); } JsonNode pythonVersionValue = siteConfigValue.get("pythonVersion"); if (pythonVersionValue != null && pythonVersionValue instanceof NullNode == false) { String pythonVersionInstance; pythonVersionInstance = pythonVersionValue.getTextValue(); siteConfigInstance.setPythonVersion(pythonVersionInstance); } JsonNode publishingPasswordValue = siteConfigValue.get("publishingPassword"); if (publishingPasswordValue != null && publishingPasswordValue instanceof NullNode == false) { String publishingPasswordInstance; publishingPasswordInstance = publishingPasswordValue.getTextValue(); siteConfigInstance.setPublishingPassword(publishingPasswordInstance); } JsonNode publishingUsernameValue = siteConfigValue.get("publishingUsername"); if (publishingUsernameValue != null && publishingUsernameValue instanceof NullNode == false) { String publishingUsernameInstance; publishingUsernameInstance = publishingUsernameValue.getTextValue(); siteConfigInstance.setPublishingUserName(publishingUsernameInstance); } JsonNode remoteDebuggingEnabledValue = siteConfigValue.get("RemoteDebuggingEnabled"); if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue instanceof NullNode == false) { boolean remoteDebuggingEnabledInstance; remoteDebuggingEnabledInstance = remoteDebuggingEnabledValue.getBooleanValue(); siteConfigInstance.setRemoteDebuggingEnabled(remoteDebuggingEnabledInstance); } JsonNode remoteDebuggingVersionValue = siteConfigValue.get("remoteDebuggingVersion"); if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue instanceof NullNode == false) { RemoteDebuggingVersion remoteDebuggingVersionInstance; remoteDebuggingVersionInstance = Enum.valueOf(RemoteDebuggingVersion.class, remoteDebuggingVersionValue.getTextValue()); siteConfigInstance.setRemoteDebuggingVersion(remoteDebuggingVersionInstance); } JsonNode requestTracingEnabledValue = siteConfigValue.get("requestTracingEnabled"); if (requestTracingEnabledValue != null && requestTracingEnabledValue instanceof NullNode == false) { boolean requestTracingEnabledInstance; requestTracingEnabledInstance = requestTracingEnabledValue.getBooleanValue(); siteConfigInstance.setRequestTracingEnabled(requestTracingEnabledInstance); } JsonNode requestTracingExpirationTimeValue = siteConfigValue .get("requestTracingExpirationTime"); if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue instanceof NullNode == false) { Calendar requestTracingExpirationTimeInstance; requestTracingExpirationTimeInstance = DatatypeConverter .parseDateTime(requestTracingExpirationTimeValue.getTextValue()); siteConfigInstance .setRequestTracingExpirationTime(requestTracingExpirationTimeInstance); } JsonNode scmTypeValue = siteConfigValue.get("scmType"); if (scmTypeValue != null && scmTypeValue instanceof NullNode == false) { String scmTypeInstance; scmTypeInstance = scmTypeValue.getTextValue(); siteConfigInstance.setScmType(scmTypeInstance); } JsonNode autoSwapSlotNameValue = siteConfigValue.get("autoSwapSlotName"); if (autoSwapSlotNameValue != null && autoSwapSlotNameValue instanceof NullNode == false) { String autoSwapSlotNameInstance; autoSwapSlotNameInstance = autoSwapSlotNameValue.getTextValue(); siteConfigInstance.setAutoSwapSlotName(autoSwapSlotNameInstance); } JsonNode use32BitWorkerProcessValue = siteConfigValue.get("use32BitWorkerProcess"); if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue instanceof NullNode == false) { boolean use32BitWorkerProcessInstance; use32BitWorkerProcessInstance = use32BitWorkerProcessValue.getBooleanValue(); siteConfigInstance.setUse32BitWorkerProcess(use32BitWorkerProcessInstance); } JsonNode webSocketsEnabledValue = siteConfigValue.get("webSocketsEnabled"); if (webSocketsEnabledValue != null && webSocketsEnabledValue instanceof NullNode == false) { boolean webSocketsEnabledInstance; webSocketsEnabledInstance = webSocketsEnabledValue.getBooleanValue(); siteConfigInstance.setWebSocketsEnabled(webSocketsEnabledInstance); } JsonNode limitsValue = siteConfigValue.get("limits"); if (limitsValue != null && limitsValue instanceof NullNode == false) { SiteLimits limitsInstance = new SiteLimits(); siteConfigInstance.setLimits(limitsInstance); JsonNode maxPercentageCpuValue = limitsValue.get("maxPercentageCpu"); if (maxPercentageCpuValue != null && maxPercentageCpuValue instanceof NullNode == false) { double maxPercentageCpuInstance; maxPercentageCpuInstance = maxPercentageCpuValue.getDoubleValue(); limitsInstance.setMaxPercentageCpu(maxPercentageCpuInstance); } JsonNode maxMemoryInMbValue = limitsValue.get("maxMemoryInMb"); if (maxMemoryInMbValue != null && maxMemoryInMbValue instanceof NullNode == false) { long maxMemoryInMbInstance; maxMemoryInMbInstance = maxMemoryInMbValue.getLongValue(); limitsInstance.setMaxMemoryInMb(maxMemoryInMbInstance); } JsonNode maxDiskSizeInMbValue = limitsValue.get("maxDiskSizeInMb"); if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue instanceof NullNode == false) { long maxDiskSizeInMbInstance; maxDiskSizeInMbInstance = maxDiskSizeInMbValue.getLongValue(); limitsInstance.setMaxDiskSizeInMb(maxDiskSizeInMbInstance); } } } JsonNode stateValue = propertiesValue.get("state"); if (stateValue != null && stateValue instanceof NullNode == false) { WebSiteState stateInstance; stateInstance = Enum.valueOf(WebSiteState.class, stateValue.getTextValue()); propertiesInstance.setState(stateInstance); } JsonNode usageStateValue = propertiesValue.get("usageState"); if (usageStateValue != null && usageStateValue instanceof NullNode == false) { WebSiteUsageState usageStateInstance; usageStateInstance = Enum.valueOf(WebSiteUsageState.class, usageStateValue.getTextValue()); propertiesInstance.setUsageState(usageStateInstance); } JsonNode webSpaceValue = propertiesValue.get("webSpace"); if (webSpaceValue != null && webSpaceValue instanceof NullNode == false) { String webSpaceInstance; webSpaceInstance = webSpaceValue.getTextValue(); propertiesInstance.setWebSpace(webSpaceInstance); } JsonNode provisioningStateValue = propertiesValue.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); propertiesInstance.setProvisioningState(provisioningStateInstance); } } JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); webSiteInstance.setId(idInstance); } JsonNode nameValue3 = responseDoc.get("name"); if (nameValue3 != null && nameValue3 instanceof NullNode == false) { String nameInstance3; nameInstance3 = nameValue3.getTextValue(); webSiteInstance.setName(nameInstance3); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); webSiteInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr6 = tagsSequenceElement.getFields(); while (itr6.hasNext()) { Map.Entry<String, JsonNode> property6 = itr6.next(); String tagsKey = property6.getKey(); String tagsValue = property6.getValue().getTextValue(); webSiteInstance.getTags().put(tagsKey, tagsValue); } } JsonNode typeValue2 = responseDoc.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); webSiteInstance.setType(typeInstance2); } } } 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.notificationhubs.NotificationHubOperationsImpl.java
/** * Lists the notification hubs associated with a namespace. * * @param resourceGroupName Required. The name of the resource group. * @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./*from w ww . j ava 2 s. c o m*/ * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The response of the List NotificationHub operation. */ @Override public NotificationHubListResponse list(String resourceGroupName, String namespaceName) throws IOException, ServiceException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } 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("resourceGroupName", resourceGroupName); tracingParameters.put("namespaceName", namespaceName); CloudTracing.enter(invocationId, this, "listAsync", 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.NotificationHubs"; url = url + "/namespaces/"; url = url + URLEncoder.encode(namespaceName, "UTF-8"); url = url + "/notificationHubs"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-09-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 // 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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result NotificationHubListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new NotificationHubListResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { JsonNode valueArray = responseDoc.get("value"); if (valueArray != null && valueArray instanceof NullNode == false) { for (JsonNode valueValue : ((ArrayNode) valueArray)) { NotificationHubResource notificationHubResourceInstance = new NotificationHubResource(); result.getValue().add(notificationHubResourceInstance); JsonNode idValue = valueValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); notificationHubResourceInstance.setId(idInstance); } JsonNode locationValue = valueValue.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); notificationHubResourceInstance.setLocation(locationInstance); } JsonNode nameValue = valueValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); notificationHubResourceInstance.setName(nameInstance); } JsonNode typeValue = valueValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); notificationHubResourceInstance.setType(typeInstance); } JsonNode tagsSequenceElement = ((JsonNode) valueValue.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); notificationHubResourceInstance.getTags().put(tagsKey, tagsValue); } } JsonNode propertiesValue = valueValue.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { NotificationHubProperties propertiesInstance = new NotificationHubProperties(); notificationHubResourceInstance.setProperties(propertiesInstance); JsonNode nameValue2 = propertiesValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); propertiesInstance.setName(nameInstance2); } JsonNode registrationTtlValue = propertiesValue.get("registrationTtl"); if (registrationTtlValue != null && registrationTtlValue instanceof NullNode == false) { String registrationTtlInstance; registrationTtlInstance = registrationTtlValue.getTextValue(); propertiesInstance.setRegistrationTtl(registrationTtlInstance); } JsonNode authorizationRulesArray = propertiesValue.get("authorizationRules"); if (authorizationRulesArray != null && authorizationRulesArray instanceof NullNode == false) { for (JsonNode authorizationRulesValue : ((ArrayNode) authorizationRulesArray)) { SharedAccessAuthorizationRuleProperties sharedAccessAuthorizationRulePropertiesInstance = new SharedAccessAuthorizationRuleProperties(); propertiesInstance.getAuthorizationRules() .add(sharedAccessAuthorizationRulePropertiesInstance); JsonNode primaryKeyValue = authorizationRulesValue.get("primaryKey"); if (primaryKeyValue != null && primaryKeyValue instanceof NullNode == false) { String primaryKeyInstance; primaryKeyInstance = primaryKeyValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance .setPrimaryKey(primaryKeyInstance); } JsonNode secondaryKeyValue = authorizationRulesValue.get("secondaryKey"); if (secondaryKeyValue != null && secondaryKeyValue instanceof NullNode == false) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance .setSecondaryKey(secondaryKeyInstance); } JsonNode keyNameValue = authorizationRulesValue.get("keyName"); if (keyNameValue != null && keyNameValue instanceof NullNode == false) { String keyNameInstance; keyNameInstance = keyNameValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance .setKeyName(keyNameInstance); } JsonNode claimTypeValue = authorizationRulesValue.get("claimType"); if (claimTypeValue != null && claimTypeValue instanceof NullNode == false) { String claimTypeInstance; claimTypeInstance = claimTypeValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance .setClaimType(claimTypeInstance); } JsonNode claimValueValue = authorizationRulesValue.get("claimValue"); if (claimValueValue != null && claimValueValue instanceof NullNode == false) { String claimValueInstance; claimValueInstance = claimValueValue.getTextValue(); sharedAccessAuthorizationRulePropertiesInstance .setClaimValue(claimValueInstance); } JsonNode rightsArray = authorizationRulesValue.get("rights"); if (rightsArray != null && rightsArray instanceof NullNode == false) { for (JsonNode rightsValue : ((ArrayNode) rightsArray)) { sharedAccessAuthorizationRulePropertiesInstance.getRights().add(Enum .valueOf(AccessRights.class, rightsValue.getTextValue())); } } JsonNode createdTimeValue = authorizationRulesValue.get("createdTime"); if (createdTimeValue != null && createdTimeValue instanceof NullNode == false) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter .parseDateTime(createdTimeValue.getTextValue()); sharedAccessAuthorizationRulePropertiesInstance .setCreatedTime(createdTimeInstance); } JsonNode modifiedTimeValue = authorizationRulesValue.get("modifiedTime"); if (modifiedTimeValue != null && modifiedTimeValue instanceof NullNode == false) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeValue.getTextValue()); sharedAccessAuthorizationRulePropertiesInstance .setModifiedTime(modifiedTimeInstance); } JsonNode revisionValue = authorizationRulesValue.get("revision"); if (revisionValue != null && revisionValue instanceof NullNode == false) { int revisionInstance; revisionInstance = revisionValue.getIntValue(); sharedAccessAuthorizationRulePropertiesInstance .setRevision(revisionInstance); } } } JsonNode apnsCredentialValue = propertiesValue.get("apnsCredential"); if (apnsCredentialValue != null && apnsCredentialValue instanceof NullNode == false) { ApnsCredential apnsCredentialInstance = new ApnsCredential(); propertiesInstance.setApnsCredential(apnsCredentialInstance); JsonNode propertiesValue2 = apnsCredentialValue.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { ApnsCredentialProperties propertiesInstance2 = new ApnsCredentialProperties(); apnsCredentialInstance.setProperties(propertiesInstance2); JsonNode apnsCertificateValue = propertiesValue2.get("apnsCertificate"); if (apnsCertificateValue != null && apnsCertificateValue instanceof NullNode == false) { String apnsCertificateInstance; apnsCertificateInstance = apnsCertificateValue.getTextValue(); propertiesInstance2.setApnsCertificate(apnsCertificateInstance); } JsonNode certificateKeyValue = propertiesValue2.get("certificateKey"); if (certificateKeyValue != null && certificateKeyValue instanceof NullNode == false) { String certificateKeyInstance; certificateKeyInstance = certificateKeyValue.getTextValue(); propertiesInstance2.setCertificateKey(certificateKeyInstance); } JsonNode endpointValue = propertiesValue2.get("endpoint"); if (endpointValue != null && endpointValue instanceof NullNode == false) { String endpointInstance; endpointInstance = endpointValue.getTextValue(); propertiesInstance2.setEndpoint(endpointInstance); } JsonNode thumbprintValue = propertiesValue2.get("thumbprint"); if (thumbprintValue != null && thumbprintValue instanceof NullNode == false) { String thumbprintInstance; thumbprintInstance = thumbprintValue.getTextValue(); propertiesInstance2.setThumbprint(thumbprintInstance); } } } JsonNode wnsCredentialValue = propertiesValue.get("wnsCredential"); if (wnsCredentialValue != null && wnsCredentialValue instanceof NullNode == false) { WnsCredential wnsCredentialInstance = new WnsCredential(); propertiesInstance.setWnsCredential(wnsCredentialInstance); JsonNode propertiesValue3 = wnsCredentialValue.get("properties"); if (propertiesValue3 != null && propertiesValue3 instanceof NullNode == false) { WnsCredentialProperties propertiesInstance3 = new WnsCredentialProperties(); wnsCredentialInstance.setProperties(propertiesInstance3); JsonNode packageSidValue = propertiesValue3.get("packageSid"); if (packageSidValue != null && packageSidValue instanceof NullNode == false) { String packageSidInstance; packageSidInstance = packageSidValue.getTextValue(); propertiesInstance3.setPackageSid(packageSidInstance); } JsonNode secretKeyValue = propertiesValue3.get("secretKey"); if (secretKeyValue != null && secretKeyValue instanceof NullNode == false) { String secretKeyInstance; secretKeyInstance = secretKeyValue.getTextValue(); propertiesInstance3.setSecretKey(secretKeyInstance); } JsonNode windowsLiveEndpointValue = propertiesValue3 .get("windowsLiveEndpoint"); if (windowsLiveEndpointValue != null && windowsLiveEndpointValue instanceof NullNode == false) { String windowsLiveEndpointInstance; windowsLiveEndpointInstance = windowsLiveEndpointValue.getTextValue(); propertiesInstance3.setWindowsLiveEndpoint(windowsLiveEndpointInstance); } } } JsonNode gcmCredentialValue = propertiesValue.get("gcmCredential"); if (gcmCredentialValue != null && gcmCredentialValue instanceof NullNode == false) { GcmCredential gcmCredentialInstance = new GcmCredential(); propertiesInstance.setGcmCredential(gcmCredentialInstance); JsonNode propertiesValue4 = gcmCredentialValue.get("properties"); if (propertiesValue4 != null && propertiesValue4 instanceof NullNode == false) { GcmCredentialProperties propertiesInstance4 = new GcmCredentialProperties(); gcmCredentialInstance.setProperties(propertiesInstance4); JsonNode gcmEndpointValue = propertiesValue4.get("gcmEndpoint"); if (gcmEndpointValue != null && gcmEndpointValue instanceof NullNode == false) { String gcmEndpointInstance; gcmEndpointInstance = gcmEndpointValue.getTextValue(); propertiesInstance4.setGcmEndpoint(gcmEndpointInstance); } JsonNode googleApiKeyValue = propertiesValue4.get("googleApiKey"); if (googleApiKeyValue != null && googleApiKeyValue instanceof NullNode == false) { String googleApiKeyInstance; googleApiKeyInstance = googleApiKeyValue.getTextValue(); propertiesInstance4.setGoogleApiKey(googleApiKeyInstance); } } } JsonNode mpnsCredentialValue = propertiesValue.get("mpnsCredential"); if (mpnsCredentialValue != null && mpnsCredentialValue instanceof NullNode == false) { MpnsCredential mpnsCredentialInstance = new MpnsCredential(); propertiesInstance.setMpnsCredential(mpnsCredentialInstance); JsonNode propertiesValue5 = mpnsCredentialValue.get("properties"); if (propertiesValue5 != null && propertiesValue5 instanceof NullNode == false) { MpnsCredentialProperties propertiesInstance5 = new MpnsCredentialProperties(); mpnsCredentialInstance.setProperties(propertiesInstance5); JsonNode mpnsCertificateValue = propertiesValue5.get("mpnsCertificate"); if (mpnsCertificateValue != null && mpnsCertificateValue instanceof NullNode == false) { String mpnsCertificateInstance; mpnsCertificateInstance = mpnsCertificateValue.getTextValue(); propertiesInstance5.setMpnsCertificate(mpnsCertificateInstance); } JsonNode certificateKeyValue2 = propertiesValue5.get("certificateKey"); if (certificateKeyValue2 != null && certificateKeyValue2 instanceof NullNode == false) { String certificateKeyInstance2; certificateKeyInstance2 = certificateKeyValue2.getTextValue(); propertiesInstance5.setCertificateKey(certificateKeyInstance2); } JsonNode thumbprintValue2 = propertiesValue5.get("thumbprint"); if (thumbprintValue2 != null && thumbprintValue2 instanceof NullNode == false) { String thumbprintInstance2; thumbprintInstance2 = thumbprintValue2.getTextValue(); propertiesInstance5.setThumbprint(thumbprintInstance2); } } } JsonNode admCredentialValue = propertiesValue.get("admCredential"); if (admCredentialValue != null && admCredentialValue instanceof NullNode == false) { AdmCredential admCredentialInstance = new AdmCredential(); propertiesInstance.setAdmCredential(admCredentialInstance); JsonNode propertiesValue6 = admCredentialValue.get("properties"); if (propertiesValue6 != null && propertiesValue6 instanceof NullNode == false) { AdmCredentialProperties propertiesInstance6 = new AdmCredentialProperties(); admCredentialInstance.setProperties(propertiesInstance6); JsonNode clientIdValue = propertiesValue6.get("clientId"); if (clientIdValue != null && clientIdValue instanceof NullNode == false) { String clientIdInstance; clientIdInstance = clientIdValue.getTextValue(); propertiesInstance6.setClientId(clientIdInstance); } JsonNode clientSecretValue = propertiesValue6.get("clientSecret"); if (clientSecretValue != null && clientSecretValue instanceof NullNode == false) { String clientSecretInstance; clientSecretInstance = clientSecretValue.getTextValue(); propertiesInstance6.setClientSecret(clientSecretInstance); } JsonNode authTokenUrlValue = propertiesValue6.get("authTokenUrl"); if (authTokenUrlValue != null && authTokenUrlValue instanceof NullNode == false) { String authTokenUrlInstance; authTokenUrlInstance = authTokenUrlValue.getTextValue(); propertiesInstance6.setAuthTokenUrl(authTokenUrlInstance); } } } JsonNode baiduCredentialValue = propertiesValue.get("baiduCredential"); if (baiduCredentialValue != null && baiduCredentialValue instanceof NullNode == false) { BaiduCredential baiduCredentialInstance = new BaiduCredential(); propertiesInstance.setBaiduCredential(baiduCredentialInstance); JsonNode propertiesValue7 = baiduCredentialValue.get("properties"); if (propertiesValue7 != null && propertiesValue7 instanceof NullNode == false) { BaiduCredentialProperties propertiesInstance7 = new BaiduCredentialProperties(); baiduCredentialInstance.setProperties(propertiesInstance7); JsonNode baiduApiKeyValue = propertiesValue7.get("baiduApiKey"); if (baiduApiKeyValue != null && baiduApiKeyValue instanceof NullNode == false) { String baiduApiKeyInstance; baiduApiKeyInstance = baiduApiKeyValue.getTextValue(); propertiesInstance7.setBaiduApiKey(baiduApiKeyInstance); } JsonNode baiduEndPointValue = propertiesValue7.get("baiduEndPoint"); if (baiduEndPointValue != null && baiduEndPointValue instanceof NullNode == false) { String baiduEndPointInstance; baiduEndPointInstance = baiduEndPointValue.getTextValue(); propertiesInstance7.setBaiduEndPoint(baiduEndPointInstance); } JsonNode baiduSecretKeyValue = propertiesValue7.get("baiduSecretKey"); if (baiduSecretKeyValue != null && baiduSecretKeyValue instanceof NullNode == false) { String baiduSecretKeyInstance; baiduSecretKeyInstance = baiduSecretKeyValue.getTextValue(); propertiesInstance7.setBaiduSecretKey(baiduSecretKeyInstance); } } } } } } JsonNode nextLinkValue = responseDoc.get("nextLink"); if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) { String nextLinkInstance; nextLinkInstance = nextLinkValue.getTextValue(); result.setNextLink(nextLinkInstance); } } } 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.notificationhubs.NotificationHubOperationsImpl.java
/** * The get authorization rules operation gets the authorization rules for a * NotificationHub.//from ww w.j a va 2s. com * * @param resourceGroupName Required. The name of the resource group. * @param namespaceName Required. The NotificationHub to get the * authorization rule for. * @param notificationHubName Required. The notification hub 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. * @return The response of the List Namespace operation. */ @Override public SharedAccessAuthorizationRuleListResponse listAuthorizationRules(String resourceGroupName, String namespaceName, String notificationHubName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (namespaceName == null) { throw new NullPointerException("namespaceName"); } if (notificationHubName == null) { throw new NullPointerException("notificationHubName"); } // 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("namespaceName", namespaceName); tracingParameters.put("notificationHubName", notificationHubName); CloudTracing.enter(invocationId, this, "listAuthorizationRulesAsync", 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.NotificationHubs"; url = url + "/namespaces/"; url = url + URLEncoder.encode(namespaceName, "UTF-8"); url = url + "/notificationHubs/"; url = url + URLEncoder.encode(notificationHubName, "UTF-8"); url = url + "/AuthorizationRules"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-09-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 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) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result SharedAccessAuthorizationRuleListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new SharedAccessAuthorizationRuleListResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { JsonNode valueArray = responseDoc.get("value"); if (valueArray != null && valueArray instanceof NullNode == false) { for (JsonNode valueValue : ((ArrayNode) valueArray)) { SharedAccessAuthorizationRuleResource sharedAccessAuthorizationRuleResourceInstance = new SharedAccessAuthorizationRuleResource(); result.getValue().add(sharedAccessAuthorizationRuleResourceInstance); JsonNode idValue = valueValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); sharedAccessAuthorizationRuleResourceInstance.setId(idInstance); } JsonNode locationValue = valueValue.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); sharedAccessAuthorizationRuleResourceInstance.setLocation(locationInstance); } JsonNode nameValue = valueValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); sharedAccessAuthorizationRuleResourceInstance.setName(nameInstance); } JsonNode typeValue = valueValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); sharedAccessAuthorizationRuleResourceInstance.setType(typeInstance); } JsonNode tagsSequenceElement = ((JsonNode) valueValue.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); sharedAccessAuthorizationRuleResourceInstance.getTags().put(tagsKey, tagsValue); } } JsonNode propertiesValue = valueValue.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { SharedAccessAuthorizationRuleProperties propertiesInstance = new SharedAccessAuthorizationRuleProperties(); sharedAccessAuthorizationRuleResourceInstance.setProperties(propertiesInstance); JsonNode primaryKeyValue = propertiesValue.get("primaryKey"); if (primaryKeyValue != null && primaryKeyValue instanceof NullNode == false) { String primaryKeyInstance; primaryKeyInstance = primaryKeyValue.getTextValue(); propertiesInstance.setPrimaryKey(primaryKeyInstance); } JsonNode secondaryKeyValue = propertiesValue.get("secondaryKey"); if (secondaryKeyValue != null && secondaryKeyValue instanceof NullNode == false) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyValue.getTextValue(); propertiesInstance.setSecondaryKey(secondaryKeyInstance); } JsonNode keyNameValue = propertiesValue.get("keyName"); if (keyNameValue != null && keyNameValue instanceof NullNode == false) { String keyNameInstance; keyNameInstance = keyNameValue.getTextValue(); propertiesInstance.setKeyName(keyNameInstance); } JsonNode claimTypeValue = propertiesValue.get("claimType"); if (claimTypeValue != null && claimTypeValue instanceof NullNode == false) { String claimTypeInstance; claimTypeInstance = claimTypeValue.getTextValue(); propertiesInstance.setClaimType(claimTypeInstance); } JsonNode claimValueValue = propertiesValue.get("claimValue"); if (claimValueValue != null && claimValueValue instanceof NullNode == false) { String claimValueInstance; claimValueInstance = claimValueValue.getTextValue(); propertiesInstance.setClaimValue(claimValueInstance); } JsonNode rightsArray = propertiesValue.get("rights"); if (rightsArray != null && rightsArray instanceof NullNode == false) { for (JsonNode rightsValue : ((ArrayNode) rightsArray)) { propertiesInstance.getRights() .add(Enum.valueOf(AccessRights.class, rightsValue.getTextValue())); } } JsonNode createdTimeValue = propertiesValue.get("createdTime"); if (createdTimeValue != null && createdTimeValue instanceof NullNode == false) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter .parseDateTime(createdTimeValue.getTextValue()); propertiesInstance.setCreatedTime(createdTimeInstance); } JsonNode modifiedTimeValue = propertiesValue.get("modifiedTime"); if (modifiedTimeValue != null && modifiedTimeValue instanceof NullNode == false) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeValue.getTextValue()); propertiesInstance.setModifiedTime(modifiedTimeInstance); } JsonNode revisionValue = propertiesValue.get("revision"); if (revisionValue != null && revisionValue instanceof NullNode == false) { int revisionInstance; revisionInstance = revisionValue.getIntValue(); propertiesInstance.setRevision(revisionInstance); } } } } JsonNode nextLinkValue = responseDoc.get("nextLink"); if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) { String nextLinkInstance; nextLinkInstance = nextLinkValue.getTextValue(); result.setNextLink(nextLinkInstance); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl.java
/** * You can retrieve the config settings for a web site by issuing an HTTP * GET request. (see//from ww w.j av a2 s . c o m * http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return The Get Configuration Web Site operation response. */ @Override public WebSiteGetConfigurationResponse getConfiguration(String webSpaceName, String webSiteName) throws IOException, ServiceException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("webSpaceName", webSpaceName); tracingParameters.put("webSiteName", webSiteName); CloudTracing.enter(invocationId, this, "getConfigurationAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); url = url + "/config"; 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/json"); httpRequest.setHeader("x-ms-version", "2014-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSiteGetConfigurationResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetConfigurationResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { JsonNode appSettingsSequenceElement = ((JsonNode) responseDoc.get("AppSettings")); if (appSettingsSequenceElement != null && appSettingsSequenceElement instanceof NullNode == false) { for (JsonNode appSettingsElement : ((ArrayNode) appSettingsSequenceElement)) { String appSettingsKey = appSettingsElement.get("Name").getTextValue(); String appSettingsValue = appSettingsElement.get("Value").getTextValue(); result.getAppSettings().put(appSettingsKey, appSettingsValue); } } JsonNode connectionStringsArray = responseDoc.get("ConnectionStrings"); if (connectionStringsArray != null && connectionStringsArray instanceof NullNode == false) { for (JsonNode connectionStringsValue : ((ArrayNode) connectionStringsArray)) { WebSiteGetConfigurationResponse.ConnectionStringInfo connectionStringInfoInstance = new WebSiteGetConfigurationResponse.ConnectionStringInfo(); result.getConnectionStrings().add(connectionStringInfoInstance); JsonNode connectionStringValue = connectionStringsValue.get("ConnectionString"); if (connectionStringValue != null && connectionStringValue instanceof NullNode == false) { String connectionStringInstance; connectionStringInstance = connectionStringValue.getTextValue(); connectionStringInfoInstance.setConnectionString(connectionStringInstance); } JsonNode nameValue = connectionStringsValue.get("Name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); connectionStringInfoInstance.setName(nameInstance); } JsonNode typeValue = connectionStringsValue.get("Type"); if (typeValue != null && typeValue instanceof NullNode == false) { ConnectionStringType typeInstance; typeInstance = ConnectionStringType.values()[typeValue.getIntValue()]; connectionStringInfoInstance.setType(typeInstance); } } } JsonNode defaultDocumentsArray = responseDoc.get("DefaultDocuments"); if (defaultDocumentsArray != null && defaultDocumentsArray instanceof NullNode == false) { for (JsonNode defaultDocumentsValue : ((ArrayNode) defaultDocumentsArray)) { result.getDefaultDocuments().add(defaultDocumentsValue.getTextValue()); } } JsonNode detailedErrorLoggingEnabledValue = responseDoc.get("DetailedErrorLoggingEnabled"); if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue instanceof NullNode == false) { boolean detailedErrorLoggingEnabledInstance; detailedErrorLoggingEnabledInstance = detailedErrorLoggingEnabledValue.getBooleanValue(); result.setDetailedErrorLoggingEnabled(detailedErrorLoggingEnabledInstance); } JsonNode documentRootValue = responseDoc.get("DocumentRoot"); if (documentRootValue != null && documentRootValue instanceof NullNode == false) { String documentRootInstance; documentRootInstance = documentRootValue.getTextValue(); result.setDocumentRoot(documentRootInstance); } JsonNode handlerMappingsArray = responseDoc.get("HandlerMappings"); if (handlerMappingsArray != null && handlerMappingsArray instanceof NullNode == false) { for (JsonNode handlerMappingsValue : ((ArrayNode) handlerMappingsArray)) { WebSiteGetConfigurationResponse.HandlerMapping handlerMappingInstance = new WebSiteGetConfigurationResponse.HandlerMapping(); result.getHandlerMappings().add(handlerMappingInstance); JsonNode argumentsValue = handlerMappingsValue.get("Arguments"); if (argumentsValue != null && argumentsValue instanceof NullNode == false) { String argumentsInstance; argumentsInstance = argumentsValue.getTextValue(); handlerMappingInstance.setArguments(argumentsInstance); } JsonNode extensionValue = handlerMappingsValue.get("Extension"); if (extensionValue != null && extensionValue instanceof NullNode == false) { String extensionInstance; extensionInstance = extensionValue.getTextValue(); handlerMappingInstance.setExtension(extensionInstance); } JsonNode scriptProcessorValue = handlerMappingsValue.get("ScriptProcessor"); if (scriptProcessorValue != null && scriptProcessorValue instanceof NullNode == false) { String scriptProcessorInstance; scriptProcessorInstance = scriptProcessorValue.getTextValue(); handlerMappingInstance.setScriptProcessor(scriptProcessorInstance); } } } JsonNode httpLoggingEnabledValue = responseDoc.get("HttpLoggingEnabled"); if (httpLoggingEnabledValue != null && httpLoggingEnabledValue instanceof NullNode == false) { boolean httpLoggingEnabledInstance; httpLoggingEnabledInstance = httpLoggingEnabledValue.getBooleanValue(); result.setHttpLoggingEnabled(httpLoggingEnabledInstance); } JsonNode logsDirectorySizeLimitValue = responseDoc.get("LogsDirectorySizeLimit"); if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue instanceof NullNode == false) { int logsDirectorySizeLimitInstance; logsDirectorySizeLimitInstance = logsDirectorySizeLimitValue.getIntValue(); result.setLogsDirectorySizeLimit(logsDirectorySizeLimitInstance); } JsonNode managedPipelineModeValue = responseDoc.get("ManagedPipelineMode"); if (managedPipelineModeValue != null && managedPipelineModeValue instanceof NullNode == false) { ManagedPipelineMode managedPipelineModeInstance; managedPipelineModeInstance = ManagedPipelineMode.values()[managedPipelineModeValue .getIntValue()]; result.setManagedPipelineMode(managedPipelineModeInstance); } JsonNode metadataSequenceElement = ((JsonNode) responseDoc.get("Metadata")); if (metadataSequenceElement != null && metadataSequenceElement instanceof NullNode == false) { for (JsonNode metadataElement : ((ArrayNode) metadataSequenceElement)) { String metadataKey = metadataElement.get("Name").getTextValue(); String metadataValue = metadataElement.get("Value").getTextValue(); result.getMetadata().put(metadataKey, metadataValue); } } JsonNode netFrameworkVersionValue = responseDoc.get("NetFrameworkVersion"); if (netFrameworkVersionValue != null && netFrameworkVersionValue instanceof NullNode == false) { String netFrameworkVersionInstance; netFrameworkVersionInstance = netFrameworkVersionValue.getTextValue(); result.setNetFrameworkVersion(netFrameworkVersionInstance); } JsonNode numberOfWorkersValue = responseDoc.get("NumberOfWorkers"); if (numberOfWorkersValue != null && numberOfWorkersValue instanceof NullNode == false) { int numberOfWorkersInstance; numberOfWorkersInstance = numberOfWorkersValue.getIntValue(); result.setNumberOfWorkers(numberOfWorkersInstance); } JsonNode phpVersionValue = responseDoc.get("PhpVersion"); if (phpVersionValue != null && phpVersionValue instanceof NullNode == false) { String phpVersionInstance; phpVersionInstance = phpVersionValue.getTextValue(); result.setPhpVersion(phpVersionInstance); } JsonNode publishingPasswordValue = responseDoc.get("PublishingPassword"); if (publishingPasswordValue != null && publishingPasswordValue instanceof NullNode == false) { String publishingPasswordInstance; publishingPasswordInstance = publishingPasswordValue.getTextValue(); result.setPublishingPassword(publishingPasswordInstance); } JsonNode publishingUsernameValue = responseDoc.get("PublishingUsername"); if (publishingUsernameValue != null && publishingUsernameValue instanceof NullNode == false) { String publishingUsernameInstance; publishingUsernameInstance = publishingUsernameValue.getTextValue(); result.setPublishingUserName(publishingUsernameInstance); } JsonNode remoteDebuggingEnabledValue = responseDoc.get("RemoteDebuggingEnabled"); if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue instanceof NullNode == false) { boolean remoteDebuggingEnabledInstance; remoteDebuggingEnabledInstance = remoteDebuggingEnabledValue.getBooleanValue(); result.setRemoteDebuggingEnabled(remoteDebuggingEnabledInstance); } JsonNode remoteDebuggingVersionValue = responseDoc.get("RemoteDebuggingVersion"); if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue instanceof NullNode == false) { RemoteDebuggingVersion remoteDebuggingVersionInstance; remoteDebuggingVersionInstance = Enum.valueOf(RemoteDebuggingVersion.class, remoteDebuggingVersionValue.getTextValue()); result.setRemoteDebuggingVersion(remoteDebuggingVersionInstance); } JsonNode requestTracingEnabledValue = responseDoc.get("RequestTracingEnabled"); if (requestTracingEnabledValue != null && requestTracingEnabledValue instanceof NullNode == false) { boolean requestTracingEnabledInstance; requestTracingEnabledInstance = requestTracingEnabledValue.getBooleanValue(); result.setRequestTracingEnabled(requestTracingEnabledInstance); } JsonNode requestTracingExpirationTimeValue = responseDoc.get("RequestTracingExpirationTime"); if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue instanceof NullNode == false) { Calendar requestTracingExpirationTimeInstance; requestTracingExpirationTimeInstance = DatatypeConverter .parseDateTime(requestTracingExpirationTimeValue.getTextValue()); result.setRequestTracingExpirationTime(requestTracingExpirationTimeInstance); } JsonNode scmTypeValue = responseDoc.get("ScmType"); if (scmTypeValue != null && scmTypeValue instanceof NullNode == false) { String scmTypeInstance; scmTypeInstance = scmTypeValue.getTextValue(); result.setScmType(scmTypeInstance); } JsonNode use32BitWorkerProcessValue = responseDoc.get("Use32BitWorkerProcess"); if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue instanceof NullNode == false) { boolean use32BitWorkerProcessInstance; use32BitWorkerProcessInstance = use32BitWorkerProcessValue.getBooleanValue(); result.setUse32BitWorkerProcess(use32BitWorkerProcessInstance); } JsonNode webSocketsEnabledValue = responseDoc.get("WebSocketsEnabled"); if (webSocketsEnabledValue != null && webSocketsEnabledValue instanceof NullNode == false) { boolean webSocketsEnabledInstance; webSocketsEnabledInstance = webSocketsEnabledValue.getBooleanValue(); result.setWebSocketsEnabled(webSocketsEnabledInstance); } JsonNode alwaysOnValue = responseDoc.get("AlwaysOn"); if (alwaysOnValue != null && alwaysOnValue instanceof NullNode == false) { boolean alwaysOnInstance; alwaysOnInstance = alwaysOnValue.getBooleanValue(); result.setAlwaysOn(alwaysOnInstance); } JsonNode routingRulesArray = responseDoc.get("RoutingRules"); if (routingRulesArray != null && routingRulesArray instanceof NullNode == false) { for (JsonNode routingRulesValue : ((ArrayNode) routingRulesArray)) { String typeName = routingRulesValue.get("__type").getTextValue(); if ("RampUpRule:http://schemas.microsoft.com/windowsazure".equals(typeName)) { RampUpRule rampUpRuleInstance = new RampUpRule(); JsonNode actionHostNameValue = routingRulesValue.get("ActionHostName"); if (actionHostNameValue != null && actionHostNameValue instanceof NullNode == false) { String actionHostNameInstance; actionHostNameInstance = actionHostNameValue.getTextValue(); rampUpRuleInstance.setActionHostName(actionHostNameInstance); } JsonNode reroutePercentageValue = routingRulesValue.get("ReroutePercentage"); if (reroutePercentageValue != null && reroutePercentageValue instanceof NullNode == false) { double reroutePercentageInstance; reroutePercentageInstance = reroutePercentageValue.getDoubleValue(); rampUpRuleInstance.setReroutePercentage(reroutePercentageInstance); } JsonNode changeStepValue = routingRulesValue.get("ChangeStep"); if (changeStepValue != null && changeStepValue instanceof NullNode == false) { double changeStepInstance; changeStepInstance = changeStepValue.getDoubleValue(); rampUpRuleInstance.setChangeStep(changeStepInstance); } JsonNode changeIntervalInMinutesValue = routingRulesValue .get("ChangeIntervalInMinutes"); if (changeIntervalInMinutesValue != null && changeIntervalInMinutesValue instanceof NullNode == false) { int changeIntervalInMinutesInstance; changeIntervalInMinutesInstance = changeIntervalInMinutesValue.getIntValue(); rampUpRuleInstance.setChangeIntervalInMinutes(changeIntervalInMinutesInstance); } JsonNode minReroutePercentageValue = routingRulesValue.get("MinReroutePercentage"); if (minReroutePercentageValue != null && minReroutePercentageValue instanceof NullNode == false) { double minReroutePercentageInstance; minReroutePercentageInstance = minReroutePercentageValue.getDoubleValue(); rampUpRuleInstance.setMinReroutePercentage(minReroutePercentageInstance); } JsonNode maxReroutePercentageValue = routingRulesValue.get("MaxReroutePercentage"); if (maxReroutePercentageValue != null && maxReroutePercentageValue instanceof NullNode == false) { double maxReroutePercentageInstance; maxReroutePercentageInstance = maxReroutePercentageValue.getDoubleValue(); rampUpRuleInstance.setMaxReroutePercentage(maxReroutePercentageInstance); } JsonNode changeDecisionCallbackUrlValue = routingRulesValue .get("ChangeDecisionCallbackUrl"); if (changeDecisionCallbackUrlValue != null && changeDecisionCallbackUrlValue instanceof NullNode == false) { String changeDecisionCallbackUrlInstance; changeDecisionCallbackUrlInstance = changeDecisionCallbackUrlValue .getTextValue(); rampUpRuleInstance .setChangeDecisionCallbackUrl(changeDecisionCallbackUrlInstance); } JsonNode nameValue2 = routingRulesValue.get("Name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); rampUpRuleInstance.setName(nameInstance2); } result.getRoutingRules().add(rampUpRuleInstance); } } } JsonNode javaVersionValue = responseDoc.get("JavaVersion"); if (javaVersionValue != null && javaVersionValue instanceof NullNode == false) { String javaVersionInstance; javaVersionInstance = javaVersionValue.getTextValue(); result.setJavaVersion(javaVersionInstance); } JsonNode javaContainerValue = responseDoc.get("JavaContainer"); if (javaContainerValue != null && javaContainerValue instanceof NullNode == false) { String javaContainerInstance; javaContainerInstance = javaContainerValue.getTextValue(); result.setJavaContainer(javaContainerInstance); } JsonNode javaContainerVersionValue = responseDoc.get("JavaContainerVersion"); if (javaContainerVersionValue != null && javaContainerVersionValue instanceof NullNode == false) { String javaContainerVersionInstance; javaContainerVersionInstance = javaContainerVersionValue.getTextValue(); result.setJavaContainerVersion(javaContainerVersionInstance); } JsonNode autoSwapSlotNameValue = responseDoc.get("AutoSwapSlotName"); if (autoSwapSlotNameValue != null && autoSwapSlotNameValue instanceof NullNode == false) { String autoSwapSlotNameInstance; autoSwapSlotNameInstance = autoSwapSlotNameValue.getTextValue(); result.setAutoSwapSlotName(autoSwapSlotNameInstance); } JsonNode siteAuthEnabledValue = responseDoc.get("SiteAuthEnabled"); if (siteAuthEnabledValue != null && siteAuthEnabledValue instanceof NullNode == false) { boolean siteAuthEnabledInstance; siteAuthEnabledInstance = siteAuthEnabledValue.getBooleanValue(); result.setSiteAuthEnabled(siteAuthEnabledInstance); } JsonNode siteAuthSettingsValue = responseDoc.get("SiteAuthSettings"); if (siteAuthSettingsValue != null && siteAuthSettingsValue instanceof NullNode == false) { SiteAuthSettings siteAuthSettingsInstance = new SiteAuthSettings(); result.setSiteAuthSettings(siteAuthSettingsInstance); JsonNode aADClientIdValue = siteAuthSettingsValue.get("AADClientId"); if (aADClientIdValue != null && aADClientIdValue instanceof NullNode == false) { String aADClientIdInstance; aADClientIdInstance = aADClientIdValue.getTextValue(); siteAuthSettingsInstance.setAADClientId(aADClientIdInstance); } JsonNode openIdIssuerValue = siteAuthSettingsValue.get("OpenIdIssuer"); if (openIdIssuerValue != null && openIdIssuerValue instanceof NullNode == false) { String openIdIssuerInstance; openIdIssuerInstance = openIdIssuerValue.getTextValue(); siteAuthSettingsInstance.setOpenIdIssuer(openIdIssuerInstance); } } JsonNode limitsValue = responseDoc.get("limits"); if (limitsValue != null && limitsValue instanceof NullNode == false) { WebSiteGetConfigurationResponse.SiteLimits limitsInstance = new WebSiteGetConfigurationResponse.SiteLimits(); result.setLimits(limitsInstance); JsonNode maxPercentageCpuValue = limitsValue.get("maxPercentageCpu"); if (maxPercentageCpuValue != null && maxPercentageCpuValue instanceof NullNode == false) { double maxPercentageCpuInstance; maxPercentageCpuInstance = maxPercentageCpuValue.getDoubleValue(); limitsInstance.setMaxPercentageCpu(maxPercentageCpuInstance); } JsonNode maxMemoryInMbValue = limitsValue.get("maxMemoryInMb"); if (maxMemoryInMbValue != null && maxMemoryInMbValue instanceof NullNode == false) { long maxMemoryInMbInstance; maxMemoryInMbInstance = maxMemoryInMbValue.getLongValue(); limitsInstance.setMaxMemoryInMb(maxMemoryInMbInstance); } JsonNode maxDiskSizeInMbValue = limitsValue.get("maxDiskSizeInMb"); if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue instanceof NullNode == false) { long maxDiskSizeInMbInstance; maxDiskSizeInMbInstance = maxDiskSizeInMbValue.getLongValue(); limitsInstance.setMaxDiskSizeInMb(maxDiskSizeInMbInstance); } } } } 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.websites.WebSiteOperationsImpl.java
/** * Gets a schedule configuration for site backups. * * @param resourceGroupName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @param slotName Optional. The name of the slot. * @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.// ww w . j a va 2s.c o m * @throws ServiceException Thrown if an unexpected response is found. * @return Scheduled backup definition. */ @Override public WebSiteGetBackupConfigurationResponse getBackupConfiguration(String resourceGroupName, String webSiteName, String slotName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("resourceGroupName", resourceGroupName); tracingParameters.put("webSiteName", webSiteName); tracingParameters.put("slotName", slotName); CloudTracing.enter(invocationId, this, "getBackupConfigurationAsync", 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.Web"; url = url + "/"; url = url + "sites"; url = url + "/"; url = url + URLEncoder.encode(webSiteName, "UTF-8"); if (slotName != null) { url = url + "/slots/" + URLEncoder.encode(slotName, "UTF-8"); } url = url + "/backup/config"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-06-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", "2014-06-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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSiteGetBackupConfigurationResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetBackupConfigurationResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { BackupScheduleRequestEnvelope backupScheduleInstance = new BackupScheduleRequestEnvelope(); result.setBackupSchedule(backupScheduleInstance); JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { BackupScheduleRequestResponse propertiesInstance = new BackupScheduleRequestResponse(); backupScheduleInstance.setProperties(propertiesInstance); JsonNode enabledValue = propertiesValue.get("enabled"); if (enabledValue != null && enabledValue instanceof NullNode == false) { boolean enabledInstance; enabledInstance = enabledValue.getBooleanValue(); propertiesInstance.setEnabled(enabledInstance); } JsonNode nameValue = propertiesValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); propertiesInstance.setName(nameInstance); } JsonNode storageAccountUrlValue = propertiesValue.get("storageAccountUrl"); if (storageAccountUrlValue != null && storageAccountUrlValue instanceof NullNode == false) { String storageAccountUrlInstance; storageAccountUrlInstance = storageAccountUrlValue.getTextValue(); propertiesInstance.setStorageAccountUrl(storageAccountUrlInstance); } JsonNode backupScheduleValue = propertiesValue.get("backupSchedule"); if (backupScheduleValue != null && backupScheduleValue instanceof NullNode == false) { BackupSchedule backupScheduleInstance2 = new BackupSchedule(); propertiesInstance.setBackupSchedule(backupScheduleInstance2); JsonNode frequencyIntervalValue = backupScheduleValue.get("frequencyInterval"); if (frequencyIntervalValue != null && frequencyIntervalValue instanceof NullNode == false) { int frequencyIntervalInstance; frequencyIntervalInstance = frequencyIntervalValue.getIntValue(); backupScheduleInstance2.setFrequencyInterval(frequencyIntervalInstance); } JsonNode frequencyUnitValue = backupScheduleValue.get("frequencyUnit"); if (frequencyUnitValue != null && frequencyUnitValue instanceof NullNode == false) { FrequencyUnit frequencyUnitInstance; frequencyUnitInstance = Enum.valueOf(FrequencyUnit.class, frequencyUnitValue.getTextValue()); backupScheduleInstance2.setFrequencyUnit(frequencyUnitInstance); } JsonNode keepAtLeastOneBackupValue = backupScheduleValue.get("keepAtLeastOneBackup"); if (keepAtLeastOneBackupValue != null && keepAtLeastOneBackupValue instanceof NullNode == false) { boolean keepAtLeastOneBackupInstance; keepAtLeastOneBackupInstance = keepAtLeastOneBackupValue.getBooleanValue(); backupScheduleInstance2.setKeepAtLeastOneBackup(keepAtLeastOneBackupInstance); } JsonNode lastExecutionTimeValue = backupScheduleValue.get("lastExecutionTime"); if (lastExecutionTimeValue != null && lastExecutionTimeValue instanceof NullNode == false) { Calendar lastExecutionTimeInstance; lastExecutionTimeInstance = DatatypeConverter .parseDateTime(lastExecutionTimeValue.getTextValue()); backupScheduleInstance2.setLastExecutionTime(lastExecutionTimeInstance); } JsonNode retentionPeriodInDaysValue = backupScheduleValue.get("retentionPeriodInDays"); if (retentionPeriodInDaysValue != null && retentionPeriodInDaysValue instanceof NullNode == false) { int retentionPeriodInDaysInstance; retentionPeriodInDaysInstance = retentionPeriodInDaysValue.getIntValue(); backupScheduleInstance2.setRetentionPeriodInDays(retentionPeriodInDaysInstance); } JsonNode startTimeValue = backupScheduleValue.get("startTime"); if (startTimeValue != null && startTimeValue instanceof NullNode == false) { Calendar startTimeInstance; startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue()); backupScheduleInstance2.setStartTime(startTimeInstance); } } JsonNode databasesArray = propertiesValue.get("databases"); if (databasesArray != null && databasesArray instanceof NullNode == false) { for (JsonNode databasesValue : ((ArrayNode) databasesArray)) { DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting(); propertiesInstance.getDatabases().add(databaseBackupSettingInstance); JsonNode connectionStringValue = databasesValue.get("connectionString"); if (connectionStringValue != null && connectionStringValue instanceof NullNode == false) { String connectionStringInstance; connectionStringInstance = connectionStringValue.getTextValue(); databaseBackupSettingInstance.setConnectionString(connectionStringInstance); } JsonNode connectionStringNameValue = databasesValue.get("connectionStringName"); if (connectionStringNameValue != null && connectionStringNameValue instanceof NullNode == false) { String connectionStringNameInstance; connectionStringNameInstance = connectionStringNameValue.getTextValue(); databaseBackupSettingInstance .setConnectionStringName(connectionStringNameInstance); } JsonNode databaseTypeValue = databasesValue.get("databaseType"); if (databaseTypeValue != null && databaseTypeValue instanceof NullNode == false) { String databaseTypeInstance; databaseTypeInstance = databaseTypeValue.getTextValue(); databaseBackupSettingInstance.setDatabaseType(databaseTypeInstance); } JsonNode nameValue2 = databasesValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); databaseBackupSettingInstance.setName(nameInstance2); } } } } JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); backupScheduleInstance.setId(idInstance); } JsonNode nameValue3 = responseDoc.get("name"); if (nameValue3 != null && nameValue3 instanceof NullNode == false) { String nameInstance3; nameInstance3 = nameValue3.getTextValue(); backupScheduleInstance.setName(nameInstance3); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); backupScheduleInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); backupScheduleInstance.getTags().put(tagsKey, tagsValue); } } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); backupScheduleInstance.setType(typeInstance); } } } 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(); } } }