[jcifs] Problem (and fix) accessing file contents using smb: url
Michael B Allen
mba2000 at ioplex.com
Tue Nov 14 22:42:07 GMT 2006
There's a mime.map file in the jar. Look at
jcifs/http/NetworkExplorer.java for how it comes up with the Content-Type.
But your fix should be added too I think. I'll add it to TheList [1].
Mike
[1] Note that I just processed The List so it will likely be another
year or two before this fix reaches mainline :-<
On Tue, 14 Nov 2006 13:22:25 -0500
"Thierry Lach" <thierry.lach at gmail.com> wrote:
> I'm trying to access a files on a unix system through a Samba share from
> java inside of a web application. I want to keep the password configuration
> separate from the url for security purposes.
>
> I'm using jcifs.Config to set all of the properties, and can access the smb:
> protocol properly. But when I try to access the file contents (as in the
> following example) I get an error indicating that the content type has not
> been set..
>
> URL url = new URL("smb://hostname/sharename/filename.xml");
> URLConnection conn = url.openConnection();
> Object contents = conn.getContent();
> if (contents instanceof InputStream) {
> BufferedReader reader = new BufferedReader(new
> InputStreamReader((InputStream) contents));
> String line;
> while ( null != (line = reader.readLine())) {
> pw.println(line);
> }
> ((InputStream)contents).close();
> }
>
>
> I added the following code to SmbFile and now it works...
>
> /**
> * This URLConnection method returns a generic content type.
> *
> * @see java.net.URLConnection#getContentType()
> */
> public String getContentType() {
> String contentType = super.getContentType();
> if (contentType == null) {
> // Call it binary since we don't know any better
> contentType = "application/octet-stream";
> }
> return contentType;
> }
>
> This can probably look at file extensions to better select a content type,
> but this is a minimalist fix.
>
--
Michael B Allen
PHP Active Directory SSO
http://www.ioplex.com/
More information about the jcifs
mailing list