Apache OpenWebBeans Peeco

Clone this repo:
  1. 379a822 Merge pull request #1 from a-rekkusu/master by Thomas Andraschko · 3 years, 10 months ago master
  2. 995bd88 initial project push by Alexander Fischer · 3 years, 10 months ago
  3. 4dce17d Create README.md by Thomas Andraschko · 3 years, 10 months ago

Peeco: an OWB centric HTTP microserver

This repository is one of the results of a GSOC 2020 (Google Summer of Code) project for OpenWebBeans at ASF. Its intention is to provide a very small and lightweight HTTP server with CDI functionalities at its core, that should hopefully become natively runnable soon, as a GraalVM native-image. For the server components, Netty is used. This repository contains the API, implementation and a showcase in the respective sub-modules.

Here's an example for how to configure and build this server:

public HttpServer init()
	return new HttpServer.Builder()
			.port(0) //applies a random valid port

And here's how you can use the API with the HttpHandler annotation:

@Inject private HttpServer httpServer;

@HttpHandler(method = {HttpMethod.GET}, url = "/hello/*", matching = Matching.WILDCARD)
public CompletionStage<Response> helloWorld(Request request)
	String responseContent = "Hello World from " + httpServer.getHost() + ":" + httpServer.getPort() + " !";
	ByteArrayInputStream output = new ByteArrayInputStream(responseContent.getBytes(StandardCharsets.UTF_8));

	return CompletableFuture.supplyAsync(() ->
		Response response = new Response();
		response.addHeader("statusCode", "200");
		response.addHeader("content-type", "text/html");
		return response;

This is a reactive example with CompletionStage; you can also straight up use Response as the method return type. The formal requirements of a valid handler method and annotation are:

  • return type must be CompletionStage<Response> or Response
  • first method parameter must be Request
  • Matching.WILDCARD needs a star at the end of the given url

For more examples please refer to the respective showcase. The implementation is found here.

PeecoExtension.java collects all methods that are annotated with our @HttpHandler and starts up the Netty Server. The flow of the request/response handling is then happening in PeecoChannelHandler.java.