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.websites.WebSiteOperationsImpl.java
/** * You can retrieve the config settings for a web site by issuing an HTTP * GET request, or update them by using HTTP PUT with a request body that * contains the settings to be updated. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx for * more information)//from w w w . java 2s . c o 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. * @return Config for the website. */ @Override public WebSiteGetConfigurationResult getConfiguration(String resourceGroupName, String webSiteName, String slotName, WebSiteGetConfigurationParameters parameters) 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); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "getConfigurationAsync", 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 + "/config/web"; 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 WebSiteGetConfigurationResult result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetConfigurationResult(); 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) { WebSiteConfigurationEnvelope resourceInstance = new WebSiteConfigurationEnvelope(); result.setResource(resourceInstance); JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { WebSiteConfiguration propertiesInstance = new WebSiteConfiguration(); resourceInstance.setProperties(propertiesInstance); JsonNode appSettingsSequenceElement = ((JsonNode) propertiesValue.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(); propertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } JsonNode connectionStringsArray = propertiesValue.get("connectionStrings"); if (connectionStringsArray != null && connectionStringsArray instanceof NullNode == false) { for (JsonNode connectionStringsValue : ((ArrayNode) connectionStringsArray)) { ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo(); propertiesInstance.getConnectionStrings().add(connStringInfoInstance); JsonNode connectionStringValue = connectionStringsValue.get("connectionString"); if (connectionStringValue != null && connectionStringValue instanceof NullNode == false) { String connectionStringInstance; connectionStringInstance = connectionStringValue.getTextValue(); connStringInfoInstance.setConnectionString(connectionStringInstance); } JsonNode nameValue = connectionStringsValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); connStringInfoInstance.setName(nameInstance); } 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 = propertiesValue.get("defaultDocuments"); if (defaultDocumentsArray != null && defaultDocumentsArray instanceof NullNode == false) { for (JsonNode defaultDocumentsValue : ((ArrayNode) defaultDocumentsArray)) { propertiesInstance.getDefaultDocuments().add(defaultDocumentsValue.getTextValue()); } } JsonNode detailedErrorLoggingEnabledValue = propertiesValue .get("detailedErrorLoggingEnabled"); if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue instanceof NullNode == false) { boolean detailedErrorLoggingEnabledInstance; detailedErrorLoggingEnabledInstance = detailedErrorLoggingEnabledValue .getBooleanValue(); propertiesInstance.setDetailedErrorLoggingEnabled(detailedErrorLoggingEnabledInstance); } JsonNode documentRootValue = propertiesValue.get("documentRoot"); if (documentRootValue != null && documentRootValue instanceof NullNode == false) { String documentRootInstance; documentRootInstance = documentRootValue.getTextValue(); propertiesInstance.setDocumentRoot(documentRootInstance); } JsonNode handlerMappingsArray = propertiesValue.get("handlerMappings"); if (handlerMappingsArray != null && handlerMappingsArray instanceof NullNode == false) { for (JsonNode handlerMappingsValue : ((ArrayNode) handlerMappingsArray)) { WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping(); propertiesInstance.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 = propertiesValue.get("httpLoggingEnabled"); if (httpLoggingEnabledValue != null && httpLoggingEnabledValue instanceof NullNode == false) { boolean httpLoggingEnabledInstance; httpLoggingEnabledInstance = httpLoggingEnabledValue.getBooleanValue(); propertiesInstance.setHttpLoggingEnabled(httpLoggingEnabledInstance); } JsonNode logsDirectorySizeLimitValue = propertiesValue.get("logsDirectorySizeLimit"); if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue instanceof NullNode == false) { int logsDirectorySizeLimitInstance; logsDirectorySizeLimitInstance = logsDirectorySizeLimitValue.getIntValue(); propertiesInstance.setLogsDirectorySizeLimit(logsDirectorySizeLimitInstance); } JsonNode managedPipelineModeValue = propertiesValue.get("managedPipelineMode"); if (managedPipelineModeValue != null && managedPipelineModeValue instanceof NullNode == false) { ManagedPipelineMode managedPipelineModeInstance; managedPipelineModeInstance = Enum.valueOf(ManagedPipelineMode.class, managedPipelineModeValue.getTextValue()); propertiesInstance.setManagedPipelineMode(managedPipelineModeInstance); } JsonNode metadataSequenceElement = ((JsonNode) propertiesValue.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(); propertiesInstance.getMetadata().put(metadataKey, metadataValue); } } JsonNode netFrameworkVersionValue = propertiesValue.get("netFrameworkVersion"); if (netFrameworkVersionValue != null && netFrameworkVersionValue instanceof NullNode == false) { String netFrameworkVersionInstance; netFrameworkVersionInstance = netFrameworkVersionValue.getTextValue(); propertiesInstance.setNetFrameworkVersion(netFrameworkVersionInstance); } JsonNode numberOfWorkersValue = propertiesValue.get("numberOfWorkers"); if (numberOfWorkersValue != null && numberOfWorkersValue instanceof NullNode == false) { int numberOfWorkersInstance; numberOfWorkersInstance = numberOfWorkersValue.getIntValue(); propertiesInstance.setNumberOfWorkers(numberOfWorkersInstance); } JsonNode phpVersionValue = propertiesValue.get("phpVersion"); if (phpVersionValue != null && phpVersionValue instanceof NullNode == false) { String phpVersionInstance; phpVersionInstance = phpVersionValue.getTextValue(); propertiesInstance.setPhpVersion(phpVersionInstance); } JsonNode pythonVersionValue = propertiesValue.get("pythonVersion"); if (pythonVersionValue != null && pythonVersionValue instanceof NullNode == false) { String pythonVersionInstance; pythonVersionInstance = pythonVersionValue.getTextValue(); propertiesInstance.setPythonVersion(pythonVersionInstance); } JsonNode publishingPasswordValue = propertiesValue.get("publishingPassword"); if (publishingPasswordValue != null && publishingPasswordValue instanceof NullNode == false) { String publishingPasswordInstance; publishingPasswordInstance = publishingPasswordValue.getTextValue(); propertiesInstance.setPublishingPassword(publishingPasswordInstance); } JsonNode publishingUsernameValue = propertiesValue.get("publishingUsername"); if (publishingUsernameValue != null && publishingUsernameValue instanceof NullNode == false) { String publishingUsernameInstance; publishingUsernameInstance = publishingUsernameValue.getTextValue(); propertiesInstance.setPublishingUserName(publishingUsernameInstance); } JsonNode remoteDebuggingEnabledValue = propertiesValue.get("RemoteDebuggingEnabled"); if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue instanceof NullNode == false) { boolean remoteDebuggingEnabledInstance; remoteDebuggingEnabledInstance = remoteDebuggingEnabledValue.getBooleanValue(); propertiesInstance.setRemoteDebuggingEnabled(remoteDebuggingEnabledInstance); } JsonNode remoteDebuggingVersionValue = propertiesValue.get("remoteDebuggingVersion"); if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue instanceof NullNode == false) { RemoteDebuggingVersion remoteDebuggingVersionInstance; remoteDebuggingVersionInstance = Enum.valueOf(RemoteDebuggingVersion.class, remoteDebuggingVersionValue.getTextValue()); propertiesInstance.setRemoteDebuggingVersion(remoteDebuggingVersionInstance); } JsonNode requestTracingEnabledValue = propertiesValue.get("requestTracingEnabled"); if (requestTracingEnabledValue != null && requestTracingEnabledValue instanceof NullNode == false) { boolean requestTracingEnabledInstance; requestTracingEnabledInstance = requestTracingEnabledValue.getBooleanValue(); propertiesInstance.setRequestTracingEnabled(requestTracingEnabledInstance); } JsonNode requestTracingExpirationTimeValue = propertiesValue .get("requestTracingExpirationTime"); if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue instanceof NullNode == false) { Calendar requestTracingExpirationTimeInstance; requestTracingExpirationTimeInstance = DatatypeConverter .parseDateTime(requestTracingExpirationTimeValue.getTextValue()); propertiesInstance .setRequestTracingExpirationTime(requestTracingExpirationTimeInstance); } JsonNode scmTypeValue = propertiesValue.get("scmType"); if (scmTypeValue != null && scmTypeValue instanceof NullNode == false) { String scmTypeInstance; scmTypeInstance = scmTypeValue.getTextValue(); propertiesInstance.setScmType(scmTypeInstance); } JsonNode autoSwapSlotNameValue = propertiesValue.get("autoSwapSlotName"); if (autoSwapSlotNameValue != null && autoSwapSlotNameValue instanceof NullNode == false) { String autoSwapSlotNameInstance; autoSwapSlotNameInstance = autoSwapSlotNameValue.getTextValue(); propertiesInstance.setAutoSwapSlotName(autoSwapSlotNameInstance); } JsonNode use32BitWorkerProcessValue = propertiesValue.get("use32BitWorkerProcess"); if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue instanceof NullNode == false) { boolean use32BitWorkerProcessInstance; use32BitWorkerProcessInstance = use32BitWorkerProcessValue.getBooleanValue(); propertiesInstance.setUse32BitWorkerProcess(use32BitWorkerProcessInstance); } JsonNode webSocketsEnabledValue = propertiesValue.get("webSocketsEnabled"); if (webSocketsEnabledValue != null && webSocketsEnabledValue instanceof NullNode == false) { boolean webSocketsEnabledInstance; webSocketsEnabledInstance = webSocketsEnabledValue.getBooleanValue(); propertiesInstance.setWebSocketsEnabled(webSocketsEnabledInstance); } JsonNode limitsValue = propertiesValue.get("limits"); if (limitsValue != null && limitsValue instanceof NullNode == false) { SiteLimits limitsInstance = new SiteLimits(); propertiesInstance.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 idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); resourceInstance.setId(idInstance); } JsonNode nameValue2 = responseDoc.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); resourceInstance.setName(nameInstance2); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); resourceInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr3 = tagsSequenceElement.getFields(); while (itr3.hasNext()) { Map.Entry<String, JsonNode> property3 = itr3.next(); String tagsKey = property3.getKey(); String tagsValue = property3.getValue().getTextValue(); resourceInstance.getTags().put(tagsKey, tagsValue); } } JsonNode typeValue2 = responseDoc.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); resourceInstance.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
/** * Creates a new NotificationHub in a namespace. (see * http://msdn.microsoft.com/en-us/library/windowsazure/jj856303.aspx for * more information)/*w w w. j ava 2 s . c om*/ * * @param resourceGroupName Required. The name of the resource group. * @param namespaceName Required. The namespace name. * @param notificationHubName Required. The notification hub name. * @param parameters Required. Parameters supplied to the create a Namespace * Resource. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return Response of the CreateOrUpdate operation on the NotificationHub */ @Override public NotificationHubCreateOrUpdateResponse update(String resourceGroupName, String namespaceName, String notificationHubName, NotificationHubCreateOrUpdateParameters parameters) 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"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLocation() == null) { throw new NullPointerException("parameters.Location"); } if (parameters.getProperties() == null) { throw new NullPointerException("parameters.Properties"); } // 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); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "updateAsync", 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"); 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 HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json"); httpRequest.setHeader("if-match", "*"); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode notificationHubCreateOrUpdateParametersValue = objectMapper.createObjectNode(); requestDoc = notificationHubCreateOrUpdateParametersValue; ((ObjectNode) notificationHubCreateOrUpdateParametersValue).put("location", parameters.getLocation()); if (parameters.getTags() != null) { if (parameters.getTags() instanceof LazyCollection == false || ((LazyCollection) parameters.getTags()).isInitialized()) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) notificationHubCreateOrUpdateParametersValue).put("tags", tagsDictionary); } } ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) notificationHubCreateOrUpdateParametersValue).put("properties", propertiesValue); if (parameters.getProperties().getName() != null) { ((ObjectNode) propertiesValue).put("name", parameters.getProperties().getName()); } if (parameters.getProperties().getRegistrationTtl() != null) { ((ObjectNode) propertiesValue).put("registrationTtl", parameters.getProperties().getRegistrationTtl()); } if (parameters.getProperties().getAuthorizationRules() != null) { if (parameters.getProperties().getAuthorizationRules() instanceof LazyCollection == false || ((LazyCollection) parameters.getProperties().getAuthorizationRules()).isInitialized()) { ArrayNode authorizationRulesArray = objectMapper.createArrayNode(); for (SharedAccessAuthorizationRuleProperties authorizationRulesItem : parameters.getProperties() .getAuthorizationRules()) { if (authorizationRulesItem.getPrimaryKey() != null) { requestDoc = authorizationRulesItem.getPrimaryKey(); } if (authorizationRulesItem.getSecondaryKey() != null) { requestDoc = authorizationRulesItem.getSecondaryKey(); } if (authorizationRulesItem.getKeyName() != null) { requestDoc = authorizationRulesItem.getKeyName(); } if (authorizationRulesItem.getClaimType() != null) { requestDoc = authorizationRulesItem.getClaimType(); } if (authorizationRulesItem.getClaimValue() != null) { requestDoc = authorizationRulesItem.getClaimValue(); } if (authorizationRulesItem.getRights() != null) { ArrayNode rightsArray = objectMapper.createArrayNode(); for (AccessRights rightsItem : authorizationRulesItem.getRights()) { rightsArray.add(rightsItem.toString()); } requestDoc = rightsArray; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); requestDoc = simpleDateFormat.format(authorizationRulesItem.getCreatedTime().getTime()); SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC")); requestDoc = simpleDateFormat2.format(authorizationRulesItem.getModifiedTime().getTime()); requestDoc = authorizationRulesItem.getRevision(); } ((ObjectNode) propertiesValue).put("authorizationRules", authorizationRulesArray); } } if (parameters.getProperties().getApnsCredential() != null) { ObjectNode apnsCredentialValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("apnsCredential", apnsCredentialValue); if (parameters.getProperties().getApnsCredential().getProperties() != null) { ObjectNode propertiesValue2 = objectMapper.createObjectNode(); ((ObjectNode) apnsCredentialValue).put("properties", propertiesValue2); if (parameters.getProperties().getApnsCredential().getProperties().getApnsCertificate() != null) { ((ObjectNode) propertiesValue2).put("apnsCertificate", parameters.getProperties().getApnsCredential().getProperties().getApnsCertificate()); } if (parameters.getProperties().getApnsCredential().getProperties().getCertificateKey() != null) { ((ObjectNode) propertiesValue2).put("certificateKey", parameters.getProperties().getApnsCredential().getProperties().getCertificateKey()); } if (parameters.getProperties().getApnsCredential().getProperties().getEndpoint() != null) { ((ObjectNode) propertiesValue2).put("endpoint", parameters.getProperties().getApnsCredential().getProperties().getEndpoint()); } if (parameters.getProperties().getApnsCredential().getProperties().getThumbprint() != null) { ((ObjectNode) propertiesValue2).put("thumbprint", parameters.getProperties().getApnsCredential().getProperties().getThumbprint()); } } } if (parameters.getProperties().getWnsCredential() != null) { ObjectNode wnsCredentialValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("wnsCredential", wnsCredentialValue); if (parameters.getProperties().getWnsCredential().getProperties() != null) { ObjectNode propertiesValue3 = objectMapper.createObjectNode(); ((ObjectNode) wnsCredentialValue).put("properties", propertiesValue3); if (parameters.getProperties().getWnsCredential().getProperties().getPackageSid() != null) { ((ObjectNode) propertiesValue3).put("packageSid", parameters.getProperties().getWnsCredential().getProperties().getPackageSid()); } if (parameters.getProperties().getWnsCredential().getProperties().getSecretKey() != null) { ((ObjectNode) propertiesValue3).put("secretKey", parameters.getProperties().getWnsCredential().getProperties().getSecretKey()); } if (parameters.getProperties().getWnsCredential().getProperties() .getWindowsLiveEndpoint() != null) { ((ObjectNode) propertiesValue3).put("windowsLiveEndpoint", parameters.getProperties().getWnsCredential().getProperties().getWindowsLiveEndpoint()); } } } if (parameters.getProperties().getGcmCredential() != null) { ObjectNode gcmCredentialValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("gcmCredential", gcmCredentialValue); if (parameters.getProperties().getGcmCredential().getProperties() != null) { ObjectNode propertiesValue4 = objectMapper.createObjectNode(); ((ObjectNode) gcmCredentialValue).put("properties", propertiesValue4); if (parameters.getProperties().getGcmCredential().getProperties().getGcmEndpoint() != null) { ((ObjectNode) propertiesValue4).put("gcmEndpoint", parameters.getProperties().getGcmCredential().getProperties().getGcmEndpoint()); } if (parameters.getProperties().getGcmCredential().getProperties().getGoogleApiKey() != null) { ((ObjectNode) propertiesValue4).put("googleApiKey", parameters.getProperties().getGcmCredential().getProperties().getGoogleApiKey()); } } } if (parameters.getProperties().getMpnsCredential() != null) { ObjectNode mpnsCredentialValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("mpnsCredential", mpnsCredentialValue); if (parameters.getProperties().getMpnsCredential().getProperties() != null) { ObjectNode propertiesValue5 = objectMapper.createObjectNode(); ((ObjectNode) mpnsCredentialValue).put("properties", propertiesValue5); if (parameters.getProperties().getMpnsCredential().getProperties().getMpnsCertificate() != null) { ((ObjectNode) propertiesValue5).put("mpnsCertificate", parameters.getProperties().getMpnsCredential().getProperties().getMpnsCertificate()); } if (parameters.getProperties().getMpnsCredential().getProperties().getCertificateKey() != null) { ((ObjectNode) propertiesValue5).put("certificateKey", parameters.getProperties().getMpnsCredential().getProperties().getCertificateKey()); } if (parameters.getProperties().getMpnsCredential().getProperties().getThumbprint() != null) { ((ObjectNode) propertiesValue5).put("thumbprint", parameters.getProperties().getMpnsCredential().getProperties().getThumbprint()); } } } if (parameters.getProperties().getAdmCredential() != null) { ObjectNode admCredentialValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("admCredential", admCredentialValue); if (parameters.getProperties().getAdmCredential().getProperties() != null) { ObjectNode propertiesValue6 = objectMapper.createObjectNode(); ((ObjectNode) admCredentialValue).put("properties", propertiesValue6); if (parameters.getProperties().getAdmCredential().getProperties().getClientId() != null) { ((ObjectNode) propertiesValue6).put("clientId", parameters.getProperties().getAdmCredential().getProperties().getClientId()); } if (parameters.getProperties().getAdmCredential().getProperties().getClientSecret() != null) { ((ObjectNode) propertiesValue6).put("clientSecret", parameters.getProperties().getAdmCredential().getProperties().getClientSecret()); } if (parameters.getProperties().getAdmCredential().getProperties().getAuthTokenUrl() != null) { ((ObjectNode) propertiesValue6).put("authTokenUrl", parameters.getProperties().getAdmCredential().getProperties().getAuthTokenUrl()); } } } if (parameters.getProperties().getBaiduCredential() != null) { ObjectNode baiduCredentialValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("baiduCredential", baiduCredentialValue); if (parameters.getProperties().getBaiduCredential().getProperties() != null) { ObjectNode propertiesValue7 = objectMapper.createObjectNode(); ((ObjectNode) baiduCredentialValue).put("properties", propertiesValue7); if (parameters.getProperties().getBaiduCredential().getProperties().getBaiduApiKey() != null) { ((ObjectNode) propertiesValue7).put("baiduApiKey", parameters.getProperties().getBaiduCredential().getProperties().getBaiduApiKey()); } if (parameters.getProperties().getBaiduCredential().getProperties().getBaiduEndPoint() != null) { ((ObjectNode) propertiesValue7).put("baiduEndPoint", parameters.getProperties().getBaiduCredential().getProperties().getBaiduEndPoint()); } if (parameters.getProperties().getBaiduCredential().getProperties().getBaiduSecretKey() != null) { ((ObjectNode) propertiesValue7).put("baiduSecretKey", parameters.getProperties().getBaiduCredential().getProperties().getBaiduSecretKey()); } } } 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"); // 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_CREATED) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result NotificationHubCreateOrUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new NotificationHubCreateOrUpdateResponse(); 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 tagsKey2 = property.getKey(); String tagsValue2 = property.getValue().getTextValue(); valueInstance.getTags().put(tagsKey2, tagsValue2); } } JsonNode propertiesValue8 = responseDoc.get("properties"); if (propertiesValue8 != null && propertiesValue8 instanceof NullNode == false) { NotificationHubProperties propertiesInstance = new NotificationHubProperties(); valueInstance.setProperties(propertiesInstance); JsonNode nameValue2 = propertiesValue8.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); propertiesInstance.setName(nameInstance2); } JsonNode registrationTtlValue = propertiesValue8.get("registrationTtl"); if (registrationTtlValue != null && registrationTtlValue instanceof NullNode == false) { String registrationTtlInstance; registrationTtlInstance = registrationTtlValue.getTextValue(); propertiesInstance.setRegistrationTtl(registrationTtlInstance); } JsonNode authorizationRulesArray2 = propertiesValue8.get("authorizationRules"); if (authorizationRulesArray2 != null && authorizationRulesArray2 instanceof NullNode == false) { for (JsonNode authorizationRulesValue : ((ArrayNode) authorizationRulesArray2)) { 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 rightsArray2 = authorizationRulesValue.get("rights"); if (rightsArray2 != null && rightsArray2 instanceof NullNode == false) { for (JsonNode rightsValue : ((ArrayNode) rightsArray2)) { 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 apnsCredentialValue2 = propertiesValue8.get("apnsCredential"); if (apnsCredentialValue2 != null && apnsCredentialValue2 instanceof NullNode == false) { ApnsCredential apnsCredentialInstance = new ApnsCredential(); propertiesInstance.setApnsCredential(apnsCredentialInstance); JsonNode propertiesValue9 = apnsCredentialValue2.get("properties"); if (propertiesValue9 != null && propertiesValue9 instanceof NullNode == false) { ApnsCredentialProperties propertiesInstance2 = new ApnsCredentialProperties(); apnsCredentialInstance.setProperties(propertiesInstance2); JsonNode apnsCertificateValue = propertiesValue9.get("apnsCertificate"); if (apnsCertificateValue != null && apnsCertificateValue instanceof NullNode == false) { String apnsCertificateInstance; apnsCertificateInstance = apnsCertificateValue.getTextValue(); propertiesInstance2.setApnsCertificate(apnsCertificateInstance); } JsonNode certificateKeyValue = propertiesValue9.get("certificateKey"); if (certificateKeyValue != null && certificateKeyValue instanceof NullNode == false) { String certificateKeyInstance; certificateKeyInstance = certificateKeyValue.getTextValue(); propertiesInstance2.setCertificateKey(certificateKeyInstance); } JsonNode endpointValue = propertiesValue9.get("endpoint"); if (endpointValue != null && endpointValue instanceof NullNode == false) { String endpointInstance; endpointInstance = endpointValue.getTextValue(); propertiesInstance2.setEndpoint(endpointInstance); } JsonNode thumbprintValue = propertiesValue9.get("thumbprint"); if (thumbprintValue != null && thumbprintValue instanceof NullNode == false) { String thumbprintInstance; thumbprintInstance = thumbprintValue.getTextValue(); propertiesInstance2.setThumbprint(thumbprintInstance); } } } JsonNode wnsCredentialValue2 = propertiesValue8.get("wnsCredential"); if (wnsCredentialValue2 != null && wnsCredentialValue2 instanceof NullNode == false) { WnsCredential wnsCredentialInstance = new WnsCredential(); propertiesInstance.setWnsCredential(wnsCredentialInstance); JsonNode propertiesValue10 = wnsCredentialValue2.get("properties"); if (propertiesValue10 != null && propertiesValue10 instanceof NullNode == false) { WnsCredentialProperties propertiesInstance3 = new WnsCredentialProperties(); wnsCredentialInstance.setProperties(propertiesInstance3); JsonNode packageSidValue = propertiesValue10.get("packageSid"); if (packageSidValue != null && packageSidValue instanceof NullNode == false) { String packageSidInstance; packageSidInstance = packageSidValue.getTextValue(); propertiesInstance3.setPackageSid(packageSidInstance); } JsonNode secretKeyValue = propertiesValue10.get("secretKey"); if (secretKeyValue != null && secretKeyValue instanceof NullNode == false) { String secretKeyInstance; secretKeyInstance = secretKeyValue.getTextValue(); propertiesInstance3.setSecretKey(secretKeyInstance); } JsonNode windowsLiveEndpointValue = propertiesValue10.get("windowsLiveEndpoint"); if (windowsLiveEndpointValue != null && windowsLiveEndpointValue instanceof NullNode == false) { String windowsLiveEndpointInstance; windowsLiveEndpointInstance = windowsLiveEndpointValue.getTextValue(); propertiesInstance3.setWindowsLiveEndpoint(windowsLiveEndpointInstance); } } } JsonNode gcmCredentialValue2 = propertiesValue8.get("gcmCredential"); if (gcmCredentialValue2 != null && gcmCredentialValue2 instanceof NullNode == false) { GcmCredential gcmCredentialInstance = new GcmCredential(); propertiesInstance.setGcmCredential(gcmCredentialInstance); JsonNode propertiesValue11 = gcmCredentialValue2.get("properties"); if (propertiesValue11 != null && propertiesValue11 instanceof NullNode == false) { GcmCredentialProperties propertiesInstance4 = new GcmCredentialProperties(); gcmCredentialInstance.setProperties(propertiesInstance4); JsonNode gcmEndpointValue = propertiesValue11.get("gcmEndpoint"); if (gcmEndpointValue != null && gcmEndpointValue instanceof NullNode == false) { String gcmEndpointInstance; gcmEndpointInstance = gcmEndpointValue.getTextValue(); propertiesInstance4.setGcmEndpoint(gcmEndpointInstance); } JsonNode googleApiKeyValue = propertiesValue11.get("googleApiKey"); if (googleApiKeyValue != null && googleApiKeyValue instanceof NullNode == false) { String googleApiKeyInstance; googleApiKeyInstance = googleApiKeyValue.getTextValue(); propertiesInstance4.setGoogleApiKey(googleApiKeyInstance); } } } JsonNode mpnsCredentialValue2 = propertiesValue8.get("mpnsCredential"); if (mpnsCredentialValue2 != null && mpnsCredentialValue2 instanceof NullNode == false) { MpnsCredential mpnsCredentialInstance = new MpnsCredential(); propertiesInstance.setMpnsCredential(mpnsCredentialInstance); JsonNode propertiesValue12 = mpnsCredentialValue2.get("properties"); if (propertiesValue12 != null && propertiesValue12 instanceof NullNode == false) { MpnsCredentialProperties propertiesInstance5 = new MpnsCredentialProperties(); mpnsCredentialInstance.setProperties(propertiesInstance5); JsonNode mpnsCertificateValue = propertiesValue12.get("mpnsCertificate"); if (mpnsCertificateValue != null && mpnsCertificateValue instanceof NullNode == false) { String mpnsCertificateInstance; mpnsCertificateInstance = mpnsCertificateValue.getTextValue(); propertiesInstance5.setMpnsCertificate(mpnsCertificateInstance); } JsonNode certificateKeyValue2 = propertiesValue12.get("certificateKey"); if (certificateKeyValue2 != null && certificateKeyValue2 instanceof NullNode == false) { String certificateKeyInstance2; certificateKeyInstance2 = certificateKeyValue2.getTextValue(); propertiesInstance5.setCertificateKey(certificateKeyInstance2); } JsonNode thumbprintValue2 = propertiesValue12.get("thumbprint"); if (thumbprintValue2 != null && thumbprintValue2 instanceof NullNode == false) { String thumbprintInstance2; thumbprintInstance2 = thumbprintValue2.getTextValue(); propertiesInstance5.setThumbprint(thumbprintInstance2); } } } JsonNode admCredentialValue2 = propertiesValue8.get("admCredential"); if (admCredentialValue2 != null && admCredentialValue2 instanceof NullNode == false) { AdmCredential admCredentialInstance = new AdmCredential(); propertiesInstance.setAdmCredential(admCredentialInstance); JsonNode propertiesValue13 = admCredentialValue2.get("properties"); if (propertiesValue13 != null && propertiesValue13 instanceof NullNode == false) { AdmCredentialProperties propertiesInstance6 = new AdmCredentialProperties(); admCredentialInstance.setProperties(propertiesInstance6); JsonNode clientIdValue = propertiesValue13.get("clientId"); if (clientIdValue != null && clientIdValue instanceof NullNode == false) { String clientIdInstance; clientIdInstance = clientIdValue.getTextValue(); propertiesInstance6.setClientId(clientIdInstance); } JsonNode clientSecretValue = propertiesValue13.get("clientSecret"); if (clientSecretValue != null && clientSecretValue instanceof NullNode == false) { String clientSecretInstance; clientSecretInstance = clientSecretValue.getTextValue(); propertiesInstance6.setClientSecret(clientSecretInstance); } JsonNode authTokenUrlValue = propertiesValue13.get("authTokenUrl"); if (authTokenUrlValue != null && authTokenUrlValue instanceof NullNode == false) { String authTokenUrlInstance; authTokenUrlInstance = authTokenUrlValue.getTextValue(); propertiesInstance6.setAuthTokenUrl(authTokenUrlInstance); } } } JsonNode baiduCredentialValue2 = propertiesValue8.get("baiduCredential"); if (baiduCredentialValue2 != null && baiduCredentialValue2 instanceof NullNode == false) { BaiduCredential baiduCredentialInstance = new BaiduCredential(); propertiesInstance.setBaiduCredential(baiduCredentialInstance); JsonNode propertiesValue14 = baiduCredentialValue2.get("properties"); if (propertiesValue14 != null && propertiesValue14 instanceof NullNode == false) { BaiduCredentialProperties propertiesInstance7 = new BaiduCredentialProperties(); baiduCredentialInstance.setProperties(propertiesInstance7); JsonNode baiduApiKeyValue = propertiesValue14.get("baiduApiKey"); if (baiduApiKeyValue != null && baiduApiKeyValue instanceof NullNode == false) { String baiduApiKeyInstance; baiduApiKeyInstance = baiduApiKeyValue.getTextValue(); propertiesInstance7.setBaiduApiKey(baiduApiKeyInstance); } JsonNode baiduEndPointValue = propertiesValue14.get("baiduEndPoint"); if (baiduEndPointValue != null && baiduEndPointValue instanceof NullNode == false) { String baiduEndPointInstance; baiduEndPointInstance = baiduEndPointValue.getTextValue(); propertiesInstance7.setBaiduEndPoint(baiduEndPointInstance); } JsonNode baiduSecretKeyValue = propertiesValue14.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:com.microsoft.azure.management.websites.WebSiteOperationsImpl.java
/** * Restart the web site./* w ww . j ava 2s . c om*/ * * @param resourceGroupName Required. The name of the resource group * @param webSiteName Required. Name of website * @param slotName Optional. The name of the slot 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 List of connection strings for the website. */ @Override public WebSiteConnectionStringsResult getConnectionStrings(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, "getConnectionStringsAsync", 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 + "/config/connectionstrings/list"; 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 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 WebSiteConnectionStringsResult result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteConnectionStringsResult(); 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) { WebSiteConnectionStringsEnvelope resourceInstance = new WebSiteConnectionStringsEnvelope(); result.setResource(resourceInstance); JsonNode propertiesArray = responseDoc.get("properties"); if (propertiesArray != null && propertiesArray instanceof NullNode == false) { for (JsonNode propertiesValue : ((ArrayNode) propertiesArray)) { ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo(); resourceInstance.getProperties().add(connStringInfoInstance); JsonNode connectionStringValue = propertiesValue.get("connectionString"); if (connectionStringValue != null && connectionStringValue instanceof NullNode == false) { String connectionStringInstance; connectionStringInstance = connectionStringValue.getTextValue(); connStringInfoInstance.setConnectionString(connectionStringInstance); } JsonNode nameValue = propertiesValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); connStringInfoInstance.setName(nameInstance); } JsonNode typeValue = propertiesValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { DatabaseServerType typeInstance; typeInstance = Enum.valueOf(DatabaseServerType.class, typeValue.getTextValue()); connStringInfoInstance.setType(typeInstance); } } } JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); resourceInstance.setId(idInstance); } JsonNode nameValue2 = responseDoc.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); resourceInstance.setName(nameInstance2); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); resourceInstance.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(); resourceInstance.getTags().put(tagsKey, tagsValue); } } JsonNode typeValue2 = responseDoc.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); resourceInstance.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:ca.oson.json.Oson.java
private <E> Enum<?> json2Enum(FieldData objectDTO) { objectDTO.valueToProcess = StringUtil.unquote(objectDTO.valueToProcess, isEscapeHtml()); Object valueToProcess = objectDTO.valueToProcess; Class<E> returnType = objectDTO.returnType; boolean required = objectDTO.required(); Enum defaultValue = (Enum) objectDTO.defaultValue; boolean json2Java = objectDTO.json2Java; if (returnType == null || valueToProcess == null) { if (required) { return defaultValue; }/*from w w w . j ava 2 s. co m*/ return null; } String value = (String) valueToProcess; Class<Enum> enumType = (Class<Enum>) returnType; try { Function function = objectDTO.getDeserializer(); if (function != null) { Object returnedValue = null; if (function instanceof Json2DataMapperFunction) { DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper, objectDTO.level, getPrettyIndentation()); returnedValue = ((Json2DataMapperFunction) function).apply(classData); } else if (function instanceof Json2FieldDataFunction) { Json2FieldDataFunction f = (Json2FieldDataFunction) function; FieldData fieldData = objectDTO.clone(); returnedValue = f.apply(fieldData); } else if (function instanceof Json2EnumFunction) { return (Enum<?>) ((Json2EnumFunction) function).apply(value); } else { returnedValue = function.apply(value); } if (returnedValue instanceof Optional) { returnedValue = ObjectUtil.unwrap(returnedValue); } if (returnedValue == null) { return null; } Class type = returnedValue.getClass(); if (Enum.class.isAssignableFrom(type)) { return (Enum<?>) returnedValue; } else if (Number.class.isAssignableFrom(type)) { int ordinal = ((Number) returnedValue).intValue(); for (Enum enumValue : enumType.getEnumConstants()) { if (enumValue.ordinal() == ordinal) { return enumValue; } } } else { String name = returnedValue.toString(); for (Enum enumValue : enumType.getEnumConstants()) { if (enumValue.toString().equalsIgnoreCase(name) || enumValue.name().equalsIgnoreCase(name)) { return enumValue; } } } } } catch (Exception ex) { } for (Method method : enumType.getDeclaredMethods()) { for (Annotation annotation : method.getDeclaredAnnotations()) { String aname = annotation.annotationType().getName(); switch (aname) { case "com.fasterxml.jackson.annotation.JsonCreator": case "org.codehaus.jackson.annotate.JsonCreator": return ObjectUtil.getMethodValue(null, method, value); case "ca.oson.json.annotation.FieldMapper": ca.oson.json.annotation.FieldMapper fieldMapper = (ca.oson.json.annotation.FieldMapper) annotation; if (fieldMapper.jsonCreator() != null && fieldMapper.jsonCreator() == BOOLEAN.TRUE) { return ObjectUtil.getMethodValue(null, method, value); } } } } String fieldName = null; for (Field field : enumType.getDeclaredFields()) { String name = null; ca.oson.json.annotation.FieldMapper fieldMapper = field .getAnnotation(ca.oson.json.annotation.FieldMapper.class); if (fieldMapper != null) { name = fieldMapper.name(); if (value.equalsIgnoreCase(name)) { fieldName = field.getName(); break; } } else { for (Annotation annotation : field.getAnnotations()) { name = ObjectUtil.getName(annotation); if (value.equalsIgnoreCase(name)) { fieldName = field.getName(); break; } } } } if (fieldName != null) { try { return Enum.valueOf(enumType, fieldName.toUpperCase()); } catch (IllegalArgumentException ex) { } } try { return Enum.valueOf(enumType, value.toUpperCase()); } catch (IllegalArgumentException ex) { } for (Enum enumValue : enumType.getEnumConstants()) { if (enumValue.toString().equalsIgnoreCase(value) || enumValue.name().equalsIgnoreCase(value)) { return enumValue; } } FieldData fieldData = new FieldData(value, Integer.class, true); Integer ordinal = json2Integer(fieldData); if (ordinal != null) { for (Enum enumValue : enumType.getEnumConstants()) { if (enumValue.ordinal() == ordinal) { return enumValue; } } } return null; }
From source file:com.microsoft.azure.management.websites.WebSiteOperationsImpl.java
/** * List the Web Sites in a resource group. * * @param resourceGroupName Required. The name of the resource group. * @param webSiteName Optional. The name of the web site. * @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.//from w w w . ja v a2 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 List Web Sites operation response. */ @Override public WebSiteListResponse list(String resourceGroupName, String webSiteName, WebSiteListParameters parameters) throws IOException, ServiceException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } // 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("parameters", parameters); 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.Web"; url = url + "/"; url = url + "sites"; if (webSiteName != null) { url = url + "/" + URLEncoder.encode(webSiteName, "UTF-8") + "/slots/"; } 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 WebSiteListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteListResponse(); 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)) { WebSite webSiteInstance = new WebSite(); result.getWebSites().add(webSiteInstance); JsonNode propertiesValue = valueValue.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 = valueValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); webSiteInstance.setId(idInstance); } JsonNode nameValue3 = valueValue.get("name"); if (nameValue3 != null && nameValue3 instanceof NullNode == false) { String nameInstance3; nameInstance3 = nameValue3.getTextValue(); webSiteInstance.setName(nameInstance3); } JsonNode locationValue = valueValue.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); webSiteInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) valueValue.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 = valueValue.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.websites.WebSiteOperationsImpl.java
/** * Returns list of all backups which are tracked by the system. * * @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. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations.// w ww .j av a 2 s . c o m * @throws ServiceException Thrown if an unexpected response is found. * @return List of backups for the website. */ @Override public WebSiteGetBackupsResponse listBackups(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, "listBackupsAsync", 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 + "/restore"; 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 WebSiteGetBackupsResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetBackupsResponse(); 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) { BackupItemsEnvelope backupListInstance = new BackupItemsEnvelope(); result.setBackupList(backupListInstance); JsonNode propertiesArray = responseDoc.get("properties"); if (propertiesArray != null && propertiesArray instanceof NullNode == false) { for (JsonNode propertiesValue : ((ArrayNode) propertiesArray)) { BackupItem backupItemInstance = new BackupItem(); backupListInstance.getProperties().add(backupItemInstance); JsonNode storageAccountUrlValue = propertiesValue.get("storageAccountUrl"); if (storageAccountUrlValue != null && storageAccountUrlValue instanceof NullNode == false) { String storageAccountUrlInstance; storageAccountUrlInstance = storageAccountUrlValue.getTextValue(); backupItemInstance.setStorageAccountUrl(storageAccountUrlInstance); } JsonNode blobNameValue = propertiesValue.get("blobName"); if (blobNameValue != null && blobNameValue instanceof NullNode == false) { String blobNameInstance; blobNameInstance = blobNameValue.getTextValue(); backupItemInstance.setBlobName(blobNameInstance); } JsonNode nameValue = propertiesValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); backupItemInstance.setName(nameInstance); } JsonNode statusValue = propertiesValue.get("status"); if (statusValue != null && statusValue instanceof NullNode == false) { BackupItemStatus statusInstance; statusInstance = Enum.valueOf(BackupItemStatus.class, statusValue.getTextValue()); backupItemInstance.setStatus(statusInstance); } JsonNode sizeInBytesValue = propertiesValue.get("sizeInBytes"); if (sizeInBytesValue != null && sizeInBytesValue instanceof NullNode == false) { long sizeInBytesInstance; sizeInBytesInstance = sizeInBytesValue.getLongValue(); backupItemInstance.setSizeInBytes(sizeInBytesInstance); } JsonNode createdValue = propertiesValue.get("created"); if (createdValue != null && createdValue instanceof NullNode == false) { Calendar createdInstance; createdInstance = DatatypeConverter.parseDateTime(createdValue.getTextValue()); backupItemInstance.setCreated(createdInstance); } JsonNode logValue = propertiesValue.get("log"); if (logValue != null && logValue instanceof NullNode == false) { String logInstance; logInstance = logValue.getTextValue(); backupItemInstance.setLog(logInstance); } JsonNode databasesArray = propertiesValue.get("databases"); if (databasesArray != null && databasesArray instanceof NullNode == false) { for (JsonNode databasesValue : ((ArrayNode) databasesArray)) { DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting(); backupItemInstance.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 scheduledValue = propertiesValue.get("scheduled"); if (scheduledValue != null && scheduledValue instanceof NullNode == false) { boolean scheduledInstance; scheduledInstance = scheduledValue.getBooleanValue(); backupItemInstance.setScheduled(scheduledInstance); } JsonNode lastRestoreTimeStampValue = propertiesValue.get("lastRestoreTimeStamp"); if (lastRestoreTimeStampValue != null && lastRestoreTimeStampValue instanceof NullNode == false) { Calendar lastRestoreTimeStampInstance; lastRestoreTimeStampInstance = DatatypeConverter .parseDateTime(lastRestoreTimeStampValue.getTextValue()); backupItemInstance.setLastRestoreTimeStamp(lastRestoreTimeStampInstance); } JsonNode finishedTimeStampValue = propertiesValue.get("finishedTimeStamp"); if (finishedTimeStampValue != null && finishedTimeStampValue instanceof NullNode == false) { Calendar finishedTimeStampInstance; finishedTimeStampInstance = DatatypeConverter .parseDateTime(finishedTimeStampValue.getTextValue()); backupItemInstance.setFinishedTimeStamp(finishedTimeStampInstance); } JsonNode correlationIdValue = propertiesValue.get("correlationId"); if (correlationIdValue != null && correlationIdValue instanceof NullNode == false) { String correlationIdInstance; correlationIdInstance = correlationIdValue.getTextValue(); backupItemInstance.setCorrelationId(correlationIdInstance); } } } JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); backupListInstance.setId(idInstance); } JsonNode nameValue3 = responseDoc.get("name"); if (nameValue3 != null && nameValue3 instanceof NullNode == false) { String nameInstance3; nameInstance3 = nameValue3.getTextValue(); backupListInstance.setName(nameInstance3); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); backupListInstance.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(); backupListInstance.getTags().put(tagsKey, tagsValue); } } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); backupListInstance.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(); } } }
From source file:com.microsoft.azure.management.websites.WebSiteOperationsImpl.java
/** * You can retrieve the connection strings for a web site by issuing an HTTP * GET request, or update them by using HTTP PUT with a request body that * contains the settings to be updated. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx for * more information)//from ww w. j a v a2 s . co m * * @param resourceGroupName Required. The name of the resource group * @param webSiteName Required. The name of the website * @param slotName Optional. The name of the slot of the website * @param parameters Required. The Update Web Site connection strings * 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. * @return List of connection strings for the website. */ @Override public WebSiteConnectionStringsResult updateConnectionStrings(String resourceGroupName, String webSiteName, String slotName, WebSiteUpdateConnectionStringsParameters parameters) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLocation() == null) { throw new NullPointerException("parameters.Location"); } if (parameters.getProperties() == null) { throw new NullPointerException("parameters.Properties"); } // 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, "updateConnectionStringsAsync", 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 + "/config/connectionstrings"; 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 HttpPut httpRequest = new HttpPut(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 webSiteUpdateConnectionStringsParametersValue = objectMapper.createObjectNode(); requestDoc = webSiteUpdateConnectionStringsParametersValue; if (parameters.getProperties() != null) { if (parameters.getProperties() instanceof LazyCollection == false || ((LazyCollection) parameters.getProperties()).isInitialized()) { ArrayNode propertiesArray = objectMapper.createArrayNode(); for (ConnectionStringInfo propertiesItem : parameters.getProperties()) { ObjectNode connStringInfoValue = objectMapper.createObjectNode(); propertiesArray.add(connStringInfoValue); if (propertiesItem.getConnectionString() != null) { ((ObjectNode) connStringInfoValue).put("connectionString", propertiesItem.getConnectionString()); } if (propertiesItem.getName() != null) { ((ObjectNode) connStringInfoValue).put("name", propertiesItem.getName()); } if (propertiesItem.getType() != null) { ((ObjectNode) connStringInfoValue).put("type", propertiesItem.getType().toString()); } } ((ObjectNode) webSiteUpdateConnectionStringsParametersValue).put("properties", propertiesArray); } } if (parameters.getId() != null) { ((ObjectNode) webSiteUpdateConnectionStringsParametersValue).put("id", parameters.getId()); } if (parameters.getName() != null) { ((ObjectNode) webSiteUpdateConnectionStringsParametersValue).put("name", parameters.getName()); } ((ObjectNode) webSiteUpdateConnectionStringsParametersValue).put("location", parameters.getLocation()); if (parameters.getTags() != null) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) webSiteUpdateConnectionStringsParametersValue).put("tags", tagsDictionary); } if (parameters.getType() != null) { ((ObjectNode) webSiteUpdateConnectionStringsParametersValue).put("type", parameters.getType()); } 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) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result WebSiteConnectionStringsResult result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteConnectionStringsResult(); 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) { WebSiteConnectionStringsEnvelope resourceInstance = new WebSiteConnectionStringsEnvelope(); result.setResource(resourceInstance); JsonNode propertiesArray2 = responseDoc.get("properties"); if (propertiesArray2 != null && propertiesArray2 instanceof NullNode == false) { for (JsonNode propertiesValue : ((ArrayNode) propertiesArray2)) { ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo(); resourceInstance.getProperties().add(connStringInfoInstance); JsonNode connectionStringValue = propertiesValue.get("connectionString"); if (connectionStringValue != null && connectionStringValue instanceof NullNode == false) { String connectionStringInstance; connectionStringInstance = connectionStringValue.getTextValue(); connStringInfoInstance.setConnectionString(connectionStringInstance); } JsonNode nameValue = propertiesValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); connStringInfoInstance.setName(nameInstance); } JsonNode typeValue = propertiesValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { DatabaseServerType typeInstance; typeInstance = Enum.valueOf(DatabaseServerType.class, typeValue.getTextValue()); connStringInfoInstance.setType(typeInstance); } } } JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); resourceInstance.setId(idInstance); } JsonNode nameValue2 = responseDoc.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); resourceInstance.setName(nameInstance2); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); resourceInstance.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 tagsKey2 = property.getKey(); String tagsValue2 = property.getValue().getTextValue(); resourceInstance.getTags().put(tagsKey2, tagsValue2); } } JsonNode typeValue2 = responseDoc.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); resourceInstance.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.clark.func.Functions.java
/** * Checks if the specified name is a valid <code>enum</code> for the class. * <p>/* w w w.j av a 2s .c om*/ * This method differs from {@link Enum#valueOf} in that checks if the name * is a valid enum without needing to catch the exception. * * @param enumClass * the class of the <code>enum</code> to get, not null * @param enumName * the enum name * @return true if the enum name is valid, otherwise false */ public static <E extends Enum<E>> boolean isValidEnum(Class<E> enumClass, String enumName) { try { Enum.valueOf(enumClass, enumName); return true; } catch (IllegalArgumentException ex) { return false; } }
From source file:com.clark.func.Functions.java
/** * Gets the <code>enum</code> for the class, returning <code>null</code> if * not found./* w ww . j a va 2 s. co m*/ * <p> * This method differs from {@link Enum#valueOf} in that it does not throw * an exception for an invalid enum name. * * @param enumClass * the class of the <code>enum</code> to get, not null * @param enumName * the enum name * @return the enum or null if not found */ public static <E extends Enum<E>> E getEnum(Class<E> enumClass, String enumName) { try { return Enum.valueOf(enumClass, enumName); } catch (IllegalArgumentException ex) { return null; } }