[jcifs] Java Webstart Problem
Adam Augusta
roxton at gmail.com
Mon Apr 23 18:50:06 GMT 2007
I'm using JCIFS 1.2.13 so that my client can use HTTP NTLM authentication to
download a PDF from a MS Reporting Services server. The server's name is
"reportserver". The client is running on a FreeBSD 6.0 box with JVM
diablo-1.5.0-b01.
When I run the short program below directly using "java", it works without a
hitch. When I deploy it with Java WebStart, though, it behaves as though I
weren't even using JCIFS.
I suspect WebStart is setting the default Authenticator, and since it can only
be set once, "jcifs.Config.registerSmbURLHandler()" does nothing. Does that
sound right? Can anyone suggest a workaround?
-----DownloadTest.java-----
package org.roxton;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class DownloadTest {
public static void main(String[] args) {
URL url;
String osName = System.getProperty("os.name");
if (osName == null || !osName.startsWith("Windows")) {
jcifs.Config.setProperty("jcifs.smb.client.domain", "MYDOMAIN");
jcifs.Config.setProperty("jcifs.smb.client.username", "MYUSERNAME");
jcifs.Config.setProperty("jcifs.smb.client.password", "MYPASSWORD");
jcifs.Config.registerSmbURLHandler();
}
byte[] pdfByteArray = null;
InputStream is;
ByteArrayOutputStream os;
try {
url = new URL(args[0]);
is = url.openStream();
os = new ByteArrayOutputStream();
// Download buffer
byte[] buffer = new byte[4096];
// Download the PDF document
int read;
while ((read = is.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
// Copy output stream to byte array
pdfByteArray = os.toByteArray();
// Close streams
is.close();
os.close();
} catch (IOException e) {
throw new RuntimeException("FAILURE", e);
}
}
}
-----JNLP (WebStart) File-----
<jnlp codebase="file:///usr/home/roxton">
<information>
<title>Download Test</title>
<vendor>Roxton Technologies</vendor>
<homepage href="http://www.mysite.com"/>
<icon href="print.jpg"/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="DownloadAuthURL.jar" main="true" download="eager"/>
<jar href="jcifs-1.2.13.jar" download="eager"/>
</resources>
<application-desc main-class="org.roxton.DownloadTest">
<argument>http://reportserver/ReportServer?WELLFORM=ATTEDPARAMETERS</argument>
</application-desc>
</jnlp>
-----Exception Thrown-----
java.lang.RuntimeException: FAILURE
at org.roxton.DownloadTest.main(DownloadTest.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[...]
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL:
http://reportserver/ReportServer?WELLFORM=ATTEDPARAMETERS
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.jav
a:1152)
at java.net.URL.openStream(URL.java:1007)
at org.roxton.DownloadTest.main(DownloadTest.java:38)
[...]
More information about the jcifs
mailing list