Commit Graph

70 Commits

Author SHA1 Message Date
Dave Syer
8ab4d61bb4 Align MVC handling between Spring 4 and Spring 5
A Spring Boot 2.0 app should behave the same as a Spering Boot 1.5
app with this change. The key thing was to change the return type
of the FunctionController and move the computation of single
valuedness for the output there (instead of trying to do it in the
return value handler, which isn't used in Spring 5).
2018-03-16 07:08:43 -04:00
Dave Syer
740a94b202 Make Gson special config conditional on Boot 1.5
That was the samples still work with Spring Boot 2.0.0.

Fixes gh-157 (but we should add some tests)
2018-03-09 12:17:24 +00:00
Dave Syer
33b33adb4b Change FunctionCatalog to key off Class<?>
Makes it possible to support other "function" types in the future.
The user is always taking a risk with the lookup that the object
returned has the generic type desired (but that hasn't changed
with this commit). FunctionCatalog is a lot simpler as a result
and also a lot more flexible.
2018-02-28 14:18:09 +00:00
Dave Syer
616e2825c6 Move FunctionCatalog into context module 2018-02-27 09:05:28 +00:00
Dave Syer
5203401e00 Use Void as input type for Supplier, etc. 2018-02-26 14:15:54 +00:00
Dave Syer
bf41055dc7 Some dependency hygiene and update to Boot 1.5.10
The web module doesn't really need to depend on tomcat and all of
the Spring Boot web stack, but users need a way to grab that stuff
quickly if they want it (hence the new starter).

Also removed all spring-boot-starter dependencies from core and
context modules.
2018-02-23 12:12:06 +00:00
Dave Syer
975398d30c Use Gson instead of Jackson by default 2018-02-23 11:19:23 +00:00
Dave Syer
1b624c3531 Support for isolated class loaders extended to cover more functions
Functions with Flux and Message (as well as POJOs and Flux of POJO
which were already supported) should now work if they are created in
an isolated class loader. Preconditions:

* The class loaders must have the reactor-core (and reactive-streams)
shared between the app and the function. Practically speaking this means
there has to be a parent class loader with just reactive types, and
sibling children for the app and the function. This is not a new
requirement (it was needed for Flux of POJO anyway).

* Message types are handled reflectively, so they don't have to be in a
shared class loader. But they do have to be  on the class path on
both sides (obviously).
2018-02-16 08:16:55 +00:00
Dave Syer
c728cd4c01 Support for Function<Publisher<...>,...> 2018-02-14 14:09:28 +00:00
Dave Syer
7b46f925d7 Switch to SmartInitializingSingleton to avoid early instantiation
Use of BeanProcessor to catch a bean before it is used is a bit
agricultural these days. SmartInitializingSingleton is better and
frees application logs from one more annoying INFO log on an
early instantiation

2018-01-04 14:17:05.930  INFO 23472 --- [       Thread-0] trationDelegate$BeanPostProcessorChecker :
  Bean 'org.springframework.cloud.function.web.flux.ReactorAutoConfiguration' of type
  [org.springframework.cloud.function.web.flux.ReactorAutoConfiguration$$EnhancerBySpringCGLIB$$8d4844e]
  is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-04 14:27:32 +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
3ccb925733 Merge core packages into one 2017-09-15 17:10:00 +01:00
Dave Syer
c8646d64d8 Strangle old inspector methods
Fixes gh-81
2017-07-13 13:37:45 +01:00
Dave Syer
d1ccef62b5 FunctionHandlerMapping needs to be defensive with debug flag
Spring Boot apps often run with --debug (no boolean value), so
we need to be defensive and not barf if it's empty (and therefore
not convertible to a boolean)
2017-06-28 15:07:07 +01: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
0d2418a47b Add "wrapper" type methods to FunctionInspector
These can be used to more reliably discover whether the user
has declared a function with flux types or "bare" POJOs. They
then pave the way to supporting single valued types in a special
way.

Also consolidate and simplify the logic in FunctionInspector
2017-05-24 09:10:46 +01:00
Dave Syer
998ea3ad35 Fix and test bug with generic input or output types
Without this fix a Function<Foo<Bar>,...> shows as having an
input type of Bar - we need to only take the parameter if the
raw type is Flux.
2017-05-22 13:27:49 +01:00
Dave Syer
6e1f0b9a6e Add FunctionInspector to deployer so types can be inspected
ALso added a bunch of DEBUG logging because it's hard to debug the
deployer app.

Fixed gh-53
2017-05-22 10:57:47 +02: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
markfisher
ff78bfc438 ensure processor is initialized when getting type 2017-05-05 09:44:27 -04: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
f02f2eaf95 Remove unused annotation class 2017-04-25 11:47:50 +01:00
Dave Syer
39ca7952b9 Fix some tests
There is one behaviour change (you have to POST an array to a function
endpoint if you are sending a body), and also a message converter that
needed to be removed so that arrays are not toStringed in the response
body.
2017-04-25 08:51:31 +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
07c9d1c460 Remove unused method parameter 2017-03-31 13:56:25 +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
markfisher
98c2ca76f5 avoid Supplier NPE 2017-03-18 21:38:08 -04: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
9b24d23df8 Add configurable base path for web resources 2017-03-13 13:43:26 +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
markfisher
1dc0489c23 introspect bean definition for Flux types
non-Flux Functions wrapped during auto-config
2017-03-02 10:53:21 -05:00
markfisher
19fd056a5e add support for simple (non-Flux) types
add objectToStringHttpMessageConverter

CompilerController accepts parameterized types
2017-02-24 12:14:57 -05:00
markfisher
2075c649a5 add null check in FunctionController 2017-02-06 15:41:19 -05:00