Hot questions for Using Azure in web applications

Top Java Programmings / Azure / web applications

Question:

I have some Azure Java WebApp. "Newest Tomcat 8" is the application container that we use. The option "Always On" is enable for our web app.

Every day tomcat shutdown gracefully:

17-Dec-2015 07:07:32.867 INFO [Thread-114] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-127.0.0.1-1170"]
17-Dec-2015 07:07:32.976 INFO [Thread-114] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina

When we do the first access in our applications tomcat automatic startup

17-Dec-2015 09:45:47.802 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 498942 ms

this happen every day.

has anyone else encountered this issue? How i can prevent tomcat to shutdown?

Thanks in advance!


Answer:

As I known, It seems to be not the Azure issue. If you were enable the option Always On for your webapp, Azure would not unload the webapp if webapp was idle for some period of time.

Here is the description for the option Always On in the Azure offical document https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/.

Always On. By default, web apps are unloaded if they are idle for some period of time. This lets the system conserve resources. In Basic or Standard mode, you can enable Always On to keep the app loaded all the time. If your app runs continuous web jobs, you should enable Always On, or the web jobs may not run reliably.

However, the issue would be caused by some case like incorrectly handle exceptions.

As reference, there is an answered thread (Tomcat randomly shuts down with an AbstractProtocol pause after mild usage) explained this issue. You can try to review it and check your issue.

Any concern, please feel free to let me know.

Question:

I'm trying to deploy my springboot project into Azure App Service. I created an App Service and uploaded via FTP two files: test.war and web.config as mentioned in their tutorials.

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
        arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar   &quot;%HOME%\site\wwwroot\test.war&quot;">
    </httpPlatform> 
  </system.webServer>
</configuration>

I'm uploading the war file into the site/wwwroot and placed the web.config file there as well.

My question is: How do I execute the war file? is it supposed to happen when I finish deploy automatically? cause right now all I get is Service Unavailable, Http Error 503.

Thanks


Answer:

@ItaiSoudry, According to the content of your web.config file, it seems that you want to use the embedded servlet container like embedded tomcat or jetty to start up the spring boot web application.

Assumption that the IDE you used is Eclipse, you need to export your spring boot project as a runnable jar file, not a war file, please see the figure below.

Note: The Launch configuration should be selected the Class which the main function contains SpringApplication.run.

Meanwhile, you need to configure the listen port with %HTTP_PLATFORM_PORT% the Azure App service supported via the argument --server.port=%HTTP_PLATFORM_PORT% in the web.config file or set the port of the class ServerProperties with the value System.getenv("HTTP_PLATFORM_PORT").

Here is a sample for web.config with --server.port=%HTTP_PLATFORM_PORT%.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
        arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\test.jar&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>

If you want to deploy a war file, you need to configure the ApplicationSettings of your app service on Azure portal, then upload the war file into the path wwwroot/webapps.

As references, please refer to the documents below.

  1. The Springboot subsection in the article https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/#application-configuration-examples
  2. Create a Java web app in Azure App Service

Hope it helps.

Question:

So I made a simple java project with Spark and was trying to deploy it to Azure, but although it complies and says deploy successfully, it won't show any content. I used both the web+mobile deployment and the java jetty deployment, but none worked. Can anyone tell me what is the problem?

The link to the github project is https://github.com/tonymuu/mini-twitter-clone

And the link to the website is minitwitter.azurewebsites.net


Answer:

There are some documents and vedios to help you deploying Java web project into Azure from GitHub.

But for your issue, I checked your Java project on GitHub, and I found the repository only contains Java source code, not be a Java web application archive directory what contains the directories WEB-INF& META-INFO, and Java classes files in the path WEB-INF/classes and other web files, as the picture below:

Deploying Java web application on Azure WebApps is similar to deploying it into Tomcat or Jetty. You should deploy it into the directory webapps. on Azure WebApps, the webapps is at the path D:\home\site\wwwroot. You can find it thru the Debug console of Kudu Tool at the url https://<azure_webapp_name>.scm.azurewebsites.net/DebugConsole.

When you are deploying project from GitHub, the Azure will clone the files & directories of a branch of project repository from GitHub to the path wwwroot on Azure.

So the simple way to deploy from Github is push the webapps/<java_app_name> directory contains the files & directories of your Java web application archive into GitHub repository. Azure will help you pulling and deloping them.

Then you can browse the url https://<azure_webapp_name>.azurewebsites.net/<java_app_name>/.

If you create a Java web project by using Eclipse, the directory WebContent will be contained in the project. You just need to copy the content of WebContent into webapps/<java_app_name> dir and push webapps into GitHub repo.

Question:

I want to deploy an app on Azure Web App engine and I encountered a problem: My app is depended on outside configuration file, which contains DB access keys and some other configuration keys I don't want to save hard-coded.

Anyway, I thought to use configuration service like Spring with Git or some other similar services to handle the configuration but all of the solutions I found were heavy.

I bet I'm not the first one who struggle with this. So What is the common way to use out configuration file with Web-App?


Answer:

you can have any of the below ways to maintain application settings or connection strings.

  1. directly use from web.config. All the app settings and connection strings would be hard coded in configuration file and publish the same to Azure Web App. this is not recommended to store secrets/connection strings
  2. you can use Application Settings provided by App Service from the portal these settings will override keys provided in Web.Config file. you can have connection strings and secrets updated here instead of web.config to avoid direct exposure to end developer.

  3. you can have all you secrets and connection strings in Azure Key Vault and refer to them from web application as URI(REST) for this, you need to register your web app with Azure AD. this is highly recommended way for production web sites.

UPDATE Incorporated this answer into my blog post here

Question:

I am trying to deploy a simple java web application to MS Azure through git. When it deploys and i try to browse it , the website turns up with a 403 error saying "you don't have permission to view this page".

However if i convert my index.jsp page to index.html page (and remove the java specific code,off course). The website runs perfectly.

Does anybody have any insight to offer on this.


Answer:

May I know which URL you have used when tried to browse your site? If you did not put index.jsp in the URL, please try to use the full URL to see if it works, e.g. YourName.azurewebsites.net/index.jsp. Per my experience, index.html is in the default page list, but index.jsp is not. So if you can open the full URL with index.jsp, then you simply need to configure the default page using the Default Documents feature on the web app Settings page: YourWebApp CONFIGURE tab -> default documents section:

More info could be found at https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/. If that still doesn't work, then please refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/ to see whether it helps.