Java tutorial
/** * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.microsoft.windowsazure.management.website; import com.microsoft.windowsazure.Configuration; import com.microsoft.windowsazure.MockIntegrationTestBase; import com.microsoft.windowsazure.core.Builder; import com.microsoft.windowsazure.core.Builder.Alteration; import com.microsoft.windowsazure.core.Builder.Registry; import com.microsoft.windowsazure.core.ServiceClient; import com.microsoft.windowsazure.core.pipeline.apache.ApacheConfigurationProperties; import com.microsoft.windowsazure.core.utils.KeyStoreType; import com.microsoft.windowsazure.management.configuration.ManagementConfiguration; import com.microsoft.windowsazure.management.websites.WebSiteManagementClient; import com.microsoft.windowsazure.management.websites.WebSiteManagementService; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.filter.LoggingFilter; import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; import java.net.URI; import java.util.Map; import java.util.concurrent.Callable; public abstract class WebSiteManagementIntegrationTestBase extends MockIntegrationTestBase { protected static String testWebsitePrefix = "azuresdktestwebsite"; protected static WebSiteManagementClient webSiteManagementClient; protected static void createService() throws Exception { // reinitialize configuration from known state Configuration config = createConfiguration(); config.setProperty(ApacheConfigurationProperties.PROPERTY_RETRY_HANDLER, new DefaultHttpRequestRetryHandler()); // add LoggingFilter to any pipeline that is created Registry builder = (Registry) config.getBuilder(); builder.alter(WebSiteManagementClient.class, Client.class, new Alteration<Client>() { @Override public Client alter(String profile, Client client, Builder builder, Map<String, Object> properties) { client.addFilter(new LoggingFilter()); return client; } }); webSiteManagementClient = WebSiteManagementService.create(config); addClient((ServiceClient<?>) webSiteManagementClient, new Callable<Void>() { @Override public Void call() throws Exception { createService(); return null; } }); } protected static Configuration createConfiguration() throws Exception { String baseUri = System.getenv(ManagementConfiguration.URI); if (IS_MOCKED) { return ManagementConfiguration.configure(new URI(MOCK_URI), MOCK_SUBSCRIPTION, null, null, null); } else { return ManagementConfiguration.configure(baseUri != null ? new URI(baseUri) : null, System.getenv(ManagementConfiguration.SUBSCRIPTION_ID), System.getenv(ManagementConfiguration.KEYSTORE_PATH), System.getenv(ManagementConfiguration.KEYSTORE_PASSWORD), KeyStoreType.fromString(System.getenv(ManagementConfiguration.KEYSTORE_TYPE))); } } }