Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[break][Undertow] Rewrite conjure-undertow API (#260)
## All implementation has moved to the runtime module * `conjure-undertow-lib` only contains interfaces. * `ServiceContext` -> `UndertowRuntime` * `StringDeserializers` -> `UndertowRuntime.plainSerDe()` * `Auth.cookie/header` -> `UndertowRuntime.auth().cookie/header` **Rationale**: All runtime behavior should be updated in lock step in `conjure-java-runtime`, this change allows the undertow runtime to behave similarly to jersey. ## Renamed Service to UndertowService Registering generated service implementations using `.api(Service)` failed to make it clear what `Service` was. `.api(UndertowService)` is immediately understandable. ## `UndertowService` creates a list of `Endpoint` `Registerable` and `EndpointRegistry` are no longer needed in this simplified model. Generated code is easier to understand and only contains one level of nested inner classes. ## Serializers and Deserializers are typed Serializer and Deserializer objects are created eagerly when Endpoints are constructed in order to match the conjure specification more closely. Each endpoint receives exactly one body type, and returns exactly one type. This avoids unnecessary type mapping for each request. ## Immutable UndertowHandler Endpoints must be added to the `UndertowHandler.Builder` before a `HttpHandler` is created to ensure behavior remains constant once a server has started. ## Example generated `EmptyPathServiceEndpoints.java` Note that the output is more verbose than previous versions, however it's also less complex in both legibility runtime cost. ```java @generated("com.palantir.conjure.java.services.UndertowServiceHandlerGenerator") public final class EmptyPathServiceEndpoints implements UndertowService { private final EmptyPathService delegate; private EmptyPathServiceEndpoints(EmptyPathService delegate) { this.delegate = delegate; } public static UndertowService of(EmptyPathService delegate) { return new EmptyPathServiceEndpoints(delegate); } @OverRide public List<Endpoint> endpoints(UndertowRuntime runtime) { return ImmutableList.of(new EmptyPathEndpoint(runtime, delegate)); } private static final class EmptyPathEndpoint implements HttpHandler, Endpoint { private final UndertowRuntime runtime; private final EmptyPathService delegate; private final Serializer<Boolean> serializer; EmptyPathEndpoint(UndertowRuntime runtime, EmptyPathService delegate) { this.runtime = runtime; this.delegate = delegate; this.serializer = runtime.bodySerDe().serializer(new TypeToken<Boolean>() {}); } @OverRide public void handleRequest(HttpServerExchange exchange) throws IOException { boolean result = delegate.emptyPath(); serializer.serialize(result, exchange); } @OverRide public HttpString method() { return Methods.GET; } @OverRide public String template() { return "/"; } @OverRide public String serviceName() { return "EmptyPathService"; } @OverRide public String name() { return "emptyPath"; } @OverRide public HttpHandler handler() { return this; } } } ```
- Loading branch information