Quark Engine
WebConnector for Java

Just as quarks are building blocks which glues subatom particles into atoms,
Quark Engine is a small, lite and fast elementary building block between web and Java server side.

Quick introduction

Quark Engine is a small JavaScript and Java web library to enable easy dynamic remote calls to exposed Java Methods.

Easy expose Java class to web

With just a few Java Annotations, Java class and its methods can be exposed to the web. No special coding required.

Small browser footprint

Complete web module is only 7KB in size, very easy to use. Maps Java package, class and methods to JavaScript counterpart.

Auto discovery and multi-channels

Exposed methods are automatically available to the browser. Based on provided service url, HTTP/s or WebSocket will be used out of the box.

What's Included

Automatic API Registration

All Java exposed classes and methods are auto discoverable and self registered by small browser script.

JSR-380 Bean Validation

Support for method parameters constraints automatic validation based on Java JSR-380 Bean Validation Specification.

Encrypted Transport

Transported JSON data is encrypted even TLS/SSL is not used making data truly protected.

Web Http/s Channels

No need to configure anything, API service is also a call handler giving you fast and easy start.

WebSocket Channels

All calls are transparent no matter what channel type is used. Simply use ws/wss url type to make calls through WebSocket.

WebSocket Data Compression

Data compression is supported for calls through WebSocket channel. Based on WebAssembly to increase performance (open-sourced compression library).

How To Use It

Follow these few steps to make it work in Java
Create Java Servlet extending Quark API Servlet and define remote service address.

API discovery and Controller will be available through HTTP channel at http://localhost/[WEB_APP]/api
@WebServlet("/api")
public class DemoAPIServlet extends APIServlet {

}
Optionally, create Java WebSocket extending Quark API WebSocket Module and define remote service address.

WebSocket channel will be available at ws://localhost/[WEB_APP]/socket
@ExtJSSession(required = false)
@ServerEndpoint(
  value = '/socket',
  configurator = WebSocketConfigurator.class,
  decoders = { WebsocketDecoder.class},
  encoders = { WebsocketEncoder.class})
public class DemoAPIWebSocketService extends WebSocketService {

}
Finally, create Java Controller class which will be exposed to the web.
Generated web object and function will be io.greenscreens.Demo.hello

API discovery and Controller will be available at
  HTTP channel http://localhost/[WEB_APP]/api
  WebSocket channel ws://localhost/[WEB_APP]/socket
@ExtJSDirect(paths = { '/socket', '/api' })
@ExtJSAction(namespace = 'io.greenscreens', action = "Demo")
public class DemoController {

  @ExtJSMethod("hello")
  public ExtJSResponse helloWorld(final String name) {
    ExtJSResponse resp = new ExtJSResponse(true);
    resp.setMsg("Hello ".concat(name));
    return resp;
  }
}
Follow these few steps to make it work in browser
Include only 7Kb small quark.min.js script into your page
<html>
 <head>
   <script type="text/javascript" charset="UTF-8" src="lib/quark.min.js"></script>
 </head>
 <body>
 </body>
</html>
Prepare service URLs API for discovery and http channel, or optionally for WebSocket.
const ws = 'ws://localhost/demo/socket`;
const api = 'http://localhost/demo/api`;
Initialize engine. Engine will use provided URLs to register exposed Java classes and methods.
await Engine.init({api: api, service:api});
or
await Engine.init({api: api, service:ws});
Call Java exposed method. Namespace 'io.greenscreens' , action 'Demo' and method 'hello' are the same as defined Java Class on server side.
const data = await io.greenscreens.Demo.hello('John Doe');
console.log(data);