I have a fully localized site that has some characters in the URL path,
that are getting HTML encoded through the Response.sendTemporaryRedirect
method:
String toReturn = /*StringEscapeUtils.unescapeHtml4(redirect)*/ redirect + "?" + URLEncoder.encode(json, "UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=UTF-8");
java.net.URI location = new java.net.URI(toReturn);
return Response.temporaryRedirect(location).build();
The redirect is getting a 404 because the "%C3%B1%C3%AD"
URL piece is being misinterpreted. Decoded, it looks like this: ñí
.
I've tried URLDecoder.decode(url, 'UTF-8')
and StringEscapeUtils.escapeHtml4
prior to the redirect with no luck.
The code works fine othwerise.
Why is javax.ws.rs.core.Response.sendTemporaryRedirect
URLEncoding the URL path?
javax.ws.rs.core.Response
, but this is also happening if I use theHttpServletResponse
. There is no constructor. – PsychotomimeticHTTPServletResponse
injected via@Context
– Psychotomimeticjson
variable? Also, there's no parameter name after"?"
, that can confuse the URI parser. Last, try the multi-param constructor to avoid the implicit parsing of the single param constructornew URI("https", "some_host:port", "/", json, null)
. – AlisaHttpServletResponse
likeresponse.sendRedirect("http://your.domain:port/and/your/page?"+URLEncoder.encode(json,"utf-8"));
where json is a json, is ok. – Barraza