├── .gitignore ├── doc ├── .gitignore ├── src │ └── main │ │ └── asciidoc │ │ ├── weld-vertx-doc.adoc │ │ ├── probe.adoc │ │ ├── highlightjs │ │ ├── LICENSE │ │ └── styles │ │ │ └── agate.min.css │ │ └── service-proxy.adoc └── pom.xml ├── core ├── .gitignore ├── src │ ├── test │ │ ├── resources │ │ │ ├── logging.properties │ │ │ └── META-INF │ │ │ │ └── beans.xml │ │ └── java │ │ │ └── org │ │ │ └── jboss │ │ │ └── weld │ │ │ └── vertx │ │ │ ├── async │ │ │ ├── reference │ │ │ │ ├── BingProducer.java │ │ │ │ ├── Hello.java │ │ │ │ ├── Baz.java │ │ │ │ ├── Juicy.java │ │ │ │ ├── Boss.java │ │ │ │ ├── BlockingFoo.java │ │ │ │ ├── NormalScopedBlockingFoo.java │ │ │ │ └── BlockingBarProducer.java │ │ │ └── worker │ │ │ │ ├── Hello.java │ │ │ │ ├── HelloCombo.java │ │ │ │ ├── BlockingFoo.java │ │ │ │ └── BlockingAlpha.java │ │ │ ├── CoolHelloService.java │ │ │ ├── container │ │ │ ├── SayHelloService.java │ │ │ ├── BeanVerticle.java │ │ │ └── WeldVerticleContainerTest.java │ │ │ ├── CacheService.java │ │ │ ├── extension │ │ │ ├── HelloObserver.java │ │ │ └── RegisterConsumersAfterBootstrapTest.java │ │ │ ├── Timeouts.java │ │ │ ├── CoolService.java │ │ │ └── CustomWeldVerticleTest.java │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── beans.xml │ │ └── java │ │ └── org │ │ └── jboss │ │ └── weld │ │ └── vertx │ │ ├── RecipientFailure.java │ │ ├── VertxHandler.java │ │ ├── VertxConsumer.java │ │ ├── VertxMessageImpl.java │ │ ├── VertxEventImpl.java │ │ ├── AsyncReference.java │ │ ├── AsyncWorker.java │ │ └── VertxEvent.java └── pom.xml ├── examples ├── hello │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── beans.xml │ │ │ └── java │ │ │ └── org │ │ │ └── jboss │ │ │ └── weld │ │ │ └── vertx │ │ │ └── examples │ │ │ └── hello │ │ │ └── HelloMain.java │ ├── README.md │ └── pom.xml ├── kotlin │ ├── .gitignore │ ├── src │ │ ├── test │ │ │ ├── resources │ │ │ │ └── logging.properties │ │ │ └── kotlin │ │ │ │ └── org │ │ │ │ └── jboss │ │ │ │ └── weld │ │ │ │ └── vertx │ │ │ │ └── kotlin │ │ │ │ └── HandlersTest.kt │ │ └── main │ │ │ ├── resources │ │ │ ├── vertx-default-jul-logging.properties │ │ │ └── META-INF │ │ │ │ └── beans.xml │ │ │ └── kotlin │ │ │ └── org │ │ │ └── jboss │ │ │ └── weld │ │ │ └── vertx │ │ │ └── kotlin │ │ │ └── Handlers.kt │ ├── README.md │ └── pom.xml └── translator │ ├── .gitignore │ ├── src │ ├── test │ │ ├── resources │ │ │ └── logging.properties │ │ └── java │ │ │ └── org │ │ │ └── jboss │ │ │ └── weld │ │ │ └── vertx │ │ │ └── examples │ │ │ └── translator │ │ │ └── TranslatorExampleTest.java │ └── main │ │ ├── resources │ │ ├── org │ │ │ └── jboss │ │ │ │ └── weld │ │ │ │ └── vertx │ │ │ │ └── examples │ │ │ │ └── translator │ │ │ │ └── data.properties │ │ ├── vertx-default-jul-logging.properties │ │ └── META-INF │ │ │ └── beans.xml │ │ └── java │ │ └── org │ │ └── jboss │ │ └── weld │ │ └── vertx │ │ └── examples │ │ └── translator │ │ ├── RootHandler.java │ │ ├── SentenceParser.java │ │ ├── TranslatorExampleRunner.java │ │ ├── Addresses.java │ │ ├── SimpleSentenceParser.java │ │ ├── TranslateHandler.java │ │ ├── TranslatorVerticle.java │ │ ├── Translator.java │ │ └── DummyDataVerticle.java │ ├── README.md │ └── pom.xml ├── probe ├── .gitignore ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ ├── services │ │ │ │ └── javax.enterprise.inject.spi.Extension │ │ │ │ └── beans.xml │ │ └── java │ │ │ └── org │ │ │ └── jboss │ │ │ └── weld │ │ │ └── vertx │ │ │ └── probe │ │ │ ├── VertxProbeExtension.java │ │ │ ├── JsonDataProviderProducer.java │ │ │ ├── Exports.java │ │ │ ├── SecurityActions.java │ │ │ └── IOUtils.java │ └── test │ │ ├── resources │ │ ├── vertx-default-jul-logging.properties │ │ └── META-INF │ │ │ └── beans.xml │ │ └── java │ │ └── org │ │ └── jboss │ │ └── weld │ │ └── vertx │ │ └── probe │ │ └── ProbeHandlersTest.java └── pom.xml ├── web ├── .gitignore ├── src │ ├── test │ │ ├── resources │ │ │ ├── logging.properties │ │ │ └── META-INF │ │ │ │ └── beans.xml │ │ └── java │ │ │ └── org │ │ │ └── jboss │ │ │ └── weld │ │ │ └── vertx │ │ │ └── web │ │ │ ├── SayHelloService.java │ │ │ ├── AlwaysFailHandler.java │ │ │ ├── BravoHandler.java │ │ │ ├── RepeatingHandler.java │ │ │ ├── AlphaHandler.java │ │ │ ├── Payment.java │ │ │ ├── HelloHandler.java │ │ │ ├── RequestHelloService.java │ │ │ ├── UniversalFailureHandler.java │ │ │ ├── HelloGetHandler.java │ │ │ ├── async │ │ │ ├── AsyncRouteObserver.java │ │ │ ├── HelloAsyncHandler.java │ │ │ ├── BlockingService.java │ │ │ ├── HelloAsyncWebRouteTest.java │ │ │ └── AsyncRouteObserversTest.java │ │ │ ├── RequestContextActiveHandler.java │ │ │ ├── PaymentService.java │ │ │ ├── observer │ │ │ ├── PaymentObserverResource.java │ │ │ └── HelloRouteObserver.java │ │ │ ├── PaymentResource.java │ │ │ └── extension │ │ │ └── RouteExtensionTest.java │ └── main │ │ └── java │ │ └── org │ │ └── jboss │ │ └── weld │ │ └── vertx │ │ └── web │ │ ├── WebRoutes.java │ │ ├── Id.java │ │ └── WeldWebVerticle.java └── pom.xml ├── service-proxy ├── .gitignore ├── src │ ├── test │ │ ├── resources │ │ │ ├── logging.properties │ │ │ └── META-INF │ │ │ │ └── beans.xml │ │ └── java │ │ │ └── org │ │ │ └── jboss │ │ │ └── weld │ │ │ └── vertx │ │ │ └── serviceproxy │ │ │ ├── package-info.java │ │ │ ├── EchoObserver.java │ │ │ ├── EchoService.java │ │ │ ├── EchoServiceVerticle.java │ │ │ ├── EchoServiceImpl.java │ │ │ ├── Echo.java │ │ │ ├── EchoServiceConsumer.java │ │ │ └── EchoServiceProxyTest.java │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ ├── services │ │ │ └── javax.enterprise.inject.spi.Extension │ │ │ └── beans.xml │ │ └── java │ │ └── org │ │ └── jboss │ │ └── weld │ │ └── vertx │ │ └── serviceproxy │ │ ├── DefaultServiceProxySupport.java │ │ ├── ServiceProxySupport.java │ │ └── ServiceProxy.java └── pom.xml ├── .travis.yml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.classpath 3 | /.project 4 | /.settings/ 5 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.settings/ 3 | /.classpath 4 | /.project 5 | -------------------------------------------------------------------------------- /core/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.classpath 3 | /.project 4 | /.vertx/ 5 | /.settings/ 6 | -------------------------------------------------------------------------------- /examples/hello/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.settings/ 3 | /.classpath 4 | /.project 5 | -------------------------------------------------------------------------------- /examples/kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.settings/ 3 | /.project 4 | /.classpath 5 | -------------------------------------------------------------------------------- /examples/translator/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.settings/ 3 | /.project 4 | /.classpath 5 | -------------------------------------------------------------------------------- /probe/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.classpath 3 | /.project 4 | /.vertx/ 5 | /.settings/ 6 | /file-uploads/ 7 | -------------------------------------------------------------------------------- /web/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.classpath 3 | /.project 4 | /.vertx/ 5 | /.settings/ 6 | /file-uploads/ 7 | -------------------------------------------------------------------------------- /service-proxy/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.classpath 3 | /.project 4 | /.vertx/ 5 | /.settings/ 6 | /file-uploads/ 7 | -------------------------------------------------------------------------------- /core/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler 2 | org.jboss.weld.level = WARNING -------------------------------------------------------------------------------- /web/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler 2 | org.jboss.weld.level = WARNING -------------------------------------------------------------------------------- /probe/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.jboss.weld.vertx.probe.VertxProbeExtension -------------------------------------------------------------------------------- /examples/kotlin/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler 2 | org.jboss.weld.level = WARNING -------------------------------------------------------------------------------- /service-proxy/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler 2 | org.jboss.weld.level = WARNING -------------------------------------------------------------------------------- /examples/translator/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler 2 | org.jboss.weld.level = WARNING -------------------------------------------------------------------------------- /service-proxy/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.jboss.weld.vertx.serviceproxy.ServiceProxyExtension -------------------------------------------------------------------------------- /examples/translator/src/main/resources/org/jboss/weld/vertx/examples/translator/data.properties: -------------------------------------------------------------------------------- 1 | hello=ahoj,dobry den 2 | name=jmeno 3 | world=svet 4 | cat=kocka 5 | life=zivot 6 | is=je 7 | cool=cool -------------------------------------------------------------------------------- /probe/src/test/resources/vertx-default-jul-logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | 3 | java.util.logging.ConsoleHandler.level=FINEST 4 | 5 | .level=INFO 6 | org.jboss.weld.level=INFO -------------------------------------------------------------------------------- /examples/kotlin/src/main/resources/vertx-default-jul-logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | 3 | java.util.logging.ConsoleHandler.level=FINEST 4 | 5 | .level=INFO 6 | org.jboss.weld.vertx.level=FINEST -------------------------------------------------------------------------------- /examples/translator/src/main/resources/vertx-default-jul-logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | 3 | java.util.logging.ConsoleHandler.level=FINEST 4 | 5 | .level=INFO 6 | org.jboss.weld.vertx.level=FINEST -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | language: java 3 | jdk: 4 | - oraclejdk8 5 | - openjdk8 6 | env: 7 | - WELD_PROFILE=weld3 8 | script: "mvn verify -D${WELD_PROFILE} -DdefaultTimeout=10000 -DglobalTimeout=20000" 9 | sudo: false 10 | -------------------------------------------------------------------------------- /service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/package-info.java: -------------------------------------------------------------------------------- 1 | @ModuleGen(name = "weld-verxt-serviceproxy-test", groupPackage = "org.jboss.weld.vertx.serviceproxy") 2 | package org.jboss.weld.vertx.serviceproxy; 3 | 4 | import io.vertx.codegen.annotations.ModuleGen; -------------------------------------------------------------------------------- /examples/hello/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /probe/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /core/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /core/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /examples/kotlin/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /examples/translator/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /probe/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /web/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /service-proxy/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /service-proxy/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/EchoObserver.java: -------------------------------------------------------------------------------- 1 | package org.jboss.weld.vertx.serviceproxy; 2 | 3 | import javax.enterprise.context.ApplicationScoped; 4 | import javax.enterprise.event.Observes; 5 | 6 | @ApplicationScoped 7 | public class EchoObserver { 8 | 9 | public void observeEcho(@Observes @Echo String result) { 10 | EchoServiceProxyTest.SYNCHRONIZER.add(result); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/RootHandler.java: -------------------------------------------------------------------------------- 1 | package org.jboss.weld.vertx.examples.translator; 2 | 3 | import org.jboss.weld.vertx.web.WebRoute; 4 | 5 | import io.vertx.core.Handler; 6 | import io.vertx.ext.web.RoutingContext; 7 | 8 | @WebRoute("/") 9 | public class RootHandler implements Handler { 10 | 11 | @Override 12 | public void handle(RoutingContext ctx) { 13 | ctx.response().setStatusCode(200).end("Weld Vert.x translator example running..."); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /doc/src/main/asciidoc/weld-vertx-doc.adoc: -------------------------------------------------------------------------------- 1 | = Weld Vert.x Extensions 2 | :toc: right 3 | :toclevels: 2 4 | :sectnumlevels: 4 5 | :sectnums: 6 | 7 | [.lead] 8 | The primary purpose of `weld-vertx` is to bring the CDI programming model into the http://vertx.io/[Vert.x] ecosystem, i.e. to extend the tool-kit for building reactive applications on the JVM. 9 | 10 | http://weld.cdi-spec.org/[Weld] is the reference implementation of CDI. It’s part of a community of http://www.redhat.com/[Red Hat] projects. 11 | 12 | include::core.adoc[] 13 | 14 | include::web.adoc[] 15 | 16 | include::service-proxy.adoc[] 17 | 18 | include::probe.adoc[] 19 | -------------------------------------------------------------------------------- /doc/src/main/asciidoc/probe.adoc: -------------------------------------------------------------------------------- 1 | == Probe 2 | 3 | * Allows to use http://docs.jboss.org/weld/reference/latest/en-US/html/devmode.html#probe[Probe] development tool in a Vert.x application 4 | * Depends on `weld-vertx-web` 5 | 6 | .Artifact GAV 7 | [source,xml] 8 | ---- 9 | 10 | org.jboss.weld.vertx 11 | weld-vertx-probe 12 | ${version.weld-vertx} 13 | 14 | ---- 15 | 16 | === How does it work? 17 | 18 | Just add `weld-vertx-probe` to the classpath, set the `org.jboss.weld.development` system property to `true` and use `WeldWebVerticle` to register the routes defined declaratively (as defined in <>). 19 | 20 | -------------------------------------------------------------------------------- /examples/hello/README.md: -------------------------------------------------------------------------------- 1 | # Weld Vert.x "Hello" Example 2 | 3 | This simple example shows how to start a very simple "hello" webapp. 4 | 5 | ## HTTP Endpoints 6 | 7 | The app has only one `@WebRoute` handler `org.jboss.weld.vertx.examples.hello.HelloMain.HelloHandler` which is discovered and registered automatically. 8 | 9 | ## Start the App 10 | 11 | ### IDE 12 | 13 | Open `org.jboss.weld.vertx.examples.hello.HelloMain` class and run it as Java app. 14 | 15 | ### Command Line 16 | 17 | 1. `mvn clean package` 18 | 2. `java -jar target/weld-vertx-hello-example-shaded.jar` 19 | 20 | ## Say Hello 21 | 22 | Open `http://localhost:8080/hello?name=Herbert` in your browser or `curl http://localhost:8080/hello?name=Marv`. 23 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/reference/BingProducer.java: -------------------------------------------------------------------------------- 1 | package org.jboss.weld.vertx.async.reference; 2 | 3 | import javax.enterprise.context.ApplicationScoped; 4 | import javax.enterprise.context.Dependent; 5 | import javax.enterprise.inject.Produces; 6 | 7 | @ApplicationScoped 8 | public class BingProducer { 9 | 10 | @Dependent 11 | @Produces 12 | Bing noBing() { 13 | return null; 14 | } 15 | 16 | @Dependent 17 | @Produces 18 | @Juicy 19 | Bing juicyBing() { 20 | return new Bing(55); 21 | } 22 | 23 | static class Bing { 24 | 25 | int value; 26 | 27 | public Bing(int value) { 28 | this.value = value; 29 | } 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /examples/kotlin/README.md: -------------------------------------------------------------------------------- 1 | # Weld Vert.x Kotlin Example 2 | 3 | This simple example shows that Weld and Vertx play well together with [Kotlin programming language](https://kotlinlang.org/). 4 | 5 | ## HTTP Endpoints 6 | 7 | The app defines two routes annoted with `@WebRoute`. 8 | `org.jboss.weld.vertx.kotlin.UpperCaseHandler` class and an observer method declared in `org.jboss.weld.vertx.kotlin.Observers`. 9 | Both are discovered and registered automatically. 10 | 11 | ## Start the App 12 | 13 | ### IDE 14 | 15 | Run `org.jboss.weld.vertx.kotlin.main` function as a Kotlin app. 16 | 17 | ### Command Line 18 | 19 | 1. `mvn clean package` 20 | 2. `java -jar target/weld-vertx-kotlin-shaded.jar` 21 | 22 | ## Convert value to uppercase 23 | 24 | Open `http://localhost:8080/upperCase?value=Herbert` in your browser or `curl http://localhost:8080/lowerCase?value=Marv`. 25 | -------------------------------------------------------------------------------- /examples/translator/README.md: -------------------------------------------------------------------------------- 1 | # Weld Vert.x Translator Example 2 | 3 | This example aims to show the features of `weld-vertx-core` and `weld-vertx-web`. 4 | 5 | ## Business Logic 6 | 7 | The app entry point is `org.jboss.weld.vertx.examples.translator.TranslateHandler` - a `@WebRoute` handler which is discovered and registered automatically. 8 | `TranslateHandler` accepts "translate" requests and sends a message to the Vert.x event bus. 9 | Another CDI bean - `org.jboss.weld.vertx.examples.translator.Translator` - consumes this event and implements the translation logic (using other CDI beans and Vert.x verticle). 10 | 11 | ## Start the App 12 | 13 | ### IDE 14 | 15 | Open `org.jboss.weld.vertx.examples.translator.TranslatorExampleRunner` class and run it as Java app. 16 | 17 | ### Command Line 18 | 19 | 1. `mvn clean package` 20 | 2. `java -jar target/weld-vertx-translator-example-shaded.jar` 21 | 22 | ## Translate 23 | 24 | Let's use `curl` to perform a request: 25 | 26 | ```bash 27 | curl -d "sentence=Hello world" http://localhost:8080/translate 28 | ``` -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/CoolHelloService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import javax.enterprise.context.Dependent; 20 | 21 | @Dependent 22 | public class CoolHelloService { 23 | 24 | String hello() { 25 | return "works"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/SentenceParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.examples.translator; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * 23 | * @author Martin Kouba 24 | */ 25 | public interface SentenceParser { 26 | 27 | List parse(String sentence); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/container/SayHelloService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.container; 18 | 19 | import javax.enterprise.context.Dependent; 20 | 21 | @Dependent 22 | public class SayHelloService { 23 | 24 | static final String MESSAGE = "Good bye EE, hello Vert.x!"; 25 | 26 | String hello() { 27 | return MESSAGE; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/SayHelloService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import javax.enterprise.context.Dependent; 20 | 21 | @Dependent 22 | public class SayHelloService { 23 | 24 | public static final String MESSAGE = "Good bye EE, hello Vert.x!"; 25 | 26 | public String hello() { 27 | return MESSAGE; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/AlwaysFailHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import io.vertx.core.Handler; 20 | import io.vertx.ext.web.RoutingContext; 21 | 22 | @WebRoute("/fail/*") 23 | public class AlwaysFailHandler implements Handler { 24 | 25 | @Override 26 | public void handle(RoutingContext ctx) { 27 | ctx.fail(500); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/BravoHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import io.vertx.core.Handler; 20 | import io.vertx.ext.web.RoutingContext; 21 | 22 | @WebRoute(value = "/chain", order = 2) 23 | public class BravoHandler implements Handler { 24 | 25 | @Override 26 | public void handle(RoutingContext ctx) { 27 | ctx.response().write("bravo").end(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/EchoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import io.vertx.codegen.annotations.ProxyGen; 20 | import io.vertx.core.AsyncResult; 21 | import io.vertx.core.Handler; 22 | 23 | /** 24 | * 25 | * @author Martin Kouba 26 | */ 27 | @ProxyGen 28 | public interface EchoService { 29 | 30 | void echo(String name, Handler> result); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/RepeatingHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import io.vertx.core.Handler; 20 | import io.vertx.ext.web.RoutingContext; 21 | 22 | @WebRoute(value = "/path-1") 23 | @WebRoute(value = "/path-2") 24 | public class RepeatingHandler implements Handler { 25 | 26 | @Override 27 | public void handle(RoutingContext ctx) { 28 | ctx.response().end("oops"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/AlphaHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import io.vertx.core.Handler; 20 | import io.vertx.ext.web.RoutingContext; 21 | 22 | @WebRoute(value = "/chain", order = 1) 23 | public class AlphaHandler implements Handler { 24 | 25 | @Override 26 | public void handle(RoutingContext ctx) { 27 | ctx.response().setChunked(true).write("alpha"); 28 | ctx.next(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/CacheService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import java.util.UUID; 20 | 21 | import javax.annotation.PostConstruct; 22 | import javax.enterprise.context.ApplicationScoped; 23 | 24 | @ApplicationScoped 25 | public class CacheService { 26 | 27 | private String id; 28 | 29 | @PostConstruct 30 | void init() { 31 | this.id = UUID.randomUUID().toString(); 32 | } 33 | 34 | String getId() { 35 | return id; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/Payment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import java.math.BigDecimal; 20 | 21 | public class Payment { 22 | 23 | private String id; 24 | 25 | private BigDecimal amount; 26 | 27 | Payment(String id, BigDecimal amount) { 28 | this.id = id; 29 | this.amount = amount; 30 | } 31 | 32 | String getId() { 33 | return id; 34 | } 35 | 36 | BigDecimal getAmount() { 37 | return amount; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/TranslatorExampleRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.examples.translator; 18 | 19 | import io.vertx.core.Vertx; 20 | 21 | /** 22 | *
23 |  * curl -d "sentence=Hello world" http://localhost:8080/translate
24 |  * 
25 | * 26 | * @author Martin Kouba 27 | */ 28 | public class TranslatorExampleRunner { 29 | 30 | public static void main(String[] args) { 31 | Vertx.vertx().deployVerticle(new TranslatorVerticle()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/HelloHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import javax.inject.Inject; 20 | 21 | import io.vertx.core.Handler; 22 | import io.vertx.ext.web.RoutingContext; 23 | 24 | @WebRoute("/hello") 25 | public class HelloHandler implements Handler { 26 | 27 | @Inject 28 | SayHelloService service; 29 | 30 | @Override 31 | public void handle(RoutingContext ctx) { 32 | ctx.response().setStatusCode(200).end(service.hello()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/reference/Hello.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.reference; 18 | 19 | import java.util.concurrent.CompletionStage; 20 | 21 | import javax.enterprise.context.Dependent; 22 | import javax.inject.Inject; 23 | 24 | import org.jboss.weld.vertx.AsyncReference; 25 | 26 | @Dependent 27 | public class Hello { 28 | 29 | @Inject 30 | AsyncReference foo; 31 | 32 | CompletionStage hello() { 33 | return foo.thenApply(BlockingFoo::getMessage); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/RequestHelloService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import java.util.UUID; 20 | 21 | import javax.annotation.PostConstruct; 22 | import javax.enterprise.context.RequestScoped; 23 | 24 | @RequestScoped 25 | public class RequestHelloService { 26 | 27 | private String id; 28 | 29 | @PostConstruct 30 | public void init() { 31 | id = UUID.randomUUID().toString(); 32 | } 33 | 34 | public String hello() { 35 | return "Hello from " + id; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/extension/HelloObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.extension; 18 | 19 | import javax.enterprise.event.Observes; 20 | 21 | import org.jboss.weld.vertx.VertxConsumer; 22 | import org.jboss.weld.vertx.VertxEvent; 23 | 24 | public class HelloObserver { 25 | 26 | static final String HELLO_ADDRESS = "hello.test"; 27 | 28 | public void observeHello(@Observes @VertxConsumer(HELLO_ADDRESS) VertxEvent event) { 29 | RegisterConsumersAfterBootstrapTest.SYNCHRONIZER.add(event.getMessageBody()); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/UniversalFailureHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import static org.jboss.weld.vertx.web.WebRoute.HandlerType.FAILURE; 20 | 21 | import io.vertx.core.Handler; 22 | import io.vertx.ext.web.RoutingContext; 23 | 24 | @WebRoute(type = FAILURE) 25 | public class UniversalFailureHandler implements Handler { 26 | 27 | @Override 28 | public void handle(RoutingContext ctx) { 29 | ctx.response().setStatusCode(ctx.statusCode() != -1 ? ctx.statusCode() : 500).end(ctx.request().path()); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/org/jboss/weld/vertx/RecipientFailure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import javax.enterprise.inject.Vetoed; 20 | 21 | /** 22 | * 23 | * @author Martin Kouba 24 | */ 25 | @Vetoed 26 | public class RecipientFailure extends RuntimeException { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | final Integer code; 31 | 32 | /** 33 | * 34 | * @param code 35 | * @param message 36 | */ 37 | public RecipientFailure(Integer code, String message) { 38 | super(message); 39 | this.code = code; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/worker/Hello.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.worker; 18 | 19 | import java.util.concurrent.CompletionStage; 20 | 21 | import javax.enterprise.context.Dependent; 22 | import javax.inject.Inject; 23 | 24 | import org.jboss.weld.vertx.AsyncWorker; 25 | 26 | @Dependent 27 | public class Hello { 28 | 29 | @Inject 30 | AsyncWorker worker; 31 | 32 | @Inject 33 | BlockingFoo foo; 34 | 35 | CompletionStage hello() { 36 | return worker.performBlocking(foo::getMessage).thenApply(m -> "Hello " + m + "!"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/Addresses.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.examples.translator; 18 | 19 | /** 20 | * 21 | * @author Martin Kouba 22 | */ 23 | public final class Addresses { 24 | 25 | public static final String TRANSLATE = "org.jboss.weld.vertx.examples.translator.translate"; 26 | 27 | public static final String REQUEST_DATA = "org.jboss.weld.vertx.examples.translator.request_data"; 28 | 29 | public static final String CLEAR_CACHE = "org.jboss.weld.vertx.examples.translator.clear_cache"; 30 | 31 | private Addresses() { 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/HelloGetHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import javax.inject.Inject; 20 | 21 | import io.vertx.core.Handler; 22 | import io.vertx.core.http.HttpMethod; 23 | import io.vertx.ext.web.RoutingContext; 24 | 25 | @WebRoute(value = "/helloget", methods = HttpMethod.GET) 26 | public class HelloGetHandler implements Handler { 27 | 28 | @Inject 29 | SayHelloService service; 30 | 31 | @Override 32 | public void handle(RoutingContext ctx) { 33 | ctx.response().setStatusCode(200).end(service.hello()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/EchoServiceVerticle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import org.jboss.weld.vertx.WeldVerticle; 20 | 21 | import io.vertx.core.Future; 22 | import io.vertx.serviceproxy.ProxyHelper; 23 | 24 | /** 25 | * 26 | * @author Martin Kouba 27 | */ 28 | public class EchoServiceVerticle extends WeldVerticle { 29 | 30 | @Override 31 | public void start(Future startFuture) throws Exception { 32 | super.start(startFuture); 33 | ProxyHelper.registerService(EchoService.class, vertx, new EchoServiceImpl(), "echo-service-address"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/async/AsyncRouteObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web.async; 18 | 19 | import javax.enterprise.context.ApplicationScoped; 20 | import javax.enterprise.event.Observes; 21 | 22 | import org.jboss.weld.vertx.AsyncReference; 23 | import org.jboss.weld.vertx.web.WebRoute; 24 | 25 | import io.vertx.ext.web.RoutingContext; 26 | 27 | @ApplicationScoped 28 | public class AsyncRouteObserver { 29 | 30 | @WebRoute("/hello-async") 31 | void hello(@Observes RoutingContext ctx, AsyncReference ref) { 32 | ref.thenAccept(service -> ctx.response().setStatusCode(200).end(service.getMessage())); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/reference/Baz.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.reference; 18 | 19 | import java.util.Optional; 20 | 21 | import javax.enterprise.context.Dependent; 22 | import javax.inject.Inject; 23 | 24 | import org.jboss.weld.vertx.AsyncReference; 25 | 26 | @Dependent 27 | public class Baz { 28 | 29 | private Optional foo = Optional.empty(); 30 | 31 | @Inject 32 | public Baz(AsyncReference asyncRef) { 33 | asyncRef.thenAccept((foo) -> this.foo = Optional.ofNullable(foo)); 34 | } 35 | 36 | public BlockingFoo getFoo() { 37 | return foo.orElse(BlockingFoo.EMPTY); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/EchoServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import io.vertx.core.AsyncResult; 20 | import io.vertx.core.Future; 21 | import io.vertx.core.Handler; 22 | 23 | /** 24 | * 25 | * @author Martin Kouba 26 | */ 27 | public class EchoServiceImpl implements EchoService { 28 | 29 | @Override 30 | public void echo(String name, Handler> result) { 31 | if ("Spock".equals(name)) { 32 | result.handle(Future.failedFuture("Cannot echo Spock!")); 33 | } else { 34 | result.handle(Future.succeededFuture(name)); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/Timeouts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | public class Timeouts { 20 | 21 | public static final long DEFAULT_TIMEOUT = initTimeout("defaultTimeout", 5000); 22 | 23 | public static final long GLOBAL_TIMEOUT = initTimeout("globalTimeout", 10000); 24 | 25 | private static long initTimeout(String key, long defaultValue) { 26 | String property = System.getProperty(key); 27 | if (property != null) { 28 | try { 29 | return Long.valueOf(property); 30 | } catch (NumberFormatException ignored) { 31 | } 32 | } 33 | return defaultValue; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /service-proxy/src/main/java/org/jboss/weld/vertx/serviceproxy/DefaultServiceProxySupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import javax.enterprise.context.ApplicationScoped; 20 | import javax.inject.Inject; 21 | 22 | import io.vertx.core.Vertx; 23 | 24 | /** 25 | * The default implementation of {@link ServiceProxySupport} relies on the functionality provided by weld-vertx-core. 26 | * 27 | * @author Martin Kouba 28 | */ 29 | @ApplicationScoped 30 | public class DefaultServiceProxySupport implements ServiceProxySupport { 31 | 32 | @Inject 33 | private Vertx vertx; 34 | 35 | @Override 36 | public Vertx getVertx() { 37 | return vertx; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/Echo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import static java.lang.annotation.ElementType.FIELD; 20 | import static java.lang.annotation.ElementType.METHOD; 21 | import static java.lang.annotation.ElementType.PARAMETER; 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.Target; 27 | 28 | import javax.inject.Qualifier; 29 | 30 | /** 31 | * 32 | * @author Martin Kouba 33 | */ 34 | @Qualifier 35 | @Target({ TYPE, METHOD, PARAMETER, FIELD }) 36 | @Retention(RUNTIME) 37 | public @interface Echo { 38 | } 39 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/container/BeanVerticle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.container; 18 | 19 | import javax.enterprise.context.Dependent; 20 | import javax.inject.Inject; 21 | 22 | import io.vertx.core.AbstractVerticle; 23 | 24 | /** 25 | * 26 | * @author Martin Kouba 27 | * 28 | */ 29 | @Dependent 30 | public class BeanVerticle extends AbstractVerticle { 31 | 32 | @Inject 33 | SayHelloService sayHelloService; 34 | 35 | @Override 36 | public void start() throws Exception { 37 | vertx.eventBus().consumer(BeanVerticle.class.getName()).handler(m -> m.reply(sayHelloService.hello())); 38 | } 39 | 40 | @Override 41 | public void stop() throws Exception { 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /doc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.jboss.weld.vertx 5 | weld-vertx-parent 6 | 1.3.0-SNAPSHOT 7 | 8 | weld-vertx-doc 9 | pom 10 | 11 | 12 | 13 | 14 | org.asciidoctor 15 | asciidoctor-maven-plugin 16 | 1.5.5 17 | 18 | 19 | render-html 20 | generate-resources 21 | 22 | process-asciidoc 23 | 24 | 25 | 26 | 27 | html 28 | highlight.js 29 | 30 | ${project.version} 31 | highlightjs 32 | agate 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /doc/src/main/asciidoc/highlightjs/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006, Ivan Sagalaev 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of highlight.js nor the names of its contributors 12 | may be used to endorse or promote products derived from this software 13 | without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/RequestContextActiveHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import static org.jboss.weld.vertx.web.WebRoute.HandlerType.BLOCKING; 20 | 21 | import javax.inject.Inject; 22 | 23 | import org.jboss.weld.context.activator.ActivateRequestContext; 24 | 25 | import io.vertx.core.Handler; 26 | import io.vertx.ext.web.RoutingContext; 27 | 28 | @WebRoute(value = "/request-context-active", type = BLOCKING) 29 | public class RequestContextActiveHandler implements Handler { 30 | 31 | @Inject 32 | RequestHelloService helloService; 33 | 34 | @ActivateRequestContext 35 | @Override 36 | public void handle(RoutingContext ctx) { 37 | ctx.response().setStatusCode(200).end(helloService.hello()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /web/src/main/java/org/jboss/weld/vertx/web/WebRoutes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import static java.lang.annotation.ElementType.METHOD; 20 | import static java.lang.annotation.ElementType.TYPE; 21 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 22 | 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.Target; 25 | 26 | import javax.enterprise.inject.Stereotype; 27 | 28 | /** 29 | * Containing annotation type for repeating annotation {@link WebRoute}. 30 | *

31 | * This annotation is annotated with {@link Stereotype} to workaround the limitations of the annotated bean discovery mode. 32 | * 33 | * @author Martin Kouba 34 | */ 35 | @Retention(RUNTIME) 36 | @Target({ TYPE, METHOD }) 37 | @Stereotype 38 | public @interface WebRoutes { 39 | 40 | WebRoute[] value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/SimpleSentenceParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.examples.translator; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import javax.enterprise.context.Dependent; 23 | 24 | import io.vertx.core.logging.Logger; 25 | import io.vertx.core.logging.LoggerFactory; 26 | 27 | /** 28 | * 29 | * @author Martin Kouba 30 | */ 31 | @Dependent 32 | public class SimpleSentenceParser implements SentenceParser { 33 | 34 | private static final Logger LOGGER = LoggerFactory.getLogger(SimpleSentenceParser.class.getName()); 35 | 36 | @Override 37 | public List parse(String sentence) { 38 | List parts = Arrays.asList(sentence.split("\\s+")); 39 | LOGGER.debug("Parsed sentence: {0}", parts); 40 | return parts; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /probe/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.jboss.weld.vertx 6 | weld-vertx-parent 7 | 1.3.0-SNAPSHOT 8 | 9 | 10 | weld-vertx-probe 11 | 12 | 13 | 14 | 15 | org.jboss.weld.vertx 16 | weld-vertx-web 17 | ${project.version} 18 | 19 | 20 | 21 | 22 | io.vertx 23 | vertx-unit 24 | 25 | 26 | 27 | junit 28 | junit 29 | 30 | 31 | 32 | io.rest-assured 33 | rest-assured 34 | 35 | 36 | 37 | org.slf4j 38 | slf4j-simple 39 | test 40 | 41 | 42 | 43 | org.jboss.weld.vertx 44 | weld-vertx-core 45 | ${project.version} 46 | test-jar 47 | test 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.jboss.weld.vertx 6 | weld-vertx-parent 7 | 1.3.0-SNAPSHOT 8 | 9 | 10 | weld-vertx-web 11 | 12 | 13 | 14 | 15 | org.jboss.weld.vertx 16 | weld-vertx-core 17 | ${project.version} 18 | 19 | 20 | 21 | io.vertx 22 | vertx-web 23 | 24 | 25 | 26 | 27 | io.vertx 28 | vertx-unit 29 | 30 | 31 | 32 | junit 33 | junit 34 | test 35 | 36 | 37 | 38 | org.slf4j 39 | slf4j-simple 40 | test 41 | 42 | 43 | 44 | org.jboss.weld.vertx 45 | weld-vertx-core 46 | ${project.version} 47 | test-jar 48 | test 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/worker/HelloCombo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.worker; 18 | 19 | import java.util.concurrent.CompletionStage; 20 | 21 | import javax.enterprise.context.Dependent; 22 | import javax.inject.Inject; 23 | 24 | import org.jboss.weld.vertx.AsyncReference; 25 | import org.jboss.weld.vertx.AsyncWorker; 26 | 27 | @Dependent 28 | public class HelloCombo { 29 | 30 | @Inject 31 | AsyncWorker worker; 32 | 33 | @Inject 34 | AsyncReference alphaReference; 35 | 36 | CompletionStage hello() { 37 | return alphaReference.thenCompose(alpha -> 38 | // At this point BlockingAlpha is ready 39 | // But getMessage() is also blocking 40 | worker.performBlocking(alpha::getMessage) 41 | // Finally modify the final message 42 | .thenApply(m -> "Hello " + m + "!")); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/EchoServiceConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import javax.enterprise.context.ApplicationScoped; 20 | import javax.enterprise.event.Event; 21 | import javax.inject.Inject; 22 | 23 | /** 24 | * 25 | * @author Martin Kouba 26 | */ 27 | @ApplicationScoped 28 | public class EchoServiceConsumer { 29 | 30 | // Injects a service proxy for a service with the given address 31 | @Inject 32 | @ServiceProxy("echo-service-address") 33 | EchoService service; 34 | 35 | @Inject 36 | @Echo 37 | Event event; 38 | 39 | public void doEchoBusiness(String value) { 40 | // By default, the result handler is executed by means of Vertx.executeBlocking() 41 | // In this case, we fire a CDI event observed by EchoObserver bean 42 | service.echo(value, (r) -> event.fire(r.result())); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /probe/src/main/java/org/jboss/weld/vertx/probe/VertxProbeExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.probe; 18 | 19 | import javax.enterprise.event.Observes; 20 | import javax.enterprise.inject.spi.Extension; 21 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 22 | 23 | import io.vertx.core.Handler; 24 | import io.vertx.ext.web.RoutingContext; 25 | 26 | /** 27 | * This extension is only used to veto handlers defined in {@link ProbeHandlers}. 28 | * 29 | * @author Martin Kouba 30 | */ 31 | public class VertxProbeExtension implements Extension { 32 | 33 | private static final String PROBE_PACKAGE = VertxProbeExtension.class.getPackage().getName(); 34 | 35 | public void vetoProbeHandlers(@Observes ProcessAnnotatedType> event) { 36 | if (event.getAnnotatedType().getJavaClass().getName().startsWith(PROBE_PACKAGE)) { 37 | event.veto(); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/reference/Juicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.reference; 18 | 19 | import static java.lang.annotation.ElementType.FIELD; 20 | import static java.lang.annotation.ElementType.METHOD; 21 | import static java.lang.annotation.ElementType.PARAMETER; 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.Target; 27 | 28 | import javax.enterprise.util.AnnotationLiteral; 29 | import javax.inject.Qualifier; 30 | 31 | @Qualifier 32 | @Target({ TYPE, METHOD, PARAMETER, FIELD }) 33 | @Retention(RUNTIME) 34 | public @interface Juicy { 35 | 36 | @SuppressWarnings("all") 37 | public static class Literal extends AnnotationLiteral implements Juicy { 38 | 39 | private Literal() { 40 | } 41 | 42 | public static final Literal INSTANCE = new Literal(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/TranslateHandler.java: -------------------------------------------------------------------------------- 1 | package org.jboss.weld.vertx.examples.translator; 2 | 3 | import static io.vertx.core.http.HttpMethod.POST; 4 | import static org.jboss.weld.vertx.examples.translator.Addresses.TRANSLATE; 5 | 6 | import org.jboss.weld.vertx.web.WebRoute; 7 | 8 | import io.vertx.core.Handler; 9 | import io.vertx.core.http.HttpServerResponse; 10 | import io.vertx.core.json.JsonArray; 11 | import io.vertx.core.logging.Logger; 12 | import io.vertx.core.logging.LoggerFactory; 13 | import io.vertx.ext.web.RoutingContext; 14 | 15 | @WebRoute(value = "/translate", methods = POST) 16 | public class TranslateHandler implements Handler { 17 | 18 | private static final Logger LOGGER = LoggerFactory.getLogger(TranslateHandler.class.getName()); 19 | 20 | @Override 21 | public void handle(RoutingContext ctx) { 22 | HttpServerResponse response = ctx.response(); 23 | String sentence = ctx.request().getFormAttribute("sentence"); 24 | if (sentence != null) { 25 | LOGGER.debug("Handle translation: {0}", sentence); 26 | // See also Translator#translate() 27 | ctx.vertx().eventBus(). send(TRANSLATE, sentence, reply -> { 28 | if (reply.succeeded()) { 29 | response.putHeader("Content-type", "application/json"); 30 | response.setStatusCode(200).end(reply.result().body().encode()); 31 | } else { 32 | response.setStatusCode(500).end(reply.cause().toString()); 33 | } 34 | }); 35 | } else { 36 | response.end("Use \"application/x-www-form-urlencoded\" content type and specify value for name \"sentence\""); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/async/HelloAsyncHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web.async; 18 | 19 | import javax.enterprise.inject.Instance; 20 | import javax.inject.Inject; 21 | 22 | import org.jboss.weld.vertx.AsyncReference; 23 | import org.jboss.weld.vertx.web.WebRoute; 24 | 25 | import io.vertx.core.Handler; 26 | import io.vertx.ext.web.RoutingContext; 27 | 28 | @WebRoute("/helloasync") 29 | public class HelloAsyncHandler implements Handler { 30 | 31 | @Inject 32 | Instance> service; 33 | 34 | @Override 35 | public void handle(RoutingContext ctx) { 36 | // Obtain a new bean instance per each invocation 37 | service.get().whenComplete((r, t) -> { 38 | if (t != null) { 39 | ctx.response().setStatusCode(500).end(); 40 | } else { 41 | ctx.response().setStatusCode(200).end(r.getMessage()); 42 | } 43 | }); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/CoolService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import java.util.UUID; 20 | 21 | import javax.annotation.PostConstruct; 22 | import javax.enterprise.context.Dependent; 23 | import javax.inject.Inject; 24 | 25 | import io.vertx.core.Context; 26 | import io.vertx.core.Vertx; 27 | 28 | @Dependent 29 | public class CoolService { 30 | 31 | @Inject 32 | private Vertx vertx; 33 | 34 | @Inject 35 | private Context context; 36 | 37 | @Inject 38 | private CacheService cacheService; 39 | 40 | private String id; 41 | 42 | @PostConstruct 43 | void init() { 44 | this.id = UUID.randomUUID().toString(); 45 | } 46 | 47 | String getId() { 48 | return id; 49 | } 50 | 51 | CacheService getCacheService() { 52 | return cacheService; 53 | } 54 | 55 | Vertx getVertx() { 56 | return vertx; 57 | } 58 | 59 | Context getContext() { 60 | return context; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /doc/src/main/asciidoc/service-proxy.adoc: -------------------------------------------------------------------------------- 1 | == Service Proxy 2 | 3 | * Allows to inject and invoke service proxies (as defined in https://github.com/vert-x3/vertx-service-proxy) 4 | * The result handler is wrapped and executed using `ServiceProxySupport#getExecutor()` (`Vertx.executeBlocking()` by default) 5 | 6 | .Artifact GAV 7 | [source,xml] 8 | ---- 9 | 10 | org.jboss.weld.vertx 11 | weld-vertx-service-proxy 12 | ${version.weld-vertx} 13 | 14 | ---- 15 | 16 | NOTE: `weld-vertx-service-proxy` does not depend directly on `weld-vertx-core`. However, the default implementation of `org.jboss.weld.vertx.serviceproxy.ServiceProxySupport` relies on the functionality provided by `weld-vertx-core`. 17 | 18 | === Injecting Service Proxies 19 | 20 | A service proxy interface annotated with `io.vertx.codegen.annotations.ProxyGen` is automatically discovered and a custom bean with `@Dependent` scope and `org.jboss.weld.vertx.serviceproxy.ServiceProxy` qualifier is registered. 21 | 22 | [source,java] 23 | ---- 24 | @ApplicationScoped 25 | public class EchoServiceConsumer { 26 | 27 | // Injects a service proxy for a service with the given address 28 | @Inject 29 | @ServiceProxy("echo-service-address") 30 | EchoService service; 31 | 32 | @Inject 33 | @Echo 34 | Event event; 35 | 36 | public void doEchoBusiness(String value) { 37 | // By default, the result handler is executed by means of Vertx.executeBlocking() 38 | // In this case, we fire a CDI event observed by EchoObserver bean 39 | service.echo(value, (r) -> event.fire(r.result())); 40 | } 41 | 42 | } 43 | ---- 44 | 45 | TIP: See also https://github.com/weld/weld-vertx/blob/master/service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/EchoServiceProxyTest.java[EchoServiceProxyTest] in the test suite. -------------------------------------------------------------------------------- /doc/src/main/asciidoc/highlightjs/styles/agate.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Agate by Taufik Nurrohman 3 | * ---------------------------------------------------- 4 | * 5 | * #ade5fc 6 | * #a2fca2 7 | * #c6b4f0 8 | * #d36363 9 | * #fcc28c 10 | * #fc9b9b 11 | * #ffa 12 | * #fff 13 | * #333 14 | * #62c8f3 15 | * #888 16 | * 17 | */ 18 | 19 | .hljs { 20 | display: block; 21 | overflow-x: auto; 22 | padding: 0.5em; 23 | background: #333; 24 | color: white; 25 | } 26 | 27 | .hljs-name, 28 | .hljs-strong { 29 | font-weight: bold; 30 | } 31 | 32 | .hljs-code, 33 | .hljs-emphasis { 34 | font-style: italic; 35 | } 36 | 37 | .hljs-tag { 38 | color: #62c8f3; 39 | } 40 | 41 | .hljs-variable, 42 | .hljs-template-variable, 43 | .hljs-selector-id, 44 | .hljs-selector-class { 45 | color: #ade5fc; 46 | } 47 | 48 | .hljs-string, 49 | .hljs-bullet { 50 | color: #a2fca2; 51 | } 52 | 53 | .hljs-type, 54 | .hljs-title, 55 | .hljs-section, 56 | .hljs-attribute, 57 | .hljs-quote, 58 | .hljs-built_in, 59 | .hljs-builtin-name { 60 | color: #ffa; 61 | } 62 | 63 | .hljs-number, 64 | .hljs-symbol, 65 | .hljs-bullet { 66 | color: #d36363; 67 | } 68 | 69 | .hljs-keyword, 70 | .hljs-selector-tag, 71 | .hljs-literal { 72 | color: #fcc28c; 73 | } 74 | 75 | .hljs-comment, 76 | .hljs-deletion, 77 | .hljs-code { 78 | color: #888; 79 | } 80 | 81 | .hljs-regexp, 82 | .hljs-link { 83 | color: #c6b4f0; 84 | } 85 | 86 | .hljs-meta { 87 | color: #fc9b9b; 88 | } 89 | 90 | .hljs-deletion { 91 | background-color: #fc9b9b; 92 | color: #333; 93 | } 94 | 95 | .hljs-addition { 96 | background-color: #a2fca2; 97 | color: #333; 98 | } 99 | 100 | .hljs a { 101 | color: inherit; 102 | } 103 | 104 | .hljs a:focus, 105 | .hljs a:hover { 106 | color: inherit; 107 | text-decoration: underline; 108 | } 109 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/worker/BlockingFoo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.worker; 18 | 19 | import java.util.concurrent.CompletableFuture; 20 | import java.util.concurrent.ExecutionException; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.concurrent.TimeoutException; 23 | 24 | import javax.enterprise.context.Dependent; 25 | 26 | import org.jboss.weld.vertx.Timeouts; 27 | 28 | @Dependent 29 | public class BlockingFoo { 30 | 31 | private static CompletableFuture future; 32 | 33 | static void complete(String value) { 34 | future.complete(value); 35 | } 36 | 37 | static void reset() { 38 | future = new CompletableFuture<>(); 39 | } 40 | 41 | String getMessage() throws InterruptedException, ExecutionException, TimeoutException { 42 | // Simulate blocking operation 43 | return future.get(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 44 | } 45 | 46 | String getMessageNonBlocking() throws InterruptedException, ExecutionException, TimeoutException { 47 | return BlockingFoo.class.getName(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/async/BlockingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web.async; 18 | 19 | import java.util.concurrent.CompletableFuture; 20 | import java.util.concurrent.ExecutionException; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.concurrent.TimeoutException; 23 | 24 | import javax.annotation.PostConstruct; 25 | import javax.enterprise.context.Dependent; 26 | 27 | import org.jboss.weld.vertx.Timeouts; 28 | 29 | @Dependent 30 | public class BlockingService { 31 | 32 | private static CompletableFuture future; 33 | 34 | static void complete(String value) { 35 | future.complete(value); 36 | } 37 | 38 | static void reset() { 39 | future = new CompletableFuture<>(); 40 | } 41 | 42 | private String message; 43 | 44 | @PostConstruct 45 | void init() { 46 | try { 47 | // Simulate blocking operation 48 | message = future.get(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 49 | } catch (InterruptedException | ExecutionException | TimeoutException ignored) { 50 | } 51 | } 52 | 53 | String getMessage() { 54 | return message; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/reference/Boss.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.reference; 18 | 19 | import java.util.List; 20 | import java.util.concurrent.atomic.AtomicBoolean; 21 | 22 | import javax.annotation.PreDestroy; 23 | import javax.enterprise.context.Dependent; 24 | import javax.inject.Inject; 25 | 26 | import org.jboss.weld.vertx.AsyncReference; 27 | import org.jboss.weld.vertx.async.reference.BingProducer.Bing; 28 | import org.jboss.weld.vertx.async.reference.BlockingBarProducer.BlockingBar; 29 | 30 | @Dependent 31 | public class Boss { 32 | 33 | static final AtomicBoolean DESTROYED = new AtomicBoolean(false); 34 | 35 | @Inject 36 | AsyncReference foo; 37 | 38 | @Inject 39 | AsyncReference> unsatisfied; 40 | 41 | @Inject 42 | AsyncReference noBing; 43 | 44 | @Inject 45 | @Juicy 46 | AsyncReference juicyBing; 47 | 48 | @Inject 49 | @Juicy 50 | AsyncReference juicyBar; 51 | 52 | boolean isReadyToTest() { 53 | return foo.isDone() && unsatisfied.isDone() && noBing.isDone() && juicyBing.isDone() && juicyBar.isDone(); 54 | } 55 | 56 | @PreDestroy 57 | void dispose() { 58 | DESTROYED.set(true); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.jboss.weld.vertx 6 | weld-vertx-parent 7 | 1.3.0-SNAPSHOT 8 | 9 | 10 | weld-vertx-core 11 | 12 | 13 | 14 | 15 | org.jboss.weld.se 16 | weld-se-core 17 | 18 | 19 | 20 | io.vertx 21 | vertx-core 22 | 23 | 24 | 25 | me.escoffier.vertx 26 | vertx-completable-future 27 | 28 | 29 | 30 | 31 | io.vertx 32 | vertx-unit 33 | 34 | 35 | 36 | junit 37 | junit 38 | 39 | 40 | 41 | org.awaitility 42 | awaitility 43 | 44 | 45 | 46 | org.slf4j 47 | slf4j-simple 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-jar-plugin 57 | 58 | 59 | 60 | test-jar 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /examples/translator/src/test/java/org/jboss/weld/vertx/examples/translator/TranslatorExampleTest.java: -------------------------------------------------------------------------------- 1 | package org.jboss.weld.vertx.examples.translator; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | 8 | import io.vertx.core.Vertx; 9 | import io.vertx.core.http.HttpClient; 10 | import io.vertx.core.http.HttpClientRequest; 11 | import io.vertx.core.http.HttpMethod; 12 | import io.vertx.ext.unit.Async; 13 | import io.vertx.ext.unit.TestContext; 14 | import io.vertx.ext.unit.junit.VertxUnitRunner; 15 | 16 | /** 17 | * 18 | * @author Martin Kouba 19 | */ 20 | @RunWith(VertxUnitRunner.class) 21 | public class TranslatorExampleTest { 22 | 23 | static final long DEFAULT_TIMEOUT = 15000; 24 | 25 | private Vertx vertx; 26 | 27 | @Before 28 | public void init(TestContext context) { 29 | vertx = Vertx.vertx(); 30 | vertx.deployVerticle(new TranslatorVerticle(), context.asyncAssertSuccess()); 31 | } 32 | 33 | @After 34 | public void close(TestContext context) { 35 | vertx.close(context.asyncAssertSuccess()); 36 | } 37 | 38 | @Test(timeout = DEFAULT_TIMEOUT) 39 | public void testTranslator(TestContext context) throws InterruptedException { 40 | Async async = context.async(); 41 | HttpClient client = vertx.createHttpClient(); 42 | HttpClientRequest request = client.request(HttpMethod.POST, 8080, "localhost", "/translate"); 43 | request.putHeader("Content-type", "application/x-www-form-urlencoded"); 44 | request.handler((response) -> { 45 | if (response.statusCode() == 200) { 46 | response.bodyHandler((buffer) -> { 47 | context.assertEquals("[{\"word\":\"Hello\",\"translations\":[\"ahoj\",\"dobry den\"]},{\"word\":\"world\",\"translations\":[\"svet\"]}]", 48 | buffer.toString()); 49 | client.close(); 50 | async.complete(); 51 | }); 52 | } 53 | }); 54 | request.end("sentence=Hello world"); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/reference/BlockingFoo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.reference; 18 | 19 | import java.util.concurrent.CompletableFuture; 20 | import java.util.concurrent.ExecutionException; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.concurrent.TimeoutException; 23 | 24 | import javax.annotation.PostConstruct; 25 | import javax.enterprise.context.Dependent; 26 | 27 | import org.jboss.weld.vertx.Timeouts; 28 | 29 | @Dependent 30 | public class BlockingFoo { 31 | 32 | static final BlockingFoo EMPTY; 33 | 34 | static { 35 | EMPTY = new BlockingFoo(); 36 | EMPTY.message = ""; 37 | } 38 | 39 | private static CompletableFuture future; 40 | 41 | static void complete(String value) { 42 | future.complete(value); 43 | } 44 | 45 | static void reset() { 46 | future = new CompletableFuture<>(); 47 | } 48 | 49 | private String message; 50 | 51 | @PostConstruct 52 | void init() { 53 | try { 54 | // Simulate blocking operation 55 | message = future.get(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 56 | } catch (InterruptedException | ExecutionException | TimeoutException ignored) { 57 | } 58 | } 59 | 60 | String getMessage() { 61 | return message; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/PaymentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import java.math.BigDecimal; 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.List; 23 | 24 | import javax.annotation.PostConstruct; 25 | import javax.enterprise.context.ApplicationScoped; 26 | 27 | import io.vertx.core.json.JsonObject; 28 | 29 | @ApplicationScoped 30 | public class PaymentService { 31 | 32 | private List payments; 33 | 34 | @PostConstruct 35 | void init() { 36 | payments = new ArrayList<>(); 37 | payments.add(new Payment("foo", BigDecimal.ONE)); 38 | payments.add(new Payment("bar", new BigDecimal("100"))); 39 | payments = Collections.unmodifiableList(payments); 40 | } 41 | 42 | public List getPayments() { 43 | return payments; 44 | } 45 | 46 | public Payment getPayment(String id) { 47 | for (Payment payment : payments) { 48 | if (payment.getId().equals(id)) { 49 | return payment; 50 | } 51 | } 52 | return null; 53 | } 54 | 55 | public JsonObject encode(Payment payment) { 56 | JsonObject result = new JsonObject(); 57 | result.put("id", payment.getId()); 58 | result.put("amount", payment.getAmount().toString()); 59 | return result; 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /web/src/main/java/org/jboss/weld/vertx/web/Id.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import static java.lang.annotation.ElementType.FIELD; 20 | import static java.lang.annotation.ElementType.METHOD; 21 | import static java.lang.annotation.ElementType.PARAMETER; 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | import java.lang.annotation.Documented; 26 | import java.lang.annotation.Retention; 27 | import java.lang.annotation.Target; 28 | 29 | import javax.enterprise.util.AnnotationLiteral; 30 | import javax.inject.Qualifier; 31 | 32 | /** 33 | * This qualifier is used to distinguish observer methods annotated with {@link WebRoute}. 34 | * 35 | * @author Martin Kouba 36 | */ 37 | @Target({ TYPE, METHOD, PARAMETER, FIELD }) 38 | @Retention(RUNTIME) 39 | @Documented 40 | @Qualifier 41 | public @interface Id { 42 | 43 | String value(); 44 | 45 | public static class Literal extends AnnotationLiteral implements Id { 46 | 47 | private static final long serialVersionUID = 1L; 48 | 49 | public static Literal of(String value) { 50 | return new Literal(value); 51 | } 52 | 53 | public Literal(String value) { 54 | this.value = value; 55 | } 56 | 57 | private final String value; 58 | 59 | @Override 60 | public String value() { 61 | return value; 62 | } 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/worker/BlockingAlpha.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.worker; 18 | 19 | import java.util.concurrent.CompletableFuture; 20 | import java.util.concurrent.ExecutionException; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.concurrent.TimeoutException; 23 | 24 | import javax.enterprise.context.Dependent; 25 | 26 | import org.jboss.weld.vertx.Timeouts; 27 | 28 | @Dependent 29 | public class BlockingAlpha { 30 | 31 | private static CompletableFuture initFuture; 32 | 33 | private static CompletableFuture operationFuture; 34 | 35 | static void completeInit() { 36 | initFuture.complete(true); 37 | } 38 | 39 | static void completeOperation(String value) { 40 | operationFuture.complete(value); 41 | } 42 | 43 | static void reset() { 44 | initFuture = new CompletableFuture<>(); 45 | operationFuture = new CompletableFuture<>(); 46 | } 47 | 48 | void init() { 49 | try { 50 | // Simulate blocking operation 51 | initFuture.get(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 52 | } catch (InterruptedException | ExecutionException | TimeoutException ignored) { 53 | } 54 | } 55 | 56 | String getMessage() throws InterruptedException, ExecutionException, TimeoutException { 57 | // Simulate blocking operation 58 | return operationFuture.get(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/reference/NormalScopedBlockingFoo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.reference; 18 | 19 | import java.util.concurrent.CompletableFuture; 20 | import java.util.concurrent.ExecutionException; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.concurrent.TimeoutException; 23 | import java.util.concurrent.atomic.AtomicBoolean; 24 | 25 | import javax.annotation.PostConstruct; 26 | import javax.enterprise.context.ApplicationScoped; 27 | 28 | import org.jboss.weld.vertx.Timeouts; 29 | 30 | @ApplicationScoped 31 | public class NormalScopedBlockingFoo { 32 | 33 | static AtomicBoolean created; 34 | 35 | private static CompletableFuture future; 36 | 37 | static void complete(String value) { 38 | future.complete(value); 39 | } 40 | 41 | static void reset() { 42 | created = new AtomicBoolean(false); 43 | future = new CompletableFuture<>(); 44 | } 45 | 46 | private String message; 47 | 48 | @PostConstruct 49 | void init() { 50 | try { 51 | // Simulate blocking operation 52 | message = future.get(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 53 | } catch (InterruptedException | ExecutionException | TimeoutException ignored) { 54 | } 55 | created.set(true); 56 | } 57 | 58 | String getMessage() { 59 | return message; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "normal"; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /core/src/main/java/org/jboss/weld/vertx/VertxHandler.java: -------------------------------------------------------------------------------- 1 | package org.jboss.weld.vertx; 2 | 3 | import javax.enterprise.event.Event; 4 | import javax.enterprise.inject.Vetoed; 5 | 6 | import io.vertx.core.Handler; 7 | import io.vertx.core.Vertx; 8 | import io.vertx.core.eventbus.Message; 9 | 10 | /** 11 | * An instance of this handler is registered per each address found by {@link org.jboss.weld.vertx.VertxExtension}}. 12 | * 13 | * @author Martin Kouba 14 | */ 15 | @Vetoed 16 | class VertxHandler implements Handler> { 17 | 18 | private final Vertx vertx; 19 | 20 | private final Event event; 21 | 22 | static VertxHandler from(Vertx vertx, Event event, String address) { 23 | return new VertxHandler(vertx, event.select(VertxEvent.class, VertxConsumer.Literal.of(address))); 24 | } 25 | 26 | private VertxHandler(Vertx vertx, Event event) { 27 | this.vertx = vertx; 28 | this.event = event; 29 | } 30 | 31 | @Override 32 | public void handle(Message message) { 33 | // Notification is potentially a blocking code 34 | // The execution of the blocking code is not ordered - see Vertx.executeBlocking(Handler>, boolean, Handler>) javadoc 35 | vertx. executeBlocking(future -> { 36 | VertxEventImpl vertxEvent = new VertxEventImpl(message, vertx.eventBus()); 37 | try { 38 | // Synchronously notify all the observer methods for a specific address 39 | event.fire(vertxEvent); 40 | future.complete(vertxEvent.getReply()); 41 | } catch (Exception e) { 42 | future.fail(e); 43 | } 44 | }, false, result -> { 45 | if (result.succeeded()) { 46 | message.reply(result.result()); 47 | } else { 48 | Throwable cause = result.cause(); 49 | if (cause instanceof RecipientFailure) { 50 | RecipientFailure recipientFailure = (RecipientFailure) cause; 51 | message.fail(recipientFailure.code, recipientFailure.getMessage()); 52 | } else { 53 | message.fail(VertxEvent.OBSERVER_FAILURE_CODE, cause.getMessage()); 54 | } 55 | } 56 | }); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/extension/RegisterConsumersAfterBootstrapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.extension; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import java.util.concurrent.BlockingQueue; 22 | import java.util.concurrent.LinkedBlockingQueue; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | import org.jboss.weld.environment.se.Weld; 26 | import org.jboss.weld.environment.se.WeldContainer; 27 | import org.jboss.weld.vertx.Timeouts; 28 | import org.jboss.weld.vertx.VertxExtension; 29 | import org.junit.Test; 30 | 31 | import io.vertx.core.Vertx; 32 | 33 | /** 34 | * 35 | * @author Martin Kouba 36 | */ 37 | public class RegisterConsumersAfterBootstrapTest { 38 | 39 | static final BlockingQueue SYNCHRONIZER = new LinkedBlockingQueue<>(); 40 | 41 | @Test 42 | public void testConsumers() throws InterruptedException { 43 | try (WeldContainer weld = new Weld().disableDiscovery().addExtension(new VertxExtension()).addPackage(false, RegisterConsumersAfterBootstrapTest.class) 44 | .initialize()) { 45 | Vertx vertx = Vertx.vertx(); 46 | try { 47 | weld.select(VertxExtension.class).get().registerConsumers(vertx, weld.event()); 48 | vertx.eventBus().send(HelloObserver.HELLO_ADDRESS, "hello"); 49 | assertEquals("hello", SYNCHRONIZER.poll(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)); 50 | } finally { 51 | vertx.close(); 52 | } 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/async/reference/BlockingBarProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.async.reference; 18 | 19 | import java.util.concurrent.CompletableFuture; 20 | import java.util.concurrent.CompletionStage; 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | 23 | import javax.enterprise.context.ApplicationScoped; 24 | import javax.enterprise.context.Dependent; 25 | import javax.enterprise.inject.Default; 26 | import javax.enterprise.inject.Produces; 27 | 28 | @ApplicationScoped 29 | public class BlockingBarProducer { 30 | 31 | static final AtomicBoolean PRODUCER_USED = new AtomicBoolean(false); 32 | 33 | static CompletableFuture future; 34 | 35 | static void complete(int code) { 36 | future.complete(new BlockingBar(code)); 37 | } 38 | 39 | static void reset() { 40 | future = new CompletableFuture<>(); 41 | PRODUCER_USED.set(false); 42 | } 43 | 44 | @Produces 45 | @Dependent 46 | @Juicy 47 | CompletionStage juicyBlockingBar() { 48 | PRODUCER_USED.set(true); 49 | return future; 50 | } 51 | 52 | // Just to verify VertxExtension.AsyncProducerMetadata.matches(Type, Set) 53 | @Produces 54 | @Dependent 55 | @Default 56 | CompletionStage defaultBlockingBar() { 57 | return CompletableFuture.completedFuture(new BlockingBar(Integer.MIN_VALUE)); 58 | } 59 | 60 | static class BlockingBar { 61 | 62 | int code; 63 | 64 | public BlockingBar(int code) { 65 | this.code = code; 66 | } 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/TranslatorVerticle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.examples.translator; 18 | 19 | import org.jboss.weld.vertx.web.WeldWebVerticle; 20 | 21 | import io.vertx.core.AbstractVerticle; 22 | import io.vertx.core.Future; 23 | import io.vertx.core.Verticle; 24 | 25 | /** 26 | * {@link Verticle} responsible for starting the application. 27 | * 28 | * @author Martin Kouba 29 | */ 30 | public class TranslatorVerticle extends AbstractVerticle { 31 | 32 | @Override 33 | public void start(Future startFuture) throws Exception { 34 | 35 | final WeldWebVerticle weldVerticle = new WeldWebVerticle(); 36 | vertx.deployVerticle(weldVerticle, r -> { 37 | if (r.succeeded()) { 38 | vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> { 39 | if (listen.succeeded()) { 40 | vertx.deployVerticle(new DummyDataVerticle(), (dummy) -> { 41 | if (dummy.failed()) { 42 | startFuture.fail("Dummy verticle failure"); 43 | } else { 44 | startFuture.complete(); 45 | } 46 | }); 47 | } else { 48 | startFuture.fail("HTTP server not listening"); 49 | } 50 | }); 51 | } else { 52 | startFuture.fail("Weld verticle failure: " + r.cause()); 53 | } 54 | }); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/org/jboss/weld/vertx/VertxConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import static java.lang.annotation.ElementType.FIELD; 20 | import static java.lang.annotation.ElementType.METHOD; 21 | import static java.lang.annotation.ElementType.PARAMETER; 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.Target; 27 | 28 | import javax.enterprise.util.AnnotationLiteral; 29 | import javax.inject.Qualifier; 30 | 31 | /** 32 | * An observer method must declare an event parameter of the type {@link VertxEvent} with {@link VertxConsumer} qualifier in order to be notified when a message 33 | * is sent via {@link io.vertx.core.eventbus.EventBus}. 34 | * 35 | * @author Martin Kouba 36 | * @see VertxEvent 37 | */ 38 | @Qualifier 39 | @Target({ TYPE, METHOD, PARAMETER, FIELD }) 40 | @Retention(RUNTIME) 41 | public @interface VertxConsumer { 42 | 43 | /** 44 | * 45 | * @return the address the consumer will be registered to 46 | */ 47 | String value(); 48 | 49 | public final class Literal extends AnnotationLiteral implements VertxConsumer { 50 | 51 | private static final long serialVersionUID = 1L; 52 | 53 | private final String value; 54 | 55 | public static Literal of(String value) { 56 | return new Literal(value); 57 | } 58 | 59 | public String value() { 60 | return value; 61 | } 62 | 63 | private Literal(String value) { 64 | this.value = value; 65 | } 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/observer/PaymentObserverResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web.observer; 18 | 19 | import static io.vertx.core.http.HttpMethod.GET; 20 | 21 | import java.util.List; 22 | 23 | import javax.enterprise.context.ApplicationScoped; 24 | import javax.enterprise.event.Observes; 25 | import javax.inject.Inject; 26 | 27 | import org.jboss.weld.vertx.web.Payment; 28 | import org.jboss.weld.vertx.web.PaymentResource; 29 | import org.jboss.weld.vertx.web.PaymentService; 30 | import org.jboss.weld.vertx.web.WebRoute; 31 | 32 | import io.vertx.core.json.JsonArray; 33 | import io.vertx.ext.web.RoutingContext; 34 | 35 | /** 36 | * Observer variant of {@link PaymentResource}. 37 | */ 38 | @ApplicationScoped 39 | class PaymentObserverResource { 40 | 41 | @Inject 42 | PaymentService paymentService; 43 | 44 | @WebRoute("/payments") 45 | void getAll(@Observes RoutingContext ctx) { 46 | List payments = paymentService.getPayments(); 47 | JsonArray array = new JsonArray(); 48 | for (Payment payment : payments) { 49 | array.add(paymentService.encode(payment)); 50 | } 51 | ctx.response().setStatusCode(200).end(array.encode()); 52 | } 53 | 54 | @WebRoute(value = "/payments/:paymentId", methods = GET) 55 | void getPayment(@Observes RoutingContext ctx) { 56 | Payment payment = paymentService.getPayment(ctx.request().getParam("paymentId")); 57 | if (payment == null) { 58 | ctx.response().setStatusCode(404).end(); 59 | } else { 60 | ctx.response().setStatusCode(200).end(paymentService.encode(payment).encode()); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/CustomWeldVerticleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import static org.jboss.weld.vertx.WeldVerticle.createDefaultWeld; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import org.jboss.weld.environment.se.WeldContainer; 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | 28 | import io.vertx.core.Vertx; 29 | import io.vertx.ext.unit.Async; 30 | import io.vertx.ext.unit.TestContext; 31 | import io.vertx.ext.unit.junit.VertxUnitRunner; 32 | 33 | /** 34 | * 35 | * @author Martin Kouba 36 | */ 37 | @RunWith(VertxUnitRunner.class) 38 | public class CustomWeldVerticleTest { 39 | 40 | private Vertx vertx; 41 | 42 | private WeldContainer weld; 43 | 44 | @Before 45 | public void init(TestContext context) { 46 | vertx = Vertx.vertx(); 47 | WeldVerticle weldVerticle = new WeldVerticle(createDefaultWeld().disableDiscovery().beanClasses(CoolHelloService.class)); 48 | Async async = context.async(); 49 | vertx.deployVerticle(weldVerticle, r -> { 50 | if (r.succeeded()) { 51 | weld = weldVerticle.container(); 52 | async.complete(); 53 | } else { 54 | context.fail(r.cause()); 55 | } 56 | }); 57 | } 58 | 59 | @After 60 | public void close(TestContext context) { 61 | vertx.close(context.asyncAssertSuccess()); 62 | } 63 | 64 | @Test 65 | public void testDiscovery() throws InterruptedException { 66 | assertTrue(weld.select(CoolService.class).isUnsatisfied()); 67 | assertTrue(weld.select(CoolHelloService.class).isResolvable()); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /service-proxy/src/main/java/org/jboss/weld/vertx/serviceproxy/ServiceProxySupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import java.util.concurrent.Executor; 20 | 21 | import io.vertx.core.Vertx; 22 | import io.vertx.core.eventbus.DeliveryOptions; 23 | 24 | /** 25 | * A bean with this type and {@link javax.enterprise.inject.Default} qualifier must be available if using weld-vertx-service-proxy. 26 | * 27 | * @author Martin Kouba 28 | */ 29 | public interface ServiceProxySupport { 30 | 31 | /** 32 | * 33 | * @return the vertx instance 34 | * @see #getExecutor() 35 | */ 36 | Vertx getVertx(); 37 | 38 | /** 39 | * 40 | * @param serviceInterface 41 | * @return the delivery options used for a particular service proxy bean instance or null 42 | */ 43 | default DeliveryOptions getDefaultDeliveryOptions(Class serviceInterface) { 44 | return null; 45 | } 46 | 47 | /** 48 | * By default, the service result handler is executed as blocking code. 49 | * 50 | * @return the executor used to execute a service result handler 51 | * @see Vertx#executeBlocking(io.vertx.core.Handler, boolean, io.vertx.core.Handler) 52 | */ 53 | default Executor getExecutor() { 54 | return new Executor() { 55 | @Override 56 | public void execute(Runnable command) { 57 | getVertx().executeBlocking((f) -> { 58 | try { 59 | command.run(); 60 | f.complete(); 61 | } catch (Exception e) { 62 | f.fail(e); 63 | } 64 | }, false, null); 65 | } 66 | }; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /probe/src/main/java/org/jboss/weld/vertx/probe/JsonDataProviderProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.probe; 18 | 19 | import java.lang.reflect.InvocationTargetException; 20 | import java.lang.reflect.Method; 21 | 22 | import javax.enterprise.context.ApplicationScoped; 23 | import javax.enterprise.context.Dependent; 24 | import javax.enterprise.inject.Produces; 25 | import javax.enterprise.inject.spi.BeanManager; 26 | 27 | import org.jboss.weld.probe.JsonDataProvider; 28 | import org.jboss.weld.probe.ProbeExtension; 29 | 30 | /** 31 | * 32 | * @author Martin Kouba 33 | */ 34 | @Dependent 35 | public class JsonDataProviderProducer { 36 | 37 | @Produces 38 | @ApplicationScoped 39 | public JsonDataProvider produce(BeanManager beanManager) { 40 | ProbeExtension extension = beanManager.getExtension(ProbeExtension.class); 41 | if (extension == null) { 42 | throw new IllegalStateException("ProbeExtension not available"); 43 | } 44 | try { 45 | // Unfortunately, getJsonDataProvider() is package-private 46 | Method getProviderMethod = SecurityActions.getDeclaredMethod(ProbeExtension.class, "getJsonDataProvider"); 47 | if (getProviderMethod == null) { 48 | throw new IllegalStateException("ProbeExtension.getJsonDataProvider() method not found or inaccessible"); 49 | } 50 | SecurityActions.ensureAccessible(getProviderMethod); 51 | return (JsonDataProvider) getProviderMethod.invoke(extension); 52 | } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 53 | throw new IllegalStateException("Unable to get JsonDataProvider", e); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /service-proxy/src/main/java/org/jboss/weld/vertx/serviceproxy/ServiceProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import static java.lang.annotation.ElementType.FIELD; 20 | import static java.lang.annotation.ElementType.METHOD; 21 | import static java.lang.annotation.ElementType.PARAMETER; 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.Target; 27 | 28 | import javax.enterprise.util.AnnotationLiteral; 29 | import javax.enterprise.util.Nonbinding; 30 | import javax.inject.Qualifier; 31 | 32 | /** 33 | * This qualifier is used to: 34 | *
    35 | *
  • distinguish a custom service proxy bean from implementation
  • 36 | *
  • specify the service address on an injection point (non-binding value)
  • 37 | *
      38 | * 39 | * @author Martin Kouba 40 | */ 41 | @Qualifier 42 | @Target({ TYPE, METHOD, PARAMETER, FIELD }) 43 | @Retention(RUNTIME) 44 | public @interface ServiceProxy { 45 | 46 | /** 47 | * 48 | * @return the address on which the service is published 49 | */ 50 | @Nonbinding 51 | String value(); 52 | 53 | public final class Literal extends AnnotationLiteral implements ServiceProxy { 54 | 55 | private static final long serialVersionUID = 1L; 56 | 57 | static final Literal EMPTY = new Literal(""); 58 | 59 | private final String value; 60 | 61 | public static Literal of(String value) { 62 | return new Literal(value); 63 | } 64 | 65 | public String value() { 66 | return value; 67 | } 68 | 69 | private Literal(String value) { 70 | this.value = value; 71 | } 72 | 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /core/src/main/java/org/jboss/weld/vertx/VertxMessageImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import javax.enterprise.inject.Vetoed; 20 | 21 | import org.jboss.weld.vertx.VertxEvent.VertxMessage; 22 | 23 | import io.vertx.core.AsyncResult; 24 | import io.vertx.core.Handler; 25 | import io.vertx.core.eventbus.DeliveryOptions; 26 | import io.vertx.core.eventbus.EventBus; 27 | import io.vertx.core.eventbus.Message; 28 | 29 | @Vetoed 30 | class VertxMessageImpl implements VertxMessage { 31 | 32 | private final String address; 33 | 34 | private final EventBus eventBus; 35 | 36 | private DeliveryOptions deliveryOptions; 37 | 38 | VertxMessageImpl(String address, EventBus eventBus) { 39 | this.address = address; 40 | this.eventBus = eventBus; 41 | } 42 | 43 | @Override 44 | public VertxMessage setDeliveryOptions(DeliveryOptions deliveryOptions) { 45 | this.deliveryOptions = deliveryOptions; 46 | return this; 47 | } 48 | 49 | @Override 50 | public void send(Object message) { 51 | if (deliveryOptions != null) { 52 | eventBus.send(address, message, deliveryOptions); 53 | } else { 54 | eventBus.send(address, message); 55 | } 56 | } 57 | 58 | @Override 59 | public void send(Object message, Handler>> replyHandler) { 60 | if (deliveryOptions != null) { 61 | eventBus.send(address, message, deliveryOptions, replyHandler); 62 | } else { 63 | eventBus.send(address, message, replyHandler); 64 | } 65 | } 66 | 67 | @Override 68 | public void publish(Object message) { 69 | if (deliveryOptions != null) { 70 | eventBus.publish(address, message, deliveryOptions); 71 | } else { 72 | eventBus.publish(address, message); 73 | } 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /examples/hello/src/main/java/org/jboss/weld/vertx/examples/hello/HelloMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.examples.hello; 18 | 19 | import org.jboss.weld.vertx.web.WebRoute; 20 | import org.jboss.weld.vertx.web.WeldWebVerticle; 21 | 22 | import io.vertx.core.Handler; 23 | import io.vertx.core.Vertx; 24 | import io.vertx.ext.web.RoutingContext; 25 | 26 | /** 27 | * This simple example shows how to start a very simple "hello" webapp. 28 | * 29 | * To access the "hello" endpoint (or just use browser ;-): 30 | * 31 | *
      32 |  * curl http://localhost:8080/hello?name=Marv
      33 |  * 
      34 | * 35 | * @author Martin Kouba 36 | */ 37 | public class HelloMain { 38 | 39 | public static void main(String[] args) { 40 | // First create a new Weld verticle 41 | // Then deploy the verticle, i.e. start CDI container and discover all @WebRoute 42 | // handlers 43 | // If successfull create the router and start the webserver 44 | Vertx vertx = Vertx.vertx(); 45 | WeldWebVerticle weldVerticle = new WeldWebVerticle(); 46 | vertx.deployVerticle(weldVerticle, result -> { 47 | if (result.succeeded()) { 48 | vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080); 49 | } else { 50 | throw new IllegalStateException("Weld verticle failure: " + result.cause()); 51 | } 52 | }); 53 | } 54 | 55 | // This handler is registered automatically 56 | // Matches all HTTP methods and /hello path 57 | @WebRoute("/hello") 58 | static class HelloHandler implements Handler { 59 | 60 | @Override 61 | public void handle(RoutingContext event) { 62 | String name = event.request().getParam("name"); 63 | if (name == null) { 64 | name = "developer"; 65 | } 66 | event.response().setStatusCode(200).end("Hello " + name + "!"); 67 | } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/Translator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.examples.translator; 18 | 19 | import static org.jboss.weld.vertx.examples.translator.Addresses.TRANSLATE; 20 | 21 | import java.util.List; 22 | 23 | import javax.enterprise.context.ApplicationScoped; 24 | import javax.enterprise.event.Observes; 25 | import javax.inject.Inject; 26 | 27 | import org.jboss.weld.vertx.VertxConsumer; 28 | import org.jboss.weld.vertx.VertxEvent; 29 | 30 | import io.vertx.core.json.JsonArray; 31 | import io.vertx.core.json.JsonObject; 32 | import io.vertx.core.logging.Logger; 33 | import io.vertx.core.logging.LoggerFactory; 34 | 35 | /** 36 | * This bean implements translator business logic, i.e. parse the sentence and attempt to translate each part of the sentence. 37 | * 38 | * @author Martin Kouba 39 | */ 40 | @ApplicationScoped 41 | public class Translator { 42 | 43 | private static final Logger LOGGER = LoggerFactory.getLogger(Translator.class); 44 | 45 | private final SentenceParser parser; 46 | 47 | private final DataCache cache; 48 | 49 | @Inject 50 | Translator(SentenceParser parser, DataCache dictionary) { 51 | this.parser = parser; 52 | this.cache = dictionary; 53 | } 54 | 55 | public void translate(@Observes @VertxConsumer(TRANSLATE) VertxEvent event) { 56 | String sentence = event.getMessageBody().toString(); 57 | LOGGER.info("Going to translate: " + sentence); 58 | 59 | JsonArray results = new JsonArray(); 60 | for (String word : parser.parse(sentence)) { 61 | 62 | JsonObject result = new JsonObject(); 63 | result.put("word", word); 64 | 65 | List translations = cache.getTranslations(word); 66 | if (translations != null) { 67 | result.put("translations", new JsonArray(translations)); 68 | } 69 | results.add(result); 70 | } 71 | event.setReply(results); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | | :warning: This repository is archived. Some of the core features were adopted in the [Quarkus](https://github.com/quarkusio/quarkus/) project. | 2 | | --- | 3 | 4 | # Weld Vert.x Extensions 5 | 6 | 7 | 8 | [![Travis CI Build Status](https://img.shields.io/travis/weld/weld-vertx/master.svg)](https://travis-ci.org/weld/weld-vertx) 9 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.jboss.weld.vertx/weld-vertx-core/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22weld-vertx-core%22) 10 | [![License](https://img.shields.io/badge/license-Apache%20License%202.0-yellow.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) 11 | 12 | The primary purpose of `weld-vertx` is to bring the CDI programming model into the [Vert.x](http://vertx.io/) ecosystem, i.e. to extend the tool-kit for building reactive applications on the JVM. 13 | 14 | ## Features 15 | 16 | * Provides `WeldVerticle` to start/stop the CDI container (using Weld SE) - see also [Core](https://github.com/weld/weld-vertx/blob/master/doc/src/main/asciidoc/core.adoc) 17 | * Makes it possible to notify CDI observer methods when a message is sent via Vert.x event bus - see also [Core](https://github.com/weld/weld-vertx/blob/master/doc/src/main/asciidoc/core.adoc) 18 | * Provides `@ApplicationScoped` beans for `io.vertx.core.Vertx` and `io.vertx.core.Context` - see also [Core](https://github.com/weld/weld-vertx/blob/master/doc/src/main/asciidoc/core.adoc) 19 | * Provides "async" helpers such as [AsyncReference](https://github.com/weld/weld-vertx/blob/master/core/src/main/java/org/jboss/weld/vertx/AsyncReference.java) and [AsyncWorker](https://github.com/weld/weld-vertx/blob/master/core/src/main/java/org/jboss/weld/vertx/AsyncWorker.java) - see also [Core](https://github.com/weld/weld-vertx/blob/master/doc/src/main/asciidoc/core.adoc) 20 | * Allows to deploy Verticles produced/injected by Weld - see also [Core](https://github.com/weld/weld-vertx/blob/master/doc/src/main/asciidoc/core.adoc) 21 | * Allows to define/register an `io.vertx.ext.web.Route` in a declarative way, using `@org.jboss.weld.vertx.web.WebRoute` - see also [Web](https://github.com/weld/weld-vertx/blob/master/doc/src/main/asciidoc/web.adoc) 22 | * Allows to inject and invoke service proxies (as defined in https://github.com/vert-x3/vertx-service-proxy) - see also [Service Proxy](https://github.com/weld/weld-vertx/blob/master/doc/src/main/asciidoc/service-proxy.adoc) 23 | 24 | ## Documentation 25 | 26 | Brief documentation can be found at: http://docs.jboss.org/weld/weld-vertx/latest/ 27 | 28 | ## Building 29 | 30 | To build simply run: 31 | 32 | > $ mvn clean install 33 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/observer/HelloRouteObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web.observer; 18 | 19 | import static org.jboss.weld.vertx.web.WebRoute.HandlerType.BLOCKING; 20 | import static org.jboss.weld.vertx.web.WebRoute.HandlerType.FAILURE; 21 | 22 | import javax.enterprise.context.ApplicationScoped; 23 | import javax.enterprise.event.Observes; 24 | 25 | import org.jboss.weld.context.activator.ActivateRequestContext; 26 | import org.jboss.weld.vertx.web.RequestHelloService; 27 | import org.jboss.weld.vertx.web.SayHelloService; 28 | import org.jboss.weld.vertx.web.WebRoute; 29 | 30 | import io.vertx.ext.web.RoutingContext; 31 | 32 | @ApplicationScoped 33 | public class HelloRouteObserver { 34 | 35 | @WebRoute("/hello") 36 | void hello(@Observes RoutingContext ctx, SayHelloService service) { 37 | ctx.response().setStatusCode(200).end(service.hello()); 38 | } 39 | 40 | @WebRoute("/foo") 41 | @WebRoute("/bar") 42 | void fooAndBar(@Observes RoutingContext ctx) { 43 | ctx.response().setStatusCode(200).end("path:" + ctx.request().path()); 44 | } 45 | 46 | @WebRoute("/fail/*") 47 | void alwaysFail(@Observes RoutingContext ctx) { 48 | throw new IllegalStateException(); 49 | } 50 | 51 | @WebRoute(type = FAILURE) 52 | void universalFailure(@Observes RoutingContext ctx) { 53 | ctx.response().setStatusCode(500).end(ctx.request().path()); 54 | } 55 | 56 | @WebRoute(value = "/request-context-active", type = BLOCKING) 57 | @ActivateRequestContext 58 | void withActiveRequestContext(@Observes RoutingContext ctx, RequestHelloService helloService) { 59 | ctx.response().setStatusCode(200).end(helloService.hello()); 60 | } 61 | 62 | @WebRoute(value = "/hello-chain", order = 2) 63 | void helloChain(@Observes RoutingContext ctx) { 64 | ctx.response().setStatusCode(200).end("ok"); 65 | } 66 | 67 | @WebRoute(value = "/hello-chain", order = 1) 68 | void helloChainIgnored(RoutingContext ctx) { 69 | ctx.fail(500); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /probe/src/test/java/org/jboss/weld/vertx/probe/ProbeHandlersTest.java: -------------------------------------------------------------------------------- 1 | package org.jboss.weld.vertx.probe; 2 | 3 | import static io.restassured.RestAssured.get; 4 | import static org.hamcrest.collection.IsEmptyCollection.empty; 5 | import static org.hamcrest.core.IsNot.not; 6 | import static org.jboss.weld.vertx.WeldVerticle.createDefaultWeld; 7 | 8 | import org.jboss.weld.environment.se.Weld; 9 | import org.jboss.weld.vertx.Timeouts; 10 | import org.jboss.weld.vertx.web.WeldWebVerticle; 11 | import org.junit.After; 12 | import org.junit.Before; 13 | import org.junit.Rule; 14 | import org.junit.Test; 15 | import org.junit.rules.Timeout; 16 | import org.junit.runner.RunWith; 17 | 18 | import io.restassured.response.Response; 19 | import io.vertx.core.Vertx; 20 | import io.vertx.ext.unit.Async; 21 | import io.vertx.ext.unit.TestContext; 22 | import io.vertx.ext.unit.junit.VertxUnitRunner; 23 | import io.vertx.ext.web.Router; 24 | import io.vertx.ext.web.handler.BodyHandler; 25 | 26 | /** 27 | * 28 | * @author Martin Kouba 29 | */ 30 | @RunWith(VertxUnitRunner.class) 31 | public class ProbeHandlersTest { 32 | 33 | static final String URL_BASE = "http://localhost:8080/weld-probe/"; 34 | 35 | private Vertx vertx; 36 | 37 | @Rule 38 | public Timeout globalTimeout = Timeout.millis(Timeouts.GLOBAL_TIMEOUT); 39 | 40 | @Before 41 | public void init(TestContext context) throws InterruptedException { 42 | vertx = Vertx.vertx(); 43 | Async async = context.async(); 44 | final WeldWebVerticle weldVerticle = new WeldWebVerticle(createDefaultWeld().property(Weld.DEV_MODE_SYSTEM_PROPERTY, true)); 45 | vertx.deployVerticle(weldVerticle, deploy -> { 46 | if (deploy.succeeded()) { 47 | Router router = Router.router(vertx); 48 | router.route().handler(BodyHandler.create()); 49 | weldVerticle.registerRoutes(router); 50 | vertx.createHttpServer().requestHandler(router::accept).listen(8080, (listen) -> { 51 | if (listen.succeeded()) { 52 | async.complete(); 53 | } else { 54 | listen.cause().printStackTrace(); 55 | } 56 | }); 57 | } else { 58 | deploy.cause().printStackTrace(); 59 | } 60 | }); 61 | } 62 | 63 | @After 64 | public void close(TestContext context) { 65 | vertx.close(context.asyncAssertSuccess()); 66 | } 67 | 68 | @Test 69 | public void testDeployment() { 70 | Response response = get(URL_BASE + "deployment"); 71 | response.then().assertThat().statusCode(200).body("configuration", not(empty())); 72 | } 73 | 74 | @Test 75 | public void testBeans() { 76 | Response response = get(URL_BASE + "beans"); 77 | response.then().assertThat().statusCode(200).body("data", not(empty())); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/PaymentResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import java.util.List; 20 | 21 | import javax.inject.Inject; 22 | 23 | import io.vertx.core.Handler; 24 | import io.vertx.core.json.JsonArray; 25 | import io.vertx.ext.web.RoutingContext; 26 | 27 | public class PaymentResource { 28 | 29 | @WebRoute("/payments") 30 | static class PaymentsHandler implements Handler { 31 | 32 | @Inject 33 | PaymentService paymentService; 34 | 35 | @Override 36 | public void handle(RoutingContext ctx) { 37 | List payments = paymentService.getPayments(); 38 | JsonArray array = new JsonArray(); 39 | for (Payment payment : payments) { 40 | array.add(paymentService.encode(payment)); 41 | } 42 | ctx.response().setStatusCode(200).end(array.encode()); 43 | } 44 | } 45 | 46 | @WebRoute("/payments/:paymentId") 47 | static class PaymentHandler implements Handler { 48 | 49 | @Inject 50 | PaymentService paymentService; 51 | 52 | @Override 53 | public void handle(RoutingContext ctx) { 54 | Payment payment = paymentService.getPayment(ctx.request().getParam("paymentId")); 55 | if (payment == null) { 56 | ctx.response().setStatusCode(404).end(); 57 | } else { 58 | ctx.response().setStatusCode(200).end(paymentService.encode(payment).encode()); 59 | } 60 | } 61 | 62 | } 63 | 64 | // This must be ignored 65 | @WebRoute("/payments/inner") 66 | class InnerClassHandler implements Handler { 67 | 68 | @Override 69 | public void handle(RoutingContext ctx) { 70 | ctx.response().setStatusCode(200).end("OK"); 71 | } 72 | 73 | } 74 | 75 | // This must be ignored 76 | @WebRoute("/payments/string") 77 | static class WrongParameterHandler implements Handler { 78 | 79 | @Override 80 | public void handle(String ctx) { 81 | } 82 | 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /core/src/test/java/org/jboss/weld/vertx/container/WeldVerticleContainerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.container; 18 | 19 | import org.jboss.weld.vertx.Timeouts; 20 | import org.jboss.weld.vertx.WeldVerticle; 21 | import org.junit.After; 22 | import org.junit.Before; 23 | import org.junit.Rule; 24 | import org.junit.Test; 25 | import org.junit.rules.Timeout; 26 | import org.junit.runner.RunWith; 27 | 28 | import io.vertx.core.Vertx; 29 | import io.vertx.ext.unit.Async; 30 | import io.vertx.ext.unit.TestContext; 31 | import io.vertx.ext.unit.junit.VertxUnitRunner; 32 | 33 | /** 34 | * 35 | * @author Martin Kouba 36 | */ 37 | @RunWith(VertxUnitRunner.class) 38 | public class WeldVerticleContainerTest { 39 | 40 | private Vertx vertx; 41 | 42 | @Rule 43 | public Timeout globalTimeout = Timeout.millis(Timeouts.GLOBAL_TIMEOUT); 44 | 45 | @Before 46 | public void init(TestContext context) throws InterruptedException { 47 | final WeldVerticle weldVerticle = new WeldVerticle(); 48 | Async async = context.async(); 49 | vertx = Vertx.vertx(); 50 | vertx.deployVerticle(weldVerticle, deployResult -> { 51 | if (deployResult.succeeded()) { 52 | // Deploy Verticle instance produced by Weld 53 | vertx.deployVerticle(weldVerticle.container().select(BeanVerticle.class).get(), (beanVerticleDeployResult) -> { 54 | if (beanVerticleDeployResult.succeeded()) { 55 | async.complete(); 56 | } 57 | }); 58 | } 59 | }); 60 | } 61 | 62 | @After 63 | public void close(TestContext context) { 64 | vertx.close(context.asyncAssertSuccess()); 65 | } 66 | 67 | @Test 68 | public void testVerticleBeans(TestContext context) throws InterruptedException { 69 | Async async = context.async(); 70 | vertx.eventBus().send(BeanVerticle.class.getName(), "hello", r -> { 71 | if (r.succeeded()) { 72 | context.assertEquals(SayHelloService.MESSAGE, r.result().body()); 73 | async.complete(); 74 | } 75 | }); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /core/src/main/java/org/jboss/weld/vertx/VertxEventImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import javax.enterprise.inject.Vetoed; 20 | 21 | import io.vertx.core.MultiMap; 22 | import io.vertx.core.eventbus.EventBus; 23 | import io.vertx.core.eventbus.Message; 24 | import io.vertx.core.logging.Logger; 25 | import io.vertx.core.logging.LoggerFactory; 26 | 27 | @Vetoed 28 | class VertxEventImpl implements VertxEvent { 29 | 30 | private static final Logger LOGGER = LoggerFactory.getLogger(VertxEventImpl.class.getName()); 31 | 32 | private final EventBus eventBus; 33 | 34 | private final Message message; 35 | 36 | private Object reply; 37 | 38 | VertxEventImpl(Message message, EventBus eventBus) { 39 | this.eventBus = eventBus; 40 | this.message = message; 41 | } 42 | 43 | @Override 44 | public String getAddress() { 45 | return message.address(); 46 | } 47 | 48 | @Override 49 | public MultiMap getHeaders() { 50 | return message.headers(); 51 | } 52 | 53 | @Override 54 | public Object getMessageBody() { 55 | return message.body(); 56 | } 57 | 58 | @Override 59 | public String getReplyAddress() { 60 | return message.replyAddress(); 61 | } 62 | 63 | @Override 64 | public boolean setReply(Object reply) { 65 | if (message.replyAddress() == null) { 66 | LOGGER.warn("The message was sent without a reply handler - the reply will be ignored"); 67 | } 68 | if (this.reply != null) { 69 | LOGGER.warn("A reply was already set - the old value is replaced"); 70 | return false; 71 | } 72 | this.reply = reply; 73 | return true; 74 | } 75 | 76 | @Override 77 | public boolean isReplied() { 78 | return reply != null; 79 | } 80 | 81 | @Override 82 | public void fail(int code, String message) { 83 | throw new RecipientFailure(code, message); 84 | } 85 | 86 | @Override 87 | public VertxMessage messageTo(String address) { 88 | return new VertxMessageImpl(address, eventBus); 89 | } 90 | 91 | Object getReply() { 92 | return reply; 93 | } 94 | 95 | } -------------------------------------------------------------------------------- /examples/translator/src/main/java/org/jboss/weld/vertx/examples/translator/DummyDataVerticle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.examples.translator; 18 | 19 | import static org.jboss.weld.vertx.examples.translator.Addresses.REQUEST_DATA; 20 | 21 | import java.util.Arrays; 22 | import java.util.Collections; 23 | import java.util.HashMap; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Map.Entry; 27 | import java.util.Properties; 28 | 29 | import io.vertx.core.AbstractVerticle; 30 | import io.vertx.core.Verticle; 31 | import io.vertx.core.json.JsonArray; 32 | import io.vertx.core.json.JsonObject; 33 | import io.vertx.core.logging.Logger; 34 | import io.vertx.core.logging.LoggerFactory; 35 | 36 | /** 37 | * {@link Verticle} to provide dummy data. 38 | * 39 | * @author Martin Kouba 40 | */ 41 | public class DummyDataVerticle extends AbstractVerticle { 42 | 43 | private static final Logger LOGGER = LoggerFactory.getLogger(DummyDataVerticle.class.getName()); 44 | 45 | private final Map> translationData; 46 | 47 | public DummyDataVerticle() { 48 | this.translationData = new HashMap<>(); 49 | } 50 | 51 | @Override 52 | public void start() throws Exception { 53 | // Read data.properties 54 | Properties properties = new Properties(); 55 | properties.load(DummyDataVerticle.class.getResourceAsStream("data.properties")); 56 | for (Entry entry : properties.entrySet()) { 57 | translationData.put(entry.getKey().toString().toLowerCase(), Arrays.asList(entry.getValue().toString().split(","))); 58 | } 59 | vertx.eventBus().consumer(REQUEST_DATA, (m) -> { 60 | String word = m.body().toString(); 61 | LOGGER.info("Find translation data for {0}", word); 62 | List result = translationData.get(word.toLowerCase()); 63 | if (result == null) { 64 | result = Collections.emptyList(); 65 | } 66 | if (result.isEmpty()) { 67 | LOGGER.warn("No translation data available for: {0}", word); 68 | } 69 | m.reply(new JsonObject().put("word", word).put("translations", new JsonArray(result))); 70 | }); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /examples/kotlin/src/main/kotlin/org/jboss/weld/vertx/kotlin/Handlers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2018, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.kotlin 18 | 19 | import io.vertx.core.Handler 20 | import io.vertx.core.Vertx 21 | import io.vertx.ext.web.RoutingContext 22 | import org.jboss.weld.vertx.web.WebRoute 23 | import org.jboss.weld.vertx.web.WeldWebVerticle 24 | import javax.enterprise.context.ApplicationScoped 25 | import javax.enterprise.context.Dependent 26 | import javax.enterprise.event.Observes 27 | import javax.inject.Inject 28 | 29 | /** 30 | * This bean only exists to demonstrate injection into handlers and observers! 31 | */ 32 | @Dependent 33 | class CaseService { 34 | 35 | fun upper(value: String): String = value.toUpperCase() 36 | 37 | fun lower(value: String): String = value.toLowerCase() 38 | 39 | } 40 | 41 | @ApplicationScoped 42 | open class Observers { 43 | 44 | @WebRoute("/lowerCase") 45 | fun lower(@Observes ctx: RoutingContext, service: CaseService) { 46 | val value = ctx.request().getParam("value") 47 | if (value != null) { 48 | ctx.response().setStatusCode(200).end(service.lower(value)) 49 | } else { 50 | ctx.response().setStatusCode(400).end("Value not specified") 51 | } 52 | } 53 | } 54 | 55 | @WebRoute("/upperCase") 56 | class UpperHandler @Inject constructor(private val service: CaseService) : Handler { 57 | 58 | override fun handle(ctx: RoutingContext) { 59 | val value = ctx.request().getParam("value") 60 | if (value != null) { 61 | ctx.response().setStatusCode(200).end(service.upper(value)) 62 | } else { 63 | ctx.response().setStatusCode(400).end("Value not specified") 64 | } 65 | } 66 | } 67 | 68 | fun main(args: Array) { 69 | // Create and deploy Weld verticle, i.e. start CDI container and discover all @WebRoute handlers 70 | val vertx = Vertx.vertx() 71 | val weldVerticle = WeldWebVerticle() 72 | 73 | vertx.deployVerticle(weldVerticle, { 74 | if (it.succeeded()) { 75 | // If successfull create the router and start the webserver 76 | vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080) 77 | } else { 78 | throw IllegalStateException("Weld verticle failure: " + it.cause()) 79 | } 80 | } 81 | ) 82 | } -------------------------------------------------------------------------------- /service-proxy/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.jboss.weld.vertx 6 | weld-vertx-parent 7 | 1.3.0-SNAPSHOT 8 | 9 | 10 | weld-vertx-service-proxy 11 | 12 | 13 | 14 | 15 | javax.enterprise 16 | cdi-api 17 | 18 | 19 | 20 | io.vertx 21 | vertx-service-proxy 22 | ${version.vertx} 23 | 24 | 25 | 26 | 27 | io.vertx 28 | vertx-codegen 29 | ${version.vertx} 30 | 31 | 32 | 33 | 34 | io.vertx 35 | vertx-unit 36 | 37 | 38 | 39 | org.jboss.weld.vertx 40 | weld-vertx-core 41 | ${project.version} 42 | test 43 | 44 | 45 | 46 | junit 47 | junit 48 | test 49 | 50 | 51 | 52 | org.slf4j 53 | slf4j-simple 54 | test 55 | 56 | 57 | 58 | org.jboss.weld.vertx 59 | weld-vertx-core 60 | ${project.version} 61 | test-jar 62 | test 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | maven-compiler-plugin 71 | 72 | 73 | default-testCompile 74 | 75 | 76 | io.vertx.codegen.CodeGenProcessor 77 | 78 | ${project.basedir}/src/test/generated 79 | 80 | -AoutputDirectory=${project.basedir}/src/test 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /examples/hello/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.jboss.weld.vertx 5 | weld-vertx-parent 6 | ../../pom.xml 7 | 1.3.0-SNAPSHOT 8 | 9 | 10 | org.jboss.weld.vertx.examples 11 | weld-vertx-hello-example 12 | 13 | 14 | 15 | 16 | org.jboss.weld.vertx 17 | weld-vertx-web 18 | ${project.version} 19 | 20 | 21 | 22 | 23 | io.vertx 24 | vertx-unit 25 | 26 | 27 | 28 | junit 29 | junit 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.apache.maven.plugins 38 | maven-shade-plugin 39 | 40 | 41 | default 42 | package 43 | 44 | shade 45 | 46 | 47 | 48 | 49 | 50 | org.jboss.weld.vertx.examples.hello.HelloMain 51 | 52 | 53 | 54 | 55 | true 56 | weld-vertx-hello-example-shaded 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | devmode 68 | 69 | 70 | devmode 71 | 72 | 73 | 74 | 75 | org.jboss.weld.vertx 76 | weld-vertx-probe 77 | ${project.version} 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /web/src/main/java/org/jboss/weld/vertx/web/WeldWebVerticle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web; 18 | 19 | import org.jboss.weld.environment.se.Weld; 20 | import org.jboss.weld.vertx.WeldVerticle; 21 | 22 | import io.vertx.ext.web.Route; 23 | import io.vertx.ext.web.Router; 24 | import io.vertx.ext.web.handler.BodyHandler; 25 | 26 | /** 27 | * This verticle extends the {@link WeldVerticle} functionality and allows to register {@link Route} handlers discovered during container initialization. 28 | *

      29 | * 30 | *

      31 |  * class MyApp {
      32 |  *     public static void main(String[] args) {
      33 |  *         final Vertx vertx = Vertx.vertx();
      34 |  *         final WeldWebVerticle weldVerticle = new WeldWebVerticle();
      35 |  *         vertx.deployVerticle(weldVerticle, result -> {
      36 |  *             if (result.succeeded()) {
      37 |  *                 // Configure the router after Weld bootstrap finished
      38 |  *                 vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080);
      39 |  *             }
      40 |  *         });
      41 |  *     }
      42 |  * }
      43 |  * 
      44 | * 45 | * @author Martin Kouba 46 | * @see WebRoute 47 | */ 48 | public class WeldWebVerticle extends WeldVerticle { 49 | 50 | public WeldWebVerticle() { 51 | super(); 52 | } 53 | 54 | public WeldWebVerticle(Weld weld) { 55 | super(weld); 56 | } 57 | 58 | @Override 59 | protected void configureWeld(Weld weld) { 60 | weld.addExtension(new RouteExtension()); 61 | } 62 | 63 | /** 64 | * Registers all the route handlers discovered. 65 | * 66 | * @param router 67 | * @throws IllegalStateException If the container is not initialized or already shut down 68 | */ 69 | public void registerRoutes(Router router) { 70 | container().getBeanManager().getExtension(RouteExtension.class).registerRoutes(router); 71 | } 72 | 73 | /** 74 | * Creates a router with {@link BodyHandler} and all discovered route handlers registered. 75 | * 76 | * @return a new router instance 77 | * @throws IllegalStateException If the container is not initialized or already shut down 78 | */ 79 | public Router createRouter() { 80 | Router router = Router.router(vertx); 81 | router.route().handler(BodyHandler.create()); 82 | registerRoutes(router); 83 | return router; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /examples/translator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.jboss.weld.vertx 5 | weld-vertx-parent 6 | ../../pom.xml 7 | 1.3.0-SNAPSHOT 8 | 9 | 10 | org.jboss.weld.vertx.examples 11 | weld-vertx-translator-example 12 | 13 | 14 | 15 | 16 | org.jboss.weld.vertx 17 | weld-vertx-web 18 | ${project.version} 19 | 20 | 21 | 22 | 23 | io.vertx 24 | vertx-unit 25 | 26 | 27 | 28 | junit 29 | junit 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.apache.maven.plugins 38 | maven-shade-plugin 39 | 40 | 41 | default 42 | package 43 | 44 | shade 45 | 46 | 47 | 48 | 49 | 50 | org.jboss.weld.vertx.examples.translator.TranslatorExampleRunner 51 | 52 | 53 | 54 | 55 | true 56 | weld-vertx-translator-example-shaded 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | devmode 68 | 69 | 70 | devmode 71 | 72 | 73 | 74 | 75 | org.jboss.weld.vertx 76 | weld-vertx-probe 77 | ${project.version} 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /probe/src/main/java/org/jboss/weld/vertx/probe/Exports.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.probe; 18 | 19 | import java.io.BufferedOutputStream; 20 | import java.io.ByteArrayOutputStream; 21 | import java.io.IOException; 22 | import java.lang.annotation.Annotation; 23 | import java.nio.charset.StandardCharsets; 24 | import java.util.Map; 25 | import java.util.zip.ZipEntry; 26 | import java.util.zip.ZipOutputStream; 27 | 28 | import javax.enterprise.context.ApplicationScoped; 29 | import javax.enterprise.context.ConversationScoped; 30 | import javax.enterprise.context.SessionScoped; 31 | 32 | import org.jboss.weld.probe.JsonDataProvider; 33 | import org.jboss.weld.util.collections.ImmutableMap; 34 | 35 | /** 36 | * See also org.jboss.weld.probe.Exports. 37 | * 38 | * @author Martin Kouba 39 | */ 40 | final class Exports { 41 | 42 | static final Map> INSPECTABLE_SCOPES = ImmutableMap.> builder() 43 | .put("application", ApplicationScoped.class).put("session", SessionScoped.class).put("conversation", ConversationScoped.class).build(); 44 | 45 | private Exports() { 46 | } 47 | 48 | static byte[] exportJsonData(JsonDataProvider jsonDataProvider) throws IOException { 49 | ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 50 | ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(bytes)); 51 | addEntry(out, "deployment", jsonDataProvider.receiveDeployment()); 52 | addEntry(out, "observers", jsonDataProvider.receiveObservers(0, 0, null, "FULL")); 53 | addEntry(out, "beans", jsonDataProvider.receiveBeans(0, 0, null, "FULL")); 54 | addEntry(out, "fired-events", jsonDataProvider.receiveEvents(0, 0, null)); 55 | addEntry(out, "invocation-trees", jsonDataProvider.receiveInvocations(0, 0, null, "FULL")); 56 | addEntry(out, "contexts", jsonDataProvider.receiveContexts()); 57 | for (String contextKey : INSPECTABLE_SCOPES.keySet()) { 58 | addEntry(out, "context-" + contextKey, jsonDataProvider.receiveContext(contextKey)); 59 | } 60 | // Intentionally do not export contextual instances 61 | out.close(); 62 | return bytes.toByteArray(); 63 | } 64 | 65 | private static void addEntry(ZipOutputStream out, String baseName, String data) throws IOException { 66 | out.putNextEntry(new ZipEntry(baseName + ".json")); 67 | out.write(data.getBytes(StandardCharsets.UTF_8)); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /probe/src/main/java/org/jboss/weld/vertx/probe/SecurityActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.probe; 18 | 19 | import java.lang.reflect.AccessibleObject; 20 | import java.lang.reflect.Method; 21 | import java.security.AccessController; 22 | import java.security.PrivilegedAction; 23 | 24 | import javax.enterprise.inject.Vetoed; 25 | 26 | /** 27 | * 28 | * @author Martin Kouba 29 | */ 30 | @Vetoed 31 | final class SecurityActions { 32 | 33 | private SecurityActions() { 34 | } 35 | 36 | /** 37 | * Set the {@code accessible} flag for this accessible object. Does not perform {@link PrivilegedAction} unless necessary. 38 | * 39 | * @param accessibleObject 40 | */ 41 | static void ensureAccessible(AccessibleObject accessibleObject) { 42 | if (accessibleObject != null) { 43 | if (!accessibleObject.isAccessible()) { 44 | if (System.getSecurityManager() != null) { 45 | AccessController.doPrivileged(new PrivilegedAction() { 46 | @Override 47 | public AccessibleObject run() { 48 | accessibleObject.setAccessible(true); 49 | return accessibleObject; 50 | } 51 | }); 52 | } else { 53 | accessibleObject.setAccessible(true); 54 | } 55 | } 56 | } 57 | } 58 | 59 | /** 60 | * Does not perform {@link PrivilegedAction} unless necessary. 61 | * 62 | * @param javaClass 63 | * @param methodName 64 | * @param parameterTypes 65 | * @return returns a method from the class or any class/interface in the inheritance hierarchy 66 | * @throws NoSuchMethodException 67 | */ 68 | static Method getDeclaredMethod(Class javaClass, String name, Class... parameterTypes) throws NoSuchMethodException { 69 | if (System.getSecurityManager() != null) { 70 | return AccessController.doPrivileged(new PrivilegedAction() { 71 | @Override 72 | public Method run() { 73 | try { 74 | return javaClass.getDeclaredMethod(name, parameterTypes); 75 | } catch (NoSuchMethodException | SecurityException e) { 76 | return null; 77 | } 78 | } 79 | }); 80 | } else { 81 | return javaClass.getDeclaredMethod(name, parameterTypes); 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /probe/src/main/java/org/jboss/weld/vertx/probe/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2015, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.probe; 18 | 19 | import java.io.BufferedReader; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.io.InputStreamReader; 23 | import java.io.StringWriter; 24 | import java.io.UnsupportedEncodingException; 25 | 26 | import io.vertx.core.buffer.Buffer; 27 | 28 | /** 29 | * See also org.jboss.weld.probe.IOUtils. 30 | * 31 | * @author Martin Kouba 32 | */ 33 | final class IOUtils { 34 | 35 | private static final int DEFAULT_BUFFER = 1024 * 8; 36 | 37 | private IOUtils() { 38 | } 39 | 40 | static String getResourceAsString(String resourceName) { 41 | StringWriter writer = new StringWriter(); 42 | BufferedReader reader = null; 43 | try { 44 | InputStream in = IOUtils.class.getResourceAsStream(resourceName); 45 | if (in == null) { 46 | return null; 47 | } 48 | reader = new BufferedReader(new InputStreamReader(in, ProbeHandlers.ENCODING_UTF8)); 49 | final char[] buffer = new char[DEFAULT_BUFFER]; 50 | int n = 0; 51 | while (-1 != (n = reader.read(buffer))) { 52 | writer.write(buffer, 0, n); 53 | } 54 | writer.flush(); 55 | return writer.toString(); 56 | } catch (UnsupportedEncodingException e) { 57 | throw new IllegalStateException(e); 58 | } catch (IOException e) { 59 | throw new IllegalStateException(e); 60 | } finally { 61 | if (reader != null) { 62 | try { 63 | reader.close(); 64 | } catch (IOException e) { 65 | throw new IllegalStateException(e); 66 | } 67 | } 68 | } 69 | } 70 | 71 | static boolean writeResource(String resourceName, Buffer buffer) { 72 | InputStream in = IOUtils.class.getResourceAsStream(resourceName); 73 | if (in == null) { 74 | return false; 75 | } 76 | try { 77 | final byte[] readBuffer = new byte[DEFAULT_BUFFER]; 78 | int n = 0; 79 | while (-1 != (n = in.read(readBuffer))) { 80 | buffer.appendBytes(readBuffer, 0, n); 81 | } 82 | return true; 83 | } catch (IOException e) { 84 | throw new IllegalStateException(e); 85 | } finally { 86 | try { 87 | in.close(); 88 | } catch (IOException e) { 89 | throw new IllegalStateException(e); 90 | } 91 | } 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /service-proxy/src/test/java/org/jboss/weld/vertx/serviceproxy/EchoServiceProxyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.serviceproxy; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import java.util.concurrent.BlockingQueue; 22 | import java.util.concurrent.LinkedBlockingQueue; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | import org.jboss.weld.vertx.Timeouts; 26 | import org.junit.After; 27 | import org.junit.Before; 28 | import org.junit.Rule; 29 | import org.junit.Test; 30 | import org.junit.rules.Timeout; 31 | import org.junit.runner.RunWith; 32 | 33 | import io.vertx.core.Vertx; 34 | import io.vertx.ext.unit.Async; 35 | import io.vertx.ext.unit.TestContext; 36 | import io.vertx.ext.unit.junit.VertxUnitRunner; 37 | 38 | /** 39 | * 40 | * @author Martin Kouba 41 | */ 42 | @RunWith(VertxUnitRunner.class) 43 | public class EchoServiceProxyTest { 44 | 45 | static final BlockingQueue SYNCHRONIZER = new LinkedBlockingQueue<>(); 46 | 47 | private Vertx vertx; 48 | 49 | private EchoServiceVerticle echoVerticle; 50 | 51 | @Rule 52 | public Timeout globalTimeout = Timeout.millis(Timeouts.GLOBAL_TIMEOUT); 53 | 54 | @Before 55 | public void init(TestContext context) throws InterruptedException { 56 | Async async = context.async(); 57 | vertx = Vertx.vertx(); 58 | echoVerticle = new EchoServiceVerticle(); 59 | vertx.deployVerticle(echoVerticle, r -> { 60 | if (r.succeeded()) { 61 | async.complete(); 62 | } else { 63 | context.fail(r.cause()); 64 | } 65 | }); 66 | SYNCHRONIZER.clear(); 67 | } 68 | 69 | @After 70 | public void close(TestContext context) { 71 | vertx.close(context.asyncAssertSuccess()); 72 | } 73 | 74 | @Test 75 | public void testEchoServiceProxy() throws InterruptedException { 76 | String message = "foooo"; 77 | echoVerticle.container().select(EchoServiceConsumer.class).get().doEchoBusiness(message); 78 | assertEquals(message, poll()); 79 | } 80 | 81 | @Test 82 | public void testEchoServiceProxyDynamicLookup() throws InterruptedException { 83 | String message = "foooo"; 84 | // Lookup service proxy with ServiceProxy qualifier literal 85 | echoVerticle.container().select(EchoService.class, ServiceProxy.Literal.of("echo-service-address")).get().echo(message, 86 | (r) -> SYNCHRONIZER.add(r.result())); 87 | assertEquals(message, poll()); 88 | } 89 | 90 | private Object poll() throws InterruptedException { 91 | return SYNCHRONIZER.poll(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /examples/kotlin/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.jboss.weld.vertx 6 | weld-vertx-parent 7 | ../../pom.xml 8 | 1.3.0-SNAPSHOT 9 | 10 | 11 | org.jboss.weld.vertx.examples 12 | weld-vertx-kotlin-example 13 | 14 | 15 | 1.2.21 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | org.jboss.weld.vertx 23 | weld-vertx-web 24 | ${project.version} 25 | 26 | 27 | 28 | org.jetbrains.kotlin 29 | kotlin-stdlib-jdk8 30 | ${kotlin.version} 31 | 32 | 33 | 34 | 35 | io.vertx 36 | vertx-unit 37 | 38 | 39 | 40 | junit 41 | junit 42 | 43 | 44 | 45 | 46 | 47 | ${project.basedir}/src/main/kotlin 48 | ${project.basedir}/src/test/kotlin 49 | 50 | 51 | kotlin-maven-plugin 52 | org.jetbrains.kotlin 53 | ${kotlin.version} 54 | 55 | 56 | compile 57 | 58 | compile 59 | 60 | 61 | 62 | test-compile 63 | 64 | test-compile 65 | 66 | 67 | 68 | 69 | 70 | org.apache.maven.plugins 71 | maven-shade-plugin 72 | 73 | 74 | default 75 | package 76 | 77 | shade 78 | 79 | 80 | 81 | 83 | 84 | org.jboss.weld.vertx.kotlin.HandlersKt 85 | 86 | 87 | 89 | 90 | true 91 | weld-vertx-kotlin-shaded 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /examples/kotlin/src/test/kotlin/org/jboss/weld/vertx/kotlin/HandlersTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2018, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.kotlin 18 | 19 | import io.vertx.core.Vertx 20 | import io.vertx.core.http.HttpClientResponse 21 | import io.vertx.core.http.HttpMethod 22 | import io.vertx.ext.unit.TestContext 23 | import io.vertx.ext.unit.junit.VertxUnitRunner 24 | import org.jboss.weld.vertx.web.WeldWebVerticle 25 | import org.junit.After 26 | import org.junit.Before 27 | import org.junit.Test 28 | import org.junit.runner.RunWith 29 | 30 | const val DEFAULT_TIMEOUT: Long = 15000; 31 | 32 | @RunWith(VertxUnitRunner::class) 33 | class HandlersTest { 34 | 35 | lateinit var vertx: Vertx; 36 | 37 | @Before 38 | fun setup(context: TestContext) { 39 | val async = context.async() 40 | vertx = Vertx.vertx() 41 | val weldVerticle = WeldWebVerticle() 42 | vertx.deployVerticle(weldVerticle, { 43 | if (it.succeeded()) { 44 | vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080) 45 | async.complete() 46 | } else { 47 | context.fail(it.cause()); 48 | } 49 | }) 50 | } 51 | 52 | @After 53 | fun close(context: TestContext) { 54 | vertx.close(context.asyncAssertSuccess()); 55 | } 56 | 57 | @Test(timeout = DEFAULT_TIMEOUT) 58 | fun testUppercase(context: TestContext) { 59 | val async = context.async() 60 | val client = vertx.createHttpClient() 61 | val request = client.request(HttpMethod.POST, 8080, "localhost", "/upperCase?value=Lu") 62 | 63 | request.handler({ response: HttpClientResponse -> 64 | if (response.statusCode() == 200) { 65 | response.bodyHandler({ buffer -> 66 | context.assertEquals("LU", buffer.toString()); 67 | client.close(); 68 | async.complete(); 69 | }) 70 | } 71 | }) 72 | request.end() 73 | } 74 | 75 | @Test(timeout = DEFAULT_TIMEOUT) 76 | fun testLowercase(context: TestContext) { 77 | val async = context.async() 78 | val client = vertx.createHttpClient() 79 | val request = client.request(HttpMethod.POST, 8080, "localhost", "/lowerCase?value=Lu") 80 | 81 | request.handler({ response: HttpClientResponse -> 82 | if (response.statusCode() == 200) { 83 | response.bodyHandler({ buffer -> 84 | context.assertEquals("lu", buffer.toString()); 85 | client.close(); 86 | async.complete(); 87 | }) 88 | } 89 | }) 90 | request.end() 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/extension/RouteExtensionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web.extension; 18 | 19 | import org.jboss.weld.environment.se.Weld; 20 | import org.jboss.weld.environment.se.WeldContainer; 21 | import org.jboss.weld.vertx.Timeouts; 22 | import org.jboss.weld.vertx.web.HelloHandler; 23 | import org.jboss.weld.vertx.web.RouteExtension; 24 | import org.jboss.weld.vertx.web.SayHelloService; 25 | import org.junit.After; 26 | import org.junit.Before; 27 | import org.junit.Rule; 28 | import org.junit.Test; 29 | import org.junit.rules.Timeout; 30 | import org.junit.runner.RunWith; 31 | 32 | import io.vertx.core.Vertx; 33 | import io.vertx.core.http.HttpClient; 34 | import io.vertx.core.http.HttpClientOptions; 35 | import io.vertx.ext.unit.Async; 36 | import io.vertx.ext.unit.TestContext; 37 | import io.vertx.ext.unit.junit.VertxUnitRunner; 38 | import io.vertx.ext.web.Router; 39 | import io.vertx.ext.web.handler.BodyHandler; 40 | 41 | /** 42 | * Test that RouteExtension is usable even without Weld verticles. 43 | * 44 | * @author Martin Kouba 45 | */ 46 | @RunWith(VertxUnitRunner.class) 47 | public class RouteExtensionTest { 48 | 49 | @Rule 50 | public Timeout globalTimeout = Timeout.millis(Timeouts.GLOBAL_TIMEOUT); 51 | 52 | private WeldContainer weld; 53 | 54 | private Vertx vertx; 55 | 56 | @Before 57 | public void init(TestContext context) throws InterruptedException { 58 | weld = new Weld().disableDiscovery().addExtension(new RouteExtension()).beanClasses(HelloHandler.class, SayHelloService.class).initialize(); 59 | vertx = Vertx.vertx(); 60 | Async async = context.async(); 61 | Router router = Router.router(vertx); 62 | weld.select(RouteExtension.class).get().registerRoutes(router); 63 | router.route().handler(BodyHandler.create()); 64 | vertx.createHttpServer().requestHandler(router::accept).listen(8080, (r) -> { 65 | if (r.succeeded()) { 66 | async.complete(); 67 | } else { 68 | context.fail(r.cause()); 69 | } 70 | }); 71 | } 72 | 73 | @After 74 | public void close(TestContext context) { 75 | if (vertx != null) { 76 | vertx.close(context.asyncAssertSuccess()); 77 | } 78 | if (weld != null) { 79 | weld.shutdown(); 80 | } 81 | } 82 | 83 | @Test 84 | public void testHandlers(TestContext context) throws InterruptedException { 85 | Async async = context.async(); 86 | HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080)); 87 | client.get("/hello").handler(response -> response.bodyHandler(b -> { 88 | context.assertEquals(SayHelloService.MESSAGE, b.toString()); 89 | async.complete(); 90 | })).end(); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /core/src/main/java/org/jboss/weld/vertx/AsyncReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import java.util.concurrent.CompletionStage; 20 | import java.util.function.BiConsumer; 21 | 22 | /** 23 | * Asynchronously processed wrapper of an injectable reference. Can be used to obtain an injectable reference of a bean whose creation involves potentially 24 | * blocking operations: 25 | * 26 | *
       27 |  * @ApplicationScoped
       28 |  * class Hello {
       29 |  *
       30 |  *     @Inject
       31 |  *     AsynReference<ServiceWithBlockingInit> service;
       32 |  *
       33 |  *     CompletionStage<String> hello() {
       34 |  *         return service.thenApply((s) -> "Hello" + s.getName() + "!");
       35 |  *     }
       36 |  * }
       37 |  * 
      38 | * 39 | *

      40 | * If there is a producer method whose return type is {@link CompletionStage} where the result type matches the required type and has all the required qualifers 41 | * (according to type-safe resolution rules) then {@link CompletionStage#whenComplete(java.util.function.BiConsumer)} is used to process the reference. 42 | * Otherwise, a worker thread is used so that the processing does not block the event loop thread. 43 | *

      44 | * 45 | *

      46 | * For a normal scoped bean the contextual instance is initialized eagerly (unlike when performing normal dependency injection). 47 | *

      48 | * 49 | *

      50 | * No method in this interface waits for completion. This interface also implements {@link CompletionStage} with an injectable reference as the result. 51 | *

      52 | * 53 | * @author Martin Kouba 54 | * @param the required type 55 | */ 56 | public interface AsyncReference extends CompletionStage { 57 | 58 | /** 59 | * 60 | * @return {@code true} if an injectable reference was obtained, {@code false} otherwise 61 | */ 62 | boolean isDone(); 63 | 64 | /** 65 | * Gets the reference. 66 | * 67 | * @return the reference, might be {@code null} 68 | */ 69 | T get(); 70 | 71 | /** 72 | * Gets the reference or the default value. 73 | * 74 | * @param defaultValue 75 | * @return the reference or the default value if the reference is {@code null} 76 | */ 77 | default T orElse(T defaultValue) { 78 | T value = get(); 79 | return value != null ? value : defaultValue; 80 | } 81 | 82 | /** 83 | * If {@link #isDone()} returns true, invoke the specified consumer with the reference (may be {@code null}) and the exception (or {@code null} 84 | * if processed successfully). 85 | * 86 | * @param consumer 87 | */ 88 | default void ifDone(BiConsumer consumer) { 89 | if (isDone()) { 90 | consumer.accept(get(), cause()); 91 | } 92 | } 93 | 94 | /** 95 | * Gets the cause in case of a failure occurs during processing. 96 | * 97 | * @return the cause or {@code null} if processed sucessfully 98 | */ 99 | Throwable cause(); 100 | 101 | } 102 | -------------------------------------------------------------------------------- /core/src/main/java/org/jboss/weld/vertx/AsyncWorker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import java.util.concurrent.Callable; 20 | import java.util.concurrent.CompletionStage; 21 | 22 | import javax.enterprise.context.Dependent; 23 | import javax.inject.Inject; 24 | 25 | import io.vertx.core.Vertx; 26 | import me.escoffier.vertx.completablefuture.VertxCompletableFuture; 27 | 28 | /** 29 | * Allows to wrap a synchronous action as an asynchronous computation. The action is performed either as blocking operation using a Vertx worker thread or as 30 | * non-blocking operation using the Vertx event-loop thread. 31 | * 32 | *
       33 |  * @ApplicationScoped
       34 |  * class Hello {
       35 |  *
       36 |  *     @Inject
       37 |  *     AsyncWorker worker;
       38 |  *
       39 |  *     @Inject
       40 |  *     Service service;
       41 |  *
       42 |  *     CompletionStage<String> hello() {
       43 |  *         return worker.performBlocking(service::getNameFromFile()).thenApply((name) -> "Hello " + name + "!");
       44 |  *     }
       45 |  *
       46 |  * }
       47 |  * 
      48 | * 49 | * @author Martin Kouba 50 | */ 51 | @Dependent 52 | public class AsyncWorker { 53 | 54 | /** 55 | * Returns a non-contextual instance. 56 | * 57 | * @param vertx 58 | * @return a new worker instance 59 | */ 60 | public static AsyncWorker from(Vertx vertx) { 61 | return new AsyncWorker(vertx); 62 | } 63 | 64 | private final Vertx vertx; 65 | 66 | @Inject 67 | public AsyncWorker(Vertx vertx) { 68 | this.vertx = vertx; 69 | } 70 | 71 | /** 72 | * Performs the specified action using the event-loop thread. The action should never block. 73 | * 74 | * @param action 75 | * @return a completion stage with the result of the specified action 76 | */ 77 | public CompletionStage perform(Callable action) { 78 | VertxCompletableFuture future = new VertxCompletableFuture<>(vertx); 79 | vertx.runOnContext(v -> { 80 | try { 81 | future.complete(action.call()); 82 | } catch (Throwable e) { 83 | future.completeExceptionally(e); 84 | } 85 | }); 86 | return future; 87 | } 88 | 89 | /** 90 | * Performs the specified action using a thread from the worker pool. 91 | * 92 | * @param action 93 | * @return a completion stage with the result of the specified action 94 | * @see Vertx#executeBlocking(io.vertx.core.Handler, io.vertx.core.Handler) 95 | */ 96 | public CompletionStage performBlocking(Callable action) { 97 | VertxCompletableFuture future = new VertxCompletableFuture<>(vertx); 98 | vertx. executeBlocking((f -> { 99 | try { 100 | f.complete(action.call()); 101 | } catch (Exception e) { 102 | f.fail(e); 103 | } 104 | }), false, (r) -> { 105 | if (r.succeeded()) { 106 | future.complete(r.result()); 107 | } else { 108 | future.completeExceptionally(r.cause()); 109 | } 110 | }); 111 | return future; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/async/HelloAsyncWebRouteTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web.async; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import java.util.concurrent.BlockingQueue; 22 | import java.util.concurrent.LinkedBlockingQueue; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | import org.jboss.weld.environment.se.Weld; 26 | import org.jboss.weld.vertx.AsyncReference; 27 | import org.jboss.weld.vertx.Timeouts; 28 | import org.jboss.weld.vertx.WeldVerticle; 29 | import org.jboss.weld.vertx.web.SayHelloService; 30 | import org.jboss.weld.vertx.web.WeldWebVerticle; 31 | import org.junit.After; 32 | import org.junit.Assert; 33 | import org.junit.Before; 34 | import org.junit.Rule; 35 | import org.junit.Test; 36 | import org.junit.rules.Timeout; 37 | import org.junit.runner.RunWith; 38 | 39 | import io.vertx.core.Vertx; 40 | import io.vertx.core.http.HttpClient; 41 | import io.vertx.core.http.HttpClientOptions; 42 | import io.vertx.ext.unit.Async; 43 | import io.vertx.ext.unit.TestContext; 44 | import io.vertx.ext.unit.junit.VertxUnitRunner; 45 | 46 | /** 47 | * 48 | * @author Martin Kouba 49 | */ 50 | @RunWith(VertxUnitRunner.class) 51 | public class HelloAsyncWebRouteTest { 52 | 53 | static final BlockingQueue SYNCHRONIZER = new LinkedBlockingQueue<>(); 54 | 55 | private Vertx vertx; 56 | 57 | @Rule 58 | public Timeout globalTimeout = Timeout.millis(Timeouts.GLOBAL_TIMEOUT); 59 | 60 | @Before 61 | public void init(TestContext context) throws InterruptedException { 62 | vertx = Vertx.vertx(); 63 | Async async = context.async(); 64 | Weld weld = WeldVerticle.createDefaultWeld().disableDiscovery().beanClasses(BlockingService.class, HelloAsyncHandler.class) 65 | .packages(AsyncReference.class); 66 | WeldWebVerticle weldVerticle = new WeldWebVerticle(weld); 67 | vertx.deployVerticle(weldVerticle, deploy -> { 68 | if (deploy.succeeded()) { 69 | // Configure the router after Weld bootstrap finished 70 | vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> { 71 | if (listen.succeeded()) { 72 | async.complete(); 73 | } else { 74 | context.fail(listen.cause()); 75 | } 76 | }); 77 | } else { 78 | context.fail(deploy.cause()); 79 | } 80 | }); 81 | SYNCHRONIZER.clear(); 82 | } 83 | 84 | @After 85 | public void close(TestContext context) { 86 | vertx.close(context.asyncAssertSuccess()); 87 | } 88 | 89 | @Test 90 | public void testAsyncReferenceHandler() throws InterruptedException { 91 | BlockingService.reset(); 92 | HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080)); 93 | client.get("/helloasync").handler(response -> response.bodyHandler(b -> SYNCHRONIZER.add(b.toString()))).end(); 94 | Assert.assertNull(SYNCHRONIZER.poll()); 95 | BlockingService.complete(SayHelloService.MESSAGE); 96 | assertEquals(SayHelloService.MESSAGE, poll()); 97 | } 98 | 99 | private Object poll() throws InterruptedException { 100 | return SYNCHRONIZER.poll(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /web/src/test/java/org/jboss/weld/vertx/web/async/AsyncRouteObserversTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx.web.async; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import java.util.concurrent.BlockingQueue; 22 | import java.util.concurrent.LinkedBlockingQueue; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | import org.jboss.weld.environment.se.Weld; 26 | import org.jboss.weld.vertx.AsyncReference; 27 | import org.jboss.weld.vertx.Timeouts; 28 | import org.jboss.weld.vertx.WeldVerticle; 29 | import org.jboss.weld.vertx.web.SayHelloService; 30 | import org.jboss.weld.vertx.web.WeldWebVerticle; 31 | import org.junit.After; 32 | import org.junit.Assert; 33 | import org.junit.Before; 34 | import org.junit.Rule; 35 | import org.junit.Test; 36 | import org.junit.rules.Timeout; 37 | import org.junit.runner.RunWith; 38 | 39 | import io.vertx.core.Vertx; 40 | import io.vertx.core.http.HttpClient; 41 | import io.vertx.core.http.HttpClientOptions; 42 | import io.vertx.ext.unit.Async; 43 | import io.vertx.ext.unit.TestContext; 44 | import io.vertx.ext.unit.junit.VertxUnitRunner; 45 | 46 | /** 47 | * 48 | * @author Martin Kouba 49 | */ 50 | @RunWith(VertxUnitRunner.class) 51 | public class AsyncRouteObserversTest { 52 | 53 | static final BlockingQueue SYNCHRONIZER = new LinkedBlockingQueue<>(); 54 | 55 | private Vertx vertx; 56 | 57 | @Rule 58 | public Timeout globalTimeout = Timeout.millis(Timeouts.GLOBAL_TIMEOUT * 1000); 59 | 60 | @Before 61 | public void init(TestContext context) throws InterruptedException { 62 | vertx = Vertx.vertx(); 63 | Async async = context.async(); 64 | Weld weld = WeldVerticle.createDefaultWeld().disableDiscovery().beanClasses(AsyncRouteObserver.class, BlockingService.class) 65 | .packages(AsyncReference.class); 66 | WeldWebVerticle weldVerticle = new WeldWebVerticle(weld); 67 | vertx.deployVerticle(weldVerticle, deploy -> { 68 | if (deploy.succeeded()) { 69 | // Configure the router after Weld bootstrap finished 70 | vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> { 71 | if (listen.succeeded()) { 72 | async.complete(); 73 | } else { 74 | context.fail(listen.cause()); 75 | } 76 | }); 77 | } else { 78 | context.fail(deploy.cause()); 79 | } 80 | }); 81 | SYNCHRONIZER.clear(); 82 | } 83 | 84 | @After 85 | public void close(TestContext context) { 86 | vertx.close(context.asyncAssertSuccess()); 87 | } 88 | 89 | @Test 90 | public void testHelloAsyncObserver() throws InterruptedException { 91 | BlockingService.reset(); 92 | HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080)); 93 | client.get("/hello-async").handler(response -> response.bodyHandler(b -> SYNCHRONIZER.add(b.toString()))).end(); 94 | Assert.assertNull(SYNCHRONIZER.poll()); 95 | BlockingService.complete(SayHelloService.MESSAGE); 96 | assertEquals(SayHelloService.MESSAGE, poll()); 97 | } 98 | 99 | private Object poll() throws InterruptedException { 100 | return SYNCHRONIZER.poll(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /core/src/main/java/org/jboss/weld/vertx/VertxEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2016, Red Hat, Inc., and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.weld.vertx; 18 | 19 | import io.vertx.core.AsyncResult; 20 | import io.vertx.core.Handler; 21 | import io.vertx.core.MultiMap; 22 | import io.vertx.core.eventbus.DeliveryOptions; 23 | import io.vertx.core.eventbus.Message; 24 | 25 | /** 26 | * Vertx {@link Message} wrapper. 27 | *

      28 | * An observer method must declare an event parameter of the type {@link VertxEvent} with {@link VertxConsumer} qualifier in order to be notified when a message 29 | * is sent via {@link io.vertx.core.eventbus.EventBus}. 30 | *

      31 | * 32 | * @author Martin Kouba 33 | * @see VertxConsumer 34 | */ 35 | public interface VertxEvent { 36 | 37 | /** 38 | * A failure code that is used if an observer method throws exception. 39 | * 40 | * @see Message#fail(int, String) 41 | */ 42 | int OBSERVER_FAILURE_CODE = 0x1B00; 43 | 44 | /** 45 | * 46 | * @return the address the message was sent to 47 | * @see Message#address() 48 | */ 49 | String getAddress(); 50 | 51 | /** 52 | * 53 | * @return the message headers 54 | * @see Message#headers() 55 | */ 56 | MultiMap getHeaders(); 57 | 58 | /** 59 | * 60 | * @return the message body/payload 61 | * @see Message#body() 62 | */ 63 | Object getMessageBody(); 64 | 65 | /** 66 | * 67 | * @return the reply address, or null in case of the message was sent without a reply handler 68 | * @see Message#replyAddress() 69 | */ 70 | String getReplyAddress(); 71 | 72 | /** 73 | * Set the reply to the message. Does not abort the processing of the event - other observer methods will be notified. The first reply set is passed to 74 | * {@link Message#reply(Object)}. 75 | *

      76 | * If the reply address is null (point-to-point messaging without reply handler) the reply is ignored. 77 | *

      78 | *

      79 | * An observer is encouraged to call {@link #fail(int, String)} if it needs to set the reply and this method returns false. 80 | *

      81 | * 82 | * @param reply 83 | * @see Message#reply(Object) 84 | * @return true if the reply was sucessfully set 85 | */ 86 | boolean setReply(Object reply); 87 | 88 | /** 89 | * Aborts the processing of the event - no other observer methods will be called (unless the thrown {@link RecipientFailure} is swallowed). 90 | * 91 | * @param code 92 | * @param message 93 | * @see Message#fail(int, String) 94 | * @throws RecipientFailure 95 | */ 96 | void fail(int code, String message); 97 | 98 | /** 99 | * 100 | * @return true if a reply was previously set, false otherwise 101 | * @see #setReply(Object) 102 | */ 103 | boolean isReplied(); 104 | 105 | /** 106 | * Send/publish messages using the Vertx event bus. 107 | * 108 | * @param address 109 | * @return a message 110 | */ 111 | VertxMessage messageTo(String address); 112 | 113 | /** 114 | * 115 | * @author Martin Kouba 116 | */ 117 | public interface VertxMessage { 118 | 119 | VertxMessage setDeliveryOptions(DeliveryOptions deliveryOptions); 120 | 121 | void send(Object message); 122 | 123 | void send(Object message, Handler>> replyHandler); 124 | 125 | void publish(Object message); 126 | 127 | } 128 | 129 | } 130 | --------------------------------------------------------------------------------