Commit Graph

38 Commits

Author SHA1 Message Date
Dave Syer
e34324b5b4 Double check that a Function can return a Mono 2018-05-15 08:43:58 +01:00
Dave Syer
af5f5b78de Tweak support for single valued text HTTP exchange 2018-05-02 13:00:22 -04:00
Dave Syer
0f8c1ce860 Make Jackson optional in web adapter
There is now a JsonMapper strategy with implementations and
autoconfiguration for Gson and Jackson. If Jackson is present
it is preferred (just like in Spring Boot).

Fixes gh-150
2018-04-24 11:57:47 +01:00
bishoy
0e41b8acc5 Support incoming application/x-www-form-urlencoded content
Fixes #129
2018-04-24 08:55:22 +01:00
Dave Syer
5aeba1ea96 Convert Consumer<Foo> to Function<Flux<Foo>,Mono<Void>>
This results in a better experience for users because the consumer
that they write is only applied to a Flux that is subscribed to
by the framework once. It gives better control over the flow of
foos, e.g. if some component wants to subscribe on a thread.
2018-03-26 10:06:13 +01:00
Dave Syer
0be5f14766 Provide new config options for streams enabling composition
User can switch off source or sink behaviour (the default is to bind
to input and output streams), and then configure the name of a
supplier (for a source) or consumer (for a sink).
2018-03-18 14:19:51 +00:00
Dave Syer
1c0b603986 Add back spring-cloud-function-web (faster startup)
With this change there are now 2 choices for web endpoints. The
stream servlet binder is useful for multi-binder use cases
(e.g. HTTP -> message broker).
2018-01-03 15:06:33 +00:00
Dave Syer
1af0d451cf Migrate to servlet binder for web features 2018-01-03 15:06:33 +00:00
Dave Syer
66beae56bd Add test for multi-valued response 2017-11-15 13:57:05 +00:00
Dave Syer
ad0ebd5cfc Add additional logic to function catalog to help with singletons
A registered singleton doesn't have a BeanDefinition, but it might have
a compiled type with enough generic information to pull out the
input and output types.
2017-11-10 12:11:55 +00:00
Dave Syer
f94d672dc4 Add test and fix type inspection for scanned functions
Fixes gh-73
2017-06-28 11:00:07 +01:00
Dave Syer
e4b181d0c4 Fix /prefix test so it asserts a 404 as well as a 200 2017-06-28 09:41:04 +01:00
Dave Syer
b61562508b Add support for Message handling in web functions
If the output is a Message we grab the headers from the first one
and send those as response headers.

