Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Spring resource classpath issue

  1. #11
    Join Date
    Sep 2006
    Location
    Russia
    Posts
    28

    Default

    I've just checked "getFile()" method and I've found an error.

    The problem with this line:

    Code:
    ResourceUtils.getFile(getURI(), getDescription());
    URI starts from "bundle", but ResourceUtils expects "file". That's why is doesn't work.

    Try to use URL or InputStream.

  2. #12
    Join Date
    Feb 2008
    Posts
    27

    Default

    Quote Originally Posted by polosatiy View Post
    I've just checked "getFile()" method and I've found an error.

    The problem with this line:

    Code:
    ResourceUtils.getFile(getURI(), getDescription());
    URI starts from "bundle", but ResourceUtils expects "file". That's why is doesn't work.

    Try to use URL or InputStream.
    So what you are saying is a bug with the spring ResourceUtils ? I guessthe value of URI getting passed is "bundle://258.0:1/repo/test.db4o".

    In ResourceUtils.getFile(),

    Code:
    if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
    			throw new FileNotFoundException(
    					description + " cannot be resolved to absolute file path " +
    					"because it does not reside in the file system: " + resourceUrl);
    		}
    Here its expecting "file" but getting "bundle" and hence the exception. Thanks for debugging this for me.

    But the follow-up question is how its so obvious that the protocol will be a file ? Any resource uri deployed in an OSGi bundle will always start with a bundle. Isn't this a bug ? My problem now is, the ObjectContainerFactoryBean is a third party code which I've little control over. Moreover, the inherent call to Db4o.openFile() is the only method available, so getting File is the only choice. Not sure how to resolve this now.

  3. #13
    Join Date
    Sep 2006
    Location
    Russia
    Posts
    28

    Default

    I think It's a bug and I've posted a bug to tracker
    https://jira.springsource.org/browse/OSGI-818

    If you need to use a file, I can suggest you to copy InputSteam from URL to a temp file like this:

    Code:
    InputStream is = resource.getURL().openStream();
    File file  = File.createTempFile("tmp", "prop");
    FileOutputStream os = new FileOutputStream(file);
    //code to copy from is to os;

  4. #14
    Join Date
    Feb 2008
    Posts
    27

    Default

    Thanks for all your help in getting this issue resolved. I followed your clue and tried couple of approaches which worked.

    1. Externalizing the file and use file:///absolute_file_path

    2. I extended ObjectContainerFactoryBean and instead and overriden the method to use inputstream and generate the file instead of using the getFile() from OSGiBundleResource.

    But now, I've got into another issue which is has lead me to open another thread :-).

    Appreciate your help....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •