Skip to content

Commit

Permalink
update the templates.json to align with the new java function runtime (
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored and xscript committed Dec 1, 2017
1 parent 3f3d191 commit 6d75d3c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion azure-functions-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>0.1.7-SNAPSHOT</version>
<version>0.1.8-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Maven Plugin for Azure Functions</name>
<description>Maven Plugin for Azure Functions</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.microsoft.azure;

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

Expand All @@ -14,22 +15,14 @@
*/
public class Function {
@FunctionName("hello")
public HttpResponseMessage httpHandler(
@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage request,
public HttpResponseMessage<String> httpHandler(
@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context
) {
context.getLogger().info("Java HTTP trigger processed a HTTP request.");
context.getLogger().info("Java HTTP trigger processed a request.");

// Parse query parameter
String name = request.getQueryParameters().get("name").toString();

if (name == null) {
// Get request body
Object body = request.getBody();
if (body != null) {
name = body.toString();
}
}
String query = request.getQueryParameters().get("name");
String name = request.getBody().orElse(query);

if (name == null) {
return request.createResponse(400, "Please pass a name on the query string or in the request body");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"userPrompt": []
},
"files": {
"function.java": "package $packageName$;\n\nimport com.microsoft.azure.serverless.functions.annotation.*;\nimport com.microsoft.azure.serverless.functions.*;\n\n/**\n * Azure Functions with HTTP trigger.\n */\npublic class $functionName$ {\n /**\n * This function will listen at HTTP endpoint \"/api/$functionName$\". Two approaches to invoke it using \"curl\" command in bash:\n * 1. curl -d \"Http Body\" {your host}/api/$functionName$\n * 2. curl {your host}/api/$functionName$?name=HTTP%20Query\n */\n @FunctionName(\"$functionName$\")\n public HttpResponseMessage httpHandler(\n @HttpTrigger(name = \"req\", methods = { \"get\", \"post\" }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage request,\n final ExecutionContext context\n ) {\n context.getLogger().info(\"Java HTTP trigger processed a request.\");\n\n // Parse query parameters\n String name = request.getQueryParameters().get(\"name\");\n\n if (name == null) {\n // Get request body\n Object body = request.getBody();\n if (body != null) {\n name = body.toString();\n }\n }\n\n if (name == null) {\n return request.createResponse(400, \"Please pass a name on the query string or in the request body\");\n } else {\n return request.createResponse(200, \"Hello, \" + name);\n }\n }\n}\n"
"function.java": "package $packageName$;\n\nimport java.util.*;\nimport com.microsoft.azure.serverless.functions.annotation.*;\nimport com.microsoft.azure.serverless.functions.*;\n\n/**\n * Azure Functions with HTTP trigger.\n */\npublic class $functionName$ {\n /**\n * This function will listen at HTTP endpoint \"/api/$functionName$\". Two approaches to invoke it using \"curl\" command in bash:\n * 1. curl -d \"Http Body\" {your host}/api/$functionName$\n * 2. curl {your host}/api/$functionName$?name=HTTP%20Query\n */\n @FunctionName(\"$functionName$\")\n public HttpResponseMessage<String> httpHandler(\n @HttpTrigger(name = \"req\", methods = { \"get\", \"post\" }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,\n final ExecutionContext context\n ) {\n context.getLogger().info(\"Java HTTP trigger processed a request.\");\n\n // Parse query parameters\n String query = request.getQueryParameters().get(\"name\");\n String name = request.getBody().orElse(query);\n\n if (name == null) {\n return request.createResponse(400, \"Please pass a name on the query string or in the request body\");\n } else {\n return request.createResponse(200, \"Hello, \" + name);\n }\n }\n}\n"
}
},
{
Expand All @@ -25,7 +25,7 @@
]
},
"files": {
"function.java": "package $packageName$;\n\nimport com.microsoft.azure.serverless.functions.annotation.*;\nimport com.microsoft.azure.serverless.functions.*;\n\n/**\n * Azure Functions with Azure Blob trigger.\n */\npublic class $functionName$ {\n /**\n * This function will be invoked when a new or updated blob is detected at the specified path. The blob contents are provided as input to this function.\n */\n @FunctionName(\"$functionName$\")\n public void blobHandler(\n @BlobTrigger(name = \"content\", path = \"$path$\", connection = \"$connection$\") String content,\n final ExecutionContext context\n ) {\n context.getLogger().info(\"Java Blob trigger function processed a blob. Blob=\" + content);\n }\n}\n"
"function.java": "package $packageName$;\n\nimport com.microsoft.azure.serverless.functions.annotation.*;\nimport com.microsoft.azure.serverless.functions.*;\n\n/**\n * Azure Functions with Azure Blob trigger.\n */\npublic class $functionName$ {\n /**\n * This function will be invoked when a new or updated blob is detected at the specified path. The blob contents are provided as input to this function.\n */\n @FunctionName(\"$functionName$\")\n @StorageAccount(\"$connection$\")\n public void blobHandler(\n @BlobTrigger(name = \"content\", path = \"$path$\", dataType = \"binary\") byte[] content,\n @BindingName(\"name\") String name,\n final ExecutionContext context\n ) {\n context.getLogger().info(\"Java Blob trigger function processed a blob. Name: \" + name + \"\\n Size: \" + content.length + \" Bytes\");\n }\n}\n"
}
},
{
Expand Down

0 comments on commit 6d75d3c

Please sign in to comment.