Servlicle

Provide a Java Servlet which will respond with a file in a decent way.

License

License

GroupId

GroupId

com.totalchange.servlicle
ArtifactId

ArtifactId

servlicle-parent
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

pom
Description

Description

Servlicle
Provide a Java Servlet which will respond with a file in a decent way.
Project URL

Project URL

https://github.com/KolonelKustard/servlicle
Project Organization

Project Organization

TotalChange
Source Code Management

Source Code Management

https://github.com/KolonelKustard/servlicle

Download servlicle-parent

How to add to project

<!-- https://jarcasting.com/artifacts/com.totalchange.servlicle/servlicle-parent/ -->
<dependency>
    <groupId>com.totalchange.servlicle</groupId>
    <artifactId>servlicle-parent</artifactId>
    <version>1.0.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.totalchange.servlicle/servlicle-parent/
implementation 'com.totalchange.servlicle:servlicle-parent:1.0.0'
// https://jarcasting.com/artifacts/com.totalchange.servlicle/servlicle-parent/
implementation ("com.totalchange.servlicle:servlicle-parent:1.0.0")
'com.totalchange.servlicle:servlicle-parent:pom:1.0.0'
<dependency org="com.totalchange.servlicle" name="servlicle-parent" rev="1.0.0">
  <artifact name="servlicle-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.totalchange.servlicle', module='servlicle-parent', version='1.0.0')
)
libraryDependencies += "com.totalchange.servlicle" % "servlicle-parent" % "1.0.0"
[com.totalchange.servlicle/servlicle-parent "1.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • tomcat8
  • servlicle

Servlicle

Provide a Java Servlet which will respond with a file in a decent way.

It's pretty annoying how each Servlet container has a "default" servlet which will return a file from your web app but only if said file exists in the web archive space of your web app. For those cases when the file comes from somewhere else you have to do some tedious stream mangling.

Servlicle provides container specific hacks to re-use the containers default servlet to return a file whose path you provide. This adds a lot of benefits such as re-use, support for weird annoying to implement things like Range's and it avoids stupid boilerplate code in your Servlet app.

Currently there is support for:

  • Tomcat 8

The hacks will be tried in the order of the above list. If the hacks fail to start up for the containers mentioned above then it will fall back to a rubbish implementation.

If your choice of container isn't available above then please add it and submit a pull request!

Oh and just to note that if you're thinking of using this in Production then maybe have a re-think of how you're doing things as for static resources in the majority of cases it'd be better to serve them from some kind of CDN.

How to Servlicle

Add the dependency to your pom.xml as follows:

<dependency>
  <groupId>com.totalchange.servlicle</groupId>
  <artifactId>servlicle</artifactId>
  <version>1.0.0</version>
</dependency>

or download from http://mvnrepository.com/artifact/com.totalchange.servlicle/servlicle

Then add a Servlet which extends Servliclet as follows:

@WebServlet("/servliclet")
public final class MyServliclet extends Servliclet {
    @Override
    protected File gimmeFile(HttpServletRequest request,
            HttpServletResponse response) {
        return new File("/my/file.mp4");
    }
}

Versions

Version
1.0.0