Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

README.org

Using Jersey in Apache Karaf

This is a small apache karaf demo application that demonstrates how to use Jersey in Apache Karaf, and how to inject OSGi services into Jersey resources.

Status

https://travis-ci.org/steinarb/jersey-demo.svg?branch=master https://coveralls.io/repos/steinarb/jersey-demo/badge.svg https://maven-badges.herokuapp.com/maven-central/no.priv.bang.demos.jerseyinkaraf/jersey-demo/badge.svg

SonarCloud

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

The structure of the Demo

The demo consists of the following maven artifacts:

  1. jerseyinkaraf The top project which in addition to containing common configuration, and the list of modules, also creates a karaf feature repository containing the features of all bundles created in the modules, and attaches the karaf feature repository to the maven artifact
  2. jerseyinkaraf.servicedef which is an OSGi bundle containing interfaces and beans defining the available OSGi services
  3. jerseinkaraf.services which is an OSGi bundle containing implementations of the services
  4. jerseyinkaraf.webapi which is an OSGi bundle that defines a REST API that plugs into the Web Whiteboard Extender and exposes the OSGi services
  5. jerseyinkaraf.webgui which is an OSGi bundle that exposes a HTML and JavaScript application that plugs into the Web Whiteboard Extender

How to install

This is how to build and install the servlet:

  1. First download and install apache karaf
  2. Clone and build jersey-demo into the local maven repository (aka. the “maven local cache”):
    git clone https://github.com/steinarb/jersey-demo.git
    cd jersey-demo
    mvn clean install
        
  3. In the apache karaf command line, install the features that pulls in the servlets with their dependencies
    feature:repo-add mvn:no.priv.bang.demos.jerseyinkaraf/jerseyinkaraf/LATEST/xml/features
    feature:install jerseyinkaraf.webapi
    feature:install jerseyinkaraf.webgui
        
  4. After this, the servlet will be listening for POST requests, at the local path “/jerseyinkaraf/api/testservice” on the karaf web server, e.g. http://localhost:8181/jerseyinkaraf for a karaf server started locally, with default settings

To uninstall the counter servlet from karaf

This is how to uninstall the servlet from karaf:

  1. At the karaf console prompt, give the following command:
    feature:uninstall webapi
        

This will cause repeated clicks on the “Increment” button to result in 405 responses, because the webgui servlet now intercepts the requests, but that servlet doesn’t support the POST requests used to increment the counter.

Reinstalling the webapi feature will cause the count to start again from 0.

License

This software project is licensed under Apache License v. 2.

See the LICENSE file for details.

About

This is a karaf application that demonstrates using Jersey to provide a REST API in karaf, and demonstrates how OSGi services can be injected into Jersey resources created by the Jersey framework.

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.