jmws

Java micro web server

License

License

GroupId

GroupId

org.riversun
ArtifactId

ArtifactId

jmws
Last Version

Last Version

1.3.3
Release Date

Release Date

Type

Type

jar
Description

Description

jmws
Java micro web server
Project URL

Project URL

https://github.com/riversun/jmws
Source Code Management

Source Code Management

https://github.com/riversun/jmws

Download jmws

How to add to project

<!-- https://jarcasting.com/artifacts/org.riversun/jmws/ -->
<dependency>
    <groupId>org.riversun</groupId>
    <artifactId>jmws</artifactId>
    <version>1.3.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.riversun/jmws/
implementation 'org.riversun:jmws:1.3.3'
// https://jarcasting.com/artifacts/org.riversun/jmws/
implementation ("org.riversun:jmws:1.3.3")
'org.riversun:jmws:jar:1.3.3'
<dependency org="org.riversun" name="jmws" rev="1.3.3">
  <artifact name="jmws" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.riversun', module='jmws', version='1.3.3')
)
libraryDependencies += "org.riversun" % "jmws" % "1.3.3"
[org.riversun/jmws "1.3.3"]

Dependencies

compile (2)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar [2.9.9,)
com.fasterxml : jackson-xml-databind jar 0.6.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.7

Project Modules

There are no modules declared in this project.

Overview

JMWS(Java micro web server) is a simple httpd for Java.

  • Web server
  • Web app server - Host your Micro Service like REST API
  • Has basic http operations POST/GET
  • Supports RFC 2388 multipart message.
    (File uploading and something.)

Maven Central

Purpose

  • Debug your web site
  • Debug your micro services logic
  • Debug your front end apps - JMWS runs straightforward without unnecessary caching.
  • Embedded server

It is licensed under MIT.

Quick start

Example Code 1 : Publish your directory to WEB

Example1.java

package com.example;

import org.riversun.jmws.WebServer;

public class Example1 {

	public static void main(String[] args) {

		final int port = 80;
		final WebServer server = new WebServer(port);

		// Publish "/usr/local/htdocs" for "/"
		server.addDirectory("/", "/usr/local/htdocs");

		server.startServer();
	}
}

Example Code 2 : Publish your REST API( GET Style) to WEB

{"result":"apple-pen" }

Example2.java

package com.example;

import java.io.*;
import org.riversun.jmws.*;
import org.riversun.jmws.core.*;

public class Example2 {

	public static void main(String[] args) {

		final int port = 80;

		final WebServer server = new WebServer(port);

		server.addService("/example", new MicroService() {

			@Override
			public void service(HttpReq req, HttpRes res) throws Exception {

				res.setContentType("application/json; charset=UTF-8");

				String str1 = req.asString("str1");
				String str2 = req.asString("str2");

				String resultText = (str1 != null ? str1 : "") + "-" + (str2 != null ? str2 : "");

				String responseJsonText = "{\"result\":\"" + resultText + "\" }";

				OutputStream os = res.getOutputStream();
				PrintWriter out = new PrintWriter(os);
				out.println(responseJsonText);
				out.flush();
				out.close();

			}
		});

		server.startServer();
	}
}

Example Code 3 : Publish your REST API (JSON POST Style) to WEB

Example3.java

package com.example;

import java.io.*;
import org.riversun.jmws.*;
import org.riversun.jmws.core.*;

public class Example3
{
	public static void main(String[] args)
	{

		final int port = 80;

		final WebServer server = new WebServer(port);

		server.addService("/json_api", new MicroService() {

			@Override
			public void service(HttpReq req, HttpRes res) throws Exception {

				// Do handle request
				final StringBuffer sb = new StringBuffer();

				String line = null;
				BufferedReader reader = req.getReader();
				while ((line = reader.readLine()) != null) {
					sb.append(line);
				}
				final String requestJsonText = sb.toString();

				System.out.println(requestJsonText);

				// Do respond
				res.setContentType("application/json; charset=UTF-8");

				String responseJsonText = "{\"result\":\"" + "somthing" + "\" }";

				OutputStream os = res.getOutputStream();
				PrintWriter out = new PrintWriter(os);
				out.println(responseJsonText);
				out.flush();
				out.close();

			}
		});

	}
}

Tips

  • If you want to stop the server.
server.stopServer();
  • Add listener for server status callback
server.setServerCallback(new ServerCallBack() {
			@Override
			public void onServerStatUpdated(EServerStatus serverStatus, String message) {
				System.out.println("serverStatus=" + serverStatus + " message=" + message);
			}
		});

Downloads

maven

  • You can add dependencies to maven pom.xml file.
<dependency>
  <groupId>org.riversun</groupId>
  <artifactId>jmws</artifactId>
  <version>1.2.0</version>
</dependency>

Versions

Version
1.3.3
1.3.1
1.3.0
1.2.0
1.1.0
1.0.5
1.0.4
1.0.3
1.0.1
1.0.0