Java create azure web app
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的更多相关文章
- Azure Web App (一)发布你的Net Core Web 项目
一,引言 今天我们看一下Azure上的一个服务-----Web 应用,我们都知道云计算的三大模式:Iaas(基础设施即服务),Paas(平台即服务),Saas(软件即服务). Iass,其实就是虚拟主 ...
- 如何用Azure Web App Services接入微信公众号
注:本文提到的代码示例下载地址>如何用Azure Web App Services接入微信公众号 如何用Azure Web App Services接入微信公众号 简介 此示例演示如何创建Azu ...
- 远程调试 Azure Web App
当我们将 Web App 部署在 Azure 上时,如果能够实现远程调试,将会极大的提高我们修复 bug 的效率.Visual Studio 一贯以功能强大.易用著称,当然可以实现基于 Azure 应 ...
- Windows Azure HandBook (7) 基于Azure Web App的企业官网改造
<Windows Azure Platform 系列文章目录> 1.用户场景: C公司是全球大型跨国连锁餐厅,在世界上大约拥有3万间分店.其IT系统主要部署其海外数据中心,或者租用其他ID ...
- java.lang.IllegalStateException:Web app root system property already set to different value 错误原因及解决 Log4j
Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口 服务器.NT的事件记录器.UNIX Syslog守护进程等: ...
- 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 ...
- Windows Azure Web Site (18) Azure Web App设置MIME
<Windows Azure Platform 系列文章目录> 在笔者之前的文章中,介绍了我们在使用Azure Web App,可以把静态资源保存到Azure Storage中: Wind ...
- VS 远程调试 Azure Web App
如果能够远程调试部署在 Azure 上的 Web App,将会极大的提高我们修复 bug 的效率.Visual Studio 一贯以功能强大.好用著称,当然可以通吃基于 Azure 应用的创建.发布和 ...
- Azure Web App (二)使用部署槽切换部署环境
一,引言 前天我们将到使用Azure的 Pass 服务 “Web App” 去部署我们的.NET Core Web项目,也同时有介绍到如何在VS中配置登陆中国区的Azure账号,今天接着讲,我们部署完 ...
随机推荐
- Open XML 检索 EXCEL
1.Excel 隐藏行判断 项目的 Hidden 属性不为 null,且 Hidden 属性的值为 True var itemList = ws.Descendants<Row>(). W ...
- 实例解说Linux命令行uniq
Linux命令uniq的作用是过滤重复部分显示文件内容,这个命令读取输入文件,并比较相邻的行.在正常情况下,第二个及以后更多个重复行将被删去,行比较是根据所用字符集的排序序列进行的.该命令加工后的结果 ...
- C51串口的SCON寄存器及工作…
原文地址:C51串口的SCON寄存器及工作方式作者:batistar 一,串行口控制寄存器SCON 它用于定义串行口的工作方式及实施接收和发送控制.字节地址为98H,其各位定义如下表: D7 D6 D ...
- Enumeration & Class & Structure
[Enumeration] 1.当一个枚举值类型已经确定后,可以使用shorter dot syntax来赋予其它值: 2.对一个枚举值switch的时候也可以使用short dot syntax: ...
- xcode中的预定义宏
[xcode中的预定义宏] 1.SRCROOT,是定义本target的proj的路径. 2.OBJROOT,对象文件根路径,对象文件(即obj文件)就是中间的临时文件.中间文件输出目录的名字以“pro ...
- pandas 中的 多条件分割, list 排序
main_comment_num_3m and avg_group_order_cnt_12m = 0.863230main_comment_score_1m and avg_group_order_ ...
- 用Linq取两个数组的差集
两个数组,取其差集,用Linq做比较方便,效率也比较高,具体如下示例 有两个数组list1 和list2 ,如下 List<int> list1 = new List<int> ...
- Oracle数据库之日期函数
今天给大家介绍一下oracle数据中的日期函数的用法.废话不多说,我们看一下oracle给我们提供了那些函数? 1.sysdate 用途:获取当前系统时间. 2.to_date('字符类型','日期类 ...
- VirtualBox安装增强功能(Linux)
我们在安装之前,必须得先安装好它所需要的依赖包,不然安装过程必定会出现错误! 一.安装依赖包 #yum install kernel-headers #yum install kernel-devel ...
- 【Head First Java 读书笔记】(五)编写程序
第五章 编写程序 伪码:伪码能帮你专注于逻辑而不需要顾虑到程序语法 测试码:测试用的程序代码 真实码:实际代码 伪码 伪码是介于真正的java程序与正常英语之间的一种语言.伪码大致包括3部分:实例变量 ...