Search in sources :

Example 1 with BookDetailsImpl

use of org.olat.modules.edubase.model.BookDetailsImpl in project openolat by klemens.

the class EdubaseManagerImpl method fetchBookDetails.

@Override
public BookDetails fetchBookDetails(String bookId) {
    BookDetails infoReponse = new BookDetailsImpl();
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT_5000_MILLIS).setConnectTimeout(TIMEOUT_5000_MILLIS).setConnectionRequestTimeout(TIMEOUT_5000_MILLIS).build();
    String url = String.format(edubaseModule.getInfoverUrl(), bookId);
    HttpGet request = new HttpGet(url);
    request.setConfig(requestConfig);
    try (CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse httpResponse = httpClient.execute(request)) {
        String json = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
        ObjectMapper objectMapper = new ObjectMapper();
        infoReponse = objectMapper.readValue(json, BookDetailsImpl.class);
    } catch (SocketTimeoutException socketTimeoutException) {
        log.warn("Socket Timeout while requesting informations of the Edubase book with the id " + bookId);
    } catch (JsonParseException | EOFException noesNotExitsException) {
        log.debug("Error while requesting informations for the Edubase book with the id " + bookId + ": Book does not exist.");
    } catch (Exception e) {
        log.error("", e);
    }
    return infoReponse;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) JsonParseException(org.codehaus.jackson.JsonParseException) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) JsonParseException(org.codehaus.jackson.JsonParseException) BookDetails(org.olat.modules.edubase.BookDetails) BookDetailsImpl(org.olat.modules.edubase.model.BookDetailsImpl) SocketTimeoutException(java.net.SocketTimeoutException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) EOFException(java.io.EOFException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with BookDetailsImpl

use of org.olat.modules.edubase.model.BookDetailsImpl in project OpenOLAT by OpenOLAT.

the class EdubaseManagerImpl method fetchBookDetails.

@Override
public BookDetails fetchBookDetails(String bookId) {
    BookDetails infoReponse = new BookDetailsImpl();
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT_5000_MILLIS).setConnectTimeout(TIMEOUT_5000_MILLIS).setConnectionRequestTimeout(TIMEOUT_5000_MILLIS).build();
    String url = String.format(edubaseModule.getInfoverUrl(), bookId);
    HttpGet request = new HttpGet(url);
    request.setConfig(requestConfig);
    try (CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse httpResponse = httpClient.execute(request)) {
        String json = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
        ObjectMapper objectMapper = new ObjectMapper();
        infoReponse = objectMapper.readValue(json, BookDetailsImpl.class);
    } catch (SocketTimeoutException socketTimeoutException) {
        log.warn("Socket Timeout while requesting informations of the Edubase book with the id " + bookId);
    } catch (JsonParseException | EOFException noesNotExitsException) {
        log.debug("Error while requesting informations for the Edubase book with the id " + bookId + ": Book does not exist.");
    } catch (Exception e) {
        log.error("", e);
    }
    return infoReponse;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) JsonParseException(org.codehaus.jackson.JsonParseException) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) JsonParseException(org.codehaus.jackson.JsonParseException) BookDetails(org.olat.modules.edubase.BookDetails) BookDetailsImpl(org.olat.modules.edubase.model.BookDetailsImpl) SocketTimeoutException(java.net.SocketTimeoutException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) EOFException(java.io.EOFException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

EOFException (java.io.EOFException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 RequestConfig (org.apache.http.client.config.RequestConfig)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 BookDetails (org.olat.modules.edubase.BookDetails)2 BookDetailsImpl (org.olat.modules.edubase.model.BookDetailsImpl)2