You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Rai Singh <ra...@gmail.com> on 2006/02/21 18:34:49 UTC

[VFS] Retrieving a FileContent instance

I am trying to get a FileContent object from a FileObject
so that I can retrieve the value from getLastModifiedTime().
I am to successfully create FileObject using the following URI:
jar:file:/c:/neo/code/dist/crosssell.jar
when calling resolveFile on FileSystemManager.

However, when I call the following, I receive a NullPointerException on the
call to getLastModifiedTime() because DefaultFileContent's default
getLastModifiedTime()
method is invoked and it is simply not implemented to do anything useful.

  // fsManager is a DefaultFileSystemManager instance.
   FileObject fileObject = fsManager.resolveFile(deployFile.getFileName());
   FileContent fileContent = fileObject.getContent();

   long lastModTime = fileContent.getLastModifiedTime();


What is the correct way to reference a FileContent object. In my case,
I am interested in FileContent for jar files.

If I am misusing the API, please advise.
Thanks,
Rai

Re: [VFS] Retrieving a FileContent instance

Posted by Rai Singh <ra...@gmail.com>.
I ended up creating a local temp file to resolve my problem:

// TMP_DIR = "/c:/tmp"
File tmpDir = new File(TMP_DIR);

// TMP_FILE = "temp.jar"
File tmpFile = new File(tmpDir, TMP_FILE);

// pathToJar is the SFTP uri
FileObject fileObject = defFileSysMgr.resolveFile(pathToJar, fso);

// populate tmpFile from the SftpFileObject
FileUtil.copyContent(fileObject, defFileSysMgr.toFileObject(tmpFile));

// read the local jar file
FileObject jarFileObject = defFileSysMgr.resolveFile("jar:" + TMP_DIR + "/"
+ TMP_FILE);


On 2/22/06, Rai Singh <ra...@gmail.com> wrote:
>
> I was successful when using:
> sftp://username:password@hostname
> /apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar
>
> I also attempting to connect via an SFTP client and was successful.
> Permissions are okay.
>
> As part of the stacktrace, the following exception seems to indicate that
> an attempt to create a
> temporary file is being made.  Do I need to configure a FileReplicator?
>
> Caused by: org.apache.commons.vfs.FileSystemException : No file replicator
> configured.
>
> This code works and returns an SftpFileObject:
> // pathToJar - sftp://username:password@hostname
> /apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar
> FileObject fileObject = defFileSysMgr.resolveFile(pathToJar, fso);
>
> This code does not and causes the exception above:
> defFileSysMgr.resolveFile("jar:" + fileObject + "!/", fso)
>
> fso is defined as
>             fso = new FileSystemOptions();
>             SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso,
> "no");
>             SftpFileSystemConfigBuilder.getInstance().setUserInfo(fso, new
> TrustEveryoneUserInfo());
>
> I am using VFS RC8.
>
> Thanks,
> Rai
>
> On 2/22/06, Mario Ivankovits <ma...@ops.co.at> wrote:
> >
> > Hi!
> > > I am attempting to retrieve the content of a jar resource via sftp
> > with the
> > > following:
> > > jar:sftp://username:password@hostname
> > > /apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar!/
> > >
> > > However, I receive:
> > > Caused by: org.apache.commons.vfs.FileSystemException: Could not
> > replicate "
> > > sftp://username:password@hostname
> > > /apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar".
> > >
> > Looks good to me. Try to copy the file without the jar: stuff, just to
> > see if you get successfully connected.
> >
> > Ciao,
> > Mario
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>

Re: [VFS] Retrieving a FileContent instance

Posted by Rai Singh <ra...@gmail.com>.
I was successful when using:
sftp://username:password@hostname
/apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar

I also attempting to connect via an SFTP client and was successful.
Permissions are okay.

As part of the stacktrace, the following exception seems to indicate that an
attempt to create a
temporary file is being made.  Do I need to configure a FileReplicator?

Caused by: org.apache.commons.vfs.FileSystemException: No file replicator
configured.

This code works and returns an SftpFileObject:
// pathToJar - sftp://username:password@hostname
/apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar
FileObject fileObject = defFileSysMgr.resolveFile(pathToJar, fso);

This code does not and causes the exception above:
defFileSysMgr.resolveFile("jar:" + fileObject + "!/", fso)

fso is defined as
            fso = new FileSystemOptions();
            SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso,
"no");
            SftpFileSystemConfigBuilder.getInstance().setUserInfo(fso, new
TrustEveryoneUserInfo());

I am using VFS RC8.

Thanks,
Rai

On 2/22/06, Mario Ivankovits <ma...@ops.co.at> wrote:
>
> Hi!
> > I am attempting to retrieve the content of a jar resource via sftp with
> the
> > following:
> > jar:sftp://username:password@hostname
> > /apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar!/
> >
> > However, I receive:
> > Caused by: org.apache.commons.vfs.FileSystemException: Could not
> replicate "
> > sftp://username:password@hostname
> > /apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar".
> >
> Looks good to me. Try to copy the file without the jar: stuff, just to
> see if you get successfully connected.
>
> Ciao,
> Mario
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: [VFS] Retrieving a FileContent instance

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> I am attempting to retrieve the content of a jar resource via sftp with the
> following:
> jar:sftp://username:password@hostname
> /apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar!/
>
> However, I receive:
> Caused by: org.apache.commons.vfs.FileSystemException: Could not replicate "
> sftp://username:password@hostname
> /apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar".
>   
Looks good to me. Try to copy the file without the jar: stuff, just to
see if you get successfully connected.

Ciao,
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [VFS] Retrieving a FileContent instance

Posted by Rai Singh <ra...@gmail.com>.
I am attempting to retrieve the content of a jar resource via sftp with the
following:
jar:sftp://username:password@hostname
/apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar!/

However, I receive:
Caused by: org.apache.commons.vfs.FileSystemException: Could not replicate "
sftp://username:password@hostname
/apps/web/eis81/WLS81SP4/domains/neodomain/neo/dist/crosssell.jar".

Is this syntax incorrect?
Thanks,
Rai


On 2/21/06, Rai Singh <ra...@gmail.com> wrote:
>
> Thank you! That worked.
>
> Regards,
> Rai
>
> On 2/21/06, Mario Ivankovits <ma...@ops.co.at> wrote:
> >
> > Hi!
> > > jar:file:/c:/neo/code/dist/crosssell.jar
> > >
> > If you would like to know the lastModTime of crossell.jar the url is
> > simply
> > file:/c:/neo/code/dist/crosssell.jar
> >
> > If you would like to access the content of the jar the url is
> > jar:file:/c:/neo/code/dist/crosssell.jar!/
> >
> > or for a file within the jar it is
> > jar:file:/c:/neo/code/dist/crosssell.jar!/path/in/jar/file.txt
> >
> > For sure it should throw a NPE with your url, but one of the urls above
> > should help.
> >
> > Ciao,
> > Mario
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>

Re: [VFS] Retrieving a FileContent instance

Posted by Rai Singh <ra...@gmail.com>.
Thank you! That worked.

Regards,
Rai

On 2/21/06, Mario Ivankovits <ma...@ops.co.at> wrote:
>
> Hi!
> > jar:file:/c:/neo/code/dist/crosssell.jar
> >
> If you would like to know the lastModTime of crossell.jar the url is
> simply
> file:/c:/neo/code/dist/crosssell.jar
>
> If you would like to access the content of the jar the url is
> jar:file:/c:/neo/code/dist/crosssell.jar!/
>
> or for a file within the jar it is
> jar:file:/c:/neo/code/dist/crosssell.jar!/path/in/jar/file.txt
>
> For sure it should throw a NPE with your url, but one of the urls above
> should help.
>
> Ciao,
> Mario
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: [VFS] Retrieving a FileContent instance

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> jar:file:/c:/neo/code/dist/crosssell.jar
>   
If you would like to know the lastModTime of crossell.jar the url is simply
file:/c:/neo/code/dist/crosssell.jar

If you would like to access the content of the jar the url is
jar:file:/c:/neo/code/dist/crosssell.jar!/

or for a file within the jar it is
jar:file:/c:/neo/code/dist/crosssell.jar!/path/in/jar/file.txt

For sure it should throw a NPE with your url, but one of the urls above
should help.

Ciao,
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org