Eclipse Vert.x 3.5.1 released!

We have just re­leased Vert.x 3.5.1!

Fixes first!

As usual this re­lease fixes bugs re­ported in 3.5.0, see the re­lease notes.

JUnit 5 support

This re­lease in­tro­duces the new vertx-​junit5 mod­ule.

JUnit 5 is a rewrite of the fa­mous Java test­ing frame­work that brings new in­ter­est­ing fea­tures, in­clud­ing:

  • nested tests,
  • the abil­ity to give a human-​readable de­scrip­tion of tests and test cases (and yes, even use emo­jis),
  • a mod­u­lar ex­ten­sion mech­a­nism that is more pow­er­ful than the JUnit 4 run­ner mech­a­nism (@Run­With an­no­ta­tion),
  • con­di­tional test ex­e­cu­tion,
  • pa­ra­me­ter­ized tests, in­clud­ing from sources such as CSV data,
  • the sup­port of Java 8 lambda ex­pres­sions in the re­worked built-​in as­ser­tions API,
  • sup­port for run­ning tests pre­vi­ously writ­ten for JUnit 4.

Sup­pose that we have a SampleVerticle ver­ti­cle that ex­poses a HTTP server on port 11981. Here is how we can test its de­ploy­ment as well as the re­sult of 10 con­cur­rent HTTP re­quests:

@Test
@DisplayName("🚀 Deploy a HTTP service verticle and make 10 requests")
void useSampleVerticle(Vertx vertx, VertxTestContext testContext) {
  WebClient webClient = WebClient.create(vertx);
  Checkpoint deploymentCheckpoint = testContext.checkpoint();

  Checkpoint requestCheckpoint = testContext.checkpoint(10);
  vertx.deployVerticle(new SampleVerticle(), testContext.succeeding(id -> {
    deploymentCheckpoint.flag();

    for (int i = 0; i < 10; i++) {
      webClient.get(11981, "localhost", "/")
        .as(BodyCodec.string())
        .send(testContext.succeeding(resp -> {
          testContext.verify(() -> {
            assertThat(resp.statusCode()).isEqualTo(200);
            assertThat(resp.body()).contains("Yo!");
            requestCheckpoint.flag();
          });
        }));
    }
  }));
}

The test method above ben­e­fits from the in­jec­tion of a work­ing Vertx con­text, a VertxTestContext for deal­ing with asyn­chro­nous op­er­a­tions, and the guar­an­tee that the ex­e­cu­tion time is bound by a time­out which can op­tion­ally be con­fig­ured using a @Timeout an­no­ta­tion.

The test suc­ceeds when all check­points have been flagged. Note that vertx-junit5 is ag­nos­tic of the as­ser­tions li­brary being used: you may opt for the built-​in JUnit 5 as­ser­tions or use a 3rd-​party li­brary such as As­sertJ as we did in the ex­am­ple above.

You can check­out the source on GitHub, read the man­ual and learn from the ex­am­ples.

Web API Contract enhancements

The pack­age vertx-web-api-contract in­cludes a va­ri­ety of fixes, from schema $ref to re­vamped doc­u­men­ta­tion. You can give a look at list of all fixes/im­prove­ments here and all break­ing changes here.

From 3.5.1 to load the ope­napi spec and in­stan­ti­ate the Router you should use new method OpenAPI3RouterFactory.create() that re­places old meth­ods createRouterFactoryFromFile() and createRouterFactoryFromURL(). This new method ac­cepts rel­a­tive paths, ab­solute paths, local URL with file:// and re­mote URL with http://. Note that if you want refeer to a file rel­a­tive to your jar’s root, you can sim­ply use a rel­a­tive path and the parser will look out the jar and into the jar for the spec.

From 3.5.1 all set­tings about OpenAPI3RouterFactory be­hav­iours dur­ing router gen­er­a­tion are in­globed in a new ob­ject called RouterFactoryOptions. From this ob­ject you can:

  • Con­fig­ure if you want to mount a de­fault val­i­da­tion fail­ure han­dler and which one (meth­ods setMountValidationFailureHandler(boolean) and setValidationFailureHandler(Handler))
  • Con­fig­ure if you want to mount a de­fault 501 not im­ple­mented han­dler and which one (meth­ods setMountNotImplementedFailureHandler(boolean) and setNotImplementedFailureHandler(Handler))
  • Con­fig­ure if you want to mount ResponseContentTypeHandler au­to­mat­i­cally (method setMountResponseContentTypeHandler(boolean))
  • Con­fig­ure if you want to fail dur­ing router gen­er­a­tion when se­cu­rity han­dlers are not con­fig­ured (method setRequireSecurityHandlers(boolean))

After ini­tial­iza­tion of route, you can mount the RouterFactoryOptions ob­ject with method routerFactory.setOptions() when you want be­fore call­ing getRouter().

RxJava deprecation removal

It is im­por­tant to know that 3.5.x will be the last re­lease with the legacy xyzObservable() meth­ods:

@Deprecated()
public Observable<HttpServer> listenObservable(int port, String host);

has been re­placed since Vert.x 3.4 by:

public Single<HttpServer> rxListen(int port, String host);

The xyzObservable() dep­re­cated meth­ods will be re­moved in Vert.x 3.6.

Wrap up

Vert.x 3.5.1 re­lease notes and break­ing changes:

The event bus client using the SockJS bridge are avail­able from NPM, Bower and as a We­b­Jar:

Docker im­ages are also avail­able on the Docker Hub. The Vert.x dis­tri­b­u­tion is also avail­able from SD­KMan and Home­Brew.

The ar­ti­facts have been de­ployed to Maven Cen­tral and you can get the dis­tri­b­u­tion on Bin­tray.

Happy cod­ing !

Next post

Google Summer of Code 2018

It's this time of year again! Google Summer of Code 2018 submission period has just started!

Read more
Previous post

Eclipse Vert.x based Framework URL Shortener Backend

We combine Vert.x with the serverless framework to write a microservice that runs on AWS Lambda.

Read more
Related posts

Unit and Integration Tests

Let’s refresh our mind about what we developed so far in the introduction to vert.x series. We forgot an important task. We didn’t test the API.

Read more

Checklist for Migrating from Vert.x 2.1.x to Vert.x 3 - Part One

So while upgrading our application, I thought I should note down all the changes that we had to do in the process. Since Vert.x 3 is a major upgrade from the previous version, with so many changes.

Read more

Things to keep in mind concerning CSRF attacks

Eclipse Vert.x like most frameworks provides an anti-CSRF defense. However, no framework can prevent all attack vectors that exist in the web. Therefore, developers need to be aware of some dangers and common attack vectors concerning CSRF defenses.

Read more