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

Catch the generic exception that might be thrown from FetchServiceHttpRequest.sendRequest(...) API

parent bef9f8e5
No related branches found
No related tags found
1 merge request!571Catch the generic exception that might be thrown from FetchServiceHttpRequest.sendRequest(...) API
Pipeline #195404 failed
......@@ -21,8 +21,8 @@ import com.google.gson.Gson;
import org.opengroup.osdu.core.common.http.FetchServiceHttpRequest;
import org.opengroup.osdu.core.common.http.IUrlFetchService;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo;
import org.opengroup.osdu.core.common.model.http.HttpResponse;
import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo;
import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties;
import org.opengroup.osdu.indexer.model.SearchRequest;
import org.opengroup.osdu.indexer.model.SearchResponse;
......@@ -63,25 +63,33 @@ public class SearchServiceImpl implements SearchService {
return new SearchResponse();
}
String body = this.gson.toJson(searchRequest);
String url = String.format("%s/%s", configurationProperties.getSearchHost(), path);
FetchServiceHttpRequest request = FetchServiceHttpRequest.builder()
.httpMethod(HttpMethods.POST)
.url(url)
.headers(this.requestInfo.getHeaders())
.body(body)
.build();
HttpResponse response = this.urlFetchService.sendRequest(request);
try {
String body = this.gson.toJson(searchRequest);
String url = String.format("%s/%s", configurationProperties.getSearchHost(), path);
FetchServiceHttpRequest request = FetchServiceHttpRequest.builder()
.httpMethod(HttpMethods.POST)
.url(url)
.headers(this.requestInfo.getHeaders())
.body(body)
.build();
HttpResponse response = this.urlFetchService.sendRequest(request);
if(response != null && response.getResponseCode() == OK_CODE) {
return gson.fromJson(response.getBody(), SearchResponse.class);
if (response != null && response.getResponseCode() == OK_CODE) {
return gson.fromJson(response.getBody(), SearchResponse.class);
} else {
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();
}
}
else {
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();
catch(URISyntaxException ex) {
throw ex;
}
catch(Exception ex) {
jaxRsDpsLog.error(String.format("Search service: failed to call the search service", ex));
throw new URISyntaxException(ex.getMessage(), "Unexpected exception type: " + ex.getClass().getName());
}
}
}
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