Skip to content

Commit c0f56ee

Browse files
[MOSIP-42615] (#122)
* [MOSIP-42083] Json Localdatetime serializer and deserializer Signed-off-by: JanardhanBS-SyncByte <janardhan@syncbyte.in> * [MOSIP-42083] Json Localdatetime serializer and deserializer Signed-off-by: JanardhanBS-SyncByte <janardhan@syncbyte.in> * [MOSIP-33324] sonar changes Signed-off-by: JanardhanBS-SyncByte <janardhan@syncbyte.in> --------- Signed-off-by: JanardhanBS-SyncByte <janardhan@syncbyte.in>
1 parent d1dac64 commit c0f56ee

2 files changed

Lines changed: 38 additions & 10 deletions

File tree

biosdk-client/src/main/java/io/mosip/biosdk/client/impl/spec_1_0/Client_V_1_0.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ private SDKInfo initForSdkUrl(Map<String, String> initParams, String sdkServiceU
179179
throw new BioSdkClientException(ResponseStatus.UNKNOWN_ERROR + "",
180180
TAG_HTTP_STATUS + responseEntity.getStatusCode().toString());
181181
}
182-
String responseBody = responseEntity.getBody().toString();
182+
Object body = responseEntity.getBody();
183+
if (body == null) {
184+
throw new NullPointerException("Response body is null");
185+
}
186+
String responseBody = body.toString();
183187
JSONParser parser = new JSONParser();
184188
JSONObject js = (JSONObject) parser.parse(responseBody);
185189

@@ -188,10 +192,7 @@ private SDKInfo initForSdkUrl(Map<String, String> initParams, String sdkServiceU
188192

189193
sdkInfo = Util.getObjectMapper().readValue(js.get("response").toString(), new TypeReference<SDKInfo>() {
190194
});
191-
} catch (ParseException e) {
192-
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "error", e);
193-
throw new BioSdkClientException(ResponseStatus.UNKNOWN_ERROR + "", e.getLocalizedMessage(), e);
194-
} catch (JsonProcessingException e) {
195+
} catch (Exception e) {
195196
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "error", e);
196197
throw new BioSdkClientException(ResponseStatus.UNKNOWN_ERROR + "", e.getLocalizedMessage(), e);
197198
}
@@ -313,7 +314,11 @@ public Response<QualityCheck> checkQuality(BiometricRecord sample, List<Biometri
313314
throw new BioSdkClientException(ResponseStatus.UNKNOWN_ERROR.getStatusCode() + "",
314315
TAG_HTTP_STATUS + responseEntity.getStatusCode().toString());
315316
}
316-
String responseBody = responseEntity.getBody().toString();
317+
Object body = responseEntity.getBody();
318+
if (body == null) {
319+
throw new NullPointerException("Response body is null");
320+
}
321+
String responseBody = body.toString();
317322
JSONParser parser = new JSONParser();
318323
JSONObject js = (JSONObject) parser.parse(responseBody);
319324
JSONObject responseJson = (JSONObject) ((JSONObject) js.get("response")).get("response");
@@ -361,7 +366,11 @@ public Response<MatchDecision[]> match(BiometricRecord sample, BiometricRecord[]
361366
throw new BioSdkClientException(ResponseStatus.UNKNOWN_ERROR + "",
362367
TAG_HTTP_STATUS + responseEntity.getStatusCode().toString());
363368
}
364-
String responseBody = responseEntity.getBody().toString();
369+
Object body = responseEntity.getBody();
370+
if (body == null) {
371+
throw new NullPointerException("Response body is null");
372+
}
373+
String responseBody = body.toString();
365374
JSONParser parser = new JSONParser();
366375
JSONObject js = (JSONObject) parser.parse(responseBody);
367376

@@ -494,7 +503,11 @@ public Response<BiometricRecord> segment(BiometricRecord biometricRecord, List<B
494503
* @throws BioSdkClientException If the JSON mapping fails during response conversion.
495504
*/
496505
private void convertAndSetResponseObject(Response<BiometricRecord> response, ResponseEntity<?> responseEntity) throws ParseException, JsonProcessingException {
497-
String responseBody = responseEntity.getBody().toString();
506+
Object body = responseEntity.getBody();
507+
if (body == null) {
508+
throw new NullPointerException("Response body is null");
509+
}
510+
String responseBody = body.toString();
498511
JSONParser parser = new JSONParser();
499512
JSONObject js = (JSONObject) parser.parse(responseBody);
500513

@@ -549,7 +562,11 @@ public BiometricRecord convertFormat(BiometricRecord sample, String sourceFormat
549562
throw new BioSdkClientException(ResponseStatus.UNKNOWN_ERROR.getStatusCode() + "",
550563
TAG_HTTP_STATUS + responseEntity.getStatusCode().toString());
551564
}
552-
String responseBody = responseEntity.getBody().toString();
565+
Object body = responseEntity.getBody();
566+
if (body == null) {
567+
throw new NullPointerException("Response body is null");
568+
}
569+
String responseBody = body.toString();
553570
JSONParser parser = new JSONParser();
554571
JSONObject js = (JSONObject) parser.parse(responseBody);
555572

@@ -601,7 +618,11 @@ public Response<BiometricRecord> convertFormatV2(BiometricRecord sample, String
601618
throw new BioSdkClientException(ResponseStatus.UNKNOWN_ERROR.getStatusCode() + "",
602619
TAG_HTTP_STATUS + responseEntity.getStatusCode().toString());
603620
}
604-
String responseBody = responseEntity.getBody().toString();
621+
Object body = responseEntity.getBody();
622+
if (body == null) {
623+
throw new NullPointerException("Response body is null");
624+
}
625+
String responseBody = body.toString();
605626
convertAndSetResponseObject(response, responseBody, new TypeReference<BiometricRecord>() {
606627
});
607628
} catch (Exception e) {

biosdk-client/src/main/java/io/mosip/biosdk/client/utils/Util.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.mosip.kernel.core.logger.spi.Logger;
1111
import org.apache.commons.lang3.BooleanUtils;
1212
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
13+
import org.apache.hc.client5.http.ssl.DefaultHostnameVerifier;
1314
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
1415
import org.apache.hc.client5.http.impl.classic.HttpClients;
1516
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
@@ -153,7 +154,13 @@ private static synchronized RestTemplate getRestTemplate() throws NoSuchAlgorith
153154
.setMaxConnTotal(getTotalMaxConnectionsFromEnv())
154155
.build();
155156
} else {
157+
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(
158+
SSLContexts.createSystemDefault(),
159+
new DefaultHostnameVerifier()
160+
);
161+
156162
connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
163+
.setSSLSocketFactory(csf)
157164
.setMaxConnPerRoute(getMaxConnectionPerRouteFromEnv())
158165
.setMaxConnTotal(getTotalMaxConnectionsFromEnv())
159166
.build();

0 commit comments

Comments
 (0)