Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src/main
README.md
pom.xml

README.md

"Hello World" Server Examples:

  1. HTTP Server Example - a simple HTTP Server utilizing HttpServerLauncher.
  2. HTTP Multithreaded Server Example - HTTP multithreaded server example.
  3. HTTP Client Example - an HTTP client example utilizing Launcher.

Launch

Servlet Examples:

  1. Middleware Servlet Example - an example of MiddlewareServlet usage.
  2. Request Parameter Example - an example of processing requests with parameter.
  3. Static Servlet Example - an example of StaticServlet utilizing.

Launch

1. "Hello World" Server Examples

Launch

To run the examples in an IDE, you need to clone DataKernel locally and import it as a Maven project. Then you should set up default working directory of run configurations in your IDE so that the examples can work correctly. In accordance to DataKernel module structure, the working directory should be set to the module folder.

In IntelliJ IDEA you can do it in the following way: Run -> Edit configurations -> |Run/Debug Configurations -> |Templates -> Application| -> |Working directory -> $MODULE_WORKING_DIR$||.

Before running the examples, build the project (Ctrl + F9 for IntelliJ IDEA).

Then open one of the classes:

  • HttpServerExample
  • HttpMultithreadedExample which are located at datakernel -> examples -> http and run main() of the chosen example.

To check how HTTP Server Example or HTTP Multithreaded Server Example works, you should start your client by opening HttpClientExample class which is located at the same folder and running its main() method.

Explanation

If you connect to the multithreaded server, you'll receive a message representing which worker processed your request:

"Hello from worker server #..." 

Otherwise, you'll see a message: "Hello World!"

The difference between HTTP Multithreaded Server Example and HTTP Server Example is that the first one creates several worker threads for requests processing.

HttpServerExample utilizes HttpServerLauncher while HttpMultithreadedServerExample extends MultithreadedHttpServerLauncher. When using predefined launchers, you should override the following methods:

  • getBusinessLogicModules() - to specify the actual logic of your application
  • getOverrideModules() - to override default modules.

2. Servlet Examples

Launch

To run the examples in an IDE, you need to clone DataKernel locally and import it as a Maven project. Then you should set up default working directory of run configurations in your IDE so that the examples can work correctly. In accordance to DataKernel module structure, the working directory should be set to the module folder.

In IntelliJ IDEA you can do it in the following way: Run -> Edit configurations -> |Run/Debug Configurations -> |Templates -> Application| -> |Working directory -> $MODULE_WORKING_DIR$||.

Before running the examples, build the project (Ctrl + F9 for IntelliJ IDEA).

Then open one of the classes:

  • MiddlewareServletExample
  • RequestParametrExample
  • StaticServletExample

which are located at datakernel -> examples -> http and run main() of the chosen example.

Now you can connect to you server by visiting localhost:8080 in your browser.

Explanation

Middleware Servlet Example processes requests and redirects you to chosen web-page. You can set up configurations for your Servlet with method with(). It sets up HTTP methods (optionally), paths and AsyncServlet.

Request Parameter Example represents requests with parameters which are received with getPostParameters() and then utilized with postParameters.get().

Static Servlet Example shows how to set up and utilize StaticServlet. Method StaticServlet.create() returns a new StaticServlet.

You can’t perform that action at this time.