I am trying to make a request and Below is the code I wrote.
import model.GlmRequest;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import util.SslUtil;
@RestController
@RequestMapping("/glm")
public class GLMRestController {
@PostMapping("/service")
public ResponseEntity<String> service(@RequestBody GlmRequest request) {
// Prepare HTTP headers
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("authKey", request.getAuthKey());
headers.set("authToken", request.getAuthKey());
// Create HTTP entity
HttpEntity<String> requestEntity = new HttpEntity<>(request.getJson(), headers);
try {
// Make POST request using RestTemplate
ResponseEntity<String> responseEntity = SslUtil.getRestTemplateWithDisabledSslVerification().exchange(
request.getUri(),
HttpMethod.POST,
requestEntity,
String.class
);
// Extract and return response body
String response = responseEntity.getBody();
return ResponseEntity.ok(response);
} catch (HttpClientErrorException.BadRequest ex) {
// Handle 400 Bad Request error
// You can extract and return the error message from the response body
String responseBody = ex.getResponseBodyAsString();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseBody);
}
}
}
I am getting the below error.
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for “https://score.farmmutualre.com/api/v1/ScoreService/DoScore”: Remote host terminated the handshake; nested exception is javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake] with root cause
java.io.EOFException: SSL peer shut down incorrectly
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:489)