/** * Queries the supported mime-types from the REST server. * * @throws ServiceException */ public static List<String> getSupportedMediaTypesOfRestServer(final String host, final int port, final String mediaTypesQueryUri) throws ServiceException { try { final HttpClient httpClient = HttpClientBuilder.create().build(); final HttpHost httpHost = new HttpHost(host, port); final HttpGet httpGet = new HttpGet(mediaTypesQueryUri); final HttpResponse httpResponse = httpClient.execute(httpHost, httpGet); validateResponse(httpGet, httpResponse); // read the comma-separated string from the response final String supportedMimeTypeString = IOUtils.toString(httpResponse.getEntity().getContent()); // and convert it to a list final String[] mimeTypes = supportedMimeTypeString.trim().split(","); final List<String> supportedMimeTypes = new ArrayList<>(); for (final String mimeType : mimeTypes) { supportedMimeTypes.add(mimeType.trim()); } return supportedMimeTypes; } catch (final ServiceException e) { throw e; } catch (final Exception e) { LOG.error("Could not obtain supported media-types from the REST server!", e); throw new ServiceException("Could not obtain supported media-types from the REST server!", e); } }
final HttpResponse response = client.execute(request); LOG.debug("Executed http request: " + request + " in (" + (System.currentTimeMillis() - startTime) + "ms)"); validateResponse(request, response);