im still a beginner with spring boot, here im trying to fetch the data from database by using JPA then post the result with RestTemplate
and everything is okay but my problem with the Arabic language, it does not send it correctly, I have searched and I found a couple of solutions like :
set the below configuration in application.property
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
or :
String message = new String(object.getMessage().getBytes(),
StandardCharsets.UTF_8);
but im still getting same problem, any idea about this ?
note : im using Oracle 11g, with encoding type: AR8ISO8859P6
public class Messenger {
private static Messenger instance = new Messenger();
private static final RestTemplate restMessengerTemplate;
private static final HttpHeaders restMessengerHeader;
private HttpEntity<VasGateway> smsEntity;
private ResponseEntity<String> messengerResponseEntity;
static {
restMessengerTemplate = new RestTemplate();
restMessengerHeader = new HttpHeaders();
restMessengerHeader.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
restMessengerHeader.add("Authorization",
"Basic " + Base64.getEncoder().encodeToString(("user:pass").getBytes()));
}
private Messenger() {
}
public static Messenger getInstance() {
return instance;
}
public String call(String messageId, String msisdn, String messageBody, String language) throws Exception {
try {
if (msisdn.startsWith("011") || msisdn.startsWith("944")) {
smsEntity = new HttpEntity<VasGateway>(
new VasGateway(new Sendsms(new ArrayList<Message>(
Collections.singletonList(new Message(messageId, "Test", msisdn,
messageBody, language.equalsIgnoreCase("EN") ? "0" : "2"))))),
restMessengerHeader);
messengerResponseEntity = restMessengerTemplate.exchange("link",
HttpMethod.POST, smsEntity, String.class);
if (messengerResponseEntity.getStatusCode() == HttpStatus.OK) {
return "\"0\"";
} else {
return messengerResponseEntity.getStatusCode().toString();
}
}
} catch (Exception e) {
throw new Exception();
}
return "\"-1\"";
}
}