Java create azure web app

來源:互聯網
上載者:User

標籤:

create a certificate

<java-install-dir>/bin/

keytool -genkey -alias <keystore-id>
-keystore <cert-store-dir>/<cert-file-name>.pfx -storepass <password>
-validity 3650 -keyalg RSA -keysize 2048 -storetype pkcs12
-dname "CN=Self Signed Certificate 20141118170652"

eg: keytool -genkey -alias javacer -keystore d:/java.pfx -storepass 123Aking -validity 3650 -keyalg RSA -keysize 2048 -storetype pkcs12
-dname "CN=Self Signed Certificate 20141118170652"

 

Convert the PFX file into JKS

<java-install-dir>/bin/keytool.exe -importkeystore
-srckeystore <cert-store-dir>/<cert-file-name>.pfx
-destkeystore <cert-store-dir>/<cert-file-name>.jks
-srcstoretype pkcs12 -deststoretype JKS

eg:keytool.exe -importkeystore -srckeystore d:/java.pfx
-destkeystore d:/javajks.jks
-srcstoretype pkcs12 -deststoretype JKS

to create cer file

<java-install-dir>/bin/keytool -export -alias <keystore-id>
-storetype pkcs12 -keystore <cert-store-dir>/<cert-file-name>.pfx
-storepass <password> -rfc -file <cert-store-dir>/<cert-file-name>.cer

eg: keytool -export -alias javacer
-storetype pkcs12 -keystore d:/java.pfx
-storepass 123Aking -rfc -file d:/javacer.cer

 

package common;import java.net.URI;import java.util.ArrayList;// Imports for Exceptionsimport java.io.IOException;import java.net.URISyntaxException;import javax.xml.parsers.ParserConfigurationException;import com.microsoft.windowsazure.exception.ServiceException;import org.xml.sax.SAXException;// Imports for Azure App Service management configurationimport com.microsoft.windowsazure.Configuration;import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;// Service management imports for App Service Web Apps creationimport com.microsoft.windowsazure.management.websites.*;import com.microsoft.windowsazure.management.websites.models.*;// Imports for authenticationimport com.microsoft.windowsazure.core.utils.KeyStoreType;import com.microsoft.windowsazure.management.websites.models.WebSpaceNames;public class createazurevm {    private static String uri = "https://management.core.windows.net/";    private static String subscriptionId = "****9";    private static String keyStoreLocation = "D:\\javajks.jks";    private static String keyStorePassword = "123Aking";    // Define web app parameter values.    private static String webAppName = "jamborjavacrate";    private static String domainName = ".azurewebsites.net";    private static String webSpaceName = WebSpaceNames.EASTASIAWEBSPACE;    private static String appServicePlanName = "jamborplan";        public static void main(String[] args)            throws IOException, URISyntaxException, ServiceException,            ParserConfigurationException, SAXException, Exception {            // Create web app            createWebApp();        }      private static void createWebApp() throws Exception {        // Specify configuration settings for the App Service management client.        Configuration config = ManagementConfiguration.configure(            new URI(uri),            subscriptionId,            keyStoreLocation,  // Path to the JKS file            keyStorePassword,  // Password for the JKS file            KeyStoreType.jks   // Flag that you are using a JKS keystore        );        // Create the App Service Web Apps management client to call Azure APIs        // and pass it the App Service management configuration object.        WebSiteManagementClient webAppManagementClient = WebSiteManagementService.create(config);        // Create an App Service plan for the web app with the specified parameters.        WebHostingPlanCreateParameters appServicePlanParams = new WebHostingPlanCreateParameters();        appServicePlanParams.setName(appServicePlanName);        appServicePlanParams.setSKU(SkuOptions.Free);        webAppManagementClient.getWebHostingPlansOperations().create(webSpaceName, appServicePlanParams);        // Set webspace parameters.        WebSiteCreateParameters.WebSpaceDetails webSpaceDetails = new WebSiteCreateParameters.WebSpaceDetails();        webSpaceDetails.setGeoRegion(GeoRegionNames.WESTUS);        webSpaceDetails.setPlan(WebSpacePlanNames.VIRTUALDEDICATEDPLAN);        webSpaceDetails.setName(webSpaceName);        // Set web app parameters.        // Note that the server farm name takes the Azure App Service plan name.        WebSiteCreateParameters webAppCreateParameters = new WebSiteCreateParameters();        webAppCreateParameters.setName(webAppName);        webAppCreateParameters.setServerFarm(appServicePlanName);        webAppCreateParameters.setWebSpace(webSpaceDetails);        // Set usage metrics attributes.        WebSiteGetUsageMetricsResponse.UsageMetric usageMetric = new WebSiteGetUsageMetricsResponse.UsageMetric();        usageMetric.setSiteMode(WebSiteMode.Basic);        usageMetric.setComputeMode(WebSiteComputeMode.Shared);        // Define the web app object.        ArrayList<String> fullWebAppName = new ArrayList<String>();        fullWebAppName.add(webAppName + domainName);        WebSite webApp = new WebSite();        webApp.setHostNames(fullWebAppName);        // Create the web app.        WebSiteCreateResponse webAppCreateResponse = webAppManagementClient.getWebSitesOperations().create(webSpaceName, webAppCreateParameters);        // Output the HTTP status code of the response; 200 indicates the request succeeded; 4xx indicates failure.        System.out.println("----------");        System.out.println("Web app created - HTTP response " + webAppCreateResponse.getStatusCode() + "\n");        // Output the name of the web app that this application created.        String shinyNewWebAppName = webAppCreateResponse.getWebSite().getName();        System.out.println("----------\n");        System.out.println("Name of web app created: " + shinyNewWebAppName + "\n");        System.out.println("----------\n");    }}

 

Java create azure web app

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.