I need to pass a constraint value which contains text from different UTF languages (German, Serbian, Catalan, Chinese, ....) as a queryParam in my HTTP Request.
Tried using URLEncoder.encode and URLDecoder.decode from the other side but didn't work.
Tried using UriComponent.encode/decode and also didnt help.
Tried adding a header to my request with utf-8 charset.
Tried using @Connsumes/@Produces/@Encoded jersy annotation but still the same.
Client side:
private static final String ENCODING = "UTF-8";
private static final String CHARSET= "charset=" + ENCODING;
Invocation.Builder builder;
try {
builder = baseTarget.path(apiPath + "setConstraint")
//.queryParam("constraint", constraint)
.queryParam("constraint",UriComponent.encode(constraint, UriComponent.Type.FRAGMENT))
.queryParam("path", URLEncoder.encode(jsonRuleIdString, ENCODING))
.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON + "; " + CHARSET );
} catch (UnsupportedEncodingException ex) {
throw new SpecificationException(ex.getMessage());
}
...
Server side:
@RequestMapping (method = RequestMethod.POST, value= "setConstraint")
@Consumes({ MediaType.APPLICATION_JSON + ";charset=UTF-8"})
@Produces({ MediaType.APPLICATION_JSON + ";charset=UTF-8"})
public RuleStruct setConstraint(
@RequestParam(value="constraint", required = true) @Encoded String constraint,
@RequestParam(value="path", required = true) String strPath) throws SpecificationException, ProjectManagementException {
logger.info("Set Constraint");
RuleId path;
try {
path = strPath.isEmpty() ? null : mapper.readValue(URLDecoder.decode(strPath, ENCODING), RuleId.class);
constraint = UriComponent.decode(constraint, UriComponent.Type.FRAGMENT);
} catch (IOException e) {
throw new SpecificationException(e.getMessage());
}
return getRuleEditorService(sessionId).editRule(path).setConstraint(constraint);
}
Regards.