use of fr.univlorraine.ecandidat.services.siscol.SiScolRestUtils.SiScolRestException in project esup-ecandidat by EsupPortail.
the class SiScolRestServiceInterface method getFile.
/**
* @param url
* @param service
* @param mapGetParameter
* @return l'input stream de la piece
* @throws SiScolRestException
* @throws SiScolException
*/
public InputStream getFile(final String url, final String service, final MultiValueMap<String, String> mapGetParameter, final KeyValue header) throws SiScolRestException, SiScolException {
try {
final URI targetUrl = SiScolRestUtils.getURIForService(url, service, mapGetParameter);
final RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new SiScolResponseErrorHandler());
restTemplate.getMessageConverters().add(new ResourceHttpMessageConverter());
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));
if (header != null && header.isNotEmpty()) {
headers.set(header.getKey(), header.getValue());
}
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<Resource> response = restTemplate.exchange(targetUrl, HttpMethod.GET, entity, Resource.class);
return response.getBody().getInputStream();
} catch (final SiScolRestException e) {
throw e;
} catch (final Exception e) {
throw new SiScolException("Erreur a l'appel du WS Rest des PJ", e);
}
}
use of fr.univlorraine.ecandidat.services.siscol.SiScolRestUtils.SiScolRestException in project esup-ecandidat by EsupPortail.
the class SiScolRestServiceInterface method getList.
/**
* @param url
* @param service
* @param klass
* @param mapGetParameter
* @return une liste d'objets pour un service donné
* @throws SiScolException
*/
public <T> List<T> getList(final String url, final String service, final Class<T[]> klass, final MultiValueMap<String, String> mapGetParameter, final KeyValue header) throws SiScolRestException, SiScolException {
try {
final URI targetUrl = SiScolRestUtils.getURIForService(url, service, mapGetParameter);
final RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new SiScolResponseErrorHandler());
final HttpHeaders headers = new HttpHeaders();
if (header != null && header.isNotEmpty()) {
headers.set(header.getKey(), header.getValue());
}
final ResponseEntity<T[]> response = restTemplate.exchange(targetUrl, HttpMethod.GET, new HttpEntity<T[]>(headers), klass);
final List<T> liste = Arrays.asList(response.getBody());
return liste;
} catch (final SiScolRestException e) {
throw e;
} catch (final Exception e) {
throw new SiScolException("Erreur a l'appel du WS Rest des PJ", e);
}
}
Aggregations