项目作者: sorskod

项目描述 :
Guice WebServer Module - backed by latest Jetty, Jersey and Jackson.
高级语言: Java
项目地址: git://github.com/sorskod/webserver.git
创建时间: 2017-08-18T19:27:52Z
项目社区:https://github.com/sorskod/webserver

开源协议:MIT License

下载


webserver

Guice WebServer Module - backed by latest Jetty, Jersey and Jackson. Without HK2-Guice bridge.

Library is useful for lite web services. Following JAX-RS convention it’s so easy to write from simple to very complex REST endpoints. Library is simple, fast with small footprint. The library is written to fully support JSON as input and output format.

Build Status

Dependencies

  • Guice
  • Jetty
  • Jersey
  • Jackson 2 (Transitive)

Installation

In your POM file, add following dependency:

  1. <dependency>
  2. <groupId>com.sorskod.webserver</groupId>
  3. <artifactId>webserver</artifactId>
  4. <version>1.1.0</version>
  5. </dependency>

Note: You may want to check for the latest version.

Snapshot installation

For the latest snapshot version, you need to add add OSS Sonartype repository to your POM file and the following dependency:

  1. <project>
  2. <repositories>
  3. <repository>
  4. <id>oss-sonatype</id>
  5. <name>oss-sonatype</name>
  6. <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
  7. <snapshots>
  8. <enabled>true</enabled>
  9. </snapshots>
  10. </repository>
  11. </repositories>
  12. <dependencies>
  13. <dependency>
  14. <groupId>com.sorskod.webserver</groupId>
  15. <artifactId>webserver</artifactId>
  16. <version>1.1-SNAPSHOT</version>
  17. </dependency>
  18. </dependencies>
  19. </project>

Usage

There is a working example in test package. However, here is the short guideline:

  1. Bind all JAX-RS resource classes in Guice context. (All classes annotated with @Path will be registered in Jersey’s context. Jersey’s auto-discovery feature is disabled.)
  2. Install WebServerModule
  3. Install HTTPConnectorModule or/and HTTPSConnectorModule
  4. Provide Configurator implementation
  5. Inject Jetty Server and call start()

Example:

  1. public class MyModule extends AbstractModule {
  2. protected void configure() {
  3. // Bind @Path annotated classes
  4. bind(MyHttpResource.class);
  5. }
  6. @Provides
  7. @DefaultConnector
  8. Configurator configuratorProvider() {
  9. return () -> 8080; // WebServer port
  10. }
  11. @ProvidesIntoSet
  12. Feature customJaxrsFeature() {
  13. // Provide custom features, register filters, etc
  14. return (context) -> {};
  15. }
  16. }
  17. Injector injector = Guice.createInjector(new WebServerModule(),
  18. new HTTPConnectorModule(),
  19. new MyModule());
  20. injector.getInstance(Server.class).start();

NOTE

Library is written for fun and test purposes. Pull requests and improvement ideas are welcome.

TODO

  • Remove HK2 and make Guice as only DI framework (Hard to accomplish)
  • README & Wiki
  • Example project