class ResourceDetailsJaxrsService {

    public Response getResourceDetails(String uri, String accept, Boolean _expanded, Set<String> expandTypes, List<String> includes,
                                       Map<String, String[]> additionalProperties) throws ErrorDescriptorException {
        final String effectiveAccept = accept != null ? accept.split(";")[0].split(",")[0] : null;
        boolean expanded = _expanded != null ? _expanded : false;
        Resource resource = singleRepositoryService.getResource(uri);
        if (resource == null) {
            throw new ResourceNotFoundException(uri);
        }
        Response response;
        final String clientType = ClientTypeHelper.extractClientType(accept);
        if (clientType == null && (resource instanceof FileResource || resource instanceof ContentResource) && !ResourceMediaType.FILE_XML.equals(effectiveAccept) && !ResourceMediaType.FILE_JSON.equals(effectiveAccept)) {
            FileResourceData data = singleRepositoryService.getFileResourceData(resource);
            FileResourceData wrapper = new SelfCleaningFileResourceDataWrapper(data);
            String type = resource instanceof FileResource ? ((FileResource) resource).getFileType() : ((ContentResource) resource).getFileType();
            response = toResponse(wrapper, resource.getName(), type);
        } else {
            ToClientConverter<? super Resource, ? extends ClientResource, ToClientConversionOptions> toClientConverter = null;
            if (clientType != null) {
                // try to find converter for specific combination of client type and server type
                toClientConverter = resourceConverterProvider.getToClientConverter(resource.getResourceType(), clientType);
            }

            ClientResource clientResource = null;
            ToClientConverter<? super Resource, ? extends ClientResource, ToClientConversionOptions> defaultToClientConverter =
                    resourceConverterProvider.getToClientConverter(resource);
            ToClientConversionOptions options = ToClientConversionOptions.getDefault()
                    .setExpanded(expanded)
                    .setExpandTypes(expandTypes)
                    .setIncludes(includes)
                    .setAcceptMediaType(effectiveAccept)
                    .setTimeZone(TimeZoneContextHolder.getTimeZone())
                    .setAdditionalProperties(additionalProperties);

            if (toClientConverter != null) {
                try {
                    clientResource = toClientConverter.toClient(resource, options);
                } catch (NotAcceptableException e) {
                    // in this layer we know all about MIME types. Adding error properties about acceptable types here.
                    final String defaultType = defaultToClientConverter.getClientResourceType();
                    e.getErrorDescriptor().addProperties(
                            new ClientProperty("acceptableType", MediaType.APPLICATION_XML),
                            new ClientProperty("acceptableType", MediaType.APPLICATION_JSON),
                            new ClientProperty("acceptableType", ResourceMediaType.RESOURCE_MEDIA_TYPE_PREFIX +
                                    defaultType + ResourceMediaType.RESOURCE_XML_TYPE),
                            new ClientProperty("acceptableType", ResourceMediaType.RESOURCE_MEDIA_TYPE_PREFIX +
                                    defaultType + ResourceMediaType.RESOURCE_JSON_TYPE)
                    );
                    throw e;
                }
            }

            if(clientResource == null){
                // no client type or no converter for client/server type combination or mime type isn't
                // supported by this client type (i.e. XML isn't supported for "domain" client type).
                // Let's take server type converter then
                toClientConverter = defaultToClientConverter;
                clientResource = toClientConverter.toClient(resource, options);
            }
            String contentTypeTemplate = effectiveAccept != null && effectiveAccept.endsWith("json") ? ResourceMediaType.RESOURCE_JSON_TEMPLATE : ResourceMediaType.RESOURCE_XML_TEMPLATE;
            response = Response.ok(clientResource)
                    .header(HttpHeaders.CONTENT_TYPE,
                            contentTypeTemplate.replace(ResourceMediaType.RESOURCE_TYPE_PLACEHOLDER,
                                    toClientConverter.getClientResourceType()))
                    .build();
        }

        return response;
    }

}