SJWS
Developer(s)Thomas Rudin
Stable release
1.1 / September 20, 2010 (2010-09-20)
Written inJava
Operating systemCross-platform (JVM)
TypeWeb server
LicenseGPL 3.0
Websiterudin.li

SJWS is a small Java-based HTTP server. SJWS is free software licensed under the GPL 3.0. The Main focus is for embedded Java applications, where a Jetty- or Tomcat-Server is too complicated to deploy.

Supported Content

edit

SJWS can host every readable resource and provide static and dynamic Web-Content. The dynamic Content is transparent to Java (mapped POJO's).

Content-Structure

edit

The Content accessed with a HTTP-Client has the same Structure as the Java-Class-Tree. For Example: A Server running with the Path "/webserver/htdocs" will map all Classes and Resources to the Web-Root-Directory "/".

Dynamic Page

edit

Dynamic Pages can be created programmatic in the Java Source-Code:

public class List
{

	@PostVariable
	public String myList;

	@PostEntry
	@GetEntry
	public Object doGet()
	{
		Html html = new Html();
		Body body = new Body();
		Head head = new Head();

		head.add(new StylesheetReference("css/main.css"));

		body.add(
				new Center()
				.add(new H2("Select-List"))
				.add(new BR())
				.add(new Form().setAction(this)
						.add(new Select().setName("myList")
								.add(new Option().setValue("opt1").add("Option1"))
								.add(new Option().setValue("opt2").add("Option2"))
								.add(new Option().setValue("opt3").add("Option3"))
								.add(new Option().setValue("opt4").add("Option4"))
						)
						.add(new InputSubmit().setValue("SAVE"))
				)
		);

		if (myList != null)
			body.add(new H3("You selected: " + myList));


		html.add(head, body);
		body.add(new NoScript().add(html.getObjectStack()));
		return html;
	}

}

Embedded Dynamic Content

edit

Dynamic Content can be indirectly accessed with the Java-HTML-Tag

<html>
<head>
</head>
<body>
	<java class="InlineRef"></java>
</body>
</html>

JSON Support

edit

JSON-Data Output is supported through Annotations:

public class Data
{

	@JsonVariable
	public Date myDate = new Date();

	@GetEntry
	public Object entry()
	{
		return JsonUtils.makeJson(this);
	}

}

Example

edit

The Example shows how to instantiate, start and stop the Server:

public static void main(String[] args) throws IOException
{
	/* Start server (you just need this one line and the .start() ) */
	server = new SJWServer("/example/htdocs", 8080);
	/* Register Hook-Interface to watch the Server (optional) */
	server.setHook(new Main());
	/* Start server */
	server.start();
	/* Stdout */
	System.out.println("Webserver started @ http://127.0.0.1:8080");
	System.out.println("Press <Enter> to stop");
	/* Wait for enter-key */
	System.in.read();
	/* Stop Server (optional?) */
	server.stop();
	/* Display some stats */
	System.out.println("Server stopped");
	System.out.println("Tx/Rx-Statistics:");
	System.out.println("Rx: " + server.getRxBytes());
	System.out.println("Tx: " + server.getTxBytes());
}

See also

edit

Notes

edit
edit