Skip to content

Commit

Permalink
Update the function archetype to align with the new runtime (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored and xscript committed Dec 1, 2017
1 parent 8ab6b6f commit 0370685
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion azure-functions-archetype/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-archetype</artifactId>
<version>1.3</version>
<version>1.4</version>
<packaging>jar</packaging>

<name>Maven Archetype for Azure Functions</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>0.1.7</version>
<version>0.1.8</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package $package;

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

Expand All @@ -13,20 +14,14 @@ public class Function {
* 2. curl {your host}/api/hello?name=HTTP%20Query
*/
@FunctionName("hello")
public HttpResponseMessage hello(@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage request,
final ExecutionContext context) {
public HttpResponseMessage<String> hello(
@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
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 @@ -5,6 +5,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;

import static org.junit.Assert.assertSame;
Expand All @@ -24,12 +25,15 @@ public class FunctionTest {
@Test
public void testHello() throws Exception {
// Setup
final HttpRequestMessage req = mock(HttpRequestMessage.class);
final HttpRequestMessage<Optional<String>> req = mock(HttpRequestMessage.class);

final Map<String, String> queryParams = new HashMap<>();
queryParams.put("name", "Azure");
doReturn(queryParams).when(req).getQueryParameters();

final Optional<String> queryBody = Optional.empty();
doReturn(queryBody).when(req).getBody();

final HttpResponseMessage res = mock(HttpResponseMessage.class);
doReturn(res).when(req).createResponse(anyInt(), anyString());

Expand Down
2 changes: 1 addition & 1 deletion 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-maven-archetypes</artifactId>
<version>1.3</version>
<version>1.4</version>
<packaging>pom</packaging>
<name>Maven Archetypes for Azure</name>
<description>Maven Archetypes for Microsoft Azure services</description>
Expand Down

0 comments on commit 0370685

Please sign in to comment.