This is an sample application of Azure Functions for Java which implement the Microsoft Translator text API.
Switch branches/tags
Nothing to show
Clone or download
yoshioterada Modified the
Modified the explanation.

FROM : Please get the source code from following URL?
TO : Please get the library from following URL?
Latest commit 1fd5e4a Nov 24, 2017

This Azure Function require additional libraries as follows. Please get the library from following URL?

Source Code of Utility Libraries is here (Cognitive-Bot-LUIS-Util)
Download jar file

After download the jar file from above, please execute following?

Please install the above jar file into your local Maven repository? (In general, your local repository will existing on ~/.m2 directory.

1. $ mvn install:install-file \
    -Dfile=$DOWNLOAD_DIR/Bot-Luis-Translator-Util-1.2.jar \
    -DgroupId=com.yoshio3 \
    -DartifactId=Bot-Luis-Translator-Util \
    -Dversion=1.2 \
    -Dpackaging=jar \

Then please get the Subscription key for Microsoft Translator Text and modify the property file in the

2. Modify the following property file? Especially following.


Then you can compile Azure Functions for Java as follows.

3. $ mvn clean package

You can confirm the Application's behavior on your local environment as follows.

4. $ mvn azure-functions:run
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Azure Java Functions 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] --- azure-functions-maven-plugin:0.1.6:run (default-cli) @ com.yoshio3 ---
AI: INFO 22-11-2017 17:30, 1: Configuration file has been successfully found as resource
AI: INFO 22-11-2017 17:30, 1: Configuration file has been successfully found as resource
[INFO] Azure Functions stage directory found at: /Users/tyoshio2002/NetBeansProjects/Azure-Cognitive-Functions/target/azure-functions/java-function-for-cognitive-services
[INFO] Azure Functions Core Tools found.
[INFO] Starting running Azure Functions...

            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@

[2017/11/22 8:30:11] Reading host configuration file '/Users/tyoshio2002/NetBeansProjects/Azure-Cognitive-Functions/target/azure-functions/java-function-for-cognitive-services/host.json'
[2017/11/22 8:30:12] Host configuration file read:
[2017/11/22 8:30:12] {}
info: Worker.Java.ed32f7f7-1409-40c0-b5e3-092e9e041c8e[0]
      Start Process: /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/bin/java  -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 "/Users/tyoshio2002/.azurefunctions/bin/workers/java/azure-functions-java-worker.jar" --host --port 54115 --workerId ed32f7f7-1409-40c0-b5e3-092e9e041c8e --requestId cd8158df-cb8d-4445-a76e-69e2c16265e7
info: Worker.Java.ed32f7f7-1409-40c0-b5e3-092e9e041c8e[0]
      Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[2017/11/22 8:30:12] Generating 1 job function(s)
[2017/11/22 8:30:12] Starting Host (HostId=yoshionombp-1225926620, Version=2.0.11370.0, ProcessId=3744, Debug=False, ConsecutiveErrors=0, StartupCount=0, FunctionsExtensionVersion=)
Listening on http://localhost:7071/
Hit CTRL-C to exit...

Http Functions:

	translate: http://localhost:7071/api/translate

info: Worker.Java.ed32f7f7-1409-40c0-b5e3-092e9e041c8e[0]
      Listening for transport dt_socket at address: 5005
info: Worker.Java.ed32f7f7-1409-40c0-b5e3-092e9e041c8e[0]
      Microsoft Azure Functions Java Runtime [build 1.0.0-beta-2]
[2017/11/22 8:30:12] Found the following functions:
[2017/11/22 8:30:12] Host.Functions.translate
[2017/11/22 8:30:12] 
[2017/11/22 8:30:12] Job host started
info: Worker.Java.ed32f7f7-1409-40c0-b5e3-092e9e041c8e[0]
      [INFO] {MessageHandler.handle}: Message generated by "StartStream.Builder"
info: Worker.Java.ed32f7f7-1409-40c0-b5e3-092e9e041c8e[0]
      Worker initialized
info: Worker.Java.ed32f7f7-1409-40c0-b5e3-092e9e041c8e[0]
      "translate" loaded (ID: a08e3d04-b117-4e28-8749-3ae194bc4024, Reflection: "/Users/tyoshio2002/NetBeansProjects/Azure-Cognitive-Functions/target/azure-functions/java-function-for-cognitive-services/com.yoshio3-1.0-SNAPSHOT.jar"::"com.yoshio3.TranslatorFunction.translate")

After executed the above, please execute following command on another console terminal?

5. $ curl -X POST -H "Content-Type:text/plain" -d "Today is so cold" -w "\n" http://localhost:7071/api/translate

{"original":"Today is so cold","translatedValue":"今日はとても寒いです。"}

You can specify not only "text/plain" but also "application/json" as follows.

6. $ curl -X POST -H "Content-Type:application/json" -d "{\"text\":\"Next month is december.\"}" -w "\n" http://localhost:7071/api/translate

{"original":"Next month is december.","translatedValue":"来月は 12 月です。"}

In order to deploy to Azure, please execute following?

7. $ mvn azure-functions:deploy

After deploy it to Azure, you can access to the public URL like follows.

8. $ curl -X POST -H "Content-Type:application/json" -d "{\"text\":\"Next month is december.\"}" -w "\n" https://***-*****-**-****-****
{"original":"Next month is december.","translatedValue":"来月は 12 月です。"}