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 Exceptions
import 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 configuration
import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration; // Service management imports for App Service Web Apps creation
import com.microsoft.windowsazure.management.websites.*;
import com.microsoft.windowsazure.management.websites.models.*; // Imports for authentication
import 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的更多相关文章

  1. Azure Web App (一)发布你的Net Core Web 项目

    一,引言 今天我们看一下Azure上的一个服务-----Web 应用,我们都知道云计算的三大模式:Iaas(基础设施即服务),Paas(平台即服务),Saas(软件即服务). Iass,其实就是虚拟主 ...

  2. 如何用Azure Web App Services接入微信公众号

    注:本文提到的代码示例下载地址>如何用Azure Web App Services接入微信公众号 如何用Azure Web App Services接入微信公众号 简介 此示例演示如何创建Azu ...

  3. 远程调试 Azure Web App

    当我们将 Web App 部署在 Azure 上时,如果能够实现远程调试,将会极大的提高我们修复 bug 的效率.Visual Studio 一贯以功能强大.易用著称,当然可以实现基于 Azure 应 ...

  4. Windows Azure HandBook (7) 基于Azure Web App的企业官网改造

    <Windows Azure Platform 系列文章目录> 1.用户场景: C公司是全球大型跨国连锁餐厅,在世界上大约拥有3万间分店.其IT系统主要部署其海外数据中心,或者租用其他ID ...

  5. java.lang.IllegalStateException:Web app root system property already set to different value 错误原因及解决 Log4j

    Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口 服务器.NT的事件记录器.UNIX Syslog守护进程等: ...

  6. 004.Create a web app with ASP.NET Core MVC using Visual Studio on Windows --【在 windows上用VS创建mvc web app】

    Create a web app with ASP.NET Core MVC using Visual Studio on Windows 在 windows上用VS创建mvc web app 201 ...

  7. Windows Azure Web Site (18) Azure Web App设置MIME

    <Windows Azure Platform 系列文章目录> 在笔者之前的文章中,介绍了我们在使用Azure Web App,可以把静态资源保存到Azure Storage中: Wind ...

  8. VS 远程调试 Azure Web App

    如果能够远程调试部署在 Azure 上的 Web App,将会极大的提高我们修复 bug 的效率.Visual Studio 一贯以功能强大.好用著称,当然可以通吃基于 Azure 应用的创建.发布和 ...

  9. Azure Web App (二)使用部署槽切换部署环境

    一,引言 前天我们将到使用Azure的 Pass 服务 “Web App” 去部署我们的.NET Core Web项目,也同时有介绍到如何在VS中配置登陆中国区的Azure账号,今天接着讲,我们部署完 ...

随机推荐

  1. 02-26C#三级省市区ajax联动控件,利用UpdatePanel,以及页面取值

    第一步:设置界面 <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PCAC ...

  2. 一些c++

    1.static 静态局部对象: 一旦被创建,在程序结束前都不会被撤销.当定义静态局部对象的函数结束时,静态局部对象不会撤销. 2.内联函数: 避免函数调用的开销. 在函数返回类型前加上关键字 inl ...

  3. 【知识碎片】Asp.Net 篇

    51.app.config 连接字符串 <?xml version="1.0" encoding="utf-8"?> <configurati ...

  4. 嵌入式Linux启动配置文件及脚本分…

    使用Busybox制作根文件系统时,/etc目录非常重要,它包含了嵌入式Linux启动所需的配置文件及脚本.由于init进程,或者说linuxrc程序会解析inittab文件,因此就从/etc/ini ...

  5. windows 共存多个位数不同的jdk时,eclipse的报错对应措施

    1. 判断当前jdk的位数 # java -version java version "1.6.0_26" Java(TM) SE Runtime Environment (bui ...

  6. PC 微信页面倒计时代码 safari不兼容date的问题

    PC: 1.html页面: <div class="aTime"> <em id="t_d"></em> <em id ...

  7. spring中二个重要点

    spring核心主要两部分: (1)aop: 面向切面编程,扩展功能不是修改源代码实现 (2)ioc: 控制反转

  8. Asp.net 动态添加Meta标签

    下面代码动态设置浏览器文档模式 HtmlHead head = (HtmlHead)Page.Header; HtmlMeta contentType = new HtmlMeta();//显示字符集 ...

  9. 4-3 线程安全性-原子性-synchronized

    原子性它提供了互斥访问,同一时刻只能有一个线程来对它进行操作.能保证同一时刻只有一个线程来对其进行操作的,除了Atomic包之外,还有锁.JDK提供锁主要分两种,synchronized是一个Java ...

  10. 【HDU4303】Hourai Jeweled

    题意 有一棵n个结点的树,每个结点都有一个值,没一条边都有一个颜色.如果某条路径上,相邻的边颜色不同,那么把这路径上所有的点的值加起来. 输出所有符合条件的路径上值的和. n<=300000. ...