How do I access the SUN Java libraries for reading from password protected URLs in MATLAB 7.0 (R14) through MATLAB 7.2 (R2006a)?

1 view (last 30 days)
I am trying to read from a password-protected URL by creating a Java URL object and using corresponding stream objects and read methods. I was successful while using MATLAB 6.5.1 (R13SP1), but the server returns an error in MATLAB 7.0 (R14).
I execute the following statements:
url = java.net.URL(my_url_str); % my_url_str is the URL I am connecting to
is = url.openStream;
st = java.io.InputStreamReader(is);
br = java.io.BufferedReader(st);
line = br.readLine
while(~isempty(line))
line = br.readLine
end
Part of the error output returned by the server upon making several calls to readLine follows:
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you are authorized to access the document
requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p>
...
I noticed that the type of the input stream object, determined by the following command
class(is)
is ice.net.HttpMessage$MarkerInputStream. In MATLAB 6.5.1 (R13SP1), it was sun.net.www.protocol.http.HttpURLConnection$HttpInputStream, which is the class I intend to use.
It appears that MATLAB is accessing some libraries other than the SUN (TM) Java libraries for creating and handling HTTP streams for URL objects.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 30 Nov 2009
This change in behavior occurs because different default HTTP stream handlers are registered with the Java Virtual Machine on different versions of MATLAB.
In particular, the non-standard stream handlers will be found in MATLAB 7.0 (R14) and some later versions. The standard stream handlers have been restored in 32-bit versions of MATLAB for Windows and Linux starting with MATLAB 7.3 (R2006b).
To avoid relying on the default stream handlers, explicitly specify a stream handler in the URL constructor:
url = java.net.URL([], my_url, sun.net.www.protocol.http.Handler);

More Answers (0)

Products


Release

R14SP2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!