Reputation: 1
So, I am working on a project using Twilio API in Java and Spring Boot but I am getting this error.
"PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
Please, provide any help or any resource if available.
This is my Controller:
@PostMapping("/trigger-alert")
public String triggerAlert(@RequestBody String phoneNumbers, Model model) {
try {
String message = "Alert: Something happened!";
smsService.sendBulkSms(phoneNumbers, message);
model.addAttribute("message", "Alert triggered, SMS sent to multiple numbers!");
model.addAttribute("phoneNumbers", phoneNumbers);
return "success";
}catch (Exception e){
System.out.println(e.getMessage());
}
return "error";
}
And this is the Service this controller is using:
public SMSService() {
Twilio.init(Account_SSID, Auth_TOKEN);
}
public void sendBulkSms(String phoneNumbers, String messageContext) {
// Implement SMS sending logic here
for (String splitPhoneNumber : splitPhoneNumbers(phoneNumbers)) {
sendSMS(splitPhoneNumber, messageContext);
}
}
private void sendSMS(String to, String userMessage){
Message message = Message.creator(
new PhoneNumber(to),
new PhoneNumber(Twilio_PhNum),
userMessage
).create();
System.out.println("Sent Message to " + to + ": " + message.getSid());
}
public static ArrayList<String> splitPhoneNumbers(String phoneNumbersCommaSeparated) {
// Trim the input string to remove any leading or trailing whitespace
String trimmedInput = phoneNumbersCommaSeparated.trim();
// Check if the input is empty
if (trimmedInput.isEmpty()) {
return new ArrayList<>(); // Return an empty ArrayList if input is empty
}
// Split the input string by commas
String[] phoneNumbersArray = trimmedInput.split("\\s*,\\s*");
// Convert the array to an ArrayList
return new ArrayList<>(Arrays.asList(phoneNumbersArray));
}
tried few things but its not working.
Upvotes: 0
Views: 14