Skip to content
Snippets Groups Projects
Commit 19adfb69 authored by Zhibin Mai's avatar Zhibin Mai
Browse files

Avoid NullPointerException when the search response is null

parent eb82eb56
No related branches found
No related tags found
3 merge requests!545Draft: add env variables,!543Draft: az/sa-support-index-extended-properties,!465Index extended properties defined in property configurations
Pipeline #185410 canceled
......@@ -72,11 +72,15 @@ public class SearchServiceImpl implements SearchService {
.body(body)
.build();
HttpResponse response = this.urlFetchService.sendRequest(request);
if(response.getResponseCode() == OK_CODE) {
if(response != null && response.getResponseCode() == OK_CODE) {
return gson.fromJson(response.getBody(), SearchResponse.class);
}
else {
jaxRsDpsLog.error(String.format("Search service: failed to call the search service: %d", response.getResponseCode()));
if(response != null)
jaxRsDpsLog.error(String.format("Search service: failed to call the search service: %d", response.getResponseCode()));
else
jaxRsDpsLog.error(String.format("Search service: failed to call the search service. The response is null."));
return new SearchResponse();
}
}
......
......@@ -134,4 +134,13 @@ public class SearchServiceImplTest {
Assert.assertNotNull(searchResponse);
Assert.assertNull(searchResponse.getResults());
}
@Test
public void query_with_null_response() throws URISyntaxException {
when(this.configurationProperties.getSearchHost()).thenReturn(searchHost);
when(this.urlFetchService.sendRequest(any())).thenReturn(null);
SearchResponse searchResponse = sut.query(new SearchRequest());
Assert.assertNotNull(searchResponse);
Assert.assertNull(searchResponse.getResults());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment