├── .gitattribute ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── action ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── action │ │ ├── AbstractActions.java │ │ ├── Action.java │ │ ├── Actions.java │ │ ├── ConcurrentActions.java │ │ ├── SimpleActions.java │ │ └── VoidAction.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── action │ │ ├── ActionsTestBase.java │ │ ├── ConcurrentActionsTest.java │ │ └── SimpleActionsTest.java │ └── resources │ └── logback.xml ├── bridge-atmosphere2 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── atmosphere2 │ │ ├── AsityAtmosphereServlet.java │ │ ├── AtmosphereServerHttpExchange.java │ │ └── AtmosphereServerWebSocket.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── atmosphere2 │ │ ├── AtmosphereServerHttpExchangeTest.java │ │ └── AtmosphereServerWebSocketTest.java │ └── resources │ └── logback.xml ├── bridge-grizzly2 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── grizzly2 │ │ ├── AsityHttpHandler.java │ │ ├── AsityWebSocketApplication.java │ │ ├── GrizzlyServerHttpExchange.java │ │ └── GrizzlyServerWebSocket.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── grizzly2 │ │ ├── GrizzlyServerHttpExchangeTest.java │ │ └── GrizzlyServerWebSocketTest.java │ └── resources │ └── logback.xml ├── bridge-jwa1 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── jwa1 │ │ ├── AsityServerEndpoint.java │ │ └── JwaServerWebSocket.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── jwa1 │ │ └── JwaServerWebSocketTest.java │ └── resources │ └── logback.xml ├── bridge-netty4 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── netty4 │ │ ├── AsityServerCodec.java │ │ ├── NettyServerHttpExchange.java │ │ └── NettyServerWebSocket.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── netty4 │ │ ├── NettyServerHttpExchangeTest.java │ │ └── NettyServerWebSocketTest.java │ └── resources │ └── logback.xml ├── bridge-play2 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── play2 │ │ ├── AsityHttpAction.java │ │ ├── AsityWebSocket.java │ │ ├── AsityWebSocketActor.java │ │ ├── PlayServerHttpExchange.java │ │ └── PlayServerWebSocket.java │ └── test │ └── resources │ └── logback.xml ├── bridge-servlet3 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── servlet3 │ │ ├── AsityServlet.java │ │ └── ServletServerHttpExchange.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── servlet3 │ │ └── ServletServerHttpExchangeTest.java │ └── resources │ └── logback.xml ├── bridge-spring-webflux5 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── spring │ │ └── webflux5 │ │ ├── AsityHandlerFunction.java │ │ ├── AsityWebSocketHandler.java │ │ ├── SpringWebFluxServerHttpExchange.java │ │ └── SpringWebFluxServerWebSocket.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── spring │ │ └── webflux5 │ │ ├── SpringWebFluxServerHttpExchangeTest.java │ │ ├── SpringWebFluxServerWebSocketTest.java │ │ └── TestApplication.java │ └── resources │ └── logback.xml ├── bridge-spring-webmvc4 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── spring │ │ └── webmvc4 │ │ ├── AsityController.java │ │ ├── AsityWebSocketHandler.java │ │ └── SpringWebMvcServerWebSocket.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── spring │ │ └── webmvc4 │ │ ├── SpringWebMvcServerHttpExchangeTest.java │ │ ├── SpringWebMvcServerWebSocketTest.java │ │ └── TestApplication.java │ └── resources │ └── logback.xml ├── bridge-vertx2 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── vertx2 │ │ ├── AsityRequestHandler.java │ │ ├── AsityWebSocketHandler.java │ │ ├── VertxServerHttpExchange.java │ │ └── VertxServerWebSocket.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── vertx2 │ │ ├── VertxServerHttpExchangeTest.java │ │ └── VertxServerWebSocketTest.java │ └── resources │ └── logback.xml ├── bridge-vertx3 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── vertx3 │ │ ├── AsityRequestHandler.java │ │ ├── AsityWebSocketHandler.java │ │ ├── VertxServerHttpExchange.java │ │ └── VertxServerWebSocket.java │ └── test │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── bridge │ │ └── vertx3 │ │ ├── VertxServerHttpExchangeTest.java │ │ └── VertxServerWebSocketTest.java │ └── resources │ └── logback.xml ├── example-atmosphere2 ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── atmosphere2 │ │ └── EchoServerInitializer.java │ └── resources │ └── logback.xml ├── example-grizzly2 ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── grizzly2 │ │ └── EchoServer.java │ └── resources │ └── logback.xml ├── example-jwa1 ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── jwa1 │ │ └── EchoServerInitializer.java │ └── resources │ └── logback.xml ├── example-netty4 ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── netty4 │ │ └── EchoServer.java │ └── resources │ └── logback.xml ├── example-play2 ├── README.md ├── app │ └── io │ │ └── cettia │ │ └── asity │ │ ├── bridge │ │ └── play2 │ │ │ ├── HttpController.java │ │ │ └── WebSocketController.java │ │ └── example │ │ └── play2 │ │ └── EchoController.java ├── build.sbt ├── conf │ ├── application.conf │ ├── logback.xml │ └── routes ├── pom.xml ├── project │ ├── build.properties │ └── plugins.sbt └── test │ └── io │ └── cettia │ └── asity │ └── bridge │ └── play2 │ ├── PlayServerHttpExchangeTest.java │ └── PlayServerWebSocketTest.java ├── example-servlet3 ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── servlet3 │ │ └── EchoServerInitializer.java │ └── resources │ └── logback.xml ├── example-spring-webflux5 ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── spring │ │ └── webflux5 │ │ └── EchoServer.java │ └── resources │ └── logback.xml ├── example-spring-webmvc4 ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── spring │ │ └── webmvc4 │ │ └── EchoServer.java │ └── resources │ └── logback.xml ├── example-vertx2 ├── README.md ├── pom.xml └── src │ └── main │ ├── assembly │ └── mod.xml │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── vertx2 │ │ └── EchoServerVerticle.java │ └── resources │ ├── logback.xml │ └── mod.json ├── example-vertx3 ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── vertx3 │ │ └── EchoServerVerticle.java │ └── resources │ └── logback.xml ├── example ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── cettia │ │ └── asity │ │ └── example │ │ └── echo │ │ ├── HttpEchoClient.java │ │ ├── HttpEchoServer.java │ │ ├── WebSocketEchoClient.java │ │ └── WebSocketEchoServer.java │ └── resources │ └── logback.xml ├── http ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── cettia │ └── asity │ └── http │ ├── AbstractServerHttpExchange.java │ ├── HttpMethod.java │ ├── HttpStatus.java │ └── ServerHttpExchange.java ├── intellij-cettia-style.xml ├── pom.xml ├── src └── main │ └── javadoc │ └── overview.html ├── test ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── cettia │ └── asity │ └── test │ ├── ServerHttpExchangeTestBase.java │ └── ServerWebSocketTestBase.java └── websocket ├── pom.xml └── src └── main └── java └── io └── cettia └── asity └── websocket ├── AbstractServerWebSocket.java └── ServerWebSocket.java /.gitattribute: -------------------------------------------------------------------------------- 1 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven - https://github.com/github/gitignore/blob/b8da0e3a89f5d75acdb9d5fed06700bfff3695f9/Maven.gitignore 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | dependency-reduced-pom.xml 9 | buildNumber.properties -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | language: java 16 | jdk: 17 | - openjdk8 18 | - openjdk9 19 | - openjdk10 20 | 21 | install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -Dgpg.skip 22 | script: mvn test -B -Dgpg.skip 23 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | GitHub Issue Tracker is used to track bug reports, feature requests and pull requests only. If your issue is a question or problem, please post it to [Google Groups](http://groups.google.com/group/cettia). 2 | 3 | Before opening a new issue, please check if the same issue already has been reported. For a complicated bug, please make sure to specify the followings. The less informations you provided, the lower priority it will get. 4 | 5 | * Asity version 6 | * What you were trying to 7 | * Expected output 8 | * Bare minimum steps, code or working demo to reproduce 9 | * Result with the latest version 10 | * Result with an older version 11 | * Anything where you think it's relevant 12 | 13 | If you want to work on a complicated and time consuming work like introducing new feature as pull request, we need to discuss it first enough for you to avoid wasting too much time and to bring out the result we all want. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Asity 2 | 3 | Asity is an HTTP/WebSocket abstraction layer for various web frameworks on the JVM. Asity provides a tool-kit for writing a web fragment, a function that handles HTTP request-response exchange and WebSocket, and allows to create web applications by combining web fragments. 4 | 5 | For example, with Asity you can write a web fragment that sends back incoming WebSocket messages as follows 6 | 7 | ```java 8 | Action action = ws -> ws.ontext(ws::send).onbinary(ws::send); 9 | ``` 10 | 11 | And plug it into Java API for WebSocket, Spring WebFlux, Spring MVC, Vert.x, Netty, Play Framework, Grizzly, and so on. Visit the Asity website for the full documentation. 12 | 13 | ## Supported Frameworks 14 | 15 | Asity supports the following frameworks. Each link points to a demo project which shows how to plug the example echo web fragment to each framework. 16 | 17 | - [Atmosphere 2](https://github.com/cettia/asity/tree/master/example-atmosphere2) 18 | - [Grizzly 2](https://github.com/cettia/asity/tree/master/example-grizzly2) 19 | - [Java API for WebSocket 1](https://github.com/cettia/asity/tree/master/example-jwa1) 20 | - [Netty 4](https://github.com/cettia/asity/tree/master/example-netty4) 21 | - [Play framework 2](https://github.com/cettia/asity/tree/master/example-play2) 22 | - [Servlet 3](https://github.com/cettia/asity/tree/master/example-servlet3) 23 | - [Spring WebFlux 5](https://github.com/cettia/asity/tree/master/example-spring-webflux5) 24 | - [Spring MVC 4](https://github.com/cettia/asity/tree/master/example-spring-webmvc4) 25 | - [Vert.x 2](https://github.com/cettia/asity/tree/master/example-vertx2) 26 | - [Vert.x 3](https://github.com/cettia/asity/tree/master/example-vertx3) 27 | 28 | ## Links 29 | 30 | Here are some useful links to learn more about Asity. If you are interested and would like to be more involved, feel free to join the mailing list and share your feedback. 31 | 32 | - [Website](https://asity.cettia.io/) 33 | - [Showcase](https://asity.cettia.io/#showcase) 34 | - [Mailing list](http://groups.google.com/group/cettia) 35 | - [Twitter](https://twitter.com/flowersits) 36 | 37 | Asity is an open source project licensed under Apache License 2.0 and driven by the community, for the community. 38 | -------------------------------------------------------------------------------- /action/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-action 25 | Asity/Action 26 | 27 | 28 | org.slf4j 29 | slf4j-api 30 | 31 | 32 | ch.qos.logback 33 | logback-core 34 | 35 | 36 | ch.qos.logback 37 | logback-classic 38 | 39 | 40 | junit 41 | junit 42 | 43 | 44 | org.hamcrest 45 | hamcrest-all 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /action/src/main/java/io/cettia/asity/action/AbstractActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.action; 17 | 18 | import java.util.Collections; 19 | import java.util.List; 20 | 21 | /** 22 | * Base implementation of {@link Actions}. 23 | * 24 | * @author Donghwan Kim 25 | */ 26 | public abstract class AbstractActions implements Actions { 27 | 28 | protected final List> actionList; 29 | private final Actions.Options options; 30 | 31 | protected AbstractActions() { 32 | this(new Actions.Options()); 33 | } 34 | 35 | protected AbstractActions(Actions.Options o) { 36 | this.options = new Actions.Options(o); 37 | this.actionList = createList(); 38 | } 39 | 40 | protected abstract List> createList(); 41 | 42 | @Override 43 | public Actions add(Action action) { 44 | if (!disabled()) { 45 | if (options.memory() && fired()) { 46 | fireOne(action, cached()); 47 | } 48 | if (!options.unique() || (options.unique() && !actionList.contains(action))) { 49 | actionList.add(action); 50 | } 51 | } 52 | return this; 53 | } 54 | 55 | protected abstract T cached(); 56 | 57 | @Override 58 | public Actions disable() { 59 | if (setDisabled()) { 60 | actionList.clear(); 61 | } 62 | return this; 63 | } 64 | 65 | protected abstract boolean setDisabled(); 66 | 67 | @Override 68 | public Actions empty() { 69 | actionList.clear(); 70 | return this; 71 | } 72 | 73 | @Override 74 | public Actions fire() { 75 | return fire(null); 76 | } 77 | 78 | @Override 79 | public Actions fire(T data) { 80 | if (!disabled() && !(options.once() && fired())) { 81 | setFired(); 82 | if (options.memory()) { 83 | setCache(data); 84 | } 85 | for (int i = 0; i < actionList.size(); i++) { 86 | fireOne(actionList.get(i), data); 87 | } 88 | } 89 | return this; 90 | } 91 | 92 | protected abstract void setFired(); 93 | 94 | protected abstract void setCache(T data); 95 | 96 | @Override 97 | public boolean has() { 98 | return !actionList.isEmpty(); 99 | } 100 | 101 | @Override 102 | public boolean has(Action action) { 103 | return actionList.contains(action); 104 | } 105 | 106 | @Override 107 | public Actions remove(Action action) { 108 | actionList.removeAll(Collections.singleton(action)); 109 | return this; 110 | } 111 | 112 | protected void fireOne(Action action, T data) { 113 | action.on(data); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /action/src/main/java/io/cettia/asity/action/Action.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.action; 17 | 18 | /** 19 | * An action. 20 | * 21 | * @author Donghwan Kim 22 | */ 23 | @FunctionalInterface 24 | public interface Action { 25 | 26 | /** 27 | * Some action is taken. 28 | */ 29 | void on(T object); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /action/src/main/java/io/cettia/asity/action/ConcurrentActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.action; 17 | 18 | import java.util.List; 19 | import java.util.concurrent.CopyOnWriteArrayList; 20 | import java.util.concurrent.atomic.AtomicBoolean; 21 | import java.util.concurrent.atomic.AtomicReference; 22 | 23 | /** 24 | * Thread-safe implementation of {@link Actions}. 25 | * 26 | * @author Donghwan Kim 27 | */ 28 | public class ConcurrentActions extends AbstractActions { 29 | 30 | private final AtomicBoolean disabled = new AtomicBoolean(); 31 | private final AtomicBoolean fired = new AtomicBoolean(); 32 | private final AtomicReference cached = new AtomicReference<>(); 33 | 34 | public ConcurrentActions() { 35 | super(); 36 | } 37 | 38 | public ConcurrentActions(Actions.Options o) { 39 | super(o); 40 | } 41 | 42 | @Override 43 | protected List> createList() { 44 | return new CopyOnWriteArrayList<>(); 45 | } 46 | 47 | @Override 48 | protected void setCache(T data) { 49 | this.cached.set(data); 50 | } 51 | 52 | @Override 53 | protected T cached() { 54 | return cached.get(); 55 | } 56 | 57 | @Override 58 | protected boolean setDisabled() { 59 | return disabled.compareAndSet(false, true); 60 | } 61 | 62 | @Override 63 | public boolean disabled() { 64 | return disabled.get(); 65 | } 66 | 67 | @Override 68 | protected void setFired() { 69 | fired.set(true); 70 | } 71 | 72 | @Override 73 | public boolean fired() { 74 | return fired.get(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /action/src/main/java/io/cettia/asity/action/SimpleActions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.action; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * Simple implementation of {@link Actions}. 23 | * 24 | * @author Donghwan Kim 25 | */ 26 | public class SimpleActions extends AbstractActions { 27 | 28 | private boolean disabled; 29 | private boolean fired; 30 | private T cached; 31 | 32 | public SimpleActions() { 33 | super(); 34 | } 35 | 36 | public SimpleActions(Actions.Options o) { 37 | super(o); 38 | } 39 | 40 | @Override 41 | protected List> createList() { 42 | return new ArrayList<>(); 43 | } 44 | 45 | @Override 46 | protected void setCache(T data) { 47 | this.cached = data; 48 | } 49 | 50 | @Override 51 | protected T cached() { 52 | return cached; 53 | } 54 | 55 | @Override 56 | protected boolean setDisabled() { 57 | boolean answer = !disabled; 58 | if (answer) { 59 | disabled = true; 60 | } 61 | return answer; 62 | } 63 | 64 | @Override 65 | public boolean disabled() { 66 | return disabled; 67 | } 68 | 69 | @Override 70 | protected void setFired() { 71 | fired = true; 72 | } 73 | 74 | @Override 75 | public boolean fired() { 76 | return fired; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /action/src/main/java/io/cettia/asity/action/VoidAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.action; 17 | 18 | /** 19 | * Action with no args. 20 | * 21 | * @deprecated Use lambda expressions. 22 | * @author Donghwan Kim 23 | */ 24 | @Deprecated 25 | public abstract class VoidAction implements Action { 26 | 27 | @Override 28 | public void on(Void object) { 29 | on(); 30 | } 31 | 32 | public abstract void on(); 33 | 34 | } -------------------------------------------------------------------------------- /action/src/test/java/io/cettia/asity/action/ConcurrentActionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.action; 17 | 18 | import io.cettia.asity.action.Actions.Options; 19 | 20 | /** 21 | * @author Donghwan Kim 22 | */ 23 | public class ConcurrentActionsTest extends ActionsTestBase { 24 | 25 | @Override 26 | protected Actions createActions() { 27 | return new ConcurrentActions<>(); 28 | } 29 | 30 | @Override 31 | protected Actions createActions(Options options) { 32 | return new ConcurrentActions<>(options); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /action/src/test/java/io/cettia/asity/action/SimpleActionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.action; 17 | 18 | import io.cettia.asity.action.Actions.Options; 19 | 20 | /** 21 | * @author Donghwan Kim 22 | */ 23 | public class SimpleActionsTest extends ActionsTestBase { 24 | 25 | @Override 26 | protected Actions createActions() { 27 | return new SimpleActions<>(); 28 | } 29 | 30 | @Override 31 | protected Actions createActions(Options options) { 32 | return new SimpleActions<>(options); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /action/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bridge-atmosphere2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-atmosphere2 25 | Asity/Bridge/Atmosphere 2 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-websocket 38 | 39 | 40 | io.cettia.asity 41 | asity-test 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | 47 | 48 | ch.qos.logback 49 | logback-core 50 | 51 | 52 | ch.qos.logback 53 | logback-classic 54 | 55 | 56 | javax.servlet 57 | javax.servlet-api 58 | ${servlet3.version} 59 | provided 60 | 61 | 62 | org.atmosphere 63 | atmosphere-runtime 64 | ${atmosphere2.version} 65 | 66 | 67 | org.eclipse.jetty 68 | jetty-client 69 | 70 | 71 | org.eclipse.jetty.websocket 72 | javax-websocket-server-impl 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /bridge-atmosphere2/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bridge-grizzly2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-grizzly2 25 | Asity/Bridge/Grizzly 2 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-websocket 38 | 39 | 40 | io.cettia.asity 41 | asity-test 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | 47 | 48 | ch.qos.logback 49 | logback-core 50 | 51 | 52 | ch.qos.logback 53 | logback-classic 54 | 55 | 56 | org.glassfish.grizzly 57 | grizzly-http-server 58 | ${grizzly2.version} 59 | 60 | 61 | org.glassfish.grizzly 62 | grizzly-websockets 63 | ${grizzly2.version} 64 | 65 | 66 | org.glassfish.grizzly 67 | grizzly-http-servlet 68 | ${grizzly2.version} 69 | 70 | 71 | javax.servlet 72 | javax.servlet-api 73 | ${servlet3.version} 74 | provided 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /bridge-grizzly2/src/main/java/io/cettia/asity/bridge/grizzly2/AsityHttpHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.grizzly2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.http.ServerHttpExchange; 22 | import org.glassfish.grizzly.http.server.HttpHandler; 23 | import org.glassfish.grizzly.http.server.Request; 24 | import org.glassfish.grizzly.http.server.Response; 25 | 26 | /** 27 | * HttpHandler to process {@link Request} and {@link Response} into 28 | * {@link GrizzlyServerHttpExchange}. 29 | *

