Update the function archetype to align with the new runtime (#8)
This commit is contained in:
Родитель
8ab6b6f1bf
Коммит
03706855a4
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package $package;
|
||||
|
||||
import java.util.*;
|
||||
import com.microsoft.azure.serverless.functions.annotation.*;
|
||||
import com.microsoft.azure.serverless.functions.*;
|
||||
|
||||
|
@ -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");
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.microsoft.azure.serverless.functions.*;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
@ -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());
|
||||
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -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>
|
||||
|
|
Загрузка…
Ссылка в новой задаче