Various servets and filters

Steinar Bang 76bd0808f8 Add version 1.1.3 to the release history in the README and update README examples to use version 1.1.3 3 months ago
jacoco-coverage-report 67640ec39c [maven-release-plugin] prepare for next development iteration 3 months ago
servlet.frontend 67640ec39c [maven-release-plugin] prepare for next development iteration 3 months ago
servlet.jersey 67640ec39c [maven-release-plugin] prepare for next development iteration 3 months ago
src e7759ffca4 Add JerseyServlet intended to be used as base class for DS components implementing REST APIs with the web whiteboard 4 months ago
.editorconfig b8b3a8dbc1 Add servlet implementing common operations for serving out webpack'ed JavaScript frontends 6 months ago
.gitignore b8b3a8dbc1 Add servlet implementing common operations for serving out webpack'ed JavaScript frontends 6 months ago
.travis.yml e1ba11a5ac Add new maven module to build an aggregate jacoco test coverage XML file and use this XML file on sonarcloud to fix 0% test coverage 4 months ago
LICENSE b8b3a8dbc1 Add servlet implementing common operations for serving out webpack'ed JavaScript frontends 6 months ago
README.org 76bd0808f8 Add version 1.1.3 to the release history in the README and update README examples to use version 1.1.3 3 months ago
pom.xml 67640ec39c [maven-release-plugin] prepare for next development iteration 3 months ago

README.org

Java servlet common code

Servlet and filter classes that are intended to be inherited to cut down on boilerplate code

Status of the project

file:https://travis-ci.org/steinarb/servlet.svg?branch=master file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.servlet%3Aservlet&metric=alert_status#.svg file:https://maven-badges.herokuapp.com/maven-central/no.priv.bang.servlet/servlet/badge.svg file:https://www.javadoc.io/badge/no.priv.bang.servlet/servlet.svg

Sonarqube

file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.servlet%3Aservlet&metric=ncloc#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.servlet%3Aservlet&metric=bugs#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.servlet%3Aservlet&metric=vulnerabilities#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.servlet%3Aservlet&metric=code_smells#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.servlet%3Aservlet&metric=coverage#.svg

Release history

Date Version Comment
<2020-04-09 Thu 22:40> 1.1.3 Compile and runtime dependencies to jersey 2.30.1, runtime dependencies to jackson 2.10.3
<2020-03-05 Thu 18:22> 1.1.2 Use runtime dependency to jackson-databind 2.9.10.3 to fix security issue CVE-2020-8840
<2020-02-21 Fri 22:42> 1.1.1 Bugfix release of the JerseyServlet with correct method name
<2020-02-19 Wed 07:52> 1.1.0 First release of the JerseyServlet
<2020-01-12 Sun 23:26> 1.0.0 First release of the FrontendServlet

Overview of the project

Frontend

This is a servlet that's intended to be extended by a servlet serving out a JS frontend packed by webpack.

The servlet will search for resources matching the pathInfo (minus the webcontext) on the classpath and serve them out, setting the content type based on the file name extension.

The servlet will try serving the file "index.html" (that must exist on the classpath) for a list of routes, that can be set by a subclass. This is to handle reloads of URLs set by e.g. the react router.

To use the servlet in an application built with maven, add the maven dependency:

no.priv.bang.servlet servlet.frontend 1.1.3

    To use the servlet in a webapp running in the apache karaf web whiteboard apache:
  1. Add a maven dependency
  2. #+begin_src xml no.priv.bang.servlet servlet.frontend 1.1.3 provided #+end_src
  3. Create an OSGi bundle containing a DS component registering with the web whiteboard
  4. #+begin_src java @Component(service={Servlet.class}, property={"alias=/myapp"}) public class ReactServlet extends FrontendServlet { public ReactServlet() { super(); setRoutes("/", "/counter", "/about"); }
    @Reference public void setLogservice(LogService logservice) { super.setLogService(logservice); } } #+end_src
  1. Add a runtime dependency to the bundle project's template feature repository (i.e. src/main/feature/feature.xml in the bundle project):
  2. #+begin_src xml mvn:no.priv.bang.servlet/servlet/1.0.0/xml/features frontend-servlet #+end_src

Jersey

This is a servlet that's intended to be extended by a servlet using jersey to implement a REST API.

    The JerseyServlet does two things:
  1. Adds a way to add injected OSGi services to the HK2 dependency injection container, so that the OSGi services can be injected into Jersey resources, allowing the Jersey resources to be thin shims over OSGi service calls
  2. Adds the subpackage ".resources" of the servlet's package as the default package to scan for Jersey resources Note! If a different package is set by configuration, this will override the default

To use the servlet in an application built with maven, add the maven dependency:

no.priv.bang.servlet servlet.jersey 1.1.3

    To use the servlet in a webapp running in the apache karaf web whiteboard apache:
  1. Add a maven dependency
  2. #+begin_src xml no.priv.bang.servlet servlet.jersey 1.1.3 provided #+end_src
  3. Create an OSGi bundle containing a DS component registering with the web whiteboard.
  4. #+begin_src java package no.priv.bang.servlet.jersey.test;

@Component(service={Servlet.class}) public class ExampleJerseyServlet extends JerseyServlet {

@Reference public void setHelloService(HelloService service) { addInjectedOsgiService(HelloService.class, service); }

    @Reference public void setLogService(LogService logservice) { super.setLogService(logservice); } } #+end_src /Note/! [[http://javadox.com/org.osgi/osgi.cmpn/6.0.0/org/osgi/service/log/LogService.html][The OSGi LogService]] must be added by a separate method, since the LogService is used by the JerseyServlet itself (as well as being added to HK2, which makes it possible to use LogService in Jersey resources).
  1. Add resources implementing REST API endpoints in the .resources sub-package of the servlet's package, and use @Inject to inject the OSGi services that JerseyServlet adds to the HK2 dependency injection container:
  2. #+begin_src java package no.priv.bang.servlet.jersey.test.resources;

@Path("/hello") public class HelloResource {

@Inject HelloService service;

    @GET @Produces("text/plain") public String getHello() { return service.hello(); } } #+end_src
  1. Add a runtime dependency to the bundle project's template feature repository (i.e. src/main/feature/feature.xml in the bundle project):
  2. #+begin_src xml mvn:no.priv.bang.servlet/servlet/1.1.3/xml/features jersey-servlet #+end_src

License

This code is licensed under the Apache license v. 2. See the LICENSE file for details.