30 | *

31 | *

32 |  * ServerConfiguration config = httpServer.getServerConfiguration();
33 |  * config.addHttpHandler(new AsityHttpHandler().onhttp(http -> {}), "/cettia");
34 |  * 
35 | * 36 | * @author Donghwan Kim 37 | */ 38 | public class AsityHttpHandler extends HttpHandler { 39 | 40 | private Actions httpActions = new ConcurrentActions<>(); 41 | 42 | @Override 43 | public void service(Request request, Response response) throws Exception { 44 | httpActions.fire(new GrizzlyServerHttpExchange(request, response)); 45 | } 46 | 47 | /** 48 | * Registers an action to be called when {@link ServerHttpExchange} is 49 | * available. 50 | */ 51 | public AsityHttpHandler onhttp(Action action) { 52 | httpActions.add(action); 53 | return this; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /bridge-grizzly2/src/main/java/io/cettia/asity/bridge/grizzly2/AsityWebSocketApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.grizzly2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | import org.glassfish.grizzly.websockets.DataFrame; 23 | import org.glassfish.grizzly.websockets.DefaultWebSocket; 24 | import org.glassfish.grizzly.websockets.WebSocket; 25 | import org.glassfish.grizzly.websockets.WebSocketApplication; 26 | 27 | import java.util.Map; 28 | import java.util.concurrent.ConcurrentHashMap; 29 | 30 | /** 31 | * WebSocketApplication to process {@link WebSocket} into 32 | * {@link GrizzlyServerWebSocket}. 33 | *

34 | *

35 | *

36 |  * NetworkListener listener = httpServer.getListener("grizzly");
37 |  * listener.registerAddOn(new WebSocketAddOn());
38 |  * WebSocketEngine.getEngine().register("", "/cettia", new AsityWebSocketApplication()
39 |  * .onwebsocket(ws -> {}));
40 |  * 
41 | * 42 | * @author Donghwan Kim 43 | */ 44 | public class AsityWebSocketApplication extends WebSocketApplication { 45 | 46 | private Actions wsActions = new ConcurrentActions<>(); 47 | private Map sockets = new ConcurrentHashMap<>(); 48 | 49 | @Override 50 | public void onConnect(WebSocket socket) { 51 | super.onConnect(socket); 52 | GrizzlyServerWebSocket ws = new GrizzlyServerWebSocket((DefaultWebSocket) socket); 53 | sockets.put(socket, ws); 54 | wsActions.fire(ws); 55 | } 56 | 57 | 58 | @Override 59 | public void onClose(WebSocket socket, DataFrame frame) { 60 | super.onClose(socket, frame); 61 | sockets.remove(socket); 62 | } 63 | 64 | @Override 65 | protected boolean onError(WebSocket webSocket, Throwable t) { 66 | boolean ret = super.onError(webSocket, t); 67 | sockets.get(webSocket).onError(t); 68 | return ret; 69 | } 70 | 71 | /** 72 | * Registers an action to be called when {@link ServerWebSocket} is 73 | * available. 74 | */ 75 | public AsityWebSocketApplication onwebsocket(Action action) { 76 | wsActions.add(action); 77 | return this; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /bridge-grizzly2/src/test/java/io/cettia/asity/bridge/grizzly2/GrizzlyServerHttpExchangeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.grizzly2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.ServerHttpExchange; 20 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 21 | import org.glassfish.grizzly.http.server.HttpServer; 22 | import org.glassfish.grizzly.http.server.Request; 23 | import org.glassfish.grizzly.http.server.Response; 24 | import org.glassfish.grizzly.http.server.ServerConfiguration; 25 | import org.junit.Test; 26 | 27 | /** 28 | * @author Donghwan Kim 29 | */ 30 | public class GrizzlyServerHttpExchangeTest extends ServerHttpExchangeTestBase { 31 | 32 | private HttpServer server; 33 | 34 | @Override 35 | protected void startServer(int port, Action requestAction) throws Exception { 36 | server = HttpServer.createSimpleServer(null, port); 37 | ServerConfiguration config = server.getServerConfiguration(); 38 | config.addHttpHandler(new AsityHttpHandler().onhttp(requestAction), TEST_PATH); 39 | server.start(); 40 | } 41 | 42 | @Override 43 | protected void stopServer() throws Exception { 44 | server.shutdownNow(); 45 | } 46 | 47 | @Test 48 | public void unwrap() throws Throwable { 49 | requestAction(http -> { 50 | threadAssertTrue(http.unwrap(Request.class) instanceof Request); 51 | threadAssertTrue(http.unwrap(Response.class) instanceof Response); 52 | resume(); 53 | }); 54 | client.newRequest(uri()).send(new org.eclipse.jetty.client.api.Response.Listener.Adapter()); 55 | await(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /bridge-grizzly2/src/test/java/io/cettia/asity/bridge/grizzly2/GrizzlyServerWebSocketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.grizzly2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import io.cettia.asity.websocket.ServerWebSocket; 21 | import org.eclipse.jetty.websocket.api.WebSocketAdapter; 22 | import org.glassfish.grizzly.http.server.HttpServer; 23 | import org.glassfish.grizzly.http.server.NetworkListener; 24 | import org.glassfish.grizzly.websockets.WebSocket; 25 | import org.glassfish.grizzly.websockets.WebSocketAddOn; 26 | import org.glassfish.grizzly.websockets.WebSocketEngine; 27 | import org.junit.Test; 28 | 29 | import java.net.URI; 30 | 31 | /** 32 | * @author Donghwan Kim 33 | */ 34 | public class GrizzlyServerWebSocketTest extends ServerWebSocketTestBase { 35 | 36 | private HttpServer server; 37 | 38 | @Override 39 | protected void startServer(int port, Action websocketAction) throws Exception { 40 | server = HttpServer.createSimpleServer(null, port); 41 | NetworkListener listener = server.getListener("grizzly"); 42 | listener.registerAddOn(new WebSocketAddOn()); 43 | WebSocketEngine.getEngine().register("", TEST_PATH, new AsityWebSocketApplication() 44 | .onwebsocket(websocketAction)); 45 | server.start(); 46 | } 47 | 48 | @Override 49 | protected void stopServer() throws Exception { 50 | server.shutdownNow(); 51 | } 52 | 53 | @Test 54 | public void unwrap() throws Throwable { 55 | websocketAction(ws -> { 56 | threadAssertTrue(ws.unwrap(WebSocket.class) instanceof WebSocket); 57 | resume(); 58 | }); 59 | client.connect(new WebSocketAdapter(), URI.create(uri())); 60 | await(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /bridge-grizzly2/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bridge-jwa1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-jwa1 25 | Asity/Bridge/Java WebSocket API 1 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-websocket 34 | 35 | 36 | io.cettia.asity 37 | asity-test 38 | 39 | 40 | org.slf4j 41 | slf4j-api 42 | 43 | 44 | ch.qos.logback 45 | logback-core 46 | 47 | 48 | ch.qos.logback 49 | logback-classic 50 | 51 | 52 | javax.websocket 53 | javax.websocket-api 54 | ${jwa1.version} 55 | provided 56 | 57 | 58 | org.eclipse.jetty.websocket 59 | javax-websocket-server-impl 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /bridge-jwa1/src/main/java/io/cettia/asity/bridge/jwa1/AsityServerEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.jwa1; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | 23 | import javax.websocket.CloseReason; 24 | import javax.websocket.Endpoint; 25 | import javax.websocket.EndpointConfig; 26 | import javax.websocket.Session; 27 | 28 | /** 29 | * Endpoint to process {@link Endpoint} and {@link Session} into {@link ServerWebSocket}. 30 | *

31 | *

32 | *

33 |  * ServerEndpointConfig config = ServerEndpointConfig.Builder.create(AsityServerEndpoint.class,
34 |  * "/cettia")
35 |  * .configurator(new Configurator() {
36 |  *     {@literal @}Override
37 |  *     protected <T> T getEndpointInstance(Class<T> endpointClass) {
38 |  *         return endpointClass.cast(new AsityServerEndpoint().onwebsocket(ws -> {}));
39 |  *     }
40 |  *
41 |  *     {@literal @}Override
42 |  *     public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
43 |  *       config.getUserProperties().put(HandshakeRequest.class.getName(), request);
44 |  *     }
45 |  * })
46 |  * .build();
47 |  * 
48 | * 49 | * @author Donghwan Kim 50 | */ 51 | public class AsityServerEndpoint extends Endpoint { 52 | 53 | private Actions wsActions = new ConcurrentActions<>(); 54 | private JwaServerWebSocket ws; 55 | 56 | @Override 57 | public void onOpen(Session session, EndpointConfig config) { 58 | ws = new JwaServerWebSocket(session); 59 | wsActions.fire(ws); 60 | } 61 | 62 | @Override 63 | public void onError(Session session, Throwable throwable) { 64 | ws.onError(throwable); 65 | } 66 | 67 | @Override 68 | public void onClose(Session session, CloseReason closeReason) { 69 | ws.onClose(); 70 | } 71 | 72 | /** 73 | * Registers an action to be called when {@link ServerWebSocket} is 74 | * available. 75 | */ 76 | public AsityServerEndpoint onwebsocket(Action action) { 77 | wsActions.add(action); 78 | return this; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /bridge-jwa1/src/test/java/io/cettia/asity/bridge/jwa1/JwaServerWebSocketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.jwa1; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import io.cettia.asity.websocket.ServerWebSocket; 21 | import org.eclipse.jetty.server.Server; 22 | import org.eclipse.jetty.server.ServerConnector; 23 | import org.eclipse.jetty.servlet.ServletContextHandler; 24 | import org.eclipse.jetty.websocket.api.WebSocketAdapter; 25 | import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; 26 | import org.junit.Test; 27 | 28 | import javax.websocket.HandshakeResponse; 29 | import javax.websocket.Session; 30 | import javax.websocket.server.HandshakeRequest; 31 | import javax.websocket.server.ServerContainer; 32 | import javax.websocket.server.ServerEndpointConfig; 33 | import javax.websocket.server.ServerEndpointConfig.Configurator; 34 | import java.net.URI; 35 | 36 | /** 37 | * @author Donghwan Kim 38 | */ 39 | public class JwaServerWebSocketTest extends ServerWebSocketTestBase { 40 | 41 | private Server server; 42 | 43 | @Override 44 | protected void startServer(int port, final Action websocketAction) throws 45 | Exception { 46 | server = new Server(); 47 | ServerConnector connector = new ServerConnector(server); 48 | connector.setPort(port); 49 | server.addConnector(connector); 50 | ServletContextHandler handler = new ServletContextHandler(); 51 | server.setHandler(handler); 52 | ServerContainer container = WebSocketServerContainerInitializer.configureContext(handler); 53 | ServerEndpointConfig config = ServerEndpointConfig.Builder.create(AsityServerEndpoint.class, 54 | TEST_PATH) 55 | .configurator(new Configurator() { 56 | @Override 57 | public T getEndpointInstance(Class endpointClass) { 58 | return endpointClass.cast(new AsityServerEndpoint().onwebsocket(websocketAction)); 59 | } 60 | 61 | @Override 62 | public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { 63 | config.getUserProperties().put(HandshakeRequest.class.getName(), request); 64 | } 65 | }) 66 | .build(); 67 | container.addEndpoint(config); 68 | server.start(); 69 | } 70 | 71 | @Test 72 | public void unwrap() throws Throwable { 73 | websocketAction(ws -> { 74 | threadAssertTrue(ws.unwrap(Session.class) instanceof Session); 75 | resume(); 76 | }); 77 | client.connect(new WebSocketAdapter(), URI.create(uri())); 78 | await(); 79 | } 80 | 81 | @Override 82 | protected void stopServer() throws Exception { 83 | server.stop(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /bridge-jwa1/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bridge-netty4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-netty4 25 | Asity/Bridge/Netty 4 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-websocket 38 | 39 | 40 | io.cettia.asity 41 | asity-test 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | 47 | 48 | ch.qos.logback 49 | logback-core 50 | 51 | 52 | ch.qos.logback 53 | logback-classic 54 | 55 | 56 | io.netty 57 | netty-codec-http 58 | ${netty4.version} 59 | 60 | 61 | io.netty 62 | netty-handler 63 | ${netty4.version} 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /bridge-netty4/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bridge-play2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-play2 25 | Asity/Bridge/Play Framework 2 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-websocket 38 | 39 | 40 | org.slf4j 41 | slf4j-api 42 | 43 | 44 | com.typesafe.play 45 | play-java_2.12 46 | ${play2.version} 47 | provided 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /bridge-play2/src/main/java/io/cettia/asity/bridge/play2/AsityHttpAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.play2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.http.ServerHttpExchange; 22 | import play.mvc.Http; 23 | import play.mvc.Result; 24 | 25 | import java.util.concurrent.CompletionStage; 26 | 27 | /** 28 | * An action to provide {@link PlayServerHttpExchange}. 29 | *

30 | *

31 |  * public CompletionStage<Result> http(Http.Request request) {
32 |  *   AsityHttpAction asityHttpAction = new AsityHttpAction();
33 |  *   asityHttpAction.onhttp(http -> {});
34 |  *
35 |  *   return asityHttpAction.apply(request);
36 |  * }
37 |  * 
38 | * 39 | * @author Donghwan Kim 40 | */ 41 | public class AsityHttpAction { 42 | 43 | private Actions httpActions = new ConcurrentActions<>(); 44 | 45 | /** 46 | * Handles the given request. 47 | */ 48 | public CompletionStage apply(Http.Request request) { 49 | PlayServerHttpExchange http = new PlayServerHttpExchange(request); 50 | httpActions.fire(http); 51 | return http.getResultFuture(); 52 | } 53 | 54 | /** 55 | * Registers an action to be called when {@link ServerHttpExchange} is available. 56 | */ 57 | public AsityHttpAction onhttp(Action action) { 58 | httpActions.add(action); 59 | return this; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /bridge-play2/src/main/java/io/cettia/asity/bridge/play2/AsityWebSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.play2; 17 | 18 | import akka.actor.ActorSystem; 19 | import akka.actor.Props; 20 | import akka.stream.Materializer; 21 | import akka.stream.OverflowStrategy; 22 | import akka.stream.javadsl.Flow; 23 | import io.cettia.asity.action.Action; 24 | import io.cettia.asity.action.Actions; 25 | import io.cettia.asity.action.ConcurrentActions; 26 | import io.cettia.asity.websocket.ServerWebSocket; 27 | import play.http.websocket.Message; 28 | import play.libs.F; 29 | import play.libs.streams.ActorFlow; 30 | import play.mvc.Http; 31 | import play.mvc.Result; 32 | import play.mvc.WebSocket; 33 | 34 | import java.util.concurrent.CompletableFuture; 35 | import java.util.concurrent.CompletionStage; 36 | 37 | /** 38 | * A {@link WebSocket} handler to provide Asity's {@link ServerWebSocket}. You should inject 39 | * {@link ActorSystem} and {@link Materializer} to a controller and pass them to 40 | * {@link AsityWebSocket#AsityWebSocket(ActorSystem actorSystem, Materializer materializer)}. 41 | *

42 | *

43 |  * public WebSocket websocket() {
44 |  *   AsityWebSocket webSocket = new AsityWebSocket(actorSystem, materializer);
45 |  *   webSocket.onwebsocket(ws -> {});
46 |  *
47 |  *   return webSocket;
48 |  * }
49 |  * 
50 | * 51 | * @author Donghwan Kim 52 | */ 53 | public class AsityWebSocket extends WebSocket { 54 | 55 | private Actions wsActions = new ConcurrentActions<>(); 56 | private final ActorSystem actorSystem; 57 | private final Materializer materializer; 58 | 59 | public AsityWebSocket(ActorSystem actorSystem, Materializer materializer) { 60 | this.actorSystem = actorSystem; 61 | this.materializer = materializer; 62 | } 63 | 64 | @Override 65 | public CompletionStage>> apply(Http.RequestHeader request) { 66 | PlayServerWebSocket ws = new PlayServerWebSocket(request); 67 | 68 | return CompletableFuture.completedFuture(F.Either.Right( 69 | ActorFlow.actorRef(ref -> Props.create(AsityWebSocketActor.class, ref, wsActions, ws), 256, 70 | OverflowStrategy.fail(), actorSystem, materializer) 71 | )); 72 | } 73 | 74 | /** 75 | * Registers an action to be called when {@link ServerWebSocket} is available. 76 | */ 77 | public AsityWebSocket onwebsocket(Action action) { 78 | wsActions.add(action); 79 | return this; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /bridge-play2/src/main/java/io/cettia/asity/bridge/play2/AsityWebSocketActor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.play2; 17 | 18 | import akka.actor.AbstractActor; 19 | import akka.actor.ActorRef; 20 | import io.cettia.asity.action.Actions; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | import play.http.websocket.Message; 23 | 24 | /** 25 | * An actor to handle a WebSocket connection. 26 | * 27 | * @author Donghwan Kim 28 | */ 29 | public class AsityWebSocketActor extends AbstractActor { 30 | 31 | final ActorRef out; 32 | private final Actions actions; 33 | private final PlayServerWebSocket ws; 34 | 35 | public AsityWebSocketActor(ActorRef out, Actions actions, PlayServerWebSocket ws) { 36 | this.out = out; 37 | this.actions = actions; 38 | this.ws = ws; 39 | } 40 | 41 | @Override 42 | public void preStart() { 43 | ws.setActor(this); 44 | actions.fire(ws); 45 | } 46 | 47 | @Override 48 | public Receive createReceive() { 49 | return receiveBuilder() 50 | .match(Message.Text.class, ws::onMessage) 51 | .match(Message.Binary.class, ws::onMessage) 52 | .build(); 53 | } 54 | 55 | @Override 56 | public void postStop() { 57 | ws.onClose(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /bridge-play2/src/main/java/io/cettia/asity/bridge/play2/PlayServerWebSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.play2; 17 | 18 | import akka.actor.PoisonPill; 19 | import akka.util.ByteString; 20 | import io.cettia.asity.websocket.AbstractServerWebSocket; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | import play.api.http.websocket.CloseCodes; 23 | import play.http.websocket.Message; 24 | import play.mvc.Http; 25 | 26 | import java.nio.ByteBuffer; 27 | import java.util.List; 28 | import java.util.Set; 29 | 30 | /** 31 | * {@link ServerWebSocket} for Play framework 2. 32 | * 33 | * @author Donghwan Kim 34 | */ 35 | public class PlayServerWebSocket extends AbstractServerWebSocket { 36 | 37 | private AsityWebSocketActor actor; 38 | private Http.RequestHeader request; 39 | 40 | public PlayServerWebSocket(Http.RequestHeader request) { 41 | this.request = request; 42 | } 43 | 44 | void setActor(AsityWebSocketActor actor) { 45 | this.actor = actor; 46 | } 47 | 48 | @Override 49 | public String uri() { 50 | return request.uri(); 51 | } 52 | 53 | @Override 54 | public Set headerNames() { 55 | return request.getHeaders().toMap().keySet(); 56 | } 57 | 58 | @Override 59 | public List headers(String name) { 60 | return request.getHeaders().getAll(name); 61 | } 62 | 63 | void onMessage(Message.Text message) { 64 | textActions.fire(message.data()); 65 | } 66 | 67 | void onMessage(Message.Binary message) { 68 | binaryActions.fire(message.data().toByteBuffer()); 69 | } 70 | 71 | void onClose() { 72 | closeActions.fire(); 73 | } 74 | 75 | @Override 76 | protected void doSend(ByteBuffer data) { 77 | actor.out.tell(new Message.Binary(ByteString.fromByteBuffer(data)), actor.self()); 78 | } 79 | 80 | @Override 81 | protected void doSend(String data) { 82 | actor.out.tell(new Message.Text(data), actor.self()); 83 | } 84 | 85 | @Override 86 | protected void doClose() { 87 | actor.out.tell(new Message.Close(CloseCodes.Regular()), actor.self()); 88 | actor.self().tell(PoisonPill.getInstance(), actor.self()); 89 | } 90 | 91 | /** 92 | * {@link AsityWebSocketActor} and {@link Http.RequestHeader} are available. 93 | */ 94 | @Override 95 | public T unwrap(Class clazz) { 96 | return AsityWebSocketActor.class.isAssignableFrom(clazz) ? 97 | clazz.cast(actor) : 98 | Http.RequestHeader.class.isAssignableFrom(clazz) ? 99 | clazz.cast(request) : 100 | null; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /bridge-play2/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bridge-servlet3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-servlet3 25 | Asity/Bridge/Servlet 3 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-test 38 | 39 | 40 | org.slf4j 41 | slf4j-api 42 | 43 | 44 | ch.qos.logback 45 | logback-core 46 | 47 | 48 | ch.qos.logback 49 | logback-classic 50 | 51 | 52 | javax.servlet 53 | javax.servlet-api 54 | ${servlet3.version} 55 | provided 56 | 57 | 58 | org.eclipse.jetty 59 | jetty-client 60 | 61 | 62 | org.eclipse.jetty.websocket 63 | javax-websocket-server-impl 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /bridge-servlet3/src/main/java/io/cettia/asity/bridge/servlet3/AsityServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.servlet3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.http.ServerHttpExchange; 22 | 23 | import javax.servlet.http.HttpServlet; 24 | import javax.servlet.http.HttpServletRequest; 25 | import javax.servlet.http.HttpServletResponse; 26 | 27 | /** 28 | * Servlet to process {@link HttpServletRequest} and {@link HttpServletResponse} 29 | * into {@link ServerHttpExchange}. When you configure servlet, you must set 30 | * asyncSupported to true 31 | * . 32 | *

33 | *

34 | *

35 |  * Servlet servlet = new AsityServlet().onhttp(http -> {});
36 |  * ServletRegistration.Dynamic reg = context.addServlet(AsityServlet.class.getName(), servlet);
37 |  * reg.setAsyncSupported(true);
38 |  * reg.addMapping("/cettia");
39 |  * 
40 | * 41 | * @author Donghwan Kim 42 | */ 43 | @SuppressWarnings("serial") 44 | public class AsityServlet extends HttpServlet { 45 | 46 | private Actions httpActions = new ConcurrentActions<>(); 47 | 48 | @Override 49 | protected void service(HttpServletRequest req, HttpServletResponse resp) { 50 | httpActions.fire(new ServletServerHttpExchange(req, resp)); 51 | } 52 | 53 | /** 54 | * Registers an action to be called when {@link ServerHttpExchange} is 55 | * available. 56 | */ 57 | public AsityServlet onhttp(Action action) { 58 | httpActions.add(action); 59 | return this; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /bridge-servlet3/src/test/java/io/cettia/asity/bridge/servlet3/ServletServerHttpExchangeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.servlet3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.ServerHttpExchange; 20 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 21 | import org.eclipse.jetty.client.api.Response; 22 | import org.eclipse.jetty.server.Server; 23 | import org.eclipse.jetty.server.ServerConnector; 24 | import org.eclipse.jetty.servlet.ServletContextHandler; 25 | import org.junit.Ignore; 26 | import org.junit.Test; 27 | 28 | import javax.servlet.Servlet; 29 | import javax.servlet.ServletContext; 30 | import javax.servlet.ServletContextEvent; 31 | import javax.servlet.ServletContextListener; 32 | import javax.servlet.ServletRegistration; 33 | import javax.servlet.http.HttpServletRequest; 34 | import javax.servlet.http.HttpServletResponse; 35 | 36 | /** 37 | * @author Donghwan Kim 38 | */ 39 | public class ServletServerHttpExchangeTest extends ServerHttpExchangeTestBase { 40 | 41 | private Server server; 42 | 43 | @Override 44 | protected void startServer(int port, final Action requestAction) throws 45 | Exception { 46 | server = new Server(); 47 | ServerConnector connector = new ServerConnector(server); 48 | connector.setPort(port); 49 | server.addConnector(connector); 50 | ServletContextHandler handler = new ServletContextHandler(); 51 | handler.addEventListener(new ServletContextListener() { 52 | @Override 53 | public void contextInitialized(ServletContextEvent event) { 54 | ServletContext context = event.getServletContext(); 55 | Servlet servlet = new AsityServlet().onhttp(requestAction); 56 | ServletRegistration.Dynamic reg = context.addServlet(AsityServlet.class.getName(), servlet); 57 | reg.setAsyncSupported(true); 58 | reg.addMapping(TEST_PATH); 59 | } 60 | 61 | @Override 62 | public void contextDestroyed(ServletContextEvent sce) { 63 | } 64 | }); 65 | server.setHandler(handler); 66 | server.start(); 67 | } 68 | 69 | @Override 70 | protected void stopServer() throws Exception { 71 | server.stop(); 72 | } 73 | 74 | @Test 75 | public void unwrap() throws Throwable { 76 | requestAction(http -> { 77 | threadAssertTrue(http.unwrap(HttpServletRequest.class) instanceof HttpServletRequest); 78 | threadAssertTrue(http.unwrap(HttpServletResponse.class) instanceof HttpServletResponse); 79 | resume(); 80 | }); 81 | client.newRequest(uri()).send(new Response.Listener.Adapter()); 82 | await(); 83 | } 84 | 85 | @Override 86 | @Test 87 | @Ignore 88 | public void testOnclose() { 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /bridge-servlet3/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bridge-spring-webflux5/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-spring-webflux5 25 | Asity/Bridge/Spring WebFlux 5 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-websocket 38 | 39 | 40 | io.cettia.asity 41 | asity-test 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | 47 | 48 | ch.qos.logback 49 | logback-core 50 | 51 | 52 | ch.qos.logback 53 | logback-classic 54 | 55 | 56 | org.springframework 57 | spring-webflux 58 | ${spring5.version} 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-starter 63 | ${spring-boot2.version} 64 | test 65 | 66 | 67 | org.springframework.boot 68 | spring-boot-starter-webflux 69 | ${spring-boot2.version} 70 | test 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /bridge-spring-webflux5/src/main/java/io/cettia/asity/bridge/spring/webflux5/AsityHandlerFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webflux5; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.http.ServerHttpExchange; 22 | import org.springframework.web.reactive.function.server.HandlerFunction; 23 | import org.springframework.web.reactive.function.server.ServerRequest; 24 | import org.springframework.web.reactive.function.server.ServerResponse; 25 | import reactor.core.publisher.Mono; 26 | 27 | /** 28 | * HandlerFunction to provide {@link SpringWebFluxServerHttpExchange}. 29 | *

30 | *

31 |  *{@literal @}Bean
32 |  * public AsityHandlerFunction handlerFunction() {
33 |  *   return new AsityHandlerFunction().on(http -> {});
34 |  * }
35 |  *
36 |  *{@literal @}Bean
37 |  * public RouterFunction<ServerResponse> httpMapping() {
38 |  *   return RouterFunction<ServerResponse> routes = RouterFunctions.route(
39 |  *     path("/cettia")
40 |  *       // To exclude WebSocket handshake requests
41 |  *       .and(headers(headers -> !"websocket".equalsIgnoreCase(headers.asHttpHeaders().getUpgrade()))),
42 |  *         handlerFunction());
43 |  * }
44 |  * 
45 | * 46 | * @author Donghwan Kim 47 | */ 48 | public class AsityHandlerFunction implements HandlerFunction { 49 | 50 | private Actions httpActions = new ConcurrentActions<>(); 51 | 52 | @Override 53 | public Mono handle(ServerRequest request) { 54 | SpringWebFluxServerHttpExchange http = new SpringWebFluxServerHttpExchange(request); 55 | return http.getServerResponse().doFinally($ -> httpActions.fire(http)); 56 | } 57 | 58 | /** 59 | * Registers an action to be called when {@link ServerHttpExchange} is available. 60 | */ 61 | public AsityHandlerFunction onhttp(Action action) { 62 | httpActions.add(action); 63 | return this; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /bridge-spring-webflux5/src/main/java/io/cettia/asity/bridge/spring/webflux5/AsityWebSocketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webflux5; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | import org.springframework.web.reactive.socket.WebSocketHandler; 23 | import org.springframework.web.reactive.socket.WebSocketSession; 24 | import reactor.core.publisher.Mono; 25 | 26 | /** 27 | * WebSocketHandler to provide {@link SpringWebFluxServerWebSocket}. 28 | *

29 | *

30 |  *{@literal @}Bean
31 |  * public AsityWebSocketHandler webSocketHandler() {
32 |  *   return new AsityWebSocketHandler().onwebsocket(ws -> {});
33 |  * }
34 |  *
35 |  *{@literal @}Bean
36 |  * public HandlerMapping wsMapping() {
37 |  *   AsityWebSocketHandler webSocketHandler = new AsityWebSocketHandler();
38 |  *   Map<String, WebSocketHandler> map = new LinkedHashMap<>();
39 |  *   map.put("/cettia", webSocketHandler());
40 |  *
41 |  *   SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
42 |  *   mapping.setUrlMap(map);
43 |  *   return mapping;
44 |  * }
45 |  * 
46 | * 47 | * @author Donghwan Kim 48 | */ 49 | public class AsityWebSocketHandler implements WebSocketHandler { 50 | 51 | private Actions wsActions = new ConcurrentActions<>(); 52 | 53 | @Override 54 | public Mono handle(WebSocketSession session) { 55 | SpringWebFluxServerWebSocket ws = new SpringWebFluxServerWebSocket(session); 56 | return ws.getMono().doOnSubscribe($ -> wsActions.fire(ws)); 57 | } 58 | 59 | /** 60 | * Registers an action to be called when {@link ServerWebSocket} is available. 61 | */ 62 | public AsityWebSocketHandler onwebsocket(Action action) { 63 | wsActions.add(action); 64 | return this; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /bridge-spring-webflux5/src/test/java/io/cettia/asity/bridge/spring/webflux5/SpringWebFluxServerHttpExchangeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webflux5; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.ServerHttpExchange; 20 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 21 | import org.eclipse.jetty.client.api.Response; 22 | import org.junit.Ignore; 23 | import org.junit.Test; 24 | import org.springframework.boot.SpringApplication; 25 | import org.springframework.boot.builder.SpringApplicationBuilder; 26 | import org.springframework.context.ConfigurableApplicationContext; 27 | import org.springframework.http.server.reactive.ServerHttpResponse; 28 | import org.springframework.web.reactive.function.server.ServerRequest; 29 | 30 | import java.util.LinkedHashMap; 31 | import java.util.Map; 32 | 33 | /** 34 | * @author Donghwan Kim 35 | */ 36 | public class SpringWebFluxServerHttpExchangeTest extends ServerHttpExchangeTestBase { 37 | 38 | private ConfigurableApplicationContext ctx; 39 | 40 | @Override 41 | protected void startServer(int port, Action requestAction) { 42 | Map props = new LinkedHashMap<>(); 43 | props.put("server.port", port); 44 | 45 | ctx = new SpringApplicationBuilder(TestApplication.class).properties(props).run(); 46 | AsityHandlerFunction asityHandlerFunction = ctx.getBean(AsityHandlerFunction.class); 47 | asityHandlerFunction.onhttp(requestAction); 48 | } 49 | 50 | @Override 51 | protected void stopServer() { 52 | SpringApplication.exit(ctx); 53 | } 54 | 55 | @Test 56 | public void unwrap() throws Throwable { 57 | requestAction(http -> { 58 | threadAssertTrue(http.unwrap(ServerRequest.class) instanceof ServerRequest); 59 | threadAssertTrue(http.unwrap(ServerHttpResponse.class) instanceof ServerHttpResponse); 60 | resume(); 61 | }); 62 | client.newRequest(uri()).send(new Response.Listener.Adapter()); 63 | await(); 64 | } 65 | 66 | @Override 67 | @Test 68 | @Ignore 69 | public void testOnclose() { 70 | } 71 | 72 | } 73 | 74 | -------------------------------------------------------------------------------- /bridge-spring-webflux5/src/test/java/io/cettia/asity/bridge/spring/webflux5/SpringWebFluxServerWebSocketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webflux5; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import io.cettia.asity.websocket.ServerWebSocket; 21 | import org.eclipse.jetty.websocket.api.WebSocketAdapter; 22 | import org.junit.Test; 23 | import org.springframework.boot.SpringApplication; 24 | import org.springframework.boot.builder.SpringApplicationBuilder; 25 | import org.springframework.context.ConfigurableApplicationContext; 26 | import org.springframework.web.reactive.socket.WebSocketSession; 27 | 28 | import java.net.URI; 29 | import java.util.LinkedHashMap; 30 | import java.util.Map; 31 | 32 | /** 33 | * @author Donghwan Kim 34 | */ 35 | public class SpringWebFluxServerWebSocketTest extends ServerWebSocketTestBase { 36 | 37 | private ConfigurableApplicationContext ctx; 38 | 39 | @Override 40 | protected void startServer(int port, Action websocketAction) { 41 | Map props = new LinkedHashMap<>(); 42 | props.put("server.port", port); 43 | 44 | ctx = new SpringApplicationBuilder(TestApplication.class).properties(props).run(); 45 | AsityWebSocketHandler asityWebSocketHandler = ctx.getBean(AsityWebSocketHandler.class); 46 | asityWebSocketHandler.onwebsocket(websocketAction); 47 | } 48 | 49 | @Override 50 | protected void stopServer() { 51 | SpringApplication.exit(ctx); 52 | } 53 | 54 | @Test 55 | public void unwrap() throws Throwable { 56 | websocketAction(ws -> { 57 | threadAssertTrue(ws.unwrap(WebSocketSession.class) instanceof WebSocketSession); 58 | resume(); 59 | }); 60 | client.connect(new WebSocketAdapter(), URI.create(uri())); 61 | await(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /bridge-spring-webflux5/src/test/java/io/cettia/asity/bridge/spring/webflux5/TestApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webflux5; 17 | 18 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.context.annotation.Bean; 22 | import org.springframework.web.reactive.HandlerMapping; 23 | import org.springframework.web.reactive.config.EnableWebFlux; 24 | import org.springframework.web.reactive.function.server.RouterFunction; 25 | import org.springframework.web.reactive.function.server.RouterFunctions; 26 | import org.springframework.web.reactive.function.server.ServerResponse; 27 | import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; 28 | import org.springframework.web.reactive.socket.WebSocketHandler; 29 | import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter; 30 | 31 | import java.util.LinkedHashMap; 32 | import java.util.Map; 33 | 34 | import static org.springframework.web.reactive.function.server.RequestPredicates.headers; 35 | import static org.springframework.web.reactive.function.server.RequestPredicates.path; 36 | 37 | /** 38 | * @author Donghwan Kim 39 | */ 40 | @SpringBootApplication 41 | @EnableWebFlux 42 | public class TestApplication { 43 | 44 | @Bean 45 | public AsityHandlerFunction handlerFunction() { 46 | return new AsityHandlerFunction(); 47 | } 48 | 49 | @Bean 50 | public RouterFunction httpMapping() { 51 | return RouterFunctions.route( 52 | path(ServerHttpExchangeTestBase.TEST_PATH) 53 | .and(headers(headers -> !"websocket".equalsIgnoreCase(headers.asHttpHeaders().getUpgrade()))), handlerFunction() 54 | ); 55 | } 56 | 57 | @Bean 58 | public AsityWebSocketHandler webSocketHandler() { 59 | return new AsityWebSocketHandler(); 60 | } 61 | 62 | @Bean 63 | public HandlerMapping wsMapping() { 64 | Map map = new LinkedHashMap<>(); 65 | map.put(ServerWebSocketTestBase.TEST_PATH, webSocketHandler()); 66 | 67 | SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); 68 | mapping.setUrlMap(map); 69 | 70 | return mapping; 71 | } 72 | 73 | @Bean 74 | public WebSocketHandlerAdapter webSocketHandlerAdapter() { 75 | return new WebSocketHandlerAdapter(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /bridge-spring-webflux5/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /bridge-spring-webmvc4/src/main/java/io/cettia/asity/bridge/spring/webmvc4/AsityController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webmvc4; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.bridge.servlet3.ServletServerHttpExchange; 22 | import io.cettia.asity.http.ServerHttpExchange; 23 | import org.springframework.web.servlet.ModelAndView; 24 | import org.springframework.web.servlet.mvc.Controller; 25 | 26 | import javax.servlet.http.HttpServletRequest; 27 | import javax.servlet.http.HttpServletResponse; 28 | 29 | /** 30 | * Controller to provide {@link ServletServerHttpExchange}. 31 | *

32 | *

33 |  *{@literal @}Bean
34 |  * public AsityController asityController() {
35 |  *   return new AsityController().onhttp(http -> {});
36 |  * }
37 |  *
38 |  *{@literal @}Bean
39 |  * public HandlerMapping httpMapping() {
40 |  *   AbstractHandlerMapping mapping = new AbstractHandlerMapping() {
41 |  *  {@literal @}Override
42 |  *   protected Object getHandlerInternal(HttpServletRequest request) {
43 |  *     //Check whether a path equals '/test'
44 |  *     return "/test".equals(request.getRequestURI()) &&
45 |  *       // Delegates WebSocket handshake requests to a webSocketHandler bean
46 |  *       !"websocket".equalsIgnoreCase(request.getHeader("upgrade")) ? asityController() : null;
47 |  *     }
48 |  *   };
49 |  *   mapping.setOrder(Ordered.HIGHEST_PRECEDENCE);
50 |  *   return mapping;
51 |  * }
52 |  * 
53 | * 54 | * @author Donghwan Kim 55 | */ 56 | public class AsityController implements Controller { 57 | 58 | private Actions httpActions = new ConcurrentActions<>(); 59 | 60 | @Override 61 | public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) { 62 | httpActions.fire(new ServletServerHttpExchange(request, response)); 63 | return null; 64 | } 65 | 66 | /** 67 | * Registers an action to be called when {@link ServerHttpExchange} is available. 68 | */ 69 | public AsityController onhttp(Action action) { 70 | httpActions.add(action); 71 | return this; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /bridge-spring-webmvc4/src/test/java/io/cettia/asity/bridge/spring/webmvc4/SpringWebMvcServerHttpExchangeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webmvc4; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.ServerHttpExchange; 20 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 21 | import org.eclipse.jetty.client.api.Response; 22 | import org.junit.Ignore; 23 | import org.junit.Test; 24 | import org.springframework.boot.SpringApplication; 25 | import org.springframework.boot.builder.SpringApplicationBuilder; 26 | import org.springframework.context.ConfigurableApplicationContext; 27 | 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | import java.util.LinkedHashMap; 31 | import java.util.Map; 32 | 33 | /** 34 | * @author Donghwan Kim 35 | */ 36 | public class SpringWebMvcServerHttpExchangeTest extends ServerHttpExchangeTestBase { 37 | 38 | private ConfigurableApplicationContext ctx; 39 | 40 | @Override 41 | protected void startServer(int port, Action requestAction) { 42 | Map props = new LinkedHashMap<>(); 43 | props.put("server.port", port); 44 | 45 | ctx = new SpringApplicationBuilder(TestApplication.class).properties(props).run(); 46 | AsityController controller = ctx.getBean(AsityController.class); 47 | controller.onhttp(requestAction); 48 | } 49 | 50 | @Override 51 | protected void stopServer() { 52 | SpringApplication.exit(ctx); 53 | } 54 | 55 | @Test 56 | public void unwrap() throws Throwable { 57 | requestAction(http -> { 58 | threadAssertTrue(http.unwrap(HttpServletRequest.class) instanceof HttpServletRequest); 59 | threadAssertTrue(http.unwrap(HttpServletResponse.class) instanceof HttpServletResponse); 60 | resume(); 61 | }); 62 | client.newRequest(uri()).send(new Response.Listener.Adapter()); 63 | await(); 64 | } 65 | 66 | @Override 67 | @Test 68 | @Ignore 69 | public void testOnclose() { 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /bridge-spring-webmvc4/src/test/java/io/cettia/asity/bridge/spring/webmvc4/SpringWebMvcServerWebSocketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webmvc4; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import io.cettia.asity.websocket.ServerWebSocket; 21 | import org.eclipse.jetty.websocket.api.WebSocketAdapter; 22 | import org.junit.Test; 23 | import org.springframework.boot.SpringApplication; 24 | import org.springframework.boot.builder.SpringApplicationBuilder; 25 | import org.springframework.context.ConfigurableApplicationContext; 26 | import org.springframework.web.socket.WebSocketSession; 27 | 28 | import java.net.URI; 29 | import java.util.LinkedHashMap; 30 | import java.util.Map; 31 | 32 | /** 33 | * @author Donghwan Kim 34 | */ 35 | public class SpringWebMvcServerWebSocketTest extends ServerWebSocketTestBase { 36 | 37 | private ConfigurableApplicationContext ctx; 38 | 39 | @Override 40 | protected void startServer(int port, Action websocketAction) { 41 | Map props = new LinkedHashMap<>(); 42 | props.put("server.port", port); 43 | 44 | ctx = new SpringApplicationBuilder(TestApplication.class).properties(props).run(); 45 | AsityWebSocketHandler webSocketHandler = ctx.getBean(AsityWebSocketHandler.class); 46 | webSocketHandler.onwebsocket(websocketAction); 47 | } 48 | 49 | @Override 50 | protected void stopServer() { 51 | SpringApplication.exit(ctx); 52 | } 53 | 54 | @Test 55 | public void unwrap() throws Throwable { 56 | websocketAction(ws -> { 57 | threadAssertTrue(ws.unwrap(WebSocketSession.class) instanceof WebSocketSession); 58 | resume(); 59 | }); 60 | client.connect(new WebSocketAdapter(), URI.create(uri())); 61 | await(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /bridge-spring-webmvc4/src/test/java/io/cettia/asity/bridge/spring/webmvc4/TestApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.spring.webmvc4; 17 | 18 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.context.annotation.Bean; 22 | import org.springframework.core.Ordered; 23 | import org.springframework.web.servlet.HandlerMapping; 24 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 25 | import org.springframework.web.servlet.handler.AbstractHandlerMapping; 26 | import org.springframework.web.socket.config.annotation.EnableWebSocket; 27 | import org.springframework.web.socket.config.annotation.WebSocketConfigurer; 28 | import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; 29 | 30 | import javax.servlet.http.HttpServletRequest; 31 | 32 | /** 33 | * @author Donghwan Kim 34 | */ 35 | @SpringBootApplication 36 | @EnableWebMvc 37 | @EnableWebSocket 38 | public class TestApplication implements WebSocketConfigurer { 39 | 40 | @Bean 41 | public AsityController asityController() { 42 | return new AsityController(); 43 | } 44 | 45 | @Bean 46 | public HandlerMapping httpMapping() { 47 | AbstractHandlerMapping mapping = new AbstractHandlerMapping() { 48 | @Override 49 | protected Object getHandlerInternal(HttpServletRequest request) { 50 | return ServerHttpExchangeTestBase.TEST_PATH.equals(request.getRequestURI()) && 51 | // Delegates WebSocket handshake requests to a webSocketHandler bean 52 | !"websocket".equalsIgnoreCase(request.getHeader("upgrade")) ? asityController() : null; 53 | } 54 | }; 55 | mapping.setOrder(Ordered.HIGHEST_PRECEDENCE); 56 | return mapping; 57 | } 58 | 59 | @Bean 60 | public AsityWebSocketHandler webSocketHandler() { 61 | return new AsityWebSocketHandler(); 62 | } 63 | 64 | @Override 65 | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 66 | registry.addHandler(webSocketHandler(), ServerWebSocketTestBase.TEST_PATH); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /bridge-spring-webmvc4/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /bridge-vertx2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-vertx2 25 | Asity/Bridge/Vert.x 2 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-websocket 38 | 39 | 40 | io.cettia.asity 41 | asity-test 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | 47 | 48 | ch.qos.logback 49 | logback-core 50 | 51 | 52 | ch.qos.logback 53 | logback-classic 54 | 55 | 56 | io.vertx 57 | vertx-core 58 | ${vertx2.version} 59 | provided 60 | 61 | 62 | io.vertx 63 | vertx-platform 64 | ${vertx2.version} 65 | provided 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /bridge-vertx2/src/main/java/io/cettia/asity/bridge/vertx2/AsityRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.http.ServerHttpExchange; 22 | import org.vertx.java.core.Handler; 23 | import org.vertx.java.core.http.HttpServerRequest; 24 | 25 | /** 26 | * Handler to process {@link HttpServerRequest} into 27 | * {@link VertxServerHttpExchange}. 28 | *

29 | *

30 | *

31 |  * httpServer.requestHandler(new AsityRequestHandler().onhttp(http -> {}));
32 |  * 
33 | * 34 | * @author Donghwan Kim 35 | */ 36 | public class AsityRequestHandler implements Handler { 37 | 38 | private Actions httpActions = new ConcurrentActions<>(); 39 | 40 | @Override 41 | public void handle(HttpServerRequest request) { 42 | httpActions.fire(new VertxServerHttpExchange(request)); 43 | } 44 | 45 | /** 46 | * Registers an action to be called when {@link ServerHttpExchange} is 47 | * available. 48 | */ 49 | public AsityRequestHandler onhttp(Action action) { 50 | httpActions.add(action); 51 | return this; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bridge-vertx2/src/main/java/io/cettia/asity/bridge/vertx2/AsityWebSocketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | import org.vertx.java.core.Handler; 23 | 24 | /** 25 | * Handler to process {@link org.vertx.java.core.http.ServerWebSocket} into 26 | * {@link VertxServerWebSocket}. 27 | *

28 | *

29 | *

30 |  * httpServer.websocketHandler(new AsityWebSocketHandler().onwebsocket(http -> {}));
31 |  * 
32 | * 33 | * @author Donghwan Kim 34 | */ 35 | public class AsityWebSocketHandler implements Handler { 36 | 37 | private Actions wsActions = new ConcurrentActions<>(); 38 | 39 | @Override 40 | public void handle(org.vertx.java.core.http.ServerWebSocket ws) { 41 | wsActions.fire(new VertxServerWebSocket(ws)); 42 | } 43 | 44 | /** 45 | * Registers an action to be called when {@link ServerWebSocket} is 46 | * available. 47 | */ 48 | public AsityWebSocketHandler onwebsocket(Action action) { 49 | wsActions.add(action); 50 | return this; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /bridge-vertx2/src/main/java/io/cettia/asity/bridge/vertx2/VertxServerWebSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx2; 17 | 18 | import io.cettia.asity.websocket.AbstractServerWebSocket; 19 | import io.cettia.asity.websocket.ServerWebSocket; 20 | import org.vertx.java.core.VoidHandler; 21 | import org.vertx.java.core.buffer.Buffer; 22 | import org.vertx.java.core.http.impl.ws.WebSocketFrameInternal; 23 | 24 | import java.nio.ByteBuffer; 25 | import java.util.List; 26 | import java.util.Set; 27 | 28 | /** 29 | * {@link ServerWebSocket} for Vert.x 2. 30 | * 31 | * @author Donghwan Kim 32 | */ 33 | public class VertxServerWebSocket extends AbstractServerWebSocket { 34 | 35 | private final org.vertx.java.core.http.ServerWebSocket socket; 36 | 37 | public VertxServerWebSocket(org.vertx.java.core.http.ServerWebSocket socket) { 38 | this.socket = socket; 39 | socket.closeHandler(new VoidHandler() { 40 | @Override 41 | protected void handle() { 42 | closeActions.fire(); 43 | } 44 | }) 45 | .exceptionHandler(errorActions::fire) 46 | .frameHandler(f -> { 47 | // Deal with only data frames 48 | WebSocketFrameInternal frame = (WebSocketFrameInternal) f; 49 | switch (frame.type()) { 50 | case TEXT: 51 | textActions.fire(frame.textData()); 52 | break; 53 | case BINARY: 54 | binaryActions.fire(frame.getBinaryData().nioBuffer()); 55 | break; 56 | default: 57 | break; 58 | } 59 | }); 60 | } 61 | 62 | @Override 63 | public String uri() { 64 | return socket.uri(); 65 | } 66 | 67 | @Override 68 | public Set headerNames() { 69 | return socket.headers().names(); 70 | } 71 | 72 | @Override 73 | public List headers(String name) { 74 | return socket.headers().getAll(name); 75 | } 76 | 77 | @Override 78 | protected void doClose() { 79 | socket.close(); 80 | } 81 | 82 | @Override 83 | protected void doSend(String data) { 84 | socket.writeTextFrame(data); 85 | } 86 | 87 | @Override 88 | protected void doSend(ByteBuffer byteBuffer) { 89 | socket.writeBinaryFrame(new Buffer().setBytes(0, byteBuffer)); 90 | } 91 | 92 | /** 93 | * {@link org.vertx.java.core.http.ServerWebSocket} is available. 94 | */ 95 | @Override 96 | public T unwrap(Class clazz) { 97 | return org.vertx.java.core.http.ServerWebSocket.class.isAssignableFrom(clazz) ? 98 | clazz.cast(socket) : 99 | null; 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /bridge-vertx2/src/test/java/io/cettia/asity/bridge/vertx2/VertxServerHttpExchangeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.ServerHttpExchange; 20 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 21 | import org.eclipse.jetty.client.api.Response; 22 | import org.junit.Test; 23 | import org.vertx.java.core.VertxFactory; 24 | import org.vertx.java.core.http.HttpServer; 25 | import org.vertx.java.core.http.HttpServerRequest; 26 | import org.vertx.java.core.http.RouteMatcher; 27 | 28 | import java.util.concurrent.CountDownLatch; 29 | 30 | /** 31 | * @author Donghwan Kim 32 | */ 33 | public class VertxServerHttpExchangeTest extends ServerHttpExchangeTestBase { 34 | 35 | private HttpServer server; 36 | 37 | @Override 38 | protected void startServer(int port, Action requestAction) throws Exception { 39 | server = VertxFactory.newVertx().createHttpServer(); 40 | RouteMatcher matcher = new RouteMatcher(); 41 | matcher.all(TEST_PATH, new AsityRequestHandler().onhttp(requestAction)); 42 | server.requestHandler(matcher); 43 | 44 | CountDownLatch latch = new CountDownLatch(1); 45 | server.listen(port, ar -> latch.countDown()); 46 | latch.await(); 47 | } 48 | 49 | @Override 50 | protected void stopServer() { 51 | server.close(); 52 | } 53 | 54 | @Test 55 | public void unwrap() throws Throwable { 56 | requestAction(http -> { 57 | threadAssertTrue(http.unwrap(HttpServerRequest.class) instanceof HttpServerRequest); 58 | resume(); 59 | }); 60 | client.newRequest(uri()).send(new Response.Listener.Adapter()); 61 | await(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /bridge-vertx2/src/test/java/io/cettia/asity/bridge/vertx2/VertxServerWebSocketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import io.cettia.asity.websocket.ServerWebSocket; 21 | import org.eclipse.jetty.websocket.api.WebSocketAdapter; 22 | import org.junit.Test; 23 | import org.vertx.java.core.VertxFactory; 24 | import org.vertx.java.core.http.HttpServer; 25 | 26 | import java.net.URI; 27 | import java.util.concurrent.CountDownLatch; 28 | 29 | /** 30 | * @author Donghwan Kim 31 | */ 32 | public class VertxServerWebSocketTest extends ServerWebSocketTestBase { 33 | 34 | private HttpServer server; 35 | 36 | @Override 37 | protected void startServer(int port, Action websocketAction) throws Exception{ 38 | server = VertxFactory.newVertx().createHttpServer(); 39 | AsityWebSocketHandler websocketHandler = new AsityWebSocketHandler().onwebsocket(websocketAction); 40 | server.websocketHandler(socket -> { 41 | if (socket.path().equals(TEST_PATH)) { 42 | websocketHandler.handle(socket); 43 | } 44 | }); 45 | 46 | CountDownLatch latch = new CountDownLatch(1); 47 | server.listen(port, ar -> latch.countDown()); 48 | latch.await(); 49 | } 50 | 51 | @Override 52 | protected void stopServer() { 53 | server.close(); 54 | } 55 | 56 | @Test 57 | public void unwrap() throws Throwable { 58 | websocketAction(ws -> { 59 | threadAssertTrue(ws.unwrap(org.vertx.java.core.http.ServerWebSocket.class) instanceof org 60 | .vertx.java.core.http.ServerWebSocket); 61 | resume(); 62 | }); 63 | client.connect(new WebSocketAdapter(), URI.create(uri())); 64 | await(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /bridge-vertx2/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bridge-vertx3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-bridge-vertx3 25 | Asity/Bridge/Vert.x 3 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-websocket 38 | 39 | 40 | io.cettia.asity 41 | asity-test 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | 47 | 48 | ch.qos.logback 49 | logback-core 50 | 51 | 52 | ch.qos.logback 53 | logback-classic 54 | 55 | 56 | io.vertx 57 | vertx-core 58 | ${vertx3.version} 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /bridge-vertx3/src/main/java/io/cettia/asity/bridge/vertx3/AsityRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.http.ServerHttpExchange; 22 | import io.vertx.core.Handler; 23 | import io.vertx.core.http.HttpServerRequest; 24 | 25 | /** 26 | * Handler<HttpServerRequest> to provide {@link VertxServerHttpExchange}. 27 | *

28 | *

29 |  * AsityRequestHandler requestHandler = new AsityRequestHandler().onhttp(http -> {});
30 |  * httpServer.requestHandler(request -> {
31 |  *   if (request.path().equals("/cettia")) {
32 |  *     requestHandler.handle(request);
33 |  *   }
34 |  * });
35 |  * 
36 | * Or 37 | *

38 | *

39 |  * AsityRequestHandler requestHandler = new AsityRequestHandler().onhttp(http -> {});
40 |  * Router router = Router.router(vertx);
41 |  * router.route("/cettia").handler(rc -> requestHandler.handle(rc.request()));
42 |  * 
43 | * 44 | * @author Donghwan Kim 45 | */ 46 | public class AsityRequestHandler implements Handler { 47 | 48 | private Actions httpActions = new ConcurrentActions<>(); 49 | 50 | @Override 51 | public void handle(HttpServerRequest request) { 52 | httpActions.fire(new VertxServerHttpExchange(request)); 53 | } 54 | 55 | /** 56 | * Registers an action to be called when {@link ServerHttpExchange} is available. 57 | */ 58 | public AsityRequestHandler onhttp(Action action) { 59 | httpActions.add(action); 60 | return this; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /bridge-vertx3/src/main/java/io/cettia/asity/bridge/vertx3/AsityWebSocketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.action.Actions; 20 | import io.cettia.asity.action.ConcurrentActions; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | import io.vertx.core.Handler; 23 | 24 | /** 25 | * Handler<io.vertx.core.http.ServerWebSocket> to provide {@link VertxServerWebSocket}. 26 | *

27 | *

28 |  * AsityWebSocketHandler websocketHandler = new AsityWebSocketHandler().onwebsocket(ws -> {});
29 |  * httpServer.websocketHandler(socket -> {
30 |  *   if (socket.path().equals("/cettia")) {
31 |  *     websocketHandler.handle(socket);
32 |  *   }
33 |  * });
34 |  * 
35 | * 36 | * @author Donghwan Kim 37 | */ 38 | public class AsityWebSocketHandler implements Handler { 39 | 40 | private Actions wsActions = new ConcurrentActions<>(); 41 | 42 | @Override 43 | public void handle(io.vertx.core.http.ServerWebSocket ws) { 44 | wsActions.fire(new VertxServerWebSocket(ws)); 45 | } 46 | 47 | /** 48 | * Registers an action to be called when {@link ServerWebSocket} is available. 49 | */ 50 | public AsityWebSocketHandler onwebsocket(Action action) { 51 | wsActions.add(action); 52 | return this; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /bridge-vertx3/src/main/java/io/cettia/asity/bridge/vertx3/VertxServerHttpExchange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.AbstractServerHttpExchange; 20 | import io.cettia.asity.http.HttpMethod; 21 | import io.cettia.asity.http.HttpStatus; 22 | import io.cettia.asity.http.ServerHttpExchange; 23 | import io.vertx.core.buffer.Buffer; 24 | import io.vertx.core.http.HttpServerRequest; 25 | import io.vertx.core.http.HttpServerResponse; 26 | 27 | import java.nio.ByteBuffer; 28 | import java.util.List; 29 | import java.util.Set; 30 | 31 | /** 32 | * {@link ServerHttpExchange} for Vert.x 3. 33 | * 34 | * @author Donghwan Kim 35 | */ 36 | public class VertxServerHttpExchange extends AbstractServerHttpExchange { 37 | 38 | private final HttpServerRequest request; 39 | private final HttpServerResponse response; 40 | 41 | public VertxServerHttpExchange(HttpServerRequest request) { 42 | this.request = request; 43 | this.response = request.response(); 44 | request.exceptionHandler(errorActions::fire); 45 | response.exceptionHandler(errorActions::fire).closeHandler(closeActions::fire).setChunked(true); 46 | } 47 | 48 | @Override 49 | public String uri() { 50 | return request.uri(); 51 | } 52 | 53 | @Override 54 | public HttpMethod method() { 55 | return HttpMethod.valueOf(request.rawMethod()); 56 | } 57 | 58 | @Override 59 | public Set headerNames() { 60 | return request.headers().names(); 61 | } 62 | 63 | @Override 64 | public List headers(String name) { 65 | return request.headers().getAll(name); 66 | } 67 | 68 | @Override 69 | protected void doRead(final Action chunkAction) { 70 | request.handler(chunk -> chunkAction.on(chunk.getByteBuf().nioBuffer())).endHandler(endActions::fire); 71 | } 72 | 73 | @Override 74 | protected void doSetStatus(HttpStatus status) { 75 | response.setStatusCode(status.code()).setStatusMessage(status.reason()); 76 | } 77 | 78 | @Override 79 | protected void doSetHeader(String name, String value) { 80 | response.putHeader(name, value); 81 | } 82 | 83 | @Override 84 | protected void doWrite(ByteBuffer byteBuffer) { 85 | response.write(Buffer.buffer().setBytes(0, byteBuffer)); 86 | } 87 | 88 | @Override 89 | protected void doEnd() { 90 | response.end(); 91 | } 92 | 93 | /** 94 | * {@link HttpServerRequest} is available. 95 | */ 96 | @Override 97 | public T unwrap(Class clazz) { 98 | return HttpServerRequest.class.isAssignableFrom(clazz) ? clazz.cast(request) : null; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /bridge-vertx3/src/main/java/io/cettia/asity/bridge/vertx3/VertxServerWebSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx3; 17 | 18 | import io.cettia.asity.websocket.AbstractServerWebSocket; 19 | import io.cettia.asity.websocket.ServerWebSocket; 20 | import io.vertx.core.buffer.Buffer; 21 | 22 | import java.nio.ByteBuffer; 23 | import java.util.List; 24 | import java.util.Set; 25 | 26 | /** 27 | * {@link ServerWebSocket} for Vert.x 3. 28 | * 29 | * @author Donghwan Kim 30 | */ 31 | public class VertxServerWebSocket extends AbstractServerWebSocket { 32 | 33 | private final io.vertx.core.http.ServerWebSocket socket; 34 | 35 | public VertxServerWebSocket(io.vertx.core.http.ServerWebSocket socket) { 36 | this.socket = socket; 37 | socket.closeHandler(closeActions::fire).exceptionHandler(errorActions::fire).frameHandler(frame -> { 38 | // Deal with only text and binary frames 39 | if (frame.isText()) { 40 | textActions.fire(frame.textData()); 41 | } else if (frame.isBinary()) { 42 | binaryActions.fire(frame.binaryData().getByteBuf().nioBuffer()); 43 | } 44 | }); 45 | } 46 | 47 | @Override 48 | public String uri() { 49 | return socket.uri(); 50 | } 51 | 52 | @Override 53 | public Set headerNames() { 54 | return socket.headers().names(); 55 | } 56 | 57 | @Override 58 | public List headers(String name) { 59 | return socket.headers().getAll(name); 60 | } 61 | 62 | @Override 63 | protected void doClose() { 64 | socket.close(); 65 | } 66 | 67 | @Override 68 | protected void doSend(String data) { 69 | socket.writeFinalTextFrame(data); 70 | } 71 | 72 | @Override 73 | protected void doSend(ByteBuffer byteBuffer) { 74 | socket.writeFinalBinaryFrame(Buffer.buffer().setBytes(0, byteBuffer)); 75 | } 76 | 77 | /** 78 | * {@link io.vertx.core.http.ServerWebSocket} is available. 79 | */ 80 | @Override 81 | public T unwrap(Class clazz) { 82 | return io.vertx.core.http.ServerWebSocket.class.isAssignableFrom(clazz) ? clazz.cast(socket) : null; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /bridge-vertx3/src/test/java/io/cettia/asity/bridge/vertx3/VertxServerHttpExchangeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.ServerHttpExchange; 20 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 21 | import io.vertx.core.Vertx; 22 | import io.vertx.core.http.HttpServer; 23 | import io.vertx.core.http.HttpServerRequest; 24 | import org.eclipse.jetty.client.api.Response; 25 | import org.junit.Test; 26 | 27 | import java.util.concurrent.CountDownLatch; 28 | 29 | /** 30 | * @author Donghwan Kim 31 | */ 32 | public class VertxServerHttpExchangeTest extends ServerHttpExchangeTestBase { 33 | 34 | private HttpServer server; 35 | 36 | @Override 37 | protected void startServer(int port, Action requestAction) throws Exception { 38 | server = Vertx.vertx().createHttpServer(); 39 | AsityRequestHandler requestHandler = new AsityRequestHandler().onhttp(requestAction); 40 | server.requestHandler(request -> { 41 | if (request.path().equals(TEST_PATH)) { 42 | requestHandler.handle(request); 43 | } 44 | }); 45 | 46 | CountDownLatch latch = new CountDownLatch(1); 47 | server.listen(port, ar -> latch.countDown()); 48 | latch.await(); 49 | } 50 | 51 | @Override 52 | protected void stopServer() { 53 | server.close(); 54 | } 55 | 56 | @Test 57 | public void unwrap() throws Throwable { 58 | requestAction(http -> { 59 | threadAssertTrue(http.unwrap(HttpServerRequest.class) instanceof HttpServerRequest); 60 | resume(); 61 | }); 62 | client.newRequest(uri()).send(new Response.Listener.Adapter()); 63 | await(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /bridge-vertx3/src/test/java/io/cettia/asity/bridge/vertx3/VertxServerWebSocketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.vertx3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import io.cettia.asity.websocket.ServerWebSocket; 21 | import io.vertx.core.Vertx; 22 | import io.vertx.core.http.HttpServer; 23 | import org.eclipse.jetty.websocket.api.WebSocketAdapter; 24 | import org.junit.Test; 25 | 26 | import java.net.URI; 27 | import java.util.concurrent.CountDownLatch; 28 | 29 | /** 30 | * @author Donghwan Kim 31 | */ 32 | public class VertxServerWebSocketTest extends ServerWebSocketTestBase { 33 | 34 | private HttpServer server; 35 | 36 | @Override 37 | protected void startServer(int port, Action websocketAction) throws Exception { 38 | server = Vertx.vertx().createHttpServer(); 39 | AsityWebSocketHandler websocketHandler = new AsityWebSocketHandler().onwebsocket(websocketAction); 40 | server.websocketHandler(socket -> { 41 | if (socket.path().equals(TEST_PATH)) { 42 | websocketHandler.handle(socket); 43 | } 44 | }); 45 | 46 | CountDownLatch latch = new CountDownLatch(1); 47 | server.listen(port, ar -> latch.countDown()); 48 | latch.await(); 49 | } 50 | 51 | @Override 52 | protected void stopServer() { 53 | server.close(); 54 | } 55 | 56 | @Test 57 | public void unwrap() throws Throwable { 58 | websocketAction(ws -> { 59 | threadAssertTrue(ws.unwrap(io.vertx.core.http.ServerWebSocket.class) instanceof io 60 | .vertx.core.http.ServerWebSocket); 61 | resume(); 62 | }); 63 | client.connect(new WebSocketAdapter(), URI.create(uri())); 64 | await(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /bridge-vertx3/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /example-atmosphere2/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-atmosphere2 6 | mvn jetty:run 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@websocket-echo-client exec:java@http-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-atmosphere2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | war 25 | asity-example-atmosphere2 26 | Asity/Example/Atmosphere 2 27 | 28 | false 29 | 30 | 31 | 32 | io.cettia.asity 33 | asity-example 34 | ${project.version} 35 | 36 | 37 | io.cettia.asity 38 | asity-bridge-atmosphere2 39 | ${project.version} 40 | 41 | 42 | javax.servlet 43 | javax.servlet-api 44 | ${servlet3.version} 45 | provided 46 | 47 | 48 | org.atmosphere 49 | atmosphere-runtime 50 | ${atmosphere2.version} 51 | 52 | 53 | ch.qos.logback 54 | logback-core 55 | compile 56 | 57 | 58 | ch.qos.logback 59 | logback-classic 60 | compile 61 | 62 | 63 | 64 | 65 | 66 | org.eclipse.jetty 67 | jetty-maven-plugin 68 | ${jetty.version} 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /example-atmosphere2/src/main/java/io/cettia/asity/example/atmosphere2/EchoServerInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.atmosphere2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.bridge.atmosphere2.AsityAtmosphereServlet; 20 | import io.cettia.asity.example.echo.HttpEchoServer; 21 | import io.cettia.asity.example.echo.WebSocketEchoServer; 22 | import io.cettia.asity.http.ServerHttpExchange; 23 | import io.cettia.asity.websocket.ServerWebSocket; 24 | import org.atmosphere.cpr.ApplicationConfig; 25 | 26 | import javax.servlet.Servlet; 27 | import javax.servlet.ServletContext; 28 | import javax.servlet.ServletContextEvent; 29 | import javax.servlet.ServletContextListener; 30 | import javax.servlet.ServletRegistration; 31 | import javax.servlet.annotation.WebListener; 32 | 33 | @WebListener 34 | public class EchoServerInitializer implements ServletContextListener { 35 | @Override 36 | public void contextInitialized(ServletContextEvent event) { 37 | // Web fragments 38 | Action httpAction = new HttpEchoServer(); 39 | Action wsAction = new WebSocketEchoServer(); 40 | 41 | ServletContext context = event.getServletContext(); 42 | Servlet servlet = new AsityAtmosphereServlet().onhttp(httpAction).onwebsocket(wsAction); 43 | ServletRegistration.Dynamic reg = context.addServlet(AsityAtmosphereServlet.class.getName(), servlet); 44 | reg.setAsyncSupported(true); 45 | reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString()); 46 | reg.addMapping("/echo"); 47 | } 48 | 49 | @Override 50 | public void contextDestroyed(ServletContextEvent sce) {} 51 | } -------------------------------------------------------------------------------- /example-atmosphere2/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-grizzly2/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-grizzly2 6 | mvn clean package exec:java 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@websocket-echo-client exec:java@http-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-grizzly2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-example-grizzly2 25 | Asity/Example/Grizzly 2 26 | 27 | 28 | io.cettia.asity 29 | asity-example 30 | ${project.version} 31 | 32 | 33 | io.cettia.asity 34 | asity-bridge-grizzly2 35 | ${project.version} 36 | 37 | 38 | org.glassfish.grizzly 39 | grizzly-http-server 40 | ${grizzly2.version} 41 | 42 | 43 | org.glassfish.grizzly 44 | grizzly-websockets 45 | ${grizzly2.version} 46 | 47 | 48 | org.glassfish.grizzly 49 | grizzly-http-servlet 50 | ${grizzly2.version} 51 | 52 | 53 | javax.servlet 54 | javax.servlet-api 55 | ${servlet3.version} 56 | 57 | 58 | ch.qos.logback 59 | logback-core 60 | compile 61 | 62 | 63 | ch.qos.logback 64 | logback-classic 65 | compile 66 | 67 | 68 | 69 | 70 | 71 | org.codehaus.mojo 72 | exec-maven-plugin 73 | ${exec.plugin.version} 74 | 75 | io.cettia.asity.example.grizzly2.EchoServer 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /example-grizzly2/src/main/java/io/cettia/asity/example/grizzly2/EchoServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.grizzly2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.bridge.grizzly2.AsityHttpHandler; 20 | import io.cettia.asity.bridge.grizzly2.AsityWebSocketApplication; 21 | import io.cettia.asity.example.echo.HttpEchoServer; 22 | import io.cettia.asity.example.echo.WebSocketEchoServer; 23 | import io.cettia.asity.http.ServerHttpExchange; 24 | import io.cettia.asity.websocket.ServerWebSocket; 25 | import org.glassfish.grizzly.http.server.HttpServer; 26 | import org.glassfish.grizzly.http.server.NetworkListener; 27 | import org.glassfish.grizzly.http.server.ServerConfiguration; 28 | import org.glassfish.grizzly.websockets.WebSocketAddOn; 29 | import org.glassfish.grizzly.websockets.WebSocketEngine; 30 | 31 | public class EchoServer { 32 | public static void main(String[] args) throws Exception { 33 | // Web fragments 34 | Action httpAction = new HttpEchoServer(); 35 | Action wsAction = new WebSocketEchoServer(); 36 | 37 | HttpServer httpServer = HttpServer.createSimpleServer(); 38 | ServerConfiguration config = httpServer.getServerConfiguration(); 39 | config.addHttpHandler(new AsityHttpHandler().onhttp(httpAction), "/echo"); 40 | NetworkListener listener = httpServer.getListener("grizzly"); 41 | listener.registerAddOn(new WebSocketAddOn()); 42 | WebSocketEngine.getEngine().register("", "/echo", new AsityWebSocketApplication().onwebsocket(wsAction)); 43 | httpServer.start(); 44 | 45 | System.in.read(); 46 | } 47 | } -------------------------------------------------------------------------------- /example-grizzly2/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-jwa1/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-jwa1 6 | mvn jetty:run 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@websocket-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-jwa1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | war 25 | asity-example-jwa1 26 | Asity/Example/Java WebSocket API 1 27 | 28 | false 29 | 30 | 31 | 32 | io.cettia.asity 33 | asity-example 34 | ${project.version} 35 | 36 | 37 | io.cettia.asity 38 | asity-bridge-jwa1 39 | ${project.version} 40 | 41 | 42 | javax.servlet 43 | javax.servlet-api 44 | ${servlet3.version} 45 | provided 46 | 47 | 48 | javax.websocket 49 | javax.websocket-api 50 | ${jwa1.version} 51 | provided 52 | 53 | 54 | ch.qos.logback 55 | logback-core 56 | compile 57 | 58 | 59 | ch.qos.logback 60 | logback-classic 61 | compile 62 | 63 | 64 | 65 | 66 | 67 | org.eclipse.jetty 68 | jetty-maven-plugin 69 | ${jetty.version} 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /example-jwa1/src/main/java/io/cettia/asity/example/jwa1/EchoServerInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.jwa1; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.bridge.jwa1.AsityServerEndpoint; 20 | import io.cettia.asity.example.echo.WebSocketEchoServer; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | 23 | import javax.servlet.ServletContext; 24 | import javax.servlet.ServletContextEvent; 25 | import javax.servlet.ServletContextListener; 26 | import javax.servlet.annotation.WebListener; 27 | import javax.websocket.DeploymentException; 28 | import javax.websocket.HandshakeResponse; 29 | import javax.websocket.server.HandshakeRequest; 30 | import javax.websocket.server.ServerContainer; 31 | import javax.websocket.server.ServerEndpointConfig; 32 | 33 | @WebListener 34 | public class EchoServerInitializer implements ServletContextListener { 35 | @Override 36 | public void contextInitialized(ServletContextEvent event) { 37 | // Web fragments 38 | Action wsAction = new WebSocketEchoServer(); 39 | 40 | ServletContext context = event.getServletContext(); 41 | ServerContainer container = (ServerContainer) context.getAttribute(ServerContainer.class.getName()); 42 | ServerEndpointConfig.Configurator configurator = new ServerEndpointConfig.Configurator() { 43 | @Override 44 | public T getEndpointInstance(Class endpointClass) { 45 | AsityServerEndpoint asityServerEndpoint = new AsityServerEndpoint().onwebsocket(wsAction); 46 | return endpointClass.cast(asityServerEndpoint); 47 | } 48 | 49 | @Override 50 | public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { 51 | config.getUserProperties().put(HandshakeRequest.class.getName(), request); 52 | } 53 | }; 54 | try { 55 | container.addEndpoint(ServerEndpointConfig.Builder.create(AsityServerEndpoint.class, "/echo").configurator(configurator).build()); 56 | } catch (DeploymentException e) { 57 | throw new RuntimeException(e); 58 | } 59 | } 60 | 61 | @Override 62 | public void contextDestroyed(ServletContextEvent sce) {} 63 | } -------------------------------------------------------------------------------- /example-jwa1/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-netty4/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-netty4 6 | mvn clean package exec:java 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@websocket-echo-client exec:java@http-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-netty4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-example-netty4 25 | Asity/Example/Netty 4 26 | 27 | 28 | io.cettia.asity 29 | asity-example 30 | ${project.version} 31 | 32 | 33 | io.cettia.asity 34 | asity-bridge-netty4 35 | ${project.version} 36 | 37 | 38 | io.netty 39 | netty-codec-http 40 | ${netty4.version} 41 | 42 | 43 | io.netty 44 | netty-handler 45 | ${netty4.version} 46 | 47 | 48 | ch.qos.logback 49 | logback-core 50 | compile 51 | 52 | 53 | ch.qos.logback 54 | logback-classic 55 | compile 56 | 57 | 58 | 59 | 60 | 61 | org.codehaus.mojo 62 | exec-maven-plugin 63 | ${exec.plugin.version} 64 | 65 | io.cettia.asity.example.netty4.EchoServer 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /example-netty4/src/main/java/io/cettia/asity/example/netty4/EchoServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.netty4; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.bridge.netty4.AsityServerCodec; 20 | import io.cettia.asity.example.echo.HttpEchoServer; 21 | import io.cettia.asity.example.echo.WebSocketEchoServer; 22 | import io.cettia.asity.http.ServerHttpExchange; 23 | import io.cettia.asity.websocket.ServerWebSocket; 24 | import io.netty.bootstrap.ServerBootstrap; 25 | import io.netty.channel.Channel; 26 | import io.netty.channel.ChannelInitializer; 27 | import io.netty.channel.ChannelPipeline; 28 | import io.netty.channel.EventLoopGroup; 29 | import io.netty.channel.nio.NioEventLoopGroup; 30 | import io.netty.channel.socket.SocketChannel; 31 | import io.netty.channel.socket.nio.NioServerSocketChannel; 32 | import io.netty.handler.codec.http.HttpRequest; 33 | import io.netty.handler.codec.http.HttpServerCodec; 34 | 35 | import java.net.URI; 36 | 37 | public class EchoServer { 38 | public static void main(String[] args) throws Exception { 39 | // Web fragments 40 | Action httpAction = new HttpEchoServer(); 41 | Action wsAction = new WebSocketEchoServer(); 42 | 43 | EventLoopGroup bossGroup = new NioEventLoopGroup(); 44 | EventLoopGroup workerGroup = new NioEventLoopGroup(); 45 | try { 46 | ServerBootstrap bootstrap = new ServerBootstrap(); 47 | bootstrap.group(bossGroup, workerGroup) 48 | .channel(NioServerSocketChannel.class) 49 | .childHandler(new ChannelInitializer() { 50 | @Override 51 | public void initChannel(SocketChannel ch) { 52 | AsityServerCodec asityServerCodec = new AsityServerCodec() { 53 | @Override 54 | protected boolean accept(HttpRequest req) { 55 | return URI.create(req.uri()).getPath().equals("/echo"); 56 | } 57 | }; 58 | asityServerCodec.onhttp(httpAction).onwebsocket(wsAction); 59 | 60 | ChannelPipeline pipeline = ch.pipeline(); 61 | pipeline.addLast(new HttpServerCodec()).addLast(asityServerCodec); 62 | } 63 | }); 64 | Channel channel = bootstrap.bind(8080).sync().channel(); 65 | channel.closeFuture().sync(); 66 | } finally { 67 | workerGroup.shutdownGracefully(); 68 | bossGroup.shutdownGracefully(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /example-netty4/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-play2/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-play2 6 | sbt run 7 | ``` 8 | 9 | FYI, you can run the application by `mvn play2:run` too. 10 | 11 | How to run the WebSocket client: 12 | 13 | ```shell 14 | cd asity/example 15 | mvn package exec:java@websocket-echo-client 16 | ``` 17 | 18 | Play framework doesn't allow to read HTTP request body by chunk so the HTTP client example that does ping-pong with the server doesn't work with this example. Instead, if you send the whole request body at once, you can see it's sent back via response body. 19 | 20 | ``` 21 | curl -v -X POST -H 'Content-Type: text/plain' -d 'A message to be sent back' http://localhost:8080/echo 22 | ``` 23 | -------------------------------------------------------------------------------- /example-play2/app/io/cettia/asity/bridge/play2/HttpController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.play2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.ServerHttpExchange; 20 | import play.mvc.BodyParser; 21 | import play.mvc.Controller; 22 | import play.mvc.Http; 23 | import play.mvc.Result; 24 | 25 | import javax.inject.Singleton; 26 | import java.util.concurrent.CompletionStage; 27 | 28 | /** 29 | * @author Donghwan Kim 30 | */ 31 | @Singleton 32 | public class HttpController extends Controller { 33 | 34 | private Action action; 35 | 36 | @BodyParser.Of(BodyParser.Raw.class) 37 | public CompletionStage http() { 38 | Http.Request request = request(); 39 | AsityHttpAction httpAction = new AsityHttpAction(); 40 | httpAction.onhttp(action); 41 | 42 | return httpAction.apply(request); 43 | } 44 | 45 | public void setAction(Action action) { 46 | this.action = action; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /example-play2/app/io/cettia/asity/bridge/play2/WebSocketController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.play2; 17 | 18 | import akka.actor.ActorSystem; 19 | import akka.stream.Materializer; 20 | import io.cettia.asity.action.Action; 21 | import io.cettia.asity.websocket.ServerWebSocket; 22 | import play.mvc.Controller; 23 | import play.mvc.WebSocket; 24 | 25 | import javax.inject.Inject; 26 | import javax.inject.Singleton; 27 | 28 | /** 29 | * @author Donghwan Kim 30 | */ 31 | @Singleton 32 | public class WebSocketController extends Controller { 33 | 34 | private final ActorSystem actorSystem; 35 | private final Materializer materializer; 36 | private Action action; 37 | 38 | @Inject 39 | public WebSocketController(ActorSystem actorSystem, Materializer materializer) { 40 | this.actorSystem = actorSystem; 41 | this.materializer = materializer; 42 | } 43 | 44 | public WebSocket websocket() { 45 | AsityWebSocket webSocket = new AsityWebSocket(actorSystem, materializer); 46 | webSocket.onwebsocket(action); 47 | 48 | return webSocket; 49 | } 50 | 51 | public void setAction(Action action) { 52 | this.action = action; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /example-play2/app/io/cettia/asity/example/play2/EchoController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.play2; 17 | 18 | import akka.actor.ActorSystem; 19 | import akka.stream.Materializer; 20 | import io.cettia.asity.action.Action; 21 | import io.cettia.asity.bridge.play2.AsityHttpAction; 22 | import io.cettia.asity.bridge.play2.AsityWebSocket; 23 | import io.cettia.asity.example.echo.HttpEchoServer; 24 | import io.cettia.asity.example.echo.WebSocketEchoServer; 25 | import io.cettia.asity.http.ServerHttpExchange; 26 | import io.cettia.asity.websocket.ServerWebSocket; 27 | import play.mvc.BodyParser; 28 | import play.mvc.Controller; 29 | import play.mvc.Http; 30 | import play.mvc.Result; 31 | import play.mvc.WebSocket; 32 | 33 | import javax.inject.Inject; 34 | import java.util.concurrent.CompletionStage; 35 | 36 | public class EchoController extends Controller { 37 | 38 | // Web fragments 39 | private final Action httpAction = new HttpEchoServer(); 40 | private final Action wsAction = new WebSocketEchoServer(); 41 | 42 | private final ActorSystem actorSystem; 43 | private final Materializer materializer; 44 | 45 | @Inject 46 | public EchoController(ActorSystem actorSystem, Materializer materializer) { 47 | this.actorSystem = actorSystem; 48 | this.materializer = materializer; 49 | } 50 | 51 | @BodyParser.Of(BodyParser.Raw.class) 52 | public CompletionStage http() { 53 | Http.Request request = request(); 54 | AsityHttpAction action = new AsityHttpAction(); 55 | action.onhttp(httpAction); 56 | 57 | return action.apply(request); 58 | } 59 | 60 | public WebSocket websocket() { 61 | AsityWebSocket webSocket = new AsityWebSocket(actorSystem, materializer); 62 | webSocket.onwebsocket(wsAction); 63 | 64 | return webSocket; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /example-play2/build.sbt: -------------------------------------------------------------------------------- 1 | lazy val root = (project in file(".")).enablePlugins(PlayJava) 2 | 3 | scalaVersion := "2.12.8" 4 | 5 | libraryDependencies += guice 6 | libraryDependencies += "io.cettia.asity" % "asity-bridge-play2" % "3.0.0-Beta2-SNAPSHOT" 7 | libraryDependencies += "io.cettia.asity" % "asity-example" % "3.0.0-Beta2-SNAPSHOT" 8 | 9 | resolvers += Resolver.mavenLocal 10 | 11 | PlayKeys.devSettings := Seq("play.server.http.port" -> "8080") -------------------------------------------------------------------------------- /example-play2/conf/application.conf: -------------------------------------------------------------------------------- 1 | # This is the main configuration file for the application. 2 | # https://www.playframework.com/documentation/latest/ConfigFile -------------------------------------------------------------------------------- /example-play2/conf/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-play2/conf/routes: -------------------------------------------------------------------------------- 1 | # Routes 2 | # This file defines all application routes (Higher priority routes first) 3 | # ~~~~ 4 | 5 | # Routes for the echo example 6 | GET /echo io.cettia.asity.example.play2.EchoController.websocket 7 | POST /echo io.cettia.asity.example.play2.EchoController.http 8 | 9 | # Routes for the bridge test 10 | GET /websocket io.cettia.asity.bridge.play2.WebSocketController.websocket 11 | GET /http io.cettia.asity.bridge.play2.HttpController.http 12 | POST /http io.cettia.asity.bridge.play2.HttpController.http 13 | PUT /http io.cettia.asity.bridge.play2.HttpController.http 14 | DELETE /http io.cettia.asity.bridge.play2.HttpController.http 15 | HEAD /http io.cettia.asity.bridge.play2.HttpController.http 16 | OPTIONS /http io.cettia.asity.bridge.play2.HttpController.http 17 | -------------------------------------------------------------------------------- /example-play2/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.8 2 | -------------------------------------------------------------------------------- /example-play2/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | // The Play plugin 2 | addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.23") -------------------------------------------------------------------------------- /example-play2/test/io/cettia/asity/bridge/play2/PlayServerHttpExchangeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.play2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.ServerHttpExchange; 20 | import io.cettia.asity.test.ServerHttpExchangeTestBase; 21 | import org.eclipse.jetty.client.api.Response; 22 | import org.eclipse.jetty.http.HttpFields; 23 | import org.junit.Ignore; 24 | import org.junit.Test; 25 | import play.Application; 26 | import play.inject.guice.GuiceApplicationBuilder; 27 | import play.mvc.Http; 28 | import play.test.Helpers; 29 | import play.test.TestServer; 30 | 31 | /** 32 | * @author Donghwan Kim 33 | */ 34 | public class PlayServerHttpExchangeTest extends ServerHttpExchangeTestBase { 35 | 36 | private TestServer server; 37 | 38 | @Override 39 | protected void startServer(int port, Action action) { 40 | Application app = new GuiceApplicationBuilder().build(); 41 | HttpController controller = app.injector().instanceOf(HttpController.class); 42 | controller.setAction(action); 43 | 44 | server = Helpers.testServer(port, app); 45 | server.start(); 46 | } 47 | 48 | @Override 49 | protected void stopServer() { 50 | server.stop(); 51 | } 52 | 53 | @Test 54 | public void unwrap() throws Throwable { 55 | requestAction(http -> { 56 | threadAssertTrue(http.unwrap(Http.Request.class) instanceof Http.Request); 57 | resume(); 58 | }); 59 | client.newRequest(uri()).send(new Response.Listener.Adapter()); 60 | await(); 61 | } 62 | 63 | @Test 64 | public void setContentTypeHeader() throws Throwable { 65 | requestAction(http -> { 66 | http.setHeader("content-type", "application/json").end(); 67 | }); 68 | client.newRequest(uri()).send(new Response.Listener.Adapter() { 69 | @Override 70 | public void onSuccess(Response res) { 71 | HttpFields headers = res.getHeaders(); 72 | threadAssertEquals(headers.get("content-type"), "application/json"); 73 | resume(); 74 | } 75 | }); 76 | await(); 77 | } 78 | 79 | 80 | @Override 81 | @Test 82 | @Ignore 83 | public void testOnclose() { 84 | } 85 | 86 | @Override 87 | @Test 88 | @Ignore 89 | public void testReadAsync() { 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /example-play2/test/io/cettia/asity/bridge/play2/PlayServerWebSocketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.bridge.play2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.test.ServerWebSocketTestBase; 20 | import io.cettia.asity.websocket.ServerWebSocket; 21 | import org.eclipse.jetty.websocket.api.WebSocketAdapter; 22 | import org.junit.Test; 23 | import play.Application; 24 | import play.inject.guice.GuiceApplicationBuilder; 25 | import play.mvc.Http; 26 | import play.test.Helpers; 27 | import play.test.TestServer; 28 | 29 | import java.net.URI; 30 | 31 | /** 32 | * @author Donghwan Kim 33 | */ 34 | public class PlayServerWebSocketTest extends ServerWebSocketTestBase { 35 | 36 | private TestServer server; 37 | 38 | @Override 39 | protected void startServer(int port, Action action) { 40 | Application app = new GuiceApplicationBuilder().build(); 41 | WebSocketController controller = app.injector().instanceOf(WebSocketController.class); 42 | controller.setAction(action); 43 | 44 | server = Helpers.testServer(port, app); 45 | server.start(); 46 | } 47 | 48 | @Override 49 | protected void stopServer() { 50 | server.stop(); 51 | } 52 | 53 | @Test 54 | public void unwrap() throws Throwable { 55 | websocketAction(ws -> { 56 | threadAssertTrue(ws.unwrap(AsityWebSocketActor.class) instanceof AsityWebSocketActor); 57 | threadAssertTrue(ws.unwrap(Http.RequestHeader.class) instanceof Http.RequestHeader); 58 | resume(); 59 | }); 60 | client.connect(new WebSocketAdapter(), URI.create(uri())); 61 | await(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /example-servlet3/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-servlet3 6 | mvn jetty:run 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@http-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-servlet3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | war 25 | asity-example-servlet3 26 | Asity/Example/Servlet 3 27 | 28 | false 29 | 30 | 31 | 32 | io.cettia.asity 33 | asity-example 34 | ${project.version} 35 | 36 | 37 | io.cettia.asity 38 | asity-bridge-servlet3 39 | ${project.version} 40 | 41 | 42 | javax.servlet 43 | javax.servlet-api 44 | ${servlet3.version} 45 | provided 46 | 47 | 48 | ch.qos.logback 49 | logback-core 50 | compile 51 | 52 | 53 | ch.qos.logback 54 | logback-classic 55 | compile 56 | 57 | 58 | 59 | 60 | 61 | org.eclipse.jetty 62 | jetty-maven-plugin 63 | ${jetty.version} 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /example-servlet3/src/main/java/io/cettia/asity/example/servlet3/EchoServerInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.servlet3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.bridge.servlet3.AsityServlet; 20 | import io.cettia.asity.example.echo.HttpEchoServer; 21 | import io.cettia.asity.http.ServerHttpExchange; 22 | 23 | import javax.servlet.Servlet; 24 | import javax.servlet.ServletContext; 25 | import javax.servlet.ServletContextEvent; 26 | import javax.servlet.ServletContextListener; 27 | import javax.servlet.ServletRegistration; 28 | import javax.servlet.annotation.WebListener; 29 | 30 | @WebListener 31 | public class EchoServerInitializer implements ServletContextListener { 32 | @Override 33 | public void contextInitialized(ServletContextEvent event) { 34 | // Web fragments 35 | Action httpAction = new HttpEchoServer(); 36 | 37 | ServletContext context = event.getServletContext(); 38 | Servlet servlet = new AsityServlet().onhttp(httpAction); 39 | ServletRegistration.Dynamic reg = context.addServlet(AsityServlet.class.getName(), servlet); 40 | reg.setAsyncSupported(true); 41 | reg.addMapping("/echo"); 42 | } 43 | 44 | @Override 45 | public void contextDestroyed(ServletContextEvent sce) {} 46 | } -------------------------------------------------------------------------------- /example-servlet3/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-spring-webflux5/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-spring-webflux5 6 | mvn spring-boot:run 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@websocket-echo-client exec:java@http-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-spring-webflux5/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-example-spring-webflux5 25 | Asity/Example/Spring WebFlux 5 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-dependencies 31 | ${spring-boot2.version} 32 | pom 33 | import 34 | 35 | 36 | 37 | 38 | 39 | io.cettia.asity 40 | asity-example 41 | ${project.version} 42 | 43 | 44 | io.cettia.asity 45 | asity-bridge-spring-webflux5 46 | ${project.version} 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-webflux 51 | 52 | 53 | ch.qos.logback 54 | logback-core 55 | compile 56 | 57 | 58 | ch.qos.logback 59 | logback-classic 60 | compile 61 | 62 | 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-maven-plugin 68 | ${spring-boot2.version} 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /example-spring-webflux5/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-spring-webmvc4/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-spring-webmvc4 6 | mvn spring-boot:run 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@websocket-echo-client exec:java@http-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-spring-webmvc4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | war 25 | asity-example-spring-webmvc4 26 | Asity/Example/Spring Web MVC 4 27 | 28 | false 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-dependencies 35 | ${spring-boot1.version} 36 | pom 37 | import 38 | 39 | 40 | 41 | 42 | 43 | io.cettia.asity 44 | asity-example 45 | ${project.version} 46 | 47 | 48 | io.cettia.asity 49 | asity-bridge-spring-webmvc4 50 | ${project.version} 51 | 52 | 53 | javax.servlet 54 | javax.servlet-api 55 | ${servlet3.version} 56 | provided 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-starter-websocket 61 | 62 | 63 | ch.qos.logback 64 | logback-core 65 | compile 66 | 67 | 68 | ch.qos.logback 69 | logback-classic 70 | compile 71 | 72 | 73 | 74 | 75 | 76 | org.springframework.boot 77 | spring-boot-maven-plugin 78 | ${spring-boot1.version} 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /example-spring-webmvc4/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-vertx2/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-vertx2 6 | mvn clean package vertx:runMod 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@websocket-echo-client exec:java@http-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-vertx2/src/main/assembly/mod.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | mod 22 | 23 | zip 24 | 25 | 26 | false 27 | 28 | 29 | 30 | 31 | ${mods.directory}/${module.name} 32 | 33 | ** 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example-vertx2/src/main/java/io/cettia/asity/example/vertx2/EchoServerVerticle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.vertx2; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.bridge.vertx2.AsityRequestHandler; 20 | import io.cettia.asity.bridge.vertx2.AsityWebSocketHandler; 21 | import io.cettia.asity.example.echo.HttpEchoServer; 22 | import io.cettia.asity.example.echo.WebSocketEchoServer; 23 | import io.cettia.asity.http.ServerHttpExchange; 24 | import io.cettia.asity.websocket.ServerWebSocket; 25 | import org.vertx.java.core.http.HttpServer; 26 | import org.vertx.java.core.http.RouteMatcher; 27 | import org.vertx.java.platform.Verticle; 28 | 29 | public class EchoServerVerticle extends Verticle { 30 | @Override 31 | public void start() { 32 | // Web fragments 33 | Action httpAction = new HttpEchoServer(); 34 | Action wsAction = new WebSocketEchoServer(); 35 | 36 | HttpServer httpServer = vertx.createHttpServer(); 37 | RouteMatcher httpMatcher = new RouteMatcher(); 38 | httpMatcher.all("/echo", new AsityRequestHandler().onhttp(httpAction)); 39 | httpServer.requestHandler(httpMatcher); 40 | AsityWebSocketHandler websocketHandler = new AsityWebSocketHandler().onwebsocket(wsAction); 41 | httpServer.websocketHandler(socket -> { 42 | if (socket.path().equals("/echo")) { 43 | websocketHandler.handle(socket); 44 | } 45 | }); 46 | httpServer.listen(8080); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /example-vertx2/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example-vertx2/src/main/resources/mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "io.cettia.asity.example.vertx2.EchoServerVerticle" 3 | } 4 | -------------------------------------------------------------------------------- /example-vertx3/README.md: -------------------------------------------------------------------------------- 1 | How to run the server: 2 | 3 | ```shell 4 | git clone https://github.com/cettia/asity.git 5 | cd asity/example-vertx3 6 | mvn clean package exec:java 7 | ``` 8 | 9 | How to run the client: 10 | 11 | ```shell 12 | cd asity/example 13 | mvn package exec:java@websocket-echo-client exec:java@http-echo-client 14 | ``` -------------------------------------------------------------------------------- /example-vertx3/src/main/java/io/cettia/asity/example/vertx3/EchoServerVerticle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.vertx3; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.bridge.vertx3.AsityRequestHandler; 20 | import io.cettia.asity.bridge.vertx3.AsityWebSocketHandler; 21 | import io.cettia.asity.example.echo.HttpEchoServer; 22 | import io.cettia.asity.example.echo.WebSocketEchoServer; 23 | import io.cettia.asity.http.ServerHttpExchange; 24 | import io.cettia.asity.websocket.ServerWebSocket; 25 | import io.vertx.core.AbstractVerticle; 26 | import io.vertx.core.http.HttpServer; 27 | 28 | public class EchoServerVerticle extends AbstractVerticle { 29 | @Override 30 | public void start() { 31 | // Web fragments 32 | Action httpAction = new HttpEchoServer(); 33 | Action wsAction = new WebSocketEchoServer(); 34 | 35 | HttpServer httpServer = vertx.createHttpServer(); 36 | AsityRequestHandler asityRequestHandler = new AsityRequestHandler().onhttp(httpAction); 37 | httpServer.requestHandler(request -> { 38 | if (request.path().equals("/echo")) { 39 | asityRequestHandler.handle(request); 40 | } 41 | }); 42 | AsityWebSocketHandler asityWebsocketHandler = new AsityWebSocketHandler().onwebsocket(wsAction); 43 | httpServer.websocketHandler(socket -> { 44 | if (socket.path().equals("/echo")) { 45 | asityWebsocketHandler.handle(socket); 46 | } 47 | }); 48 | httpServer.listen(8080); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /example-vertx3/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %level [%thread] %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-example 25 | Asity/Example 26 | 27 | 28 | io.cettia.asity 29 | asity-http 30 | 31 | 32 | io.cettia.asity 33 | asity-websocket 34 | 35 | 36 | org.eclipse.jetty 37 | jetty-client 38 | compile 39 | 40 | 41 | org.eclipse.jetty.websocket 42 | websocket-client 43 | compile 44 | 45 | 46 | ch.qos.logback 47 | logback-core 48 | compile 49 | 50 | 51 | ch.qos.logback 52 | logback-classic 53 | compile 54 | 55 | 56 | 57 | 58 | 59 | org.codehaus.mojo 60 | exec-maven-plugin 61 | ${exec.plugin.version} 62 | 63 | 64 | http-echo-client 65 | 66 | java 67 | 68 | 69 | io.cettia.asity.example.echo.HttpEchoClient 70 | 71 | 72 | 73 | websocket-echo-client 74 | 75 | java 76 | 77 | 78 | io.cettia.asity.example.echo.WebSocketEchoClient 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /example/src/main/java/io/cettia/asity/example/echo/HttpEchoClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.echo; 17 | 18 | import org.eclipse.jetty.client.HttpClient; 19 | import org.eclipse.jetty.client.api.Response; 20 | import org.eclipse.jetty.client.api.Result; 21 | import org.eclipse.jetty.client.util.DeferredContentProvider; 22 | 23 | import java.nio.ByteBuffer; 24 | import java.util.Queue; 25 | import java.util.concurrent.ConcurrentLinkedQueue; 26 | import java.util.concurrent.CountDownLatch; 27 | import java.util.concurrent.Executors; 28 | import java.util.concurrent.ScheduledExecutorService; 29 | import java.util.concurrent.TimeUnit; 30 | 31 | /** 32 | * This HTTP client opens an HTTP persistent connection to 33 | * http://localhost:8080/echo, sends elements of {@link HttpEchoClient#ECHO_QUEUE} 34 | * one by one by retrieving and removing the head of the queue when the server sends the received 35 | * data back, and close the connection when the queue becomes empty. 36 | * 37 | * @author Donghwan Kim 38 | */ 39 | public class HttpEchoClient { 40 | private static final String ECHO_URI = "http://localhost:8080/echo"; 41 | private static final Queue ECHO_QUEUE = new ConcurrentLinkedQueue() {{ 42 | add("AAAAA"); 43 | add("BBBBB"); 44 | add("CCCCC"); 45 | add("DDDDD"); 46 | add("EEEEE"); 47 | }}; 48 | 49 | public static void main(String... args) throws Exception { 50 | CountDownLatch latch = new CountDownLatch(1); 51 | HttpClient client = new HttpClient(); 52 | client.start(); 53 | 54 | DeferredContentProvider content = new DeferredContentProvider(); 55 | client.POST(ECHO_URI).content(content, "text/plain; charset=utf-8").send(new Response.Listener.Adapter() { 56 | @Override 57 | public void onContent(Response response, ByteBuffer byteBuffer) { 58 | String data = ECHO_QUEUE.poll(); 59 | if (data == null) { 60 | content.close(); 61 | } else { 62 | content.offer(ByteBuffer.wrap(data.getBytes())); 63 | } 64 | } 65 | 66 | @Override 67 | public void onComplete(Result result) { 68 | latch.countDown(); 69 | } 70 | }); 71 | 72 | ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); 73 | executorService.schedule(() -> { 74 | content.offer(ByteBuffer.wrap(ECHO_QUEUE.poll().getBytes())); 75 | executorService.shutdown(); 76 | }, 1, TimeUnit.SECONDS); 77 | 78 | latch.await(); 79 | client.stop(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /example/src/main/java/io/cettia/asity/example/echo/HttpEchoServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.echo; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.http.HttpStatus; 20 | import io.cettia.asity.http.ServerHttpExchange; 21 | 22 | /** 23 | * @author Donghwan Kim 24 | */ 25 | public class HttpEchoServer implements Action { 26 | @Override 27 | public void on(ServerHttpExchange http) { 28 | // Reads request URI, method and headers 29 | System.out.println(http.method() + " " + http.uri()); 30 | http.headerNames().stream().forEach(name -> System.out.println(name + ": " + String.join(", ", http.headers(name)))); 31 | 32 | // Writes response status code and headers 33 | http.setStatus(HttpStatus.OK).setHeader("content-type", http.header("content-type")); 34 | 35 | // Reads a chunk from request body and writes it to response body 36 | http.onchunk((String chunk) -> http.write(chunk)).readAsText(); 37 | // If request body is binary, 38 | // http.onchunk((ByteBuffer binary) -> http.write(binary)).readAsBinary(); 39 | 40 | // Ends response if request ends 41 | http.onend((Void v) -> http.end()); 42 | 43 | // Exception handling 44 | http.onerror((Throwable t) -> t.printStackTrace()).onclose((Void v) -> System.out.println("disconnected")); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/src/main/java/io/cettia/asity/example/echo/WebSocketEchoClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.echo; 17 | 18 | import org.eclipse.jetty.websocket.api.Session; 19 | import org.eclipse.jetty.websocket.api.WebSocketAdapter; 20 | import org.eclipse.jetty.websocket.client.WebSocketClient; 21 | 22 | import java.net.URI; 23 | import java.util.Queue; 24 | import java.util.concurrent.ConcurrentLinkedQueue; 25 | import java.util.concurrent.CountDownLatch; 26 | 27 | 28 | /** 29 | * This WebSocket client opens a WebSocket connection to ws://localhost:8080/echo, 30 | * sends elements of {@link WebSocketEchoClient#ECHO_QUEUE} one by one by retrieving and removing 31 | * the head of the queue when the server sends the received data back, and close the connection 32 | * when the queue becomes empty. 33 | * 34 | * @author Donghwan Kim 35 | */ 36 | public class WebSocketEchoClient { 37 | private static final String ECHO_URI = "ws://localhost:8080/echo"; 38 | private static final Queue ECHO_QUEUE = new ConcurrentLinkedQueue() {{ 39 | add("AAAAA"); 40 | add("BBBBB"); 41 | add("CCCCC"); 42 | add("DDDDD"); 43 | add("EEEEE"); 44 | }}; 45 | 46 | public static void main(String... args) throws Exception { 47 | CountDownLatch latch = new CountDownLatch(1); 48 | WebSocketClient client = new WebSocketClient(); 49 | client.start(); 50 | 51 | client.connect(new WebSocketAdapter() { 52 | @Override 53 | public void onWebSocketConnect(Session session) { 54 | super.onWebSocketConnect(session); 55 | getRemote().sendStringByFuture(ECHO_QUEUE.poll()); 56 | } 57 | 58 | @Override 59 | public void onWebSocketText(String message) { 60 | String data = ECHO_QUEUE.poll(); 61 | if (data == null) { 62 | getSession().close(); 63 | } else { 64 | getRemote().sendStringByFuture(data); 65 | } 66 | } 67 | 68 | @Override 69 | public void onWebSocketClose(int statusCode, String reason) { 70 | latch.countDown(); 71 | } 72 | }, URI.create(ECHO_URI)); 73 | 74 | latch.await(); 75 | client.stop(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /example/src/main/java/io/cettia/asity/example/echo/WebSocketEchoServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.example.echo; 17 | 18 | import io.cettia.asity.action.Action; 19 | import io.cettia.asity.websocket.ServerWebSocket; 20 | 21 | import java.nio.ByteBuffer; 22 | 23 | /** 24 | * @author Donghwan Kim 25 | */ 26 | public class WebSocketEchoServer implements Action { 27 | @Override 28 | public void on(ServerWebSocket ws) { 29 | // Reads handshake request URI and headers 30 | System.out.println(ws.uri()); 31 | ws.headerNames().stream().forEach(name -> System.out.println(name + ": " + String.join(", ", ws.headers(name)))); 32 | 33 | // Sends the received text frame and binary frame back 34 | ws.ontext((String text) -> ws.send(text)).onbinary((ByteBuffer binary) -> ws.send(binary)); 35 | 36 | // Exception handling 37 | ws.onerror((Throwable t) -> t.printStackTrace()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{mm:ss.SSS} %logger{10} [%file:%line] %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /http/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-http 25 | Asity/HTTP 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | org.slf4j 33 | slf4j-api 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /http/src/main/java/io/cettia/asity/http/HttpMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.http; 17 | 18 | /** 19 | * Represents the HTTP method. 20 | * 21 | * @author Donghwan Kim 22 | * @see HTTP 24 | * Method Registry 25 | */ 26 | public enum HttpMethod { 27 | 28 | GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH 29 | 30 | } 31 | -------------------------------------------------------------------------------- /intellij-cettia-style.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/main/javadoc/overview.html: -------------------------------------------------------------------------------- 1 | 2 |

This is the API documentation for the Asity.

3 | 4 | -------------------------------------------------------------------------------- /test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-test 25 | Asity/Test 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | io.cettia.asity 33 | asity-http 34 | 35 | 36 | io.cettia.asity 37 | asity-websocket 38 | 39 | 40 | org.eclipse.jetty 41 | jetty-client 42 | compile 43 | 44 | 45 | org.eclipse.jetty.websocket 46 | websocket-client 47 | compile 48 | 49 | 50 | junit 51 | junit 52 | compile 53 | 54 | 55 | org.hamcrest 56 | hamcrest-all 57 | compile 58 | 59 | 60 | net.jodah 61 | concurrentunit 62 | compile 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /websocket/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | io.cettia.asity 21 | asity-parent 22 | 4.0.0-Beta1-SNAPSHOT 23 | 24 | asity-websocket 25 | Asity/WebSocket 26 | 27 | 28 | io.cettia.asity 29 | asity-action 30 | 31 | 32 | org.slf4j 33 | slf4j-api 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /websocket/src/main/java/io/cettia/asity/websocket/ServerWebSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.cettia.asity.websocket; 17 | 18 | import io.cettia.asity.action.Action; 19 | 20 | import java.nio.ByteBuffer; 21 | import java.util.List; 22 | import java.util.Set; 23 | 24 | /** 25 | * Represents a server-side WebSocket. 26 | *

27 | * Implementations are not thread-safe. 28 | * 29 | * @author Donghwan Kim 30 | * @see RFC6455 - The WebSocket 31 | * Protocol 32 | */ 33 | public interface ServerWebSocket { 34 | 35 | /** 36 | * The URI used to connect. 37 | */ 38 | String uri(); 39 | 40 | /** 41 | * The names of the handshake request headers. HTTP header is not case-sensitive 42 | * but {@link Set} is case-sensitive. 43 | */ 44 | Set headerNames(); 45 | 46 | /** 47 | * Returns the first handshake request header associated with the given name. 48 | */ 49 | String header(String name); 50 | 51 | /** 52 | * Returns the handshake request headers associated with the given name or empty list 53 | * if no header is found. 54 | */ 55 | List headers(String name); 56 | 57 | /** 58 | * Closes the connection. This method has no side effect if called more than 59 | * once. 60 | */ 61 | void close(); 62 | 63 | /** 64 | * Sends a text frame through the connection. 65 | */ 66 | ServerWebSocket send(String data); 67 | 68 | /** 69 | * Sends a binary frame through the connection. 70 | */ 71 | ServerWebSocket send(ByteBuffer byteBuffer); 72 | 73 | /** 74 | * Attaches an action for the text frame. 75 | */ 76 | ServerWebSocket ontext(Action action); 77 | 78 | /** 79 | * Attaches an action for the binary frame. 80 | */ 81 | ServerWebSocket onbinary(Action action); 82 | 83 | /** 84 | * Attaches an action for the close event. After this event, the instance 85 | * shouldn't be used and all the other events will be disabled. 86 | */ 87 | ServerWebSocket onclose(Action action); 88 | 89 | /** 90 | * Attaches an action to handle error from various things. Its exact 91 | * behavior is platform-specific and error created by the platform is 92 | * propagated. 93 | */ 94 | ServerWebSocket onerror(Action action); 95 | 96 | /** 97 | * Returns the provider-specific component. 98 | */ 99 | T unwrap(Class clazz); 100 | 101 | } 102 | --------------------------------------------------------------------------------