All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class IdenticonServletextends HttpServlet
This servlet generates identicon (visual identifier) images ranging from 16x16 to 1024x1024 in size.

Supported Image Formats

Currently only PNG is supported because javax.imageio package does not come with built-in GIF encoder and PNG is the only remaining reasonable format.

Initialization Parameters:

version
bump this to invalidate cached identicons after a change that alters the rendered result. It is part of the ETag. Defaults to 1. (Optional)
cacheProvider
full class path to IdenticonCache implementation. Without one, every request is rendered and nothing is cached. (Optional)

Request Parameters

c
identicon code to render, as a number, a base32 or base64 hash, or any other string. Required: a request without it is answered with 404 rather than an identicon derived from the requester's IP address. (Required)
s
identicon size in pixels. Defaults to 32x32. Values outside 16 to 1024 are clamped to that range, and a non-numeric value is ignored in favour of the default. (Optional)
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Fixed id, the servlet is never serialized across versions.
      See Also:
    • INIT_PARAM_VERSION

      private static final String INIT_PARAM_VERSION
      Init parameter naming the cache version.
      See Also:
    • INIT_PARAM_CACHE_PROVIDER

      private static final String INIT_PARAM_CACHE_PROVIDER
      Init parameter naming the cache implementation.
      See Also:
    • PARAM_IDENTICON_SIZE_SHORT

      private static final String PARAM_IDENTICON_SIZE_SHORT
      Request parameter naming the identicon size.
      See Also:
    • PARAM_IDENTICON_CODE_SHORT

      private static final String PARAM_IDENTICON_CODE_SHORT
      Request parameter naming the identicon seed.
      See Also:
    • IDENTICON_IMAGE_FORMAT

      private static final String IDENTICON_IMAGE_FORMAT
      Image format the servlet writes identicons in.
      See Also:
    • IDENTICON_IMAGE_MIMETYPE

      private static final String IDENTICON_IMAGE_MIMETYPE
      Content type sent with an identicon.
      See Also:
    • DEFAULT_IDENTICON_EXPIRES_IN_MILLIS

      private static final long DEFAULT_IDENTICON_EXPIRES_IN_MILLIS
      Identicons are cached for 24 hours by default.
      See Also:
    • DEFAULT_IDENTICON_SIZE

      static final int DEFAULT_IDENTICON_SIZE
      Requested size when the "s" parameter is missing or unparsable.
      See Also:
    • MIN_IDENTICON_SIZE

      static final int MIN_IDENTICON_SIZE
      Smallest size the renderer is asked for; smaller requests are clamped up.
      See Also:
    • MAX_IDENTICON_SIZE

      static final int MAX_IDENTICON_SIZE
      Largest size the renderer is asked for; larger requests are clamped down.
      See Also:
    • version

      private int version
      Rendering version, folded into the ETag so rendering changes force a refresh.
    • renderer

      private final IdenticonRenderer renderer
      Draws the PNG for a given code and size.
    • cache

      private IdenticonCache cache
      Optional rendered-image cache; null disables caching.
    • identiconExpiresInMillis

      private long identiconExpiresInMillis
      How long a cached image stays fresh, in milliseconds.
  • Constructor Details

    • IdenticonServlet

      public IdenticonServlet()
      Constructor. Jetty instantiates the servlet reflectively with no arguments and configures it through init parameters, so a bare instance is expected.
  • Method Details