A function can add headers to messages. The HTTP response will
contain only headers that are in x-* _or_ were added to the message
by user (i.e. they weren't in the request).
We certainly do not want to pass through all HTTP headers (request
headers can conflict with or invalidate response headers).
2017-06-22 09:45:12 +01:00
Dave Syer
1d53cd1234 Ensure debug flag gets resolved in controller 2017-06-22 09:45:12 +01:00
Dave Syer
c685866f09 Fix compiled scripts demo from README
Compiled functions always show up with no metadata, and you can only
guess what the types are from the bean definition. Probably we should
add more information to the bean definition if we have it when we
compile the function.

There is still a problem if user defines functions that are not of
Flux<String> (but that has always been the case).
2017-05-25 07:53:29 +01:00
Dave Syer
5589804d2c Add support for single valued Supplier as well 2017-05-24 11:00:32 +01:00
Dave Syer
20a6796793 Add support for rendering single value in response
If the request is a single value, we already know, so if we also
know that the function returned a single-valued type, then we can
render the single value, instead of an array with a single item.

See gh-36
2017-05-24 10:16:22 +01:00
Dave Syer
120d2da496 Add support for POSTing a single POJO
You need to cache the request body so it can be read twice, once
to see if it's an array, and again to turn it into a POJO.
2017-05-16 10:26:10 +01:00
Dave Syer
69c22482d1 Add more subtle content negotiation in web layer
So that single Strings can be POSTed without JSON conversion.
There's still some work to do to support single POJOs in JSON, and
to reach parity with the WebFlux reactive type handlers, but it's
now closer to what we had before we moved the String conversion
out of the function layer.
2017-05-05 09:22:23 +01:00
Dave Syer
4686e450b1 Alternative approach to MVC handling
Doesn't rely on manipulating the FunctionCatalog, and does type
conversion/coercion in the MVC layer.
2017-04-24 16:31:09 +01:00
Dave Syer
5055369cb5 Fix prefix issue 2017-04-24 16:31:09 +01:00
Dave Syer
2b88eaeb08 Extend support for simple types to Consumer and Supplier
The function catalog now always wraps beans that deal with non-flux
generic types.
2017-03-31 14:08:35 +01:00
Dave Syer
38dcbaffff Add test for priority of looking up supplier in GET mapping 2017-03-31 13:48:36 +01:00
Dave Syer
cadd5546da Add custom HandlerMapping to allow more flexible request mapping 2017-03-31 13:44:11 +01:00
Dave Syer
787ab65d55 On POST to a Consumer, reflect input and send 202 2017-03-30 16:42:19 +01:00
Dave Syer
0d08735dda Test POST to Consumer
See gh-36
2017-03-30 16:42:19 +01:00
Dave Syer
915ff401be Make GET /{function}/{value} single valued (Mono)
When the user has sent us a single value, we can make the signature
of the handler and the format of the HTTP response much more
natural if it is single valued too (i.e. a Mono).
2017-03-13 15:01:10 +00:00
Dave Syer
2ee97721ab Support HTTP GET of single value value Function
E.g. a Function<Long, Foo> can be used to fetch a single entity of
type Foo with a long ID., via /{function}/{id}
2017-03-10 16:33:34 +00:00
Dave Syer
17b644f563 If HTTP client asks for JSON, then time out the response
An HTTP response does not have to be an infinite stream, and in fact
life is simpler if it is not. The timeout in the web wrappers can
be used to close the response and return normally to a client
that has been waiting more than (say) 1s, instead of treating
it as an error condition.

Error handling is still kind of unsolved.
2017-03-09 16:10:08 +00:00
Dave Syer
ec097a563d Tweak SSE emitter a bit so that it handles empty responses
An empty response should either be empty or complete JSON. I went
for the latter.
2017-03-08 15:02:35 +00:00
Dave Syer
0c4dcfaf72 Fix bug in response when JSON is empty 2017-03-07 16:54:34 +00:00
Dave Syer
425be34b98 Send content type to web response if available 2017-01-23 09:37:02 +00:00
Dave Syer
946f4a3bf3 Fix HTTP responses that caller asked to be JSON
If caller says he accepts application/json we need to be sure that
we send an array. That wasn't quite working and hadn't been tested.
2017-01-20 13:54:23 -05:00
Dave Syer
452106f287 Fix some logic with media types
If user sends "Accept: */*" we don't want to default to sending
an SSE (for instance). So the logic for detecting those preferences
has to take MediaType.ALL into account as a special case.
2017-01-20 13:10:57 +00:00
Dave Syer
216e5c9207 Add MVC body processors to handle Flux
We don't need to cover all the possible uses of Flux (only
Flux<String> really), so this isn't comprehensive coverage of
all the features in Spring WebFlux, but it's good enough for
functions to run with Spring Boot 1.5.
2017-01-12 08:55:46 -05:00
Dave Syer
fc9d258564 Add custom JsonObjectDecoder to extract a Flux<String> from request 2017-01-06 15:21:56 +00:00
Dave Syer
3357a93cef Add some tests for JSON mime types in rest endpoints 2017-01-06 14:11:48 +00:00
Dave Syer
4ad01be090 Add support for server-side events and tests
User can POST to web endpoint in SSE style, i.e:

HTTP/1.1
Content-Type: text/event-stream

data:foo

data:bar

Will be converted to a Flux with values foo and bar
2017-01-06 12:43:38 +00:00