UrlEncodingService (interface)

Defines a consistent way to convert strings to/from a form safe for use within a URL.

The service is used by the framework to map mementos (derived from the state of the view model itself) into a form that can be used as a view model. When the framework needs to recreate the view model (for example to invoke an action on it), this URL is converted back into a view model memento, from which the view model can be hydrated.

API

UrlEncodingService.java
interface UrlEncodingService {
  String encode(final byte[] bytes)     (1)
  byte[] decode(String str)     (2)
  String encodeString(final String str)
  String decodeToString(final String str)
}
1 [encode__byte][encode(byte[])]

Converts the string (eg view model memento) into a string safe for use within an URL

2 decode(String)

Unconverts the string from its URL form into its original form URL.

Members

encode(byte[])

Converts the string (eg view model memento) into a string safe for use within an URL

decode(String)

Unconverts the string from its URL form into its original form URL.

Reciprocal of #encode(byte[]) .

Implementation

The framework provides a default implementation, o.a.i.core.runtimeservices.urlencoding.UrlEncodingServiceWithCompression, that first (gzip) compresses the state and then uses base-64 encoding of the resulting bytes.

Usage Notes

Defining this functionality as an SPI has two use cases:

  • first, (though some browsers support longer strings), there is a limit of 2083 characters for URLs. For view model mementos that correspond to large strings (as might occur when serializing a JAXB @XmlRootElement-annotated view model), the service provides a hook.

    For example, each memento string could be mapped to a GUID held in some cluster-aware cache.

  • the service provides the ability, to encrypt the string in order to avoid leakage of potentially sensitive state within the URL.

For large view models, there’s the possibility that the 2083 character limit could be exceeded; in such cases register an alternative implementation of this service.

See also