I dealt with Azure Functions not working in Java

I was able to run it locally, but when I deployed it, an error occurred. The details of the countermeasures are described.

** 6/15 postscript ** It seems that Maven plugins etc. were released after writing this article.

Event that occurred

As mentioned above, it works fine locally using the Maven plugin, but when I deploy it to Azure and run it, I get the following error.

502-Bad Gateway The specified CGI application encountered an error and the server terminated the process.

Cause

According to the following, it seems that the old code has stopped working due to the release of the new Runtime. https://stackoverflow.com/questions/50615746/azure-java-function-502-bad-gateway https://github.com/Azure/app-service-announcements/issues/112

It works locally with the old Runtime, so it's okay, but when deployed it runs on the new Runtime, so it seems that an error has occurred.

Coping

You can fix it to work with the new Runtime, but as of June 14, 2018, this is not possible yet. This is because the azure-functions-maven-plugin that supports this has not been released yet.

Therefore, we will implement the following as a provisional measure.

Specify the Runtime version

Specify the version of Runtime on Azure. Open the Function App "Application Settings" from the Azure portal. Change FUNCTIONS_EXTENSION_VERSION to 2.0.11776-alpha. (The default should be beta.)

無題.png

In addition, this version is valid until the end of June.

~~ (For reference) ~~ How to support the new Runtime

~~ Maven Plugin has not been released, but other parts that need to be dealt with are as follows. In addition, since it will be a half-finished response, it will be an environment that does not work even locally. ~~

** 6/15 postscript ** Since the corresponding Maven Plugin has been released, the following correspondence is OK.

Modify pom.xml

It is assumed that the project was created from Maven Archetype, so if you are customizing it, please read it as appropriate. ~~ In addition, when azure-functions-maven-plugin is released, it seems that it is necessary to modify the version specified in plugin Management. ~~

Modify dependency

<dependency>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-functions-java-core</artifactId>
  <version>1.0.0-beta-3</version>
</dependency>
<dependency>
  <groupId>com.microsoft.azure.functions</groupId>
  <artifactId>azure-functions-java-library</artifactId>
  <version>1.0.0-beta-4</version>
</dependency>

Change maven-dependency-plugin settings

Here, the setting to add the jar file defined by pom to the lib folder is set. Originally it was set to exclude azure-functions-java-core, so modify it as follows to exclude azure-functions-java-library.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>3.0.2</version>
  <executions>
    <execution>
      <id>copy-dependencies</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>copy-dependencies</goal>
      </goals>
      <configuration>
        <outputDirectory>${stagingDirectory}/lib</outputDirectory>
        <overWriteReleases>false</overWriteReleases>
        <overWriteSnapshots>false</overWriteSnapshots>
        <overWriteIfNewer>true</overWriteIfNewer>
        <includeScope>runtime</includeScope>
        <excludeArtifactIds>azure-functions-java-library</excludeArtifactIds> <!--here-->
      </configuration>
    </execution>
  </executions>
</plugin>

Changed the version of azure-maven-plugin (6/15 postscript)

Change the version to 1.0.0-beta-2.

<plugin>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-functions-maven-plugin</artifactId>
  <version>1.0.0-beta-2</version> <!--here-->
</plugin>

Fix the code

The package has changed and needs to be fixed.

import com.microsoft.azure.serverless.functions.annotation.*;
import com.microsoft.azure.serverless.functions.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;

It seems that serverless is gone.

Upgrade the local Runtime

When it was an update, I couldn't figure out the version specification, so I uninstalled it and reinstalled it.

npm -g uninstall azure-functions-core-tools
npm -g install azure-functions-core-tools@core

As I was writing this article, people who recently started running Azure Functions in Java don't even work locally. (Because if you follow the procedure, a new Runtime will be installed)

For such people, it may be better to lower the version of Runtime and install it.

npm -g uninstall azure-functions-core-tools
npm -g install [email protected]

** 6/15 postscript ** Since the corresponding version has been released, I think that it is better to make modifications so that it can support the new Runtime, instead of lowering the version of Runtime.

Recommended Posts

I dealt with Azure Functions not working in Java
Azure functions in java
Create Azure Functions in Java
Working with huge JSON in Java Lambda
Solution for NetBeans 8.2 not working in Java 9 environment
Practice working with Unicode surrogate pairs in Java
How to call functions in bulk with Java reflection
Use Thymeleaf with Azure Functions
Lombok not working with Gradle5
I tried metaprogramming in Java
Log aggregation and analysis (working with AWS Athena in Java)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to implement various functions with kotlin and java!
I sent an email in Java
Morphological analysis in Java with Kuromoji
I created a PDF in Java.
I can't create a Java class with a specific name in IntelliJ
Use Azure Bing SpellCheck with Java
[Java] Do not use "+" in append!
I tried to interact with Java
Use Java 11 with Google Cloud Functions
I wrote Goldbach's theorem in java
What I learned with Java Gold
I made an annotation in Java.
I tried using JWT in Java
[Java] I want to perform distinct with the key in the object
Play with Markdown in Java flexmark-java
What I learned with Java Silver
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
I wrote a Lambda function in Java and deployed it with SAM
I want to ForEach an array with a Lambda expression in Java
[Java] I participated in ABC-188 of Atcorder.
I tried using Elasticsearch API in Java
Concurrency Method in Java with basic example
I tried the new era in Java
I tried using OpenCV with Java + Tomcat
Read xlsx file in Java with Selenium
I did OpenCV camera calibration in Java
Split a string with ". (Dot)" in Java
I built Step Functions with AWS CDK.
Get Timestamp with Azure BlobStorage Java SDK
[* Java *] I participated in JJUG CCC 2019 Spring
Do not declare variables in List in Java
Create Java applications with IBM Cloud Functions
In some cases, Java code was nativeized with GraalVM, but it was not accelerated.
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
[Java] Rewrite the functions created by myself in the past from java.io.File with NIO.2.
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
I made a primality test program in Java
Read a string in a PDF file with Java
I tried to make Basic authentication with Java
Refactored GUI tools made with Java8 + JavaFX in 2016
I want to send an email in Java.
Static code analysis with Checkstyle in Java + Gradle
Deploy Java web app to Azure with maven
I want to use java8 forEach with index
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I wrote a primality test program in Java
Text extraction in Java from PDF with pdfbox-2.0.8
I made a rock-paper-scissors game in Java (CLI)
rsync4j --I want to touch rsync in Java.