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. MIDL相关

    根据MIDL的语义, 指针总被认为是指向单一元素而不是数组.因此以上方法中只有串中的第一个字符被封送.为此,MIDL引入了[string]特性来说明传递的是一个字符串 http://www.cnblo ...

  2. Make Cents

    Every year, an elephant qualifies to the Arab Collegiate Programming Competition. He graduated this ...

  3. Redis搭建(二):主从复制

    一.引言 Redis有三种集群模式: 第一个就是主从模式 第二种“哨兵”模式,在Redis 2.6版本开始提供,2.8版本稳定 第三种是Cluster集群模式,在Redis 3.x以后的版本才增加进来 ...

  4. 当一个SQL语句同时出现了where,group by,having,order by的时候,执行顺序和编写顺序

    当一个查询语句同时出现了where,group by,having,order by的时候,执行顺序和编写顺序 1.执行where xx对全表数据做筛选,返回第1个结果集. 2.针对第1个结果集使用g ...

  5. dojo模块化开发

    转自https://www.cnblogs.com/sharpest/p/6242801.html

  6. wampserver无法打开http://127.0.0.1/

    如果你更换了端口号那么你就应该把相应的端口号也带上,比如localhost:8080(或127.0.0.1:8080)这样应该就可以了,因为只有80端口是默认才不用输入的.

  7. Docker学习笔记_安装和使用Rabbitmq

    一.准备 1.宿主机OS:Win10 64bit 2.虚拟机OS:Ubuntu18.04 3.账号:docker 4.虚拟机IP:192.168.8.25 二.安装 1.搜索镜像            ...

  8. Linux Valgrind命令

    一.简介 C/C++程序,最常见的错误之一就是内存泄露.Valgrind 是一款 Linux下的内存调试工具,它可以对编译后的二进制程序进行内存使用监测找出内存泄漏问题. Valgrind通常包括如下 ...

  9. python之yield函数

    yield的英文单词意思是生产,刚接触Python的时候感到非常困惑,一直没弄明白yield的用法. 只是粗略的知道yield可以用来为一个函数返回值塞数据,比如下面的例子: def addlist( ...

  10. 使用 Sentry集中处理错误

    Sentry的简介 Sentry 是一个实时的事件日志和聚合平台,基于 Django 构建. Sentry 可以帮助你将程序的所有 exception 自动记录下来,处理 exception 是每个程 ...