Skip to content
Advertisement

JAX-RS and RegEx @Paths with spaces

Spaces in URIs are allowed if they’re encoded, as discussed here.

JAX-RS (Jersey on Payara) doesn’t seem to allow spaces defined in the path regex pattern.

JavaScript

The above regex should match the encoded ABC%20XYZ, but it doesn’t.

Request:

JavaScript

Internally, Payara throws a 404:

JavaScript

Removing %20 (space) succeeds.

In JAX-RS Spec 2.1 Final, section 3.3.2 Parameters, it states you have to explicitly disable decoding of the URI:

enter image description here

An in section 3.4 they provide an example of using space in a path:

enter image description here

I’m wondering, are spaces in regex pattern treated the same? Is the Jersey implementation incorrect, or am I doing something wrong here?

Possible issue (reported 2008, closed 2009 without resolution): https://github.com/eclipse-ee4j/jersey/issues/446

Advertisement

Answer

Regex patterns are not encoded, but Jersey match URLs in encoded form.

This workaround should work:

JavaScript

JAX-RS specification states the use of normalized URIs (section 3.7.1), and normalized URIs are encoded.

Advertisement