Skip to content

Commit 270293a

Browse files
authored
Merge pull request #3 from wanjunlei/java
support multiple functions in one pod
2 parents 132cfcb + 0409767 commit 270293a

File tree

21 files changed

+510
-415
lines changed

21 files changed

+510
-415
lines changed

functions-framework-api/src/main/java/dev/openfunction/functions/BindingEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Map;
2121

2222
public class BindingEvent {
23-
2423
/**
2524
* The name of the input binding component.
2625
*/

functions-framework-api/src/main/java/dev/openfunction/functions/CloudEventFunction.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818

1919
import io.cloudevents.CloudEvent;
2020

21-
@FunctionalInterface
2221
public interface CloudEventFunction {
23-
24-
/**
25-
* @param ctx Context
26-
* @param event cloud event
27-
* @return Error
28-
* @throws Exception Exception
29-
*/
30-
Error accept(Context ctx, CloudEvent event) throws Exception;
22+
/**
23+
* @param ctx Context
24+
* @param event cloud event
25+
* @return Error
26+
* @throws Exception Exception
27+
*/
28+
Error accept(Context ctx, CloudEvent event) throws Exception;
3129
}

functions-framework-api/src/main/java/dev/openfunction/functions/Component.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
import java.util.Map;
2020

2121
public class Component {
22-
2322
private String uri;
2423
private String componentName;
2524
private String componentType;
2625
private Map<String, String> metadata;
27-
private String Operation;
26+
private String operation;
2827

2928

3029
public String getUri() {
@@ -60,11 +59,11 @@ public void setMetadata(Map<String, String> metadata) {
6059
}
6160

6261
public String getOperation() {
63-
return Operation;
62+
return operation;
6463
}
6564

6665
public void setOperation(String operation) {
67-
Operation = operation;
66+
this.operation = operation;
6867
}
6968
}
7069

functions-framework-api/src/main/java/dev/openfunction/functions/Context.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* An interface for event function context.
2525
*/
2626
public interface Context {
27-
2827
/**
2928
* send provides the ability to allow the user to send data to a specified output target.
3029
*

functions-framework-api/src/main/java/dev/openfunction/functions/HttpFunction.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
package dev.openfunction.functions;
1818

1919
public interface HttpFunction {
20-
/**
21-
* Called to service an incoming HTTP request. This interface is implemented by user code to
22-
* provide the action for a given function. If the method throws any exception (including any
23-
* {@link Error}) then the HTTP response will have a 500 status code.
24-
*
25-
* @param request a representation of the incoming HTTP request.
26-
* @param response an object that can be used to provide the corresponding HTTP response.
27-
* @throws Exception if thrown, the HTTP response will have a 500 status code.
28-
*/
29-
void service(HttpRequest request, HttpResponse response) throws Exception;
20+
/**
21+
* Called to service an incoming HTTP request. This interface is implemented by user code to
22+
* provide the action for a given function. If the method throws any exception (including any
23+
* {@link Error}) then the HTTP response will have a 500 status code.
24+
*
25+
* @param request a representation of the incoming HTTP request.
26+
* @param response an object that can be used to provide the corresponding HTTP response.
27+
* @throws Exception if thrown, the HTTP response will have a 500 status code.
28+
*/
29+
void service(HttpRequest request, HttpResponse response) throws Exception;
3030
}

functions-framework-api/src/main/java/dev/openfunction/functions/HttpMessage.java

Lines changed: 84 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -23,94 +23,96 @@
2323
import java.util.Map;
2424
import java.util.Optional;
2525

26-
/** Represents an HTTP message, either an HTTP request or a part of a multipart HTTP request. */
26+
/**
27+
* Represents an HTTP message, either an HTTP request or a part of a multipart HTTP request.
28+
*/
2729
public interface HttpMessage {
28-
/**
29-
* Returns the value of the {@code Content-Type} header, if any.
30-
*
31-
* @return the content type, if any.
32-
*/
33-
Optional<String> getContentType();
30+
/**
31+
* Returns the value of the {@code Content-Type} header, if any.
32+
*
33+
* @return the content type, if any.
34+
*/
35+
Optional<String> getContentType();
3436

35-
/**
36-
* Returns the numeric value of the {@code Content-Length} header.
37-
*
38-
* @return the content length.
39-
*/
40-
long getContentLength();
37+
/**
38+
* Returns the numeric value of the {@code Content-Length} header.
39+
*
40+
* @return the content length.
41+
*/
42+
long getContentLength();
4143

42-
/**
43-
* Returns the character encoding specified in the {@code Content-Type} header, or {@code
44-
* Optional.empty()} if there is no {@code Content-Type} header or it does not have the {@code
45-
* charset} parameter.
46-
*
47-
* @return the character encoding for the content type, if one is specified.
48-
*/
49-
Optional<String> getCharacterEncoding();
44+
/**
45+
* Returns the character encoding specified in the {@code Content-Type} header, or {@code
46+
* Optional.empty()} if there is no {@code Content-Type} header or it does not have the {@code
47+
* charset} parameter.
48+
*
49+
* @return the character encoding for the content type, if one is specified.
50+
*/
51+
Optional<String> getCharacterEncoding();
5052

51-
/**
52-
* Returns an {@link InputStream} that can be used to read the body of this HTTP request. Every
53-
* call to this method on the same {@link HttpMessage} will return the same object. This method is
54-
* typically used to read binary data. If the body is text, the {@link #getReader()} method is
55-
* more appropriate.
56-
*
57-
* @return an {@link InputStream} that can be used to read the body of this HTTP request.
58-
* @throws IOException if a valid {@link InputStream} cannot be returned for some reason.
59-
* @throws IllegalStateException if {@link #getReader()} has already been called on this instance.
60-
*/
61-
InputStream getInputStream() throws IOException;
53+
/**
54+
* Returns an {@link InputStream} that can be used to read the body of this HTTP request. Every
55+
* call to this method on the same {@link HttpMessage} will return the same object. This method is
56+
* typically used to read binary data. If the body is text, the {@link #getReader()} method is
57+
* more appropriate.
58+
*
59+
* @return an {@link InputStream} that can be used to read the body of this HTTP request.
60+
* @throws IOException if a valid {@link InputStream} cannot be returned for some reason.
61+
* @throws IllegalStateException if {@link #getReader()} has already been called on this instance.
62+
*/
63+
InputStream getInputStream() throws IOException;
6264

63-
/**
64-
* Returns a {@link BufferedReader} that can be used to read the text body of this HTTP request.
65-
* Every call to this method on the same {@link HttpMessage} will return the same object.
66-
*
67-
* @return a {@link BufferedReader} that can be used to read the text body of this HTTP request.
68-
* @throws IOException if a valid {@link BufferedReader} cannot be returned for some reason.
69-
* @throws IllegalStateException if {@link #getInputStream()} has already been called on this
70-
* instance.
71-
*/
72-
BufferedReader getReader() throws IOException;
65+
/**
66+
* Returns a {@link BufferedReader} that can be used to read the text body of this HTTP request.
67+
* Every call to this method on the same {@link HttpMessage} will return the same object.
68+
*
69+
* @return a {@link BufferedReader} that can be used to read the text body of this HTTP request.
70+
* @throws IOException if a valid {@link BufferedReader} cannot be returned for some reason.
71+
* @throws IllegalStateException if {@link #getInputStream()} has already been called on this
72+
* instance.
73+
*/
74+
BufferedReader getReader() throws IOException;
7375

74-
/**
75-
* Returns a map describing the headers of this HTTP request, or this part of a multipart request.
76-
* If the headers look like this...
77-
*
78-
* <pre>
79-
* Content-Type: text/plain
80-
* Some-Header: some value
81-
* Some-Header: another value
82-
* </pre>
83-
*
84-
* ...then the returned value will map {@code "Content-Type"} to a one-element list containing
85-
* {@code "text/plain"}, and {@code "Some-Header"} to a two-element list containing {@code "some
86-
* value"} and {@code "another value"}.
87-
*
88-
* @return a map where each key is an HTTP header and the corresponding {@code List} value has one
89-
* element for each occurrence of that header.
90-
*/
91-
Map<String, List<String>> getHeaders();
76+
/**
77+
* Returns a map describing the headers of this HTTP request, or this part of a multipart request.
78+
* If the headers look like this...
79+
*
80+
* <pre>
81+
* Content-Type: text/plain
82+
* Some-Header: some value
83+
* Some-Header: another value
84+
* </pre>
85+
* <p>
86+
* ...then the returned value will map {@code "Content-Type"} to a one-element list containing
87+
* {@code "text/plain"}, and {@code "Some-Header"} to a two-element list containing {@code "some
88+
* value"} and {@code "another value"}.
89+
*
90+
* @return a map where each key is an HTTP header and the corresponding {@code List} value has one
91+
* element for each occurrence of that header.
92+
*/
93+
Map<String, List<String>> getHeaders();
9294

93-
/**
94-
* Convenience method that returns the value of the first header with the given name. If the
95-
* headers look like this...
96-
*
97-
* <pre>
98-
* Content-Type: text/plain
99-
* Some-Header: some value
100-
* Some-Header: another value
101-
* </pre>
102-
*
103-
* ...then {@code getFirstHeader("Some-Header")} will return {@code Optional.of("some value")},
104-
* and {@code getFirstHeader("Another-Header")} will return {@code Optional.empty()}.
105-
*
106-
* @param name an HTTP header name.
107-
* @return the first value of the given header, if present.
108-
*/
109-
default Optional<String> getFirstHeader(String name) {
110-
List<String> headers = getHeaders().get(name);
111-
if (headers == null || headers.isEmpty()) {
112-
return Optional.empty();
95+
/**
96+
* Convenience method that returns the value of the first header with the given name. If the
97+
* headers look like this...
98+
*
99+
* <pre>
100+
* Content-Type: text/plain
101+
* Some-Header: some value
102+
* Some-Header: another value
103+
* </pre>
104+
* <p>
105+
* ...then {@code getFirstHeader("Some-Header")} will return {@code Optional.of("some value")},
106+
* and {@code getFirstHeader("Another-Header")} will return {@code Optional.empty()}.
107+
*
108+
* @param name an HTTP header name.
109+
* @return the first value of the given header, if present.
110+
*/
111+
default Optional<String> getFirstHeader(String name) {
112+
List<String> headers = getHeaders().get(name);
113+
if (headers == null || headers.isEmpty()) {
114+
return Optional.empty();
115+
}
116+
return Optional.of(headers.get(0));
113117
}
114-
return Optional.of(headers.get(0));
115-
}
116118
}

0 commit comments

Comments
 (0)