question

Abdelhaq Lazar Efficiencymanagementconsulting avatar image

Spring boot - error on POST request

Hello,

In this application I have followed the FFDC Spring Boot example.

Please find below the environment, Entity, FFDC API Class, and the error stack trace:

I get the error when I try to call addCustomer method from FFDC Api class only (getCustomer works fine).


Please let me know if you need any other details.


====== Environment ======

Java 8
Spring Boot 2.3.3
Spring web
Spring Security Oauth2 2.1.0
httpClient 4.5.9
 
                
====== Entity =======
@AllArgsConstructor
 @NoArgsConstructor
 @Data
 @Builder
 public class FFDCCustomer {
     //private String id;
     private String branch;
     private String country;
     private String legalName;
     private String shortName;
     private String externalId;
     private String customerStatus;
     private boolean specialLoan;
     private boolean restricted;
     private boolean majorUnderwriter;
     private LegalAddress legalAddress;
 }
 
                
====== FFDC API =======
@Component
 public class FfdcApi {
 
     @Value("${ffdcapi.baseUrl}")
     private String baseUrl;
 
     @Autowired
     private OAuth2RestTemplate restTemplate;
 
     @Autowired
     private OAuth2ClientContext oAuth2ClientContext;
 
                
public FFDCCustomer getCustomer(String id) {
     UriComponents uriBuilder = UriComponentsBuilder
             .fromUriString(baseUrl + "/corporate/lending/customer/v1/customers/" + id)
             .build();
     ResponseEntity<FFDCCustomer> response = restTemplate.exchange(uriBuilder.toUri(), HttpMethod.GET, null, FFDCCustomer.class);
     return response.getBody();
 }
 
 public FFDCCustomer addCustomer(FFDCCustomer ffdcCustomer) {
     UriComponents uriBuilder = UriComponentsBuilder
             .fromUriString(baseUrl + "/corporate/lending/customer/v1/customers")
             .build();
     ffdcCustomer.setExternalId("92933");
     ObjectMapper mapper = new ObjectMapper();
     ResponseEntity<FFDCCustomer> response = null;
     try {
         HttpHeaders headers = new HttpHeaders();
         headers.setBearerAuth(oAuth2ClientContext.getAccessToken().getValue());
         headers.setContentType(MediaType.APPLICATION_JSON);
         headers.setAccept(Arrays.asList(MediaType.ALL));
         headers.set("Host", baseUrl);
         String jsonCustomer = mapper.writeValueAsString(ffdcCustomer);
         HttpEntity<String> requestEntity = new HttpEntity<>(jsonCustomer, headers);
         response = restTemplate.postForEntity(uriBuilder.toUri(),requestEntity, FFDCCustomer.class);
     } catch (JsonProcessingException e) {
         e.printStackTrace();
     } catch (Exception e) {
         e.printStackTrace();
     }
 
     return response == null ? new FFDCCustomer() : ffdcCustomer;
   }
}


getCustomer method works without any problem.


addCustomer method throws the below error.


====== Error stack trace =======

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://api.fusionfabric.cloud/corporate/lending/customer/v1/customers": Connection reset; nested exception is javax.net.ssl.SSLException: Connection reset

at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:748)

at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:714)

at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:467)

..

..

..

Caused by: java.net.SocketException: Connection reset

at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)

at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)

at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:467)

at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:461)

at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)

at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1145)

at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:832)



Thank you in advance for your help.

API - Corporate Banking
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Szymon Patacz avatar image
Szymon Patacz answered

Hello,

please check if your request contains all the required information as described:

https://developer.fusionfabric.cloud/api/corporate-lending-customer-management-v1-742f6550-b6c7-44b0-bef9-6cdf334683c2/docs#operation/post-customer

To create customer required information is header Idempotency-Key (random string <=50 characters), and Body of message should contain at least information about shortname:

{
"shortName": "value"
}


Best Regards,

Szymon

2 comments
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Hello Szymon,

Thank you for taking the time answer my question.

For the request Body, it contains all the customer details including the shortName, and I have added the Idempotency-Key to the header, but it still displaying the same error.


Thanks and regards,

Abdelhaq

0 Likes 0 ·
Szymon Patacz avatar image Szymon Patacz ♦♦ Abdelhaq Lazar Efficiencymanagementconsulting commented ·

Hello,

We are investigating your issue internally. We will come back to you once we have more information.

Best Regards,

Szymon Patacz

0 Likes 0 ·
Szymon Patacz avatar image
Szymon Patacz answered

Hello,


We have tested Spring boot example and API used by you. There are no issues with either of them. Please review your code for any potential issues.

Best Regards,

Szymon Patacz

10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.