/** * Gets a {@link IMarshaller} by querying the REST server's supported mime-types and trying to * find a match by the clients supported mime-types. * * @param host the host of the REST server * @param port the port of the REST server * @param restServerUri the URI which returns the mime-types in text/plain * @return the {@link IMarshaller} * @throws ServiceException */ public static IMarshaller getMarshallerToCommunicateWithRestServer(final String host, final int port, final String restServerUri) throws ServiceException { // first determine which mime-types the rest server supports final List<String> registryServerMimeTypes = ServiceUtils.getSupportedMediaTypesOfRestServer(host, port, restServerUri); // try to get a matching marshaller for the supported mime-type IMarshaller marshaller = null; for (final String mimeType : registryServerMimeTypes) { marshaller = MarshallerFactory.get(mimeType); if (marshaller != null) { break; } } // check if a common mime-type was found if (marshaller == null) { throw new ServiceException("Could not find common mime-type to communicate with reqistry server. A marshaller for one of the following mime-types must be provided: " + registryServerMimeTypes); } return marshaller; }