I am getting the above error when making post request, using spring resttemplate with mutual authentication.
@Bean
public RestTemplate restTemplate() throws UnrecoverableKeyException,
NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException, CertificateException {
KeyStore clientStore = KeyStore.getInstance("PKCS12");
clientStore.load(new FileInputStream(pfxFile), pfxPass.toCharArray());
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.useProtocol("TLS");
sslContextBuilder.loadKeyMaterial(clientStore, pfxPass.toCharArray());
sslContextBuilder.loadTrustMaterial(new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContextBuilder.build());
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslConnectionSocketFactory)
.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
requestFactory.setConnectTimeout(Integer.parseInt(timeOut)); // 10 seconds
requestFactory.setReadTimeout(Integer.parseInt(timeOut)); // 10 seconds
RestTemplate restTemplate = new RestTemplate(requestFactory);
restTemplate.setInterceptors( Collections.singletonList(new RequestResponseLoggingInterceptor()));
return restTemplate;
}
Code using the resttemplate is as below
public ResponseEntity<OauthResponse> getOauthToken(String clientScope,
String BasicAuthUser,String BasicAuthPass){
String accessToken = Base64.getEncoder().encodeToString((BasicAuthUser+":"+BasicAuthPass).getBytes());
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
// headers.set("apikey", BasicAuthUser);
// headers.set("Authorization", "Basic "+accessToken);
HttpEntity<?> entity = new HttpEntity<>(headers);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(oauthUrl)
.queryParam("grant_type", "client_credentials")
.queryParam("scope", clientScope);
return restTemplate.exchange(
builder.toUriString(),
HttpMethod.POST,
entity,
OauthResponse.class);
}
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://example.com": The size of the handshake message (47942) exceeds the maximum allowed size (32768); nested exception is javax.net.ssl.SSLProtocolException: The size of the handshake message (47942) exceeds the maximum allowed size (32768)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:748)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:583)
at in.co.confluent.gopayhrfc.restwrapper.hdfcapi.service.OauthService.getOauthToken(OauthService.java:38)
at in.co.confluent.gopayhrfc.restwrapper.hdfcapi.service.OauthServiceTest.checkOauthServiceResponse(OauthServiceTest.java:26)
I have tried with oracle jdk 8 and 11 but same error, has anyone faced similar issue.