“Asity is the most suitable toolkit to support server-side Java”
Web fragment authors can now write a web fragment once and support almost all popular web frameworks in Java, and end-users can choose any technology stack they wish and use web fragments without being frustrated by compatibility issues. Sounds interesting? This is the concept behind Asity, a lightweight abstraction layer for various web frameworks on the JVM. We talked to Donghwan Kim, creator of Asity about what’s under the project’s hood.
JAXenter: What is Asity and what are its main benefits?
Donghwan Kim: Asity is a lightweight abstraction layer for various web frameworks on the Java Virtual Machine. It is designed to achieve and exploit “Write Once, Run Anywhere” by establishing an ecosystem of universally reusable web fragments* that run across different frameworks in the Java ecosystem. It provides abstractions for HTTP and WebSocket, and implementations per framework called bridges which are transparent to end-users and don’t sacrifice the framework’s performance, productivity and philosophy.
The main benefits are that web fragment authors can write a web fragment once and support almost all popular web frameworks in Java, and end-users can choose any technology stack they wish and use web fragments without being frustrated by compatibility issues.
* Web fragment represents a component that receives HTTP request-response or WebSocket connection like a controller in MVC but is able to be compatible with any web framework on the JVM.
JAXenter: What’s new in Asity 2.0.0?
Think of Asity as an alternative of the Node’s HTTP module for Java. We can build a middleware layer for Java on top of Asity using web fragments.
Donghwan Kim: To allow to write WebSocket subprotocol, a feature to read WebSocket handshake request headers has been added to Asity 2.0.0. With this feature, a developer can retrieve headers from a ServerWebSocket directly such as Authorization and Sec-WebSocket-Protocol, and use them to implement WebSocket subprotocols like STOMP and WAMP.
As for framework support, Spring support is finally shipped. Spring 5’s reactive stack’s web framework, Spring WebFlux, and, Spring 4’s servlet stack’s web framework, Spring MVC are supported. Vert.x 3 support has also been added.
Also, to help web fragments authors and users to get started, we created working examples per supported framework and renewed the website. From now on, web fragment authors can just link the website’s ‘Run Anywhere’ section instead of explaining how to run their web fragments on each framework one by one.
JAXenter: Could you name some use cases for Asity?
- A framework built on top of HTTP and WebSocket
As a framework or library author, if there’s no option but to depend on existing web frameworks, it’s essential to support as many frameworks as possible. One of the typical examples is a real-time web app framework like Socket.IO. Now if you want to enable Socket.IO in a Servlet based web app, you have to use a Netty-based implementation that listens on another port, write new implementation from scratch for Servlet, or use an alternative like Spring’s STOMP support.
If Socket.IO implementation had been written in Asity, there would be no such problems since it would just work regardless of framework. In fact, Asity is created to run Cettia, a full-featured real-time web app framework for Java, on any frameworks on the JVM. If you are interested, please check out Cettia and how it uses Asity.
- A server-side Java implementation
It has always been difficult to properly support server-side Java. If you skim the server stub generator wiki of the Swagger project, you will see that while there are 9 stubs for Java, Node and .NET has only 1 stub each. The same thing also happens in GraphQL. GraphQL Java supports only Servlet, and GraphiQL is supported only through Spring Boot.
Asity is the most suitable toolkit to support server-side Java in that a web fragment author can write a web fragment once and support almost all popular web frameworks in Java.
- Pluginification of standalone projects
From a general-purpose CMS to a collaborative real-time editor, many projects which cover both client side and server side prefer to be standalone which spawns a new process. But, in most cases, coupling two standalone applications eventually increases the overall technical debt.
Here, Asity can be used to pluginify a standalone project by converting it to a web fragment. Since arbitrary web fragment and a bridge for certain framework are mere components of the framework from a framework perspective, end-users can keep their focus on the single application they are working on, without sacrificing the cohesion.
The reason why the middleware pattern is widely adopted and used in Node.js is that Node users trust and use the Node’s HTTP module. For better or worse, Servlet has failed from this point of view. Think of Asity as an alternative of the Node’s HTTP module for Java. We can build a middleware layer for Java on top of Asity using web fragments.
JAXenter: Which frameworks are supported and why those?
Web fragments can work with serverless architecture.
Donghwan Kim: Currently, the following frameworks are supported:
- Java API for WebSocket 1 e.g. Tyrus
- Servlet 3 e.g. Tomcat, Jetty, and Undertow
- Spring WebFlux 5
- Spring MVC 4
- Vert.x 3
- Netty 4
- Grizzly 2
- Vert.x 2
- Atmosphere 2
The reason why we chose the above frameworks is that these ranked high in reports such as JetBrains’s The State of Developer Ecosystem, and also the community wanted them.
JAXenter: What’s next for Asity?
Donghwan Kim: As an abstraction layer for HTTP and WebSocket, as the name suggests, we will support even more web frameworks. In the next major version, we will support Play framework and Spark Java, and also consider supporting Function-as-a-Service like Amazon Web Service Lambda and Microsoft Azure Functions. The latter is really interesting; web fragments can work with serverless architecture.
At the same time, we will start working on the above use cases to demonstrate that Asity’s vision is effective and feasible, and also recognize and write reusable web fragments while working on them to ultimately promote an ecosystem of web fragments.
JAXenter: How can the community get involved?
Donghwan Kim: Asity aims to bring “Write Once, Run Anywhere” paradigm to Java web development. It’s something everyone may have wanted but doesn’t google for it. Please tweet about #Asity, suggest Asity if questions on StackOverflow have similar issues to the above use cases, or even better, write articles about Asity.
What if a myriad of web fragments compose Asity’s ecosystem, and accordingly the future of Java web development? If you are interested and would like to be more involved, feel free to join the mailing list and share your feedback. Or, you may want to star and watch the Github repository or follow @flowersits on Twitter to catch the latest news and updates of Asity.