Search code examples
javaweb-servicesrestlet

Restlet Reference decoding "#" sign


I have setup a URI as below:

router.attach("/pmap/campaign/{campaign}/staffCat/{staffCat}/isp/{isp}", PMAPResource.class);

In the PMAPResource.class I have the following code:

public Representation represent()
{
    String campaignID   = (String) this.getRequestAttributes().get("campaign");
    String staffCat     = Reference.decode((String) this.getRequestAttributes().get("staffCat"));
    String ispID        = (String) this.getRequestAttributes().get("isp");
}

The staffCat field is manual input from user, it can be anything. Some examples are:

BAA2(A)
BAB1#(A)
BA B1

It works for most cases until it hits the # sign where it returns 404 Not Found error. Console dump shows the following /fwd-PMAP/pmap/campaign/1/staffCat/BAB1.

What should I do in order to read the "#" so I can get BAB1#(A) as it is?


Solution

  • # has special meaning in a URL. It must be escaped.

    There are actually many special characters in URLs, so you should always escape arbitrary text when building a URL in the client.

    In this particular case, the correct URL sent by the client would be something like:

    /fwd-PMAP/pmap/campaign/1/staffCat/BAB1%23(A)/isp/XXX

    Again, this is a problem that needs to be fixed on the client. The server will decode the %23 for you.