Skip to content

Upgrade Jooby #40

@pierre

Description

@pierre

Jooby 2.x is a significant rewrite. The major breaking change is that there is no more Servlet support, which is a blocker for us.

Here are my notes from a quick investigation.

  1. org.jooby.Result and org.jooby.Results are gone, the new io.jooby.Context should be used instead.
@Singleton
@Path("/something")
public class SomethingResource {
    @GET
    public Result getSomething(final Optional<String> maybeSomething) {
        return Results.ok(...);
    }
}

becomes

@Singleton
@Path("/something")
public class SomethingResource {
    @GET
    public void getSomething(final Optional<String> maybeSomething, final Context context) {
        context.setResponseCode(StatusCode.OK);
    }
}
  1. Jooby#use(config) has been removed: instead, we need to create a new environment (https://jooby.io/#configuration-custom-environment). Maybe something like that (untested):
    public PluginApp build() {
        final PluginApp app = new PluginApp(jackson, services, routeClasses);
        final Environment origEnv = app.getEnvironment();
        final Environment newEnv = new Environment(origEnv.getClassLoader(),
                                                   this.config.withFallback(origEnv.getConfig()),
                                                   origEnv.getActiveNames());
        app.setEnvironment(newEnv);
        return app;
    }
  1. org.jooby.Sse has become io.jooby.ServerSentEmitter
  2. org.jooby.mvc.Local has become io.jooby.annotations.ContextParam
  3. There is no injection framework in 2.x. Guice has been replaced with a simple hash map service registry. Extra work is needed to integrate Guice again: https://jooby.io/#dependency-injection-guice

As part of the upgrade, we should add a few tests (https://jooby.io/#testing) in our base framework, to help with such upgrades in the future.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions