Skip to content

Commit 03a663a

Browse files
authored
Merge pull request #20 from Azure/dev
Merge dev to master for release 1.0.0-beta-5
2 parents 5c79beb + d5f66c0 commit 03a663a

File tree

8 files changed

+201
-59
lines changed

8 files changed

+201
-59
lines changed

appveyor.yml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ build_script:
2525
- ps: mkdir .pkg
2626

2727
artifacts:
28-
- path: '*.nupkg'
2928
- path: 'azure-functions-java-library/target/**.jar'
3029

3130
cache:

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.microsoft.azure.functions</groupId>
44
<artifactId>azure-functions-java-library</artifactId>
5-
<version>1.0.0-beta-4</version>
5+
<version>1.0.0-beta-5</version>
66
<packaging>jar</packaging>
77

88
<name>Microsoft Azure Functions Java Core Types</name>
@@ -93,7 +93,7 @@
9393
<plugin>
9494
<groupId>org.apache.maven.plugins</groupId>
9595
<artifactId>maven-javadoc-plugin</artifactId>
96-
<version>3.0.0-M1</version>
96+
<version>3.0.1</version>
9797
<executions>
9898
<execution>
9999
<id>attach-javadocs</id>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.microsoft.azure.functions;
2+
3+
/**
4+
* Enum for HTTP methods in the HTTP Binding of Azure Functions.
5+
*
6+
* @author Bruno Borges
7+
*/
8+
public enum HttpMethod {
9+
10+
GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE;
11+
12+
/**
13+
* Converts passed value to upper case to extract valueOf() of this Enum.
14+
* @param value of http method in any case
15+
* @return this enum
16+
*/
17+
public static HttpMethod value(String value) {
18+
return HttpMethod.valueOf(value.toUpperCase());
19+
}
20+
21+
}

src/main/java/com/microsoft/azure/functions/HttpRequestMessage.java

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
17
package com.microsoft.azure.functions;
28

39
import java.net.URI;
@@ -22,10 +28,10 @@ public interface HttpRequestMessage<T> {
2228
URI getUri();
2329

2430
/**
25-
* Returns the HTTP method name, such as "GET" and "POST".
26-
* @return the HTTP method name, such as "GET" and "POST".
31+
* Returns the HTTP method name as Enum
32+
* @return type of HttpMethod
2733
*/
28-
String getMethod();
34+
HttpMethod getHttpMethod();
2935

3036
/**
3137
* Returns a map of headers that were contained within this HTTP request.
@@ -46,22 +52,11 @@ public interface HttpRequestMessage<T> {
4652
T getBody();
4753

4854
/**
49-
* Generates a {@link HttpResponseMessage} instance containing the given HTTP status code and no response body.
50-
* Additional headers may be added by calling appropriate methods on {@link HttpResponseMessage}.
55+
* Returns a {@link HttpResponseMessage.Builder} instance to build a HTTP status code and no response body.
5156
*
5257
* @param status The HTTP status code to return to the caller of the function.
53-
* @return An {@link HttpResponseMessage} instance containing the provided status and empty body.
58+
* @return An {@link HttpResponseMessage.Builder} instance containing the provided status and empty body.
5459
*/
55-
HttpResponseMessage<Object> createResponse(int status);
60+
HttpResponseMessage.Builder createResponseBuilder(HttpStatus status);
5661

57-
/**
58-
* Generates a {@link HttpResponseMessage} instance containing the given HTTP status code and response body.
59-
* Additional headers may be added by calling appropriate methods on {@link HttpResponseMessage}.
60-
*
61-
* @param status The HTTP status code to return to the caller of the function.
62-
* @param body The body content to return to the caller of the function.
63-
* @param <R> The type of the body, as determined by the return type specified on the function itself.
64-
* @return An {@link HttpResponseMessage} instance containing the provided status and body content.
65-
*/
66-
<R> HttpResponseMessage<R> createResponse(int status, R body);
6762
}
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,86 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
17
package com.microsoft.azure.functions;
28

39
/**
4-
* An HttpResponseMessage instance is returned by Azure Functions methods that are triggered by an
10+
* An HttpResponseMessage instance is returned by Azure Functions methods that
11+
* are triggered by an
512
* {@link com.microsoft.azure.functions.annotation.HttpTrigger}.
613
*
714
* @see com.microsoft.azure.functions.annotation.HttpTrigger
815
* @see HttpRequestMessage
9-
* @param <T> The type of the body, as determined by the return type specified on the function itself.
1016
* @since 1.0.0
1117
*/
12-
public interface HttpResponseMessage<T> {
18+
public interface HttpResponseMessage {
1319

1420
/**
1521
* Returns the status code set on the HttpResponseMessage instance.
22+
*
1623
* @return the status code set on the HttpResponseMessage instance.
1724
*/
18-
int getStatus();
19-
20-
/**
21-
* Sets the status code on the HttpResponseMessage instance.
22-
* @param status An HTTP status code representing the outcome of the HTTP request.
23-
*/
24-
void setStatus(int status);
25-
26-
/**
27-
* Adds a (key,value) header to the response.
28-
* @param key The key of the header value.
29-
* @param value The value of the header value.
30-
*/
31-
void addHeader(String key, String value);
25+
HttpStatus getStatus();
3226

3327
/**
3428
* Returns a header value for the given key.
29+
*
3530
* @param key The key for which the header value is sought.
36-
* @return Returns the value if the key has previously been added, or null if it has not.
31+
* @return Returns the value if the key has previously been added, or null if it
32+
* has not.
3733
*/
3834
String getHeader(String key);
3935

4036
/**
4137
* Returns the body of the HTTP response.
38+
*
4239
* @return the body of the HTTP response.
4340
*/
44-
T getBody();
41+
Object getBody();
4542

4643
/**
47-
* Sets the body of the HTTP response.
48-
* @param body The body of the HTTP response
44+
* A builder to create an instance of HttpResponseMessage
45+
*
46+
* @author Bruno Borges
47+
* @since 1.0
4948
*/
50-
void setBody(T body);
49+
public static interface Builder {
50+
51+
/**
52+
* Sets the status code to be used in the HttpResponseMessage object.
53+
*
54+
* @param status An HTTP status code representing the outcome of the HTTP
55+
* request.
56+
*
57+
* @return this builder
58+
*/
59+
Builder status(HttpStatus status);
60+
61+
/**
62+
* Adds a (key, value) header to the response.
63+
*
64+
* @param key The key of the header value.
65+
* @param value The value of the header value.
66+
* @return this builder
67+
*/
68+
Builder header(String key, String value);
69+
70+
/**
71+
* Sets the body of the HTTP response.
72+
*
73+
* @param body The body of the HTTP response
74+
* @return this builder
75+
*/
76+
Builder body(Object body);
77+
78+
/**
79+
* Creates an instance of HttpMessageResponse with the values configured
80+
* in this builder.
81+
*
82+
* @return an HttpMessageResponse object
83+
*/
84+
HttpResponseMessage build();
85+
}
5186
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
7+
package com.microsoft.azure.functions;
8+
9+
/**
10+
* Enum to represent HTTP Status codes.
11+
*
12+
* @author Bruno Borges
13+
* @since 1.0
14+
*/
15+
public enum HttpStatus {
16+
17+
// HTTP Status 100+
18+
CONTINUE(100), SWITCHING_PROTOCOLS(101), PROCESSING(102), CHECKPOINT(103),
19+
20+
// HTTP Status 200+
21+
OK(200), CREATED(201), ACCEPTED(202), NON_AUTHORITATIVE_INFORMATION(203), NO_CONTENT(204), RESET_CONTENT(205),
22+
PARTIAL_CONTENT(206), MULTI_STATUS(207), ALREADY_REPORTED(208), IM_USED(226),
23+
24+
// HTTP Status 300+
25+
MULTIPLE_CHOICES(300), MOVED_PERMANENTLY(301), FOUND(302), SEE_OTHER(303), NOT_MODIFIED(304),
26+
TEMPORARY_REDIRECT(307), PERMANENT_REDIRECT(308),
27+
28+
// HTTP Status 400+
29+
BAD_REQUEST(400), UNAUTHORIZED(401), PAYMENT_REQUIRED(402), FORBIDDEN(403), NOT_FOUND(404), METHOD_NOT_ALLOWED(405),
30+
NOT_ACCEPTABLE(406), PROXY_AUTHENTICATION_REQUIRED(407), REQUEST_TIMEOUT(408), CONFLICT(409), GONE(410),
31+
LENGTH_REQUIRED(411), PRECONDITION_FAILED(412), PAYLOAD_TOO_LARGE(413), URI_TOO_LONG(414),
32+
UNSUPPORTED_MEDIA_TYPE(415), REQUESTED_RANGE_NOT_SATISFIABLE(416), EXPECTATION_FAILED(417), I_AM_A_TEAPOT(418),
33+
UNPROCESSABLE_ENTITY(422), LOCKED(423), FAILED_DEPENDENCY(424), UPGRADE_REQUIRED(426), PRECONDITION_REQUIRED(428),
34+
TOO_MANY_REQUESTS(429), REQUEST_HEADER_FIELDS_TOO_LARGE(431), UNAVAILABLE_FOR_LEGAL_REASONS(451),
35+
36+
// HTTP Status 500+
37+
INTERNAL_SERVER_ERROR(500), NOT_IMPLEMENTED(501), BAD_GATEWAY(502), SERVICE_UNAVAILABLE(503), GATEWAY_TIMEOUT(504),
38+
HTTP_VERSION_NOT_SUPPORTED(505), VARIANT_ALSO_NEGOTIATES(506), INSUFFICIENT_STORAGE(507), LOOP_DETECTED(508),
39+
BANDWIDTH_LIMIT_EXCEEDED(509), NOT_EXTENDED(510), NETWORK_AUTHENTICATION_REQUIRED(511);
40+
41+
private final int value;
42+
43+
HttpStatus(int value) {
44+
this.value = value;
45+
}
46+
47+
/**
48+
* Returns the code of this HTTPStatus enum.
49+
*
50+
* @return int value for this http status
51+
*/
52+
public int value() {
53+
return this.value;
54+
}
55+
56+
/**
57+
* Maps the int code to an HttpStatus enum.
58+
*
59+
* @param value for http code
60+
* @return HttpStatus enum
61+
*/
62+
public static HttpStatus valueOf(int value) {
63+
for (HttpStatus status : HttpStatus.values()) {
64+
if (value == status.value)
65+
return status;
66+
}
67+
68+
throw new IllegalArgumentException("HTTP Status code unknown: " + value);
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
7+
package com.microsoft.azure.functions;
8+
9+
/**
10+
* List of supported WebHooks for HttpTrigger.
11+
*
12+
* <p>
13+
* Configures the HTTP trigger to act as a webhook receiver for the specified
14+
* provider. Don't set the methods property if you set this property. The
15+
* webhook type can be one of the following values:
16+
* </p>
17+
*
18+
* <ul>
19+
* <li><strong>genericJson</strong>: A general-purpose webhook endpoint without
20+
* logic for a specific provider. This setting restricts requests to only those
21+
* using HTTP POST and with the {@code application/json} content type.</li>
22+
* <li><strong>github</strong>: The function responds to
23+
* <a href="https://developer.github.com/webhooks/">GitHub webhooks</a>. Do not
24+
* use the {@code com.microsoft.azure.functions.annotation.HttpTrigger.authLevel()} property with GitHub webhooks.</li>
25+
* <li><strong>slack</strong>: The function responds to
26+
* <a href="https://api.slack.com/outgoing-webhooks">Slack webhooks</a>. Do not
27+
* use the {@code com.microsoft.azure.functions.annotation.HttpTrigger.authLevel()} property with Slack webhooks.</li>
28+
* </ul>
29+
*/
30+
public enum WebHookType {
31+
NONE, GENERICJSON, GITHUB, SLACK;
32+
}

src/main/java/com/microsoft/azure/functions/annotation/HttpTrigger.java

+7-17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import java.lang.annotation.RetentionPolicy;
1212
import java.lang.annotation.Target;
1313

14+
import com.microsoft.azure.functions.HttpMethod;
15+
import com.microsoft.azure.functions.WebHookType;
16+
1417
/**
1518
* <p>The HttpTrigger annotation is applied to Azure functions that will be triggered by a call to the HTTP endpoint that
1619
* the function is located at. The HttpTrigger annotation should be applied to a method parameter of one of the following
@@ -110,7 +113,7 @@
110113
*
111114
* @return An array containing all valid HTTP methods.
112115
*/
113-
String[] methods() default {};
116+
HttpMethod[] methods() default {};
114117

115118
/**
116119
* <p>Determines what keys, if any, need to be present on the request in order to invoke the function. The authorization
@@ -130,22 +133,9 @@
130133
AuthorizationLevel authLevel() default AuthorizationLevel.FUNCTION;
131134

132135
/**
133-
* <p>Configures the HTTP trigger to act as a webhook receiver for the specified provider. Don't set the methods
134-
* property if you set this property. The webhook type can be one of the following values:</p>
135-
*
136-
* <ul>
137-
* <li><strong>genericJson</strong>: A general-purpose webhook endpoint without logic for a specific provider.
138-
* This setting restricts requests to only those using HTTP POST and with the {@code application/json} content
139-
* type.</li>
140-
* <li><strong>github</strong>: The function responds to
141-
* <a href="https://developer.github.com/webhooks/">GitHub webhooks</a>. Do not use the {@link #authLevel()}
142-
* property with GitHub webhooks.</li>
143-
* <li><strong>slack</strong>: The function responds to
144-
* <a href="https://api.slack.com/outgoing-webhooks">Slack webhooks</a>. Do not use the {@link #authLevel()}
145-
* property with Slack webhooks.</li>
146-
* </ul>
136+
* Defines the WebHook type for this HttpTrigger
147137
*
148-
* @return A string representing the desired webhook type.
138+
* @return A webhook type.
149139
*/
150-
String webHookType() default "";
140+
WebHookType webHookType() default WebHookType.NONE;
151141
}

0 commit comments

Comments
 (0)