Skip to content

Version 0.2.1

Latest
Compare
Choose a tag to compare
@mestebangutierrez mestebangutierrez released this 16 Jun 22:48
· 13 commits to master since this release

Release Notes

Version 0.2.1 is now available. This release includes the new features, enhancements and fixes described below.

New features

Addition of HTTP content-negotiation utilities

This feature is oriented to the framework developer and consists on a collection of utility classes for supporting the HTTP content negotiation process.

The mechanism provided carries out the content negotiation taking into account both the supported and the acceptable media types, character encodings, and languages.

The mechanism implements a simplified version of the HTTP Remote Variant Selection Algorithm -- RVSA/1.0 defined in RFC 2296.
The differences between the implemented algorithm and the original one are the following:

  1. There is no support for features,
  2. Variant source-quality is assigned linearly (with ratio -0.125) of the values suggested in Section 5.3 of RFC 2296;
  3. The round5 function is not applied during the computation of overall quality values.

The reason for this latter difference is that in the presence of fine-grained qualities (i.e., 0.001) computed quality values converge to 10^-12, and can make variants with non-zero computed qualities appear like they are not amenable to selection.

You can see an example usage of these utilities down below:

MediaType TEXT_HTML = MediaTypes.of("text", "html");
MediaType POSTSCRIPT = MediaTypes.of("application", "postscript");
CharacterEncoding UTF_8 = CharacterEncodings.of(StandardCharsets.UTF_8);
CharacterEncoding US_ASCII = CharacterEncodings.of(StandardCharsets.US_ASCII);
CharacterEncoding ISO_8859_1 = CharacterEncodings.of(StandardCharsets.ISO_8859_1);
Language FRENCH = Languages.of(Locale.FRENCH);
Language ENGLISH = Languages.of(Locale.ENGLISH);

NegotiationResult result =
	ContentNegotiator.
		newInstance().
			// Client side preferences
			accept("*/*;q=0.8").
			accept("text/html;q=1.0").
			acceptLanguage("en;q=1.0").
			acceptLanguage("fr;q=0.5").
			acceptCharset("utf-8").
			acceptCharset("iso-8859-1").
			// Server side preferences
			support(ContentNegotiator.DEFAULT_MEDIA_TYPE).
			support(POSTSCRIPT).
			support(FRENCH).
			support(ENGLISH).
			support(UTF_8).
			support(ISO_8859_1).
			support(Variants.builder().type(TEXT_HTML).language(ENGLISH).alternative(0.5D)).
			support(Variants.builder().type(TEXT_HTML).language(FRENCH).alternative(0.7D)).
			support(Variants.builder().type(POSTSCRIPT).language(ENGLISH).alternative(1.0D)).
			negotiate();

assertThat(result.isAcceptable(),equalTo(true));
assertThat(result.variant().type(),equalTo(TEXT_HTML));
assertThat(result.variant().language(),equalTo(ENGLISH));
assertThat(result.variant().charset(),nullValue());
assertThat(result.quality(),equalTo(0.5D));

For the server preferences above, we can calculate with the abovementioned algorithm the alternatives available for content negotiation:

{0.500 {type text/html} {language en}}
{0.700 {type text/html} {language fr}}
{1.000 {type application/postscript} {language en}}
{1.000 {type text/plain} {charset utf-8} {language fr}}
{0.875 {type text/plain} {charset utf-8} {language en}}
{0.750 {type application/postscript} {charset utf-8} {language fr}}
{0.625 {type application/postscript} {charset utf-8} {language en}}

We can see that the result is not the best server alternative, but the alternative that best matches the client requiremente (text/html and en with q=1.0). We can also see that despite both the client and server support UTF-8, the response does not include that charset as the winning alternative does not specify it.

Enhancements

Improved Travis CI configuration

  • Updated build scripts in '.travis/' to leverage the CI environment variable for tuning the execution.
    Thus, if the variable equals to 'skip' the execution of the scripts'functionalities will be totally skipped. However, if the value is 'porcelain' all the checks prior to their execution will be carried out, but no the functionalities themselves.
    In addition, the QA script checks if the value is 'noqa' in which case, the SonarQube analysis is skipped.
  • Updated scripts to avoid using the 'exit' built-in command as it may interfere with the CI internals (see https://docs.travis-ci.com/user/customizing-the-build/#How-does-this-work%3F-(Or%2C-why-you-should-not-use-exit-in-build-steps)).
  • Enhanced the way in which the QA script checks whether or not the SonarQube server is available. Apart from enforcing the success of the curl command (i.e., a response is received), check that the response is an OK. Additional information is provided in case of failure. It is possible to select which application to use for carrying out check (curl/wget) leveraging the CHECKER environment variable. By default, wget will be used.
    Additional log messages for the checking process can be shown by setting the DEBUG environment variable to 'verbose'.
  • Provide additional information if the unshallowing of the git repository fails.
  • Enabled debugging the shell script leveraging the DEBUG environment variable. A value 'trace' will enable the 'xtrace' Bash option (see http://tldp.org/LDP/abs/html/options.html). The debugging capabilities hide sensible information (i.e., passwords) in the logs.
  • Granted clean termination of the QA script (disabling the usage of the 'errexit' Bash option and always returning 0) in avoid breaking the build accidentally.

Other

  • Issue #20: Remove deprecated method org.ldp4j.application.ApplicationContext.disposeSession(WriteSession)

Fixes

  • Issue #19: MutableDataSet isEmpty method returns its negated expected value
  • Issue #22: Response body encoding problems when using entities that mix data from various charsets