code: public static String getResourceUri(Resource resource) {
          try {
              return resource.getURI().toString();
          } catch (FileNotFoundException e) {
              return resource.getDescription();
          } catch (IOException e) {
              throw new RuntimeException("Could not create URI for resource: " + resource, e);
          }
      }
docs: First tries {@link Resource#getURI()} and if that fails with a FileNotFoundException then
  {@link Resource#getDescription()} is returned.