diff --git a/core-examples/README.adoc b/core-examples/README.adoc index f34866082..b0abb6923 100644 --- a/core-examples/README.adoc +++ b/core-examples/README.adoc @@ -464,26 +464,6 @@ Happily served by 97297@Macintosh.local The verticle has been migrated. -== Groovy verticles - -Vert.x supports several _formats_ to develop verticles in Groovy. This link:src/main/groovy/verticles[directory] -illustrates the different formats: - -* link:src/main/groovy/verticles/script.groovy[plain script] - a verticle developed as a plain Groovy script -* link:src/main/groovy/verticles/script-with-hooks.groovy[plain script with hooks] - a verticle developed as a script - with hooks called by vert.x when the verticle is deployed and un-deployed -* link:src/main/groovy/verticles/verticle-extending-abstract-verticle.groovy[class extending AbstractVerticle] - a -verticle developed as a class extending `AbstractVerticle` -* link:src/main/groovy/verticles/verticle-extending-groovy-verticle.groovy[class extending GroovyVerticle] - a -verticle developed as a class extending `GroovyVerticle` - -You can run these examples using the `vertx` command line. For example: - -[source,shell] ----- -vertx run script.groovy ----- - == JSON streaming parser A simple example illustrating how to use the streaming `JsonParser` to parse a giant array of small objects. diff --git a/core-examples/pom.xml b/core-examples/pom.xml index c43766a9e..760273276 100644 --- a/core-examples/pom.xml +++ b/core-examples/pom.xml @@ -6,7 +6,7 @@ io.vertx core-examples - 4.3.1 + 4.3.5 @@ -17,16 +17,9 @@ com.fasterxml.jackson.core - jackson-annotations - 2.11.3 + jackson-databind + 2.14.0 - - - io.netty - netty-tcnative-boringssl-static - 2.0.34.Final - - io.vertx vertx-hazelcast diff --git a/core-examples/src/main/java/io/vertx/example/core/http/https/Client.java b/core-examples/src/main/java/io/vertx/example/core/http/https/Client.java index cc02f8569..4d75e73f3 100644 --- a/core-examples/src/main/java/io/vertx/example/core/http/https/Client.java +++ b/core-examples/src/main/java/io/vertx/example/core/http/https/Client.java @@ -4,10 +4,12 @@ import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpMethod; +import io.vertx.core.net.JksOptions; import io.vertx.example.util.Runner; /* * @author Tim Fox + * @author linghengqian */ public class Client extends AbstractVerticle { @@ -21,7 +23,9 @@ public void start() throws Exception { // Note! in real-life you wouldn't often set trust all to true as it could leave you open to man in the middle attacks. - HttpClientOptions options = new HttpClientOptions().setSsl(true).setTrustAll(true); + HttpClientOptions options = new HttpClientOptions().setSsl(true).setTrustAll(true).setKeyStoreOptions( + new JksOptions().setPath("server-keystore.jks").setPassword("wibble") + ); HttpClient client = vertx.createHttpClient(options); client.request(HttpMethod.GET, 4443, "localhost", "/") .compose(req -> req.send() diff --git a/core-examples/src/main/java/io/vertx/example/core/http/simpleformupload/people.json b/core-examples/src/main/java/io/vertx/example/core/http/simpleformupload/people.json deleted file mode 100644 index 54ffe800d..000000000 --- a/core-examples/src/main/java/io/vertx/example/core/http/simpleformupload/people.json +++ /dev/null @@ -1,33 +0,0 @@ -[ - { - "name": "Paulo Lopes", - "gravatar": "paulo@mlopes.net", - "github": "pmlopes", - "tz": "Europe/Amsterdam" - }, - { - "name": "Clement Escoffier", - "github": "cescoffier", - "tz": "Europe/Paris" - }, - { - "name": "Julien Viet", - "github": "vietj", - "tz": "Europe/Paris" - }, - { - "name": "Eric Zhao", - "github": "sczyh30", - "tz": "Asia/Shanghai" - }, - { - "name":"Jayamine Alupotha", - "github": "jaymine", - "tz": "Asia/Colombo" - }, - { - "name":"Ricardo Hernandez-Montoya", - "github": "ricardohmon", - "tz": "Europe/Berlin" - } -] diff --git a/core-examples/src/main/java/io/vertx/example/core/http2/customframes/Client.java b/core-examples/src/main/java/io/vertx/example/core/http2/customframes/Client.java index 5e95dbd4a..e28a451a2 100644 --- a/core-examples/src/main/java/io/vertx/example/core/http2/customframes/Client.java +++ b/core-examples/src/main/java/io/vertx/example/core/http2/customframes/Client.java @@ -6,10 +6,12 @@ import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpMethod; import io.vertx.core.http.HttpVersion; +import io.vertx.core.net.PemKeyCertOptions; import io.vertx.example.util.Runner; /* * @author Tim Fox + * @author linghengqian */ public class Client extends AbstractVerticle { @@ -27,7 +29,8 @@ public void start() throws Exception { setSsl(true). setUseAlpn(true). setProtocolVersion(HttpVersion.HTTP_2). - setTrustAll(true); + setTrustAll(true). + setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem")); HttpClient client = vertx.createHttpClient(options); @@ -49,6 +52,6 @@ public void start() throws Exception { request.writeCustomFrame(10, 0, Buffer.buffer("ping")); }); }); - }); + }).onFailure(Throwable::printStackTrace); } } diff --git a/core-examples/src/main/java/io/vertx/example/core/http2/push/Client.java b/core-examples/src/main/java/io/vertx/example/core/http2/push/Client.java index b3e84b5d2..c3a816d56 100755 --- a/core-examples/src/main/java/io/vertx/example/core/http2/push/Client.java +++ b/core-examples/src/main/java/io/vertx/example/core/http2/push/Client.java @@ -2,10 +2,12 @@ import io.vertx.core.AbstractVerticle; import io.vertx.core.http.*; +import io.vertx.core.net.PemKeyCertOptions; import io.vertx.example.util.Runner; /* * @author Tim Fox + * @author linghengqian */ public class Client extends AbstractVerticle { @@ -23,11 +25,12 @@ public void start() throws Exception { setSsl(true). setUseAlpn(true). setProtocolVersion(HttpVersion.HTTP_2). - setTrustAll(true); + setTrustAll(true). + setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem")); HttpClient client = vertx.createHttpClient(options); - client.request(HttpMethod.GET, 8080, "localhost", "/").compose(request -> { + client.request(HttpMethod.GET, 8443, "localhost", "/").compose(request -> { // Set handler for server side push request.pushHandler(pushedReq -> { diff --git a/core-examples/src/main/java/io/vertx/example/core/http2/push/Server.java b/core-examples/src/main/java/io/vertx/example/core/http2/push/Server.java index 212fb9233..f9ef1cb92 100755 --- a/core-examples/src/main/java/io/vertx/example/core/http2/push/Server.java +++ b/core-examples/src/main/java/io/vertx/example/core/http2/push/Server.java @@ -10,6 +10,7 @@ /* * @author Tim Fox + * @author linghengqian */ public class Server extends AbstractVerticle { @@ -37,8 +38,6 @@ public void start() throws Exception { System.out.println("sending push"); HttpServerResponse pushedResp = ar.result(); pushedResp.sendFile("script.js"); - } else { - // Sometimes Safari forbids push : "Server push not allowed to opposite endpoint." } }); diff --git a/core-examples/src/main/java/io/vertx/example/core/http2/simple/Client.java b/core-examples/src/main/java/io/vertx/example/core/http2/simple/Client.java index 304f0b5df..c88effb71 100755 --- a/core-examples/src/main/java/io/vertx/example/core/http2/simple/Client.java +++ b/core-examples/src/main/java/io/vertx/example/core/http2/simple/Client.java @@ -5,12 +5,20 @@ import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpMethod; import io.vertx.core.http.HttpVersion; +import io.vertx.core.net.PemKeyCertOptions; +import io.vertx.example.util.Runner; /* * @author Tim Fox + * @author linghengqian */ public class Client extends AbstractVerticle { + // Convenience method so you can run it in your IDE + public static void main(String[] args) { + Runner.runExample(Client.class); + } + @Override public void start() throws Exception { @@ -20,16 +28,16 @@ public void start() throws Exception { setSsl(true). setUseAlpn(true). setProtocolVersion(HttpVersion.HTTP_2). - setTrustAll(true); - + setTrustAll(true). + setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem")); HttpClient client = vertx.createHttpClient(options); - client.request(HttpMethod.GET, 8080, "localhost", "/") + client.request(HttpMethod.GET, 8443, "localhost", "/") .compose(req -> req.send() .compose(resp -> { System.out.println("Got response " + resp.statusCode()); return resp.body(); })).onSuccess(body -> { - System.out.println("Got data " + body.toString("ISO-8859-1")); - }).onFailure(Throwable::printStackTrace); + System.out.println("Got data " + body.toString("ISO-8859-1")); + }).onFailure(Throwable::printStackTrace); } } diff --git a/core-examples/src/main/java/io/vertx/example/core/net/echossl/Client.java b/core-examples/src/main/java/io/vertx/example/core/net/echossl/Client.java index 51ee443ee..75dfeccda 100644 --- a/core-examples/src/main/java/io/vertx/example/core/net/echossl/Client.java +++ b/core-examples/src/main/java/io/vertx/example/core/net/echossl/Client.java @@ -1,6 +1,7 @@ package io.vertx.example.core.net.echossl; import io.vertx.core.AbstractVerticle; +import io.vertx.core.net.JksOptions; import io.vertx.core.net.NetClientOptions; import io.vertx.core.net.NetSocket; import io.vertx.example.util.Runner; @@ -18,7 +19,9 @@ public static void main(String[] args) { @Override public void start() throws Exception { - NetClientOptions options = new NetClientOptions().setSsl(true).setTrustAll(true); + NetClientOptions options = new NetClientOptions().setSsl(true).setTrustAll(true) + .setKeyStoreOptions(new JksOptions().setPath("server-keystore.jks") + .setPassword("wibble")); vertx.createNetClient(options).connect(1234, "localhost", res -> { if (res.succeeded()) { diff --git a/core-examples/src/main/java/io/vertx/example/core/net/greeter/Client.java b/core-examples/src/main/java/io/vertx/example/core/net/greeter/Client.java deleted file mode 100644 index 4c612c1f7..000000000 --- a/core-examples/src/main/java/io/vertx/example/core/net/greeter/Client.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2017 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.vertx.example.core.net.greeter; - -import io.vertx.core.AbstractVerticle; -import io.vertx.core.net.NetSocket; -import io.vertx.core.parsetools.RecordParser; -import io.vertx.example.util.Runner; - -import java.util.stream.Stream; - -/* - * @author Thomas Segismont - */ -public class Client extends AbstractVerticle { - - // Convenience method so you can run it in your IDE - public static void main(String[] args) { - Runner.runExample(Client.class); - } - - @Override - public void start() throws Exception { - vertx.createNetClient().connect(1234, "localhost", res -> { - - if (res.succeeded()) { - NetSocket socket = res.result(); - - RecordParser.newDelimited("\n", socket) - .endHandler(v -> socket.close()) - .exceptionHandler(t -> { - t.printStackTrace(); - socket.close(); - }) - .handler(buffer -> { - String greeting = buffer.toString("UTF-8"); - System.out.println("Net client receiving: " + greeting); - }); - - // Now send some data - Stream.of("John", "Joe", "Lisa", "Bill").forEach(name -> { - System.out.println("Net client sending: " + name); - socket.write(name); - socket.write("\n"); - }); - - } else { - System.out.println("Failed to connect " + res.cause()); - } - }); - } -} diff --git a/core-examples/src/main/java/io/vertx/example/core/net/greeter/Server.java b/core-examples/src/main/java/io/vertx/example/core/net/greeter/Server.java deleted file mode 100644 index 5da08aec3..000000000 --- a/core-examples/src/main/java/io/vertx/example/core/net/greeter/Server.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2017 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.vertx.example.core.net.greeter; - -import io.vertx.core.AbstractVerticle; -import io.vertx.core.parsetools.RecordParser; -import io.vertx.example.util.Runner; - -/* - * @author Thomas Segismont - */ -public class Server extends AbstractVerticle { - - // Convenience method so you can run it in your IDE - public static void main(String[] args) { - Runner.runExample(Server.class); - } - - @Override - public void start() throws Exception { - - vertx.createNetServer().connectHandler(sock -> { - - RecordParser parser = RecordParser.newDelimited("\n", sock); - - parser - .endHandler(v -> sock.close()) - .exceptionHandler(t -> { - t.printStackTrace(); - sock.close(); - }) - .handler(buffer -> { - String name = buffer.toString("UTF-8"); - sock.write("Hello " + name + "\n", "UTF-8"); - }); - - }).listen(1234); - - System.out.println("Echo server is now listening"); - - } -}