I had a few ideas I put together and would appreciate some feedback. A lot
of it revolves around Java 8 but I kept all of the extensions themselves at
Java 7. The main goal of Java 8 was to make constructing HttpHandlers
easier when you delegate to other handlers.
Example:
Handlers.routing()
.add(Methods.GET, "/messages", HandlerBuilder
.create(CustomHandlers.json(Messages::getMessages))
.wrap(CustomHandlers::timing, "getMessages")
.wrap(BlockingHandler::new)
.build())
Here is my branch
https://github.com/billoneil/undertow/tree/feature/ext
Here is the entry point to an example that puts it all together.
https://github.com/billoneil/undertow/blob/feature/ext/ext/examples/src/m...
Please excuse the boring example I couldn't think of anything interesting.
If you run it locally
curl -X POST localhost:8080/messages/optional -d '{"title":
"Optional",
"message": "Using optional"}'
{"success":true}
curl -X POST localhost:8080/messages/lambda -d '{"title":
"Lambda",
"message": "Using Lambda"}'
{"success":true}
curl -X POST localhost:8080/messages -d '{"title": "Method
References",
"message": "Using method references"}'
{"success":true}
curl -X GET localhost:8080/messages
[
-
{
- title: "Optional",
- message: "Using optional"
},
-
{
- title: "Lambda",
- message: "Using Lambda"
},
-
{
- title: "Method References",
- message: "Using method references"
}
]
curl -X GET localhost:8080/info/metrics
{
- version: "3.0.0",
- gauges: { },
- counters: { },
- histograms: { },
- meters:
{
- response.status.code.200:
{
- count: 8,
- m15_rate: 21.787938213503697,
- m1_rate: 6.5304307794735275,
- m5_rate: 18.017228623496,
- mean_rate: 4.457584495510739,
- units: "events/minute"
}
},
- timers:
{
- createMessageLambda:
{
- count: 1,
- max: 1.169,
- mean: 1.169,
- min: 1.169,
- p50: 1.169,
- p75: 1.169,
- p95: 1.169,
- p98: 1.169,
- p99: 1.169,
- p999: 1.169,
- stddev: 0,
- m15_rate: 0.059490549916151686,
- m1_rate: 0.1812199126454006,
- m5_rate: 0.14211865026090975,
- mean_rate: 0.5343847126926461,
- duration_units: "milliseconds",
- rate_units: "calls/minute"
},
- createMessageMethodReferences:
{
- count: 1,
- max: 0.648,
- mean: 0.648,
- min: 0.648,
- p50: 0.648,
- p75: 0.648,
- p95: 0.648,
- p98: 0.648,
- p99: 0.648,
- p999: 0.648,
- stddev: 0,
- m15_rate: 0.05982197273776584,
- m1_rate: 0.19696865690816925,
- m5_rate: 0.14450714325124409,
- mean_rate: 0.5343791108783038,
- duration_units: "milliseconds",
- rate_units: "calls/minute"
},
- createMessageOptional:
{
- count: 1,
- max: 94.579,
- mean: 94.579,
- min: 94.579,
- p50: 94.579,
- p75: 94.579,
- p95: 94.579,
- p98: 94.579,
- p99: 94.579,
- p999: 94.579,
- stddev: 0,
- m15_rate: 10.678581251856285,
- m1_rate: 2.0852873214053433,
- m5_rate: 8.456257076624562,
- mean_rate: 0.5343875445806129,
- duration_units: "milliseconds",
- rate_units: "calls/minute"
},
- getMessages:
{
- count: 3,
- max: 9.809999999999999,
- mean: 3.6413333333333333,
- min: 0.514,
- p50: 0.6,
- p75: 9.809999999999999,
- p95: 9.809999999999999,
- p98: 9.809999999999999,
- p99: 9.809999999999999,
- p999: 9.809999999999999,
- stddev: 5.342395093339066,
- m15_rate: 0.18767034671569677,
- m1_rate: 1.2185014871528328,
- m5_rate: 0.49650226189858143,
- mean_rate: 1.6030845484157583,
- duration_units: "milliseconds",
- rate_units: "calls/minute"
},
- getMetrics:
{
- count: 0,
- max: 0,
- mean: 0,
- min: 0,
- p50: 0,
- p75: 0,
- p95: 0,
- p98: 0,
- p99: 0,
- p999: 0,
- stddev: 0,
- m15_rate: 0,
- m1_rate: 0,
- m5_rate: 0,
- mean_rate: 0,
- duration_units: "milliseconds",
- rate_units: "calls/minute"
}
}
}
On Thu, Jul 3, 2014 at 9:28 AM, Bill O'Neil <bill(a)dartalley.com> wrote:
I have mostly just been getting familiar with undertow for side
projects.
I would be happy to share anything I come up with though to get some
feedback.
On Wed, Jul 2, 2014 at 10:44 AM, Jason Greene <jason.greene(a)redhat.com>
wrote:
> On Jul 2, 2014, at 9:02 AM, Bill O'Neil <bill(a)dartalley.com> wrote:
>
> > Is there any plan to open up an undertow-ext library where the
> community can make small modules that hook into 3rd party dependencies?
> For example, an HttpHandler that uses Jackson/Gson to serialize to json
> and set appropriate headers, or an HTML templating framework for rendering
> HTML.
> >
> > Would you prefer these to be hosted by 3rd parties instead?
>
> I think this is a great idea. Are you interested in being a maintainer of
> such a thing?
>
> --
> Jason T. Greene
> WildFly Lead / JBoss EAP Platform Architect
> JBoss, a division of Red Hat
>
>