A servlet to capture POST bodies into files

dependabot[bot] bd2fbc4671 Bump junit from 4.12 to 4.13.1 3 years ago
src 1f49ffb309 Make Servlet field final, as required by Sonar. 6 years ago
.editorconfig c29b084618 Initial commit. 6 years ago
.gitignore c29b084618 Initial commit. 6 years ago
.travis.yml c29b084618 Initial commit. 6 years ago
LICENSE c29b084618 Initial commit. 6 years ago
README.org 34e3f5db87 Use the new sonarcloud badges in the README. 6 years ago
pom.xml bd2fbc4671 Bump junit from 4.12 to 4.13.1 3 years ago

README.org

A servlet to capture POST bodies into files

I needed something that could capture POST bodies so that I could use real POST bodies in unit tests (specifically: I needed some examples of Sonar Webhooks for my sonar-collector utility).

    The solution was this servlet:
  1. The servlet installs into an apache karaf instance
  2. All POST bodies are written to a temp file, and the file name is written to the log as an INFO message. Example log message:
  3. #+BEGIN_EXAMPLE [INFO] Saved body of POST to http://localhost:8181/post-body-capture to file: /tmp/postbodycaptureservlet628424040798817132.json #+END_EXAMPLE

Note: The temp files aren't cleaned up by the servlet or when uninstalling the servlet, so leaving this servlet running can create a lot of clutter in the temp directory.

Note also, that this servlet is written to be installed as a karaf feature in Apache Karaf and connect to the Pax Web Whiteboard Extender.

But outside of OSGi, Pax Web and Karaf, this is just a plain servlet with no special dependencies, and can presumably be used everywhere such a servlet can be used. I haven't tried this myself, however.

Status

file:https://travis-ci.org/steinarb/post-body-capture.svg?branch=master file:https://coveralls.io/repos/steinarb/post-body-capture/badge.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.debug-utils%3Apost-body-capture&metric=alert_status#.svg file:https://maven-badges.herokuapp.com/maven-central/no.priv.bang.debug-utils/post-body-capture/badge.svg

SonarCloud

file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.debug-utils%3Apost-body-capture&metric=ncloc#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.debug-utils%3Apost-body-capture&metric=bugs#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.debug-utils%3Apost-body-capture&metric=vulnerabilities#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.debug-utils%3Apost-body-capture&metric=code_smells#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.debug-utils%3Apost-body-capture&metric=coverage#.svg

How to install

    This is how to build and install the servlet:
  1. First download and install apache karaf
  2. In the apache karaf command line, install the feature that pulls in the servlet with dependencies
  3. #+BEGIN_EXAMPLE feature:repo-add mvn:no.priv.bang.debug-utils/post-body-capture/LATEST/xml/features feature:install post-body-capture #+END_EXAMPLE
  4. After this, the servlet will be listening for POST requests, at the local path "/post-body-capture" on the karaf web server, e.g. http://localhost:8181/post-body-capture for a karaf server started locally, with default settings

To uninstall the servlet from karaf

    This is how to uninstall the servlet from karaf:
  1. At the karaf console prompt, give the following command:
  2. #+BEGIN_EXAMPLE feature:uninstall post-body-capture #+END_EXAMPLE

This will disconnect the servlet from the Pax Web Whiteboard Extender and uninstall the servlet, and all dependencies (e.g. Pax Web) that has been pulled in by this feature.

However, if a different feature has pulled in the same dependencies, the dependencies won't be uninstalled until everything that has required them is uninstalled.

License

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

See the LICENSE file for details.