Search in sources :

Example 1 with EnsemblRestClientException

use of uk.ac.ebi.spot.goci.exception.EnsemblRestClientException in project goci by EBISPOT.

the class EnsemblRestTemplateService method exec.

public RestResponseResult exec(String url) {
    ResponseEntity<String> out;
    RestResponseResult result = new RestResponseResult();
    RestTemplate restTemplate = this.getRestTemplate();
    HttpEntity<Object> entity = this.getEntity();
    getLog().debug("Querying " + url);
    //and do I need this JSON media type for my use case?
    try {
        out = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
        result.setStatus(out.getStatusCode().value());
        result.setUrl(url);
        JsonNode body = new JsonNode(out.getBody().toString());
        result.setRestResult(body);
        getLog().debug("Response: 200");
    //result.setValue(out.getBody());
    } catch (EnsemblRestClientException erce) {
        getLog().debug("EnsemblRestClientException");
        result = erce.getEnsemblLookup();
        result.setUrl(url);
    } catch (Exception e) {
        getLog().debug("Exception not managed");
    }
    return result;
}
Also used : EnsemblRestClientException(uk.ac.ebi.spot.goci.exception.EnsemblRestClientException) RestTemplate(org.springframework.web.client.RestTemplate) RestResponseResult(uk.ac.ebi.spot.goci.model.RestResponseResult) JSONObject(org.json.JSONObject) JsonNode(com.mashape.unirest.http.JsonNode) MalformedURLException(java.net.MalformedURLException) EnsemblRestClientException(uk.ac.ebi.spot.goci.exception.EnsemblRestClientException)

Aggregations

JsonNode (com.mashape.unirest.http.JsonNode)1 MalformedURLException (java.net.MalformedURLException)1 JSONObject (org.json.JSONObject)1 RestTemplate (org.springframework.web.client.RestTemplate)1 EnsemblRestClientException (uk.ac.ebi.spot.goci.exception.EnsemblRestClientException)1 RestResponseResult (uk.ac.ebi.spot.goci.model.RestResponseResult)1