Java Create Azure Web App

Source: Internet
Author: User
Tags app service configuration settings dname pkcs12 rfc self signed certificate pfx file

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"

< span class= "tag" >< span class= "tag" >< span class= "tag" >convert the PFX file into JKS

< span class= "tag" >< span class= "tag" >< span class= "tag" ><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

< span class= "tag" ><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 classCREATEAZUREVM {Private StaticString URI ="https://management.core.windows.net/"; Private StaticString SubscriptionId ="****9"; Private StaticString keystorelocation ="D:\\javajks.jks"; Private StaticString Keystorepassword ="123Aking"; //Define web App parameter values.    Private StaticString Webappname ="jamborjavacrate"; Private StaticString DomainName =". Azurewebsites.net"; Private StaticString Webspacename =Webspacenames.eastasiawebspace; Private StaticString Appserviceplanname ="Jamborplan";  Public Static voidMain (string[] args) throws IOException, URISyntaxException, Serviceexception, Parserconfigurat Ionexception, Saxexception, Exception {//Create web AppCreatewebapp (); }      Private Static voidCreatewebapp () throws Exception {//specify configuration settings for the APP Service management client.Configuration config =Managementconfiguration.configure (NewUri (URI), SubscriptionId, Keystorelocation,//Path to the JKS fileKeystorepassword,//Password for the JKS fileKeystoretype.jks//Flag that is 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 =Newwebhostingplancreateparameters ();        Appserviceplanparams.setname (Appserviceplanname);        Appserviceplanparams.setsku (Skuoptions.free);        Webappmanagementclient.getwebhostingplansoperations (). Create (Webspacename, appserviceplanparams); //Set webspace parameters.Websitecreateparameters.webspacedetails webspacedetails =Newwebsitecreateparameters.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 =Newwebsitecreateparameters ();        Webappcreateparameters.setname (Webappname);        Webappcreateparameters.setserverfarm (Appserviceplanname);        Webappcreateparameters.setwebspace (webspacedetails); //Set usage metrics attributes.Websitegetusagemetricsresponse.usagemetric usagemetric =Newwebsitegetusagemetricsresponse.usagemetric ();        Usagemetric.setsitemode (Websitemode.basic);        Usagemetric.setcomputemode (websitecomputemode.shared); //Define the Web App object.Arraylist<string> Fullwebappname =NewArraylist<string>(); Fullwebappname.add (Webappname+domainName); WebSite webApp=NewWebSite ();        Webapp.sethostnames (Fullwebappname); //Create the Web App.Websitecreateresponse Webappcreateresponse =webappmanagementclient.getwebsitesoperations (). Create (Webspacename, webappcreateparameters); //Output The HTTP status code of the response; 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 is 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.