Hot questions for Using Azure in azure web app service

Top Java Programmings / Azure / azure web app service

Question:

I have a java-application (standard springboot from default tutorial: https://spring.io/guides/gs/spring-boot-for-azure/ ) that I "successfuly" deploy to my WebApp (created during deployment) via Eclipse/maven plugin azure-webapp:deploy

Once deployed, files are inside the WebApp, I can see them. If start-up is successful I do get running application, but if it is not - I do not know how to troubleshoot. I don't know where to find error logs, what caused the problem and as consequence, how to solve it.

as an example of how to make it fail, add this line:

throw new RuntimeException("Doomed to fail");

I tried enabling logs from "diagnostic logs tab" and expected to see them under LogFiles/Applications but that folder remains empty.

How do I troubleshoot java-application that fails to start in WebApps of Azure?

edit: additional example of Exception to troubleshoot:

public static void main(String[] args) {
    throw new RuntimeException("start failure #21");
    //SpringApplication.run(Application.class, args);
}

Answer:

It sounds like you followed the springboot tutorial Deploying a Spring Boot app to Azure to build the GitHub project microsoft/gs-spring-boot and deploy to Azure, but not works.

Here is my steps which I also followed the tutorial, but deployed via my own way.

  1. I created a directory SpringBoot on my local machine, and to do the commands cd SpringBoot and git clone https://github.com/microsoft/gs-spring-boot.
  2. Then, to build it via commands cd gs-spring-boot/complete and mvnw clean package

Note: I reviewed the sections of the tutorial under Create a sample Spring Boot web app which seems to do on Linux, but the web.config file in microsoft/gs-spring-boot/complete is ready to Azure WebApp for Windows. However, there is not any comments to describe the deployment target that be Azure WebApp for Windows or Linux.

  1. So I used my existing WebApp for Windows to test my deployment. I open my Kudu console in browser via the url https://<webapp name>.scm.azurewebsites.net/DebugConsole and drag the files complete/web.config and complete/target/gs-spring-boot-0.1.0.jar to site/wwwroot as the figure below. Then, I started my webapp, and it works fine.

Note: Please check the JAVA_HOME environment variable which has been configured on Azure via command echo %JAVA_HOME% as the figure below.

If not, you need to set Java runtime in the Application settings tab of Azure portal.

Or you can also configure the web.config file to replace the reference %JAVA_HOME% with an existing Java runtime installed in the path D:\Program Files\Java of Azure WebApp, as below.

<?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" -->
        <httpPlatform processPath="D:\Program Files\Java\jre1.8.0_181\bin\java.exe"
                      arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\gs-spring-boot-0.1.0.jar&quot;">
        </httpPlatform>
    </system.webServer>
</configuration>

Question:

I am trying to upload a basic RESTful API following this springboot tutorial. Basically, I have an endpoint /greeting which returns a json {"id":1,"content":"Hello, World!"}. Here is the request in code:

@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
    return new Greeting(counter.incrementAndGet(), String.format(template,  name));
}

This works perfectly fine when I run on a local server, but fails when I upload to my Azure App Service. I am not sure where things are going wrong and could use some help.

I am using Eclipse with the Azure toolkit and I am using a maven project. I publish to Azure by right clicking the project -> Azure -> publish as Azure Web App.

When the publish completes and I try to go to my /greeting endpoint on the Azure server, I have a 404 error. If I include a blank html page, the response I get from Postman is simply the contents of the html file, rather than the json that I want to return.

My expected result is to get that json back and I could use some advice.


Answer:

I just downloaded the sample code from the springboot tutorial you mentioned and tried to deploy it to my azure web app service.It does works for me.

Please refer to my steps and check if you missed something.

Step 1: Use mvn package to bulid the JAR package in the directory under which the pom.xml file is located. (Here is E:\Downloads\gs-rest-service-master\gs-rest-service-master\complete for me)

Step 2:Then you could see the JAR package in the target folder.

Deploy it to root wwwroot/ on KUDU with web.config file.

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\gs-rest-service-0.1.0.jar&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>

Please make sure that the jar package name configured in web.config is the same as the uploaded jar package name!

Step 3: Please make sure ApplicationSettings matches your project such as jdk version,tomcat version.

Step 4: Restart your app service and access the url : https://<your app name>.azurewebsites.net/greeting

Hope it helps you.

Question:

How do I make my own custom fonts available to the JVM when deployed in Azure as a Web Application? (note - this is different than serving them back in an html page and configuring the proper MIME types. I'm applying fonts to an image generated using lucee and coldfusion.)

In the old world when we used a virtual machine, we would simply add the fonts to the system font folder and the JVM would have them available at run time. With Azure Web Applications, this folder is not accessible to me. We are running Java 8.

Things I thought should work, but don't seem to:

  • using the JAVA_FONTS environment variable to specify a path to my custom fonts folder (with ttf files in it)
  • Making Java calls to create and register the font within my web application. getLocalGraphicsEnvironment / CreateFont / RegisterFont (this registers the fonts, but the Garbage Collector thread chokes and crashes on the Disposer - crashing my JVM every few hours. Take the font loading out, and it runs smoooooth)

Now the fact they didn't work for me might be as simple as misunderstanding the exact syntax of the process.

How can I load my fonts in?


Answer:

Base on what I found in this document.

I think the main reason for your Garbage Collector thread crash is that the CreateFont method creates a large amount of temporary files.

Solution:

You could refer to the snippet of the code below replace the inputStream method.

String pathString = FontLoader.class.getResource("/font/xxx.ttf").getFile();
Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, new File(pathString));

You could also refer to the SO thread:Font.createFont leaves files in temp directory.

Hope it helps you.

Question:

I've created a webapp in Azure and uploaded a war file in D:\home\site\wwwroot\webapps folder. I use an app service plan with a standard pricing tier. I've done the settings to activate Java and Tomcat in Application Settings menu:

  • java version : Java 8
  • java minor version : Newest
  • Web Container: Newest Tomcat

If the option "Always On" is not activated, my Tomcat does not start. No java process is started, my war file is not unzipped. I've done several stop/start of the app and nothing happens. Once I've activated the "Always On", the Tomcat starts and the app is deployed. The "Always On" is not available on Service Plan with a Free pricing tier.

Does anybody know why Azure behaves that way ?


Answer:

I tried to reproduce the behavior as you said via FTP, here is what I observed on Tomcat 8.5.6 as @GopiKolla said, as below .

  1. If disabled Always on option, the .war file uploaded will not be unpacked automatically. However, when I tried to access the url of the webapp of the .war file, it was unpacked to a directory which named as same as war after ten more seconds.
  2. If enabled this option, all war file will be unpacked automatically & immdiately.

I had check all configurations & environment variables which include the attributes autodeploy, unpackWARs & deployOnStartup, etc, these would not change with the option switch. I searched the explaination for this case from the offical related documents of Tomcat (1, 2 ,3), there is nothing useful information which can explain it. Just a guess & per my experience, I think Azure limits the lifecycle of runtime via IIS to determine whether activate the httpPlatformHandler process defined in the web.config via the option Always on.

Hope it helps.