Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Version 1.0
Date: 10.04.2010
Avkash Chauhan
avkashc@microsoft.com
1|W indows Azur e L earni ng S eri es 2 0 1 0
Contents
a. Tomcat
We will be using version 6.0
http://tomcat.apache.org/download-60.cgi
Please use ZIP based deployment instead of MSI Installation version of Tomcat (This is
because the installer is missing a bunch of files in BIN folder which can cause problem
during building the TOMCAT solution)
In this case I used either 32bit or 64bit Windows Zip
Now verify by opening ZIP that you have these files in the BIN folder
b. JAVA Runtime
http://www.java.com/en/download/manual.jsp
Checkpoint:
Now we will have these 3 files:
Installation:
Pre-requisite:
1. Create a folder name Tomcat-Azure where we will install all of these packages
2. I created C:\Tomcat-Azure
Tomcat Installation:
Because we downloaded the ZIP binaries so we will just unzip tomcat in our Tomcat-Azure
folder.
In the above dialog bog select Change destination Folder and set our desired folder as below:
10 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
You will prompt by UAC to accept the installation so please accept it.
11 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Based on above you can verify that all of our 3 components are successfully installed.
12 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Opening the installation folder for tomcat accelerator solution we see the following files:
If you have VS2010/VS2008 or VS2010 Web Developer Express in your machine, please open the tomcat
solution file Tomcat.sln
13 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
14 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
15 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
response = RunCommand(Environment.GetEnvironmentVariable("RoleRoot") +
@"\approot\setupTomcat.bat", tomcatLocation, tomcatPort,
Environment.GetEnvironmentVariable("RoleRoot") + @"\approot");
// In the line below we are actually launching the JAVA.EXE process to kickstart the
TOMCAT
response = StartTomcatProcess(tomcatLocation);
}
1. In this function as you can see setupTomcat.bat is called. This file actually
copy all the Tomcat Binaries from E:\approot to
C:\Resources\Directory\<Tomcat_workerrole_folder_on_Cloud>
@echo off
%3\TomcatConfigManager.exe %catalina_home%\conf\server.xml %2
2. As you can see in this batch file, tomcat is copying from E:\ to C:\<Azure
runtime folder for roles>
3. This is the function responsible for tomcat config as well using the
CONF\server.xml (in Tomcat server.xml is equivalent to IIS web.config)
16 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Tomcat comes with all the command line build scripts. If you see the Tomcat solution
accelerator you will find these 3 batch files:
1. Buildme.bat
2. Runme.bat
3. Packme.bat
Pre requisite:
1. Verify that you have Azure Cloud Tools installed in your machine
C:\Program Files\Windows Azure SDK\v1.2
To check this please open command window in admin mode:
17 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
18 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
The error message is very much distracting. This error is caused because you do not have all files in your
Tomcat BIN folder. If you look your Tomcat BIN folder you will that there are only 4 files as below:
And you have only 4 files because you have used Tomcat installation from the link below instead of
xcopy deployment which I mentioned earlier.
To solve this problem you must have all the required files in your bin folder and this will occur only when
you have deployed Tomcat form the 32-bit Windows zip or 64-bit Windows zip from the link above.
Now you can actually look into the tomcat folder for new created files and folders and understand what
the buildme.bat actually did.
20 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
. And if you look inside Tomcat folder you will see whole tomcat installation and Java run time (seen
below as jre1.5.0_19 folder) is included in this folder.
21 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
22 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
So if you need to make changes to Tomcat you are going to make changes at folder
C:\Tomcat-Azure\TomcatSetup_x64\Tomcat\TomcatWorkerRole\bin\Release\tomcat
Now your Azure tomcat project contains everything needed to run JAVA on Azure.
Download Link
You can download the full solution from the link below which contained for Tomcat and Java within
Tomcat Solution Accelerator so you dont need to install JAVA and TOMCAT on your machine.
<LINK>
23 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
The solution execution is distributed into two parts. First we will run the Tomcat solution in
Development Fabric mode and once all if working well we will publish the solution to Windows
Azure portal so we can test on cloud. Lets start with the first one.
You can verify in your command window that JRE_HOME is available as below:
3. If you dont have JRE_HOME set in your command windows please setup a new Environment
variable as below:
24 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
You will see some activity in your task tray as below (We will there a little later..)
After some progress you will see a new CMD windows open with the content as below and
25 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Please select Allow access button in the above dialog box for JAVA.EXE to run.
26 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
While opening the Development Fabric UI and looking the role command window you will see the
following highlighted error:
27 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
So lets start the Development Storage by selecting the Start Development Storage service in
the same Azure Simulation Environment dialog box as below:
28 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
After that verify that both development fabric and storage is running:
Now you can kill the current development fabric deployment (in this case deployment(6) as shown in
the image below) by selecting the Remove Service Deployment icon in the development fabric UI:
29 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Now as we have both development fabric and storage running lets launch Runme.bat again:
The final runme.bat UI looks as below and you can see it is little different than previous we saw:
You can also see that this time we dont have the following YELLOW highlighted message in the Runme
window:
30 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Above you can see that there is no error in the role command window. Now you can launch the Tomcat
in your IE windows as there were no errors.
Selecting Service details will give the list of roles and there IP address and port number to test the
service locally. In this case we will open browser with 127.0.0.1:81 to check the Tomcat:
Tomcat web Address: http://127.0.0.1:81
31 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Launching browser with http://127.0.0.1:81/ and you can verify that tomcat is running in local
development fabric as below:
32 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Based on above details we can find the Tomcat runtime location as below:
C:\Users\avkashc\AppData\Local\dftmp\s0\deployment(22)\res\deployment(22).TomcatRole.TomcatW
orKerRole.0\directory\TomcatLocation
Now opening the above folder can see the exact Tomcat folder as we saw in our CSPKG:
33 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
So when you add more code to your Tomcat service or setup logging or do anything with Tomcat you
will be looking at the folder above for the logs or results.
34 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
I have enabled the manager role and then added a user name manager as below to manage the
tomcat:
Now when I run the service I can administrator to tomcat using the .
35 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
And you can deploy Java solution in the form of JAR or WAR using the Deploy section of the
management windows:
When you try to deploy a JAR file here the only issue I will see is that this deployment will be done on a
location which will be active only during the life of Azure instance running. If by any ready Azure
instance rebooted or you have suspended and then restarted you will need to redeploy it.
In Development Fabric the JAR or WAR deployment will occur as below:
36 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
We can find the JAR or WAR deployment location from the above Development Fabric UI window:
C:\Users\avkashc\AppData\Local\dftmp\s0\deployment(39)\res\deployment(39).TomcatRole.TomcatW
orKerRole.0\directory\TomcatLocation\webapps
Thats why it is best to have your target Java solution already in webapps folder ready and tested so
when you deploy on Azure it just runs over there.
37 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
38 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
If I want to remove this warning, you can set this environment variable
_CSPACK_FORCE_NOENCRYPT_ to false as below:
You can also see in the above screen that running Packme.bat does not show the warning as well.
Now we can verify CSPKG and CSCFG files in the same folder as below also you can see the base package
size if around 53MB:
39 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
After clicking Deploy button you will see another web page to select the CSPKG and CSCFG file as
below:
In the above windows please select the Browse button and you will asked to select the CSPKG file so
go to your TOMCAT folder where Tomcat.cspkg exist and select the file as below:
40 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
You will see that Tomcat.cspkg file is available in the input box as below:
41 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
You will see that ServiceConfiguration.cscfg file is available in the input box as below:
Finally you can give the label for your deployment and select deploy.
42 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
It might take some time to upload the package on cloud because of its size (around 53MB) so keep
patience while upload is being done and after a while you will see the following web page on portal:
43 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Please Select Run on above windows to start the Service you will see the progress as below:
44 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
After the Enabling deployment is done you will that your Tomcat Worker Role is in initializing stage at
this time:
Now after a little while you will see that your service is ready as below:
45 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Now you can launch the service using the Web Site URL from the above ready window:
46 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
47 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
The diagnostics is divided into two sections: Error logging and the log visualization. Lets start with the
first one:
Error Logging:
In Tomcat you can do two types of logging:
1. JDL Logging (Described here)
2. Log4J custom logging (Please visit the link below to setup)
For more info please visit:
http://tomcat.apache.org/tomcat-5.5-doc/logging.html
I will give you quick details about JDK logging here which just needs to make modification into your
logging configuration file.
The default logging.properties specifies a ConsoleHandler for routing logging to stdout and also a
FileHandler. A handler's log level threshold can be set using SEVERE, WARNING, INFO, CONFIG, FINE,
FINER, FINEST or ALL. The logging.properties shipped with JDK is set to INFO.
Open logging.properties located @
C:\Tomcat-Azure\TomcatSetup_x64\Tomcat\TomcatWorkerRole\bin\Release\tomcat\conf
Original looks likes as below:
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.FileHandler.prefix = manager.
4host-manager.org.apache.juli.FileHandler.level = FINE
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.FileHandler.prefix = host-manager.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
48 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
49 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
50 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Now you can open catalina.YYYY-MM-DD.log file to verify the logging details based on the configuration
we have just set. For example:
While running Tomcat on Azure you may want to collect these logs as well. Here is the information you
could use to collect the Tomcat logs and a method you can try:
Location for the Log:
51 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
4. Now use the Java code the list all files in this folder and setup a hypertext link for each file
for its own
5. As all files are TEXT type so clicking on each file will show the low content immediately
52 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Mostly JAVA solution are deployed as JAR/WAR files which are compressed zip file containing full
solution in it or solution distributed in multiple folders within Tomcat solution folder. The solutions are
mostly existed at webapps folder as below:
In the image below you can see I have added a solution name TestDates within webapps folder
Now we will look for our solution location in runtime. To do this open the Development Fabric UI as
below and get the Tomcat execution folder from the highlighted are:
Now when you will open the above folder you will see our solution as well:
54 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Opening the folder you will see your application is deployed as well:
Now when you will package your solution to Azure now you can run your solution same way on cloud.
55 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Based on above details you could run Tomcat on Window Azure over HTTP (port 80), what if you decide
to run it on port HTTPS (port 443) as more security to it as other websites.
Adding HTTPS security to any website is basically a certificate based security based on PKI security
concept and to start with you first need to obtain a valid certificate for client and server validation
from a Certificate Authority i.e. Verisign or Go Daddy or Thawte etc. I will not be discussing here
who you will choose and how you will get this certificate. I would assume that you know the concepts
and have certificate ready to add HTTPS security to your Tomcat service.
You will be given a Certificate to verify your domain name such as www.yourdomain.com so the
certificate will be linked to your domain this way.
The process of adding SSL to tomcat is defined in the following steps:
1.
2.
3.
4.
57 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
58 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Once the solution is open please select the TomcatWorkerRole and open its properties dialog box as
below:
59 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Now please select Endpoints tab and you will see the windows as below:
In the Endpoints tab please select Add Endpoint button and add TCP endpoint with port 443.
For Tomcat the HTTPS endpoint defined as a tcp endpoint like HTTP. Setting protocol to http or
https means that Azure will perform an http.sys reservation for that endpoint on the appropriate port.
Since Tomcat does not use http.sys internally, we needed to make sure to model tomcat HTTPS
endpoints as tcp.
60 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Now to make things in full perspective, we already know that Tomcat already has SSL certificates in its
keystore.bin, so using TCP endpoint with port 443 will work even there is no certificate associated with
it.
Now please save the project and verify that ServiceDefinition.cdef have the following data:
61 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
Now please select Manage and you will see the following screen:
62 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
You can also see the list of certificates install on server as below:
<StoredCertificates>
<StoredCertificate name="YourIntermediateSSL"
certificateId="sha1:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" storeName="CA"
configurationLevel="System" />
<StoredCertificate name="YourRootSSL"
certificateId="sha1:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4" storeName="CA"
configurationLevel="System" />
<StoredCertificate name="Your_Domain_SSL"
certificateId="sha1:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5" storeName="My"
configurationLevel="System" />
</StoredCertificates>
Now when you publish your service to Azure portal these certificates will be used to configure your
Tomcat service and you will be able to use SSL with your Tomcat service.
63 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
64 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0
65 | W i n d o w s A z u r e L e a r n i n g S e r i e s 2 0 1 0