From 2dea143b52392862a3b9fe26a5425c336c5389a0 Mon Sep 17 00:00:00 2001 From: robertoffmoura Date: Tue, 13 Aug 2024 12:02:22 +0100 Subject: [PATCH 1/2] Update version number --- README.md | 2 +- plotly/plotly_aux/plotly_version.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c34ffc..2f9225b 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ -Version: 2.2.10 +Version: 3.0.0 *MATLAB is a registered trademarks of The MathWorks, Inc.* diff --git a/plotly/plotly_aux/plotly_version.m b/plotly/plotly_aux/plotly_version.m index 3623358..f56f549 100644 --- a/plotly/plotly_aux/plotly_version.m +++ b/plotly/plotly_aux/plotly_version.m @@ -1,3 +1,3 @@ function version = plotly_version() - version = '2.2.10'; + version = "3.0.0"; end From 0b830477054136039b2e655a2222ebb719ac56c7 Mon Sep 17 00:00:00 2001 From: robertoffmoura Date: Tue, 13 Aug 2024 14:29:26 +0100 Subject: [PATCH 2/2] Use built-in 'webread' and 'webwrite' (introduced in R2015a) instead of vendoring 'urlread2' --- plotly/plotly_aux/makecall.m | 28 +- plotly/plotly_aux/plotlygenimage.m | 47 +-- plotly/plotly_aux/plotlygetfile.m | 29 +- plotly/plotly_aux/response_handler.m | 41 -- .../plotly_aux/urlread2/http_createHeader.m | 11 - .../plotly_aux/urlread2/http_paramsToString.m | 62 --- plotly/plotly_aux/urlread2/license.txt | 24 -- plotly/plotly_aux/urlread2/urlread2.m | 371 ------------------ plotly/plotly_aux/urlread2/urlread_notes.txt | 86 ---- plotly/plotly_aux/urlread2/urlread_todos.txt | 13 - .../urlread2/urlread_versionInfo.txt | 13 - plotly/plotly_offline_aux/getplotlyoffline.m | 16 +- 12 files changed, 39 insertions(+), 702 deletions(-) delete mode 100644 plotly/plotly_aux/response_handler.m delete mode 100755 plotly/plotly_aux/urlread2/http_createHeader.m delete mode 100755 plotly/plotly_aux/urlread2/http_paramsToString.m delete mode 100644 plotly/plotly_aux/urlread2/license.txt delete mode 100755 plotly/plotly_aux/urlread2/urlread2.m delete mode 100755 plotly/plotly_aux/urlread2/urlread_notes.txt delete mode 100755 plotly/plotly_aux/urlread2/urlread_todos.txt delete mode 100755 plotly/plotly_aux/urlread2/urlread_versionInfo.txt diff --git a/plotly/plotly_aux/makecall.m b/plotly/plotly_aux/makecall.m index 4a525dc..6c070de 100644 --- a/plotly/plotly_aux/makecall.m +++ b/plotly/plotly_aux/makecall.m @@ -1,6 +1,7 @@ -function st = makecall(args, origin, structargs) +function st = makecall(args, origin, kwargs) % check if signed in and grab username, key, domain [un, key, domain] = signin; + if isempty(un) || isempty(key) error('Plotly:CredentialsNotFound',... ['It looks like you haven''t set up your plotly '... @@ -13,21 +14,16 @@ platform = 'MATLAB'; - args = m2json(args); - kwargs = m2json(structargs); url = [domain '/clientresp']; - payload = {'platform', platform, 'version', plotly_version, ... - 'args', args, 'un', un, 'key', key, 'origin', origin, ... - 'kwargs', kwargs}; - - if (is_octave) - % use octave super_powers - resp = urlread(url, 'post', payload); - else - % do it matlab way - resp = urlread(url, 'Post', payload); - end + payload = struct( ... + platform=platform, ... + version=plotly_version, ... + args=args, ... + un=un, ... + key=key, ... + origin=origin, ... + kwargs=kwargs ... + ); - st = jsondecode(resp); - response_handler(resp); + st = webwrite(url, payload); end diff --git a/plotly/plotly_aux/plotlygenimage.m b/plotly/plotly_aux/plotlygenimage.m index 1bcf5ef..8a89968 100644 --- a/plotly/plotly_aux/plotlygenimage.m +++ b/plotly/plotly_aux/plotlygenimage.m @@ -1,5 +1,5 @@ function plotlygenimage(figure_or_data, filename, varargin) - [pathstr, name, ext] = fileparts(filename); + [~, ~, ext] = fileparts(filename); if nargin < 3 format = ext(2:length(ext)); else @@ -23,46 +23,23 @@ function plotlygenimage(figure_or_data, filename, varargin) figure = struct('data', data); end - body = struct('figure', figure, 'format', format); - - payload = m2json(body); + payload = struct(figure=figure, format=format); [un, key, domain] = signin; url = [domain, '/apigenimage/']; - headers = struct(... - 'name',... - {... - 'plotly-username',... - 'plotly-apikey',... - 'plotly-version',... - 'plotly-platform',... - 'user-agent' - },... - 'value',... - {... - un,... - key,... - plotly_version,... - 'MATLAB',... - 'MATLAB' - }); - % return the response as bytes - - % convert the bytes to unicode chars if the response fails or isn't - % (pdf, png, or jpeg) ... gnarly! - [response_string, extras] = urlread2(url, 'Post', payload, headers, ... - 'CAST_OUTPUT', false); - if ( extras.status.value ~= 200 || ... - ~(strcmp(extras.allHeaders.Content_Type, 'image/jpeg') || ... - strcmp(extras.allHeaders.Content_Type, 'image/png') || ... - strcmp(extras.allHeaders.Content_Type, 'application/pdf'))) - response_string = native2unicode(response_string); - end + headerFields = [ ... + "plotly-username", string(un); ... + "plotly-apikey", string(key); ... + "plotly-version", plotly_version; ... + "plotly-platform", "MATLAB"; ... + "user-agent", "MATLAB" ... + ]; + + response_object = webwrite(url, payload, weboptions("HeaderFields", headerFields)); + image_data = response_object; - response_handler(response_string, extras); - image_data = response_string; - fileID = fopen(filename, 'w'); fwrite(fileID, image_data); fclose(fileID); diff --git a/plotly/plotly_aux/plotlygetfile.m b/plotly/plotly_aux/plotlygetfile.m index dabd45a..c0bd68f 100644 --- a/plotly/plotly_aux/plotlygetfile.m +++ b/plotly/plotly_aux/plotlygetfile.m @@ -1,28 +1,15 @@ function figure = plotlygetfile(file_owner, file_id) [un, key, domain] = signin; - headers = struct(... - 'name',... - {... - 'plotly-username',... - 'plotly-apikey',... - 'plotly-version',... - 'plotly-platform',... - 'user-agent' - },... - 'value',... - {... - un,... - key,... - plotly_version,... - 'MATLAB',... - 'MATLAB' - }); - + headerFields = [ ... + "plotly-username", string(un); ... + "plotly-apikey", string(key); ... + "plotly-version", plotly_version; ... + "plotly-platform", "MATLAB"; ... + "user-agent", "MATLAB" ... + ]; url = [domain, '/apigetfile/', file_owner, '/', num2str(file_id)]; - [response_string, extras] = urlread2(url, 'Get', '', headers); - response_handler(response_string, extras); - response_object = jsondecode(response_string); + response_object = webread(url, weboptions("HeaderFields", headerFields)); figure = response_object.payload.figure; end diff --git a/plotly/plotly_aux/response_handler.m b/plotly/plotly_aux/response_handler.m deleted file mode 100644 index e7d7b45..0000000 --- a/plotly/plotly_aux/response_handler.m +++ /dev/null @@ -1,41 +0,0 @@ -function response_handler(response_body, varargin) - % varargin is the optional `extras` struct - % returned by urlread2 - if (length(varargin)==1) - extras = varargin{1}; - if (strcmp(extras.allHeaders.Content_Type, 'image/jpeg') || ... - strcmp(extras.allHeaders.Content_Type, 'image/png') || ... - strcmp(extras.allHeaders.Content_Type, 'application/pdf') || ... - strcmp(extras.allHeaders.Content_Type, 'image/svg+xml')) - return; - end - end - - response_struct = jsondecode(response_body); - - if (isempty(fieldnames(response_struct))) - error(['Unexpected Response: ', response_body]) - end - f = fieldnames(response_struct); - - if ((any(strcmp(f, 'error')) && (~isempty(response_struct.error))) || ... - (length(varargin) == 1 && varargin{1}.status.value ~= 200)) - % If the error string is nonempty - % then check the `extras` - % object for a status code - % and embed that in the response - if (length(varargin)==1) - extras = varargin{1}; - error(['BadResponse:StatusCode', ... - num2str(extras.status.value)], response_struct.error) - else - error(response_struct.error) - end - end - if any(strcmp(f, 'warning')) - fprintf(response_struct.warning) - end - if any(strcmp(f, 'message')) - fprintf(response_struct.message) - end -end diff --git a/plotly/plotly_aux/urlread2/http_createHeader.m b/plotly/plotly_aux/urlread2/http_createHeader.m deleted file mode 100755 index 0e80241..0000000 --- a/plotly/plotly_aux/urlread2/http_createHeader.m +++ /dev/null @@ -1,11 +0,0 @@ -function header = http_createHeader(name,value) -%http_createHeader Simple function for creating input header to urlread2 -% -% header = http_createHeader(name,value) -% -% CODE: header = struct('name',name,'value',value); -% -% See Also: -% urlread2 - -header = struct('name',name,'value',value); \ No newline at end of file diff --git a/plotly/plotly_aux/urlread2/http_paramsToString.m b/plotly/plotly_aux/urlread2/http_paramsToString.m deleted file mode 100755 index 376a0fa..0000000 --- a/plotly/plotly_aux/urlread2/http_paramsToString.m +++ /dev/null @@ -1,62 +0,0 @@ -function [str,header] = http_paramsToString(params,encodeOption) -%http_paramsToString Creates string for a POST or GET requests -% -% [queryString,header] = http_paramsToString(params, *encodeOption) -% -% INPUTS -% ======================================================================= -% params: cell array of property/value pairs -% NOTE: If the input is in a 2 column matrix, then first column -% entries are properties and the second column entries are -% values, however this is NOT necessary (generally linear) -% encodeOption: (default 1) -% 1 - the typical URL encoding scheme (Java call) -% -% OUTPUTS -% ======================================================================= -% queryString: querystring to add onto URL (LACKS "?", see example) -% header : the header that should be attached for post requests when -% using urlread2 -% -% EXAMPLE: -% ============================================================== -% params = {'cmd' 'search' 'db' 'pubmed' 'term' 'wtf batman'}; -% queryString = http_paramsToString(params); -% queryString => cmd=search&db=pubmed&term=wtf+batman -% -% IMPORTANT: This function does not filter parameters, sort them, -% or remove empty inputs (if necessary), this must be done before hand - -if ~exist('encodeOption','var') - encodeOption = 1; -end - -if size(params,2) == 2 && size(params,1) > 1 - params = params'; - params = params(:); -end - -str = ''; -for i=1:2:length(params) - if (i == 1), separator = ''; else separator = '&'; end - switch encodeOption - case 1 - param = urlencode(params{i}); - value = urlencode(params{i+1}); -% case 2 -% param = oauth.percentEncodeString(params{i}); -% value = oauth.percentEncodeString(params{i+1}); -% header = http_getContentTypeHeader(1); - otherwise - error('Case not used') - end - str = [str separator param '=' value]; %#ok -end - -switch encodeOption - case 1 - header = http_createHeader('Content-Type','application/x-www-form-urlencoded'); -end - - -end \ No newline at end of file diff --git a/plotly/plotly_aux/urlread2/license.txt b/plotly/plotly_aux/urlread2/license.txt deleted file mode 100644 index 1d783b7..0000000 --- a/plotly/plotly_aux/urlread2/license.txt +++ /dev/null @@ -1,24 +0,0 @@ -Copyright (c) 2012, Jim Hokanson -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the distribution - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. diff --git a/plotly/plotly_aux/urlread2/urlread2.m b/plotly/plotly_aux/urlread2/urlread2.m deleted file mode 100755 index b552861..0000000 --- a/plotly/plotly_aux/urlread2/urlread2.m +++ /dev/null @@ -1,371 +0,0 @@ -function [output,extras] = urlread2(urlChar,method,body,headersIn,varargin) -%urlread2 Makes HTTP requests and processes response -% -% [output,extras] = urlread2(urlChar, *method, *body, *headersIn, varargin) -% -% * indicates optional inputs that must be entered in place -% -% UNDOCUMENTED MATLAB VERSION -% -% EXAMPLE CALLING FORMS -% ... = urlread2(urlChar) -% ... = urlread2(urlChar,'GET','',[],prop1,value1,prop2,value2,etc) -% ... = urlread2(urlChar,'POST',body,headers) -% -% FEATURES -% ======================================================================= -% 1) Allows specification of any HTTP method -% 2) Allows specification of any header. Very little is hard-coded -% in for header handling. -% 3) Returns response status and headers -% 4) Should handle unicode properly ... -% -% OUTPUTS -% ======================================================================= -% output : body of the response, either text or binary depending upon -% CAST_OUTPUT property -% extras : (structure) -% .allHeaders - stucture, fields have cellstr values, HTTP headers may -% may be repeated but will have a single field entry, with each -% repeat's value another being another entry in the cellstr, for -% example: -% .Set_Cookie = {'first_value' 'second_value'} -% .firstHeaders - (structure), variable fields, contains the first -% string entry for each field in allHeaders, this -% structure can be used to avoid dereferencing a cell -% for fields you expect not to be repeated ... -% EXAMPLE: -% .Response : 'HTTP/1.1 200 OK'} -% .Server : 'nginx' -% .Date : 'Tue, 29 Nov 2011 02:23:16 GMT' -% .Content_Type : 'text/html; charset=UTF-8' -% .Content_Length : '109155' -% .Connection : 'keep-alive' -% .Vary : 'Accept-Encoding, User-Agent' -% .Cache_Control : 'max-age=60, private' -% .Set_Cookie : 'first_value' -% .status - (structure) -% .value : numeric value of status, ex. 200 -% .msg : message that goes along with status, ex. 'OK' -% .url - eventual url that led to output, this can change from -% the input with redirects, see FOLLOW_REDIRECTS -% .isGood - (logical) I believe this is an indicator of the presence of 400 -% or 500 status codes (see status.value) but more -% testing is needed. In other words, true if status.value < 400. -% In code, set true if the response was obtainable without -% resorting to checking the error stream. -% -% INPUTS -% ======================================================================= -% urlChar : The full url, must include scheme (http, https) -% method : examples: 'GET' 'POST' etc -% body : (vector)(char, uint8 or int8) body to write, generally used -% with POST or PUT, use of uint8 or int8 ensures that the -% body input is not manipulated before sending, char is sent -% via unicode2native function with ENCODING input (see below) -% headersIn : (structure array), use empty [] or '' if no headers are needed -% but varargin property/value pairs are, multiple headers -% may be passed in as a structure array -% .name - (string), name of the header, a name property is used -% instead of a field because the name must match a valid -% header -% .value - (string), value to use -% -% OPTIONAL INPUTS (varargin, property/value pairs) -% ======================================================================= -% CAST_OUTPUT : (default true) output is uint8, useful if the body -% of the response is not text -% ENCODING : (default ''), ENCODING input to function unicode2native -% FOLLOW_REDIRECTS : (default true), if false 3xx status codes will -% be returned and need to be handled by the user, -% note this does not handle javascript or meta tag -% redirects, just server based ones -% READ_TIMEOUT : (default 0), 0 means no timeout, value is in -% milliseconds -% -% EXAMPLES -% ======================================================================= -% GET: -% -------------------------------------------- -% url = 'http://www.mathworks.com/matlabcentral/fileexchange/'; -% query = 'urlread2'; -% params = {'term' query}; -% queryString = http_paramsToString(params,1); -% url = [url '?' queryString]; -% [output,extras] = urlread2(url); -% -% POST: -% -------------------------------------------- -% url = 'http://posttestserver.com/post.php'; -% params = {'testChars' char([2500 30000]) 'new code' '?'}; -% [paramString,header] = http_paramsToString(params,1); -% [output,extras] = urlread2(url,'POST',paramString,header); -% -% From behind a firewall, use the Preferences to set your proxy server. -% -% See Also: -% http_paramsToString -% unicode2native -% native2unicode -% -% Subfunctions: -% fixHeaderCasing - small subfunction to fix case errors encountered in real -% world, requires updating when casing doesn't match expected form, like -% if someone sent the header content-Encoding instead of -% Content-Encoding -% -% Based on original urlread code by Matthew J. Simoneau -% -% VERSION = 1.1 - -in.CAST_OUTPUT = true; -in.FOLLOW_REDIRECTS = true; -in.READ_TIMEOUT = 0; -in.ENCODING = ''; - -%Input handling -%--------------------------------------- -if ~isempty(varargin) - for i = 1:2:numel(varargin) - prop = upper(varargin{i}); - value = varargin{i+1}; - if isfield(in,prop) - in.(prop) = value; - else - error('Unrecognized input to function: %s',prop) - end - end -end - -if ~exist('method','var') || isempty(method), method = 'GET'; end -if ~exist('body','var'), body = ''; end -if ~exist('headersIn','var'), headersIn = []; end - -assert(usejava('jvm'),'Function requires Java') - -import com.mathworks.mlwidgets.io.InterruptibleStreamCopier; -com.mathworks.mlwidgets.html.HTMLPrefs.setProxySettings %Proxy settings need to be set - -%Create a urlConnection. -%----------------------------------- -urlConnection = getURLConnection(urlChar); -%For HTTP uses sun.net.www.protocol.http.HttpURLConnection -%Might use ice.net.HttpURLConnection but this has more overhead - -%SETTING PROPERTIES -%------------------------------------------------------- -urlConnection.setRequestMethod(upper(method)); -urlConnection.setFollowRedirects(in.FOLLOW_REDIRECTS); -urlConnection.setReadTimeout(in.READ_TIMEOUT); - -for iHeader = 1:length(headersIn) - curHeader = headersIn(iHeader); - urlConnection.setRequestProperty(curHeader.name,curHeader.value); -end - -if ~isempty(body) - %Ensure vector? - if size(body,1) > 1 - if size(body,2) > 1 - error('Input parameter to function: body, must be a vector') - else - body = body'; - end - end - - if ischar(body) - %NOTE: '' defaults to Matlab's default encoding scheme - body = unicode2native(body,in.ENCODING); - elseif ~(strcmp(class(body),'uint8') || strcmp(class(body),'int8')) - error('Function input: body, should be of class char, uint8, or int8, detected: %s',class(body)) - end - - urlConnection.setRequestProperty('Content-Length',int2str(length(body))); - urlConnection.setDoOutput(true); - outputStream = urlConnection.getOutputStream; - outputStream.write(body); - outputStream.close; -else - urlConnection.setRequestProperty('Content-Length','0'); -end - -%========================================================================== -% Read the data from the connection. -%========================================================================== -%This should be done first because it tells us if things are ok or not -%NOTE: If there is an error, functions below using urlConnection, notably -%getResponseCode, will fail as well -try - inputStream = urlConnection.getInputStream; - isGood = true; -catch ME - isGood = false; -%NOTE: HTTP error codes will throw an error here, we'll allow those for now -%We might also get another error in which case the inputStream will be -%undefined, those we will throw here - inputStream = urlConnection.getErrorStream; - - if isempty(inputStream) - msg = ME.message; - I = strfind(msg,char([13 10 9])); %see example by setting timeout to 1 - %Should remove the barf of the stack, at ... at ... at ... etc - %Likely that this could be improved ... (generate link with full msg) - if ~isempty(I) - msg = msg(1:I(1)-1); - end - fprintf(2,'Response stream is undefined\n below is a Java Error dump (truncated):\n'); - error(msg) - end -end - -%POPULATING HEADERS -%-------------------------------------------------------------------------- -allHeaders = struct; -allHeaders.Response = {char(urlConnection.getHeaderField(0))}; -done = false; -headerIndex = 0; - -while ~done - headerIndex = headerIndex + 1; - headerValue = char(urlConnection.getHeaderField(headerIndex)); - if ~isempty(headerValue) - headerName = char(urlConnection.getHeaderFieldKey(headerIndex)); - headerName = fixHeaderCasing(headerName); %NOT YET FINISHED - - %Important, for name safety all hyphens are replace with underscores - headerName(headerName == '-') = '_'; - if isfield(allHeaders,headerName) - allHeaders.(headerName) = [allHeaders.(headerName) headerValue]; - else - allHeaders.(headerName) = {headerValue}; - end - else - done = true; - end -end - -firstHeaders = struct; -fn = fieldnames(allHeaders); -for iHeader = 1:length(fn) - curField = fn{iHeader}; - firstHeaders.(curField) = allHeaders.(curField){1}; -end - -status = struct(... - 'value', urlConnection.getResponseCode(),... - 'msg', char(urlConnection.getResponseMessage)); - -%PROCESSING OF OUTPUT -%---------------------------------------------------------- -byteArrayOutputStream = java.io.ByteArrayOutputStream; -% This StreamCopier is unsupported and may change at any time. OH GREAT :/ -isc = InterruptibleStreamCopier.getInterruptibleStreamCopier; -isc.copyStream(inputStream,byteArrayOutputStream); -inputStream.close; -byteArrayOutputStream.close; - -if in.CAST_OUTPUT - charset = ''; - - %Extraction of character set from Content-Type header if possible - if isfield(firstHeaders,'Content_Type') - text = firstHeaders.Content_Type; - %Always open to regexp improvements - charset = regexp(text,'(?<=charset=)[^\s]*','match','once'); - end - - if ~isempty(charset) - output = native2unicode(typecast(byteArrayOutputStream.toByteArray','uint8'),charset); - else - output = char(typecast(byteArrayOutputStream.toByteArray','uint8')); - end -else - %uint8 is more useful for later charecter conversions - %uint8 or int8 is somewhat arbitary at this point - output = typecast(byteArrayOutputStream.toByteArray','uint8'); -end - -extras = struct; -extras.allHeaders = allHeaders; -extras.firstHeaders = firstHeaders; -extras.status = status; -%Gets eventual url even with redirection -extras.url = char(urlConnection.getURL); -extras.isGood = isGood; - - - -end - -function headerNameOut = fixHeaderCasing(headerName) -%fixHeaderCasing Forces standard casing of headers -% -% headerNameOut = fixHeaderCasing(headerName) -% -% This is important for field access in a structure which -% is case sensitive -% -% Not yet finished. -% I've been adding to this function as problems come along - - switch lower(headerName) - case 'location' - headerNameOut = 'Location'; - case 'content_type' - headerNameOut = 'Content_Type'; - otherwise - headerNameOut = headerName; - end -end - -%========================================================================== -%========================================================================== -%========================================================================== - -function urlConnection = getURLConnection(urlChar) -%getURLConnection -% -% urlConnection = getURLConnection(urlChar) - -% Determine the protocol (before the ":"). -protocol = urlChar(1:find(urlChar==':',1)-1); - - -% Try to use the native handler, not the ice.* classes. -try - switch protocol - case 'http' - %http://www.docjar.com/docs/api/sun/net/www/protocol/http/HttpURLConnection.html - handler = sun.net.www.protocol.http.Handler; - case 'https' - handler = sun.net.www.protocol.https.Handler; - end -catch ME - handler = []; -end - -% Create the URL object. -try - if isempty(handler) - url = java.net.URL(urlChar); - else - url = java.net.URL([],urlChar,handler); - end -catch ME - error('Failure to parse URL or protocol not supported for:\nURL: %s',urlChar); -end - -% Get the proxy information using MathWorks facilities for unified proxy -% preference settings. -mwtcp = com.mathworks.net.transport.MWTransportClientPropertiesFactory.create(); -proxy = mwtcp.getProxy(); - -% Open a connection to the URL. -if isempty(proxy) - urlConnection = url.openConnection; -else - urlConnection = url.openConnection(proxy); -end - - -end diff --git a/plotly/plotly_aux/urlread2/urlread_notes.txt b/plotly/plotly_aux/urlread2/urlread_notes.txt deleted file mode 100755 index 8257f09..0000000 --- a/plotly/plotly_aux/urlread2/urlread_notes.txt +++ /dev/null @@ -1,86 +0,0 @@ -========================================================================== - Unicode & Matlab -========================================================================== -native2unicode - works with uint8, fails with char - -Taking a unicode character and encoding as bytes: -unicode2native(char(1002),'UTF-8') -back to the character: -native2unicode(uint8([207 170]),'UTF-8') -this doesn't work: -native2unicode(char([207 170]),'UTF-8') -in documentation: If BYTES is a CHAR vector, it is returned unchanged. - -Java - only supports int8 -Matlab to Java -> uint8 or int8 to bytes -Java to Matlab -> bytes to int8 -char - 16 bit - -Maintenance of underlying bytes: -typecast(java.lang.String(uint8(250)).getBytes,'uint8') = 250 -see documentation: Handling Data Returned from a Java Method - -Command Window difficulty --------------------------------------------------------------------- -The typical font in the Matlab command window will often fail to render -unicode properly. I often can see unicode better in the variable editor -although this may be fixed if you change your font preferences ... -Copying unicode from the command window often results in the -generations of the value 26 (aka substitute) - -More documentation on input/output to urlread2 to follow eventually ... - -small notes to self: -for output -native2unicode(uint8(output),encoding) - -========================================================================== - HTTP Headers -========================================================================== -Handling of repeated http readers is a bit of a tricky situation. Most -headers are not repeated although sometimes http clients will assume this -for too many headers which can result in a problem if you want to see -duplicated headers. I've passed the problem onto the user who can decide -to handle it how they wish instead of providing the right solution, which -after some brief searching, I am not sure exists. - -========================================================================== - PROBLEMS -========================================================================== -1) Page requires following a redirect: -%------------------------------------------- -ref: http://www.mathworks.com/matlabcentral/newsreader/view_thread/302571 -fix: FOLLOW_REDIRECTS is enabled by default, you're fine. - -2) Basic authentication required: -%------------------------------------------ -Create and pass in the following header: -user = 'test'; -password = 'test'; -encoder = sun.misc.BASE64Encoder(); -str = java.lang.String([user ':' password]) %NOTE: format may be -%different for your server -header = http_createHeader('Authorization',char(encoder.encode(str.getBytes()))) -NOTE: Ideally you would make this a function - -3) The text returned doesn't make sense. -%----------------------------------------- -The text may not be encoded correctly. Requires native2unicode function. -See Unicode & Matlab section above. - -4) I get a different result in my web browser than I do in Matlab -%----------------------------------------- -This is generally seen for two reasons. -1 - The easiest and silly reason is user agent filtering. -When you make a request you identify yourself -as being a particular "broswer" or "user agent". Setting a header -with the user agent of the browser may fix the problem. -See: http://en.wikipedia.org/wiki/User_agent -See: http://whatsmyuseragent.com -value = '' -header = http_createHeader('User-Agent',value); -2 - You are not processing cookies and the server is not sending -you information because you haven't sent it cookies (everyone likes em!) -I've implemented cookie support but it requires some extra files that -I need to clean up. Feel free to email me if you'd really like to have them. - diff --git a/plotly/plotly_aux/urlread2/urlread_todos.txt b/plotly/plotly_aux/urlread2/urlread_todos.txt deleted file mode 100755 index 0434bce..0000000 --- a/plotly/plotly_aux/urlread2/urlread_todos.txt +++ /dev/null @@ -1,13 +0,0 @@ -========================================================================== - IMPROVEMENTS -========================================================================== -1) The function could be improved to support file streaming both in sending -and in receiving (saving) to reduce memory usage but this is very low priority - -2) Implement better casing handling - -3) Choose a better function name than urlread2 -> sorry Chris :) - -4) Support multipart/form-data, this ideally would be handled by a helper function - -5) Allow for throwing an error if the HTTP status code is an error (400) and 500 as well? \ No newline at end of file diff --git a/plotly/plotly_aux/urlread2/urlread_versionInfo.txt b/plotly/plotly_aux/urlread2/urlread_versionInfo.txt deleted file mode 100755 index a8448f4..0000000 --- a/plotly/plotly_aux/urlread2/urlread_versionInfo.txt +++ /dev/null @@ -1,13 +0,0 @@ -===================== -Version 1.1 -3/25/2012 - -Summary: Bug fixes related to Matlab throwing errors when it shouldn't have been. Thanks to Shane Lin for pointing out the problems. - -Bug Fix: Modified code so that http status errors wouldn't throw errors in the code, but rather would be passed on to the user to process - -Bug Fix: Provided GET example code apparently doesn't work for all users, changed to a different example. - -===================== -Version 1 -3/17/2012 \ No newline at end of file diff --git a/plotly/plotly_offline_aux/getplotlyoffline.m b/plotly/plotly_offline_aux/getplotlyoffline.m index 765d6a2..98fd687 100644 --- a/plotly/plotly_offline_aux/getplotlyoffline.m +++ b/plotly/plotly_offline_aux/getplotlyoffline.m @@ -1,13 +1,11 @@ function getplotlyoffline(plotly_bundle_url) - % download bundle - [plotly_bundle, extras] = urlread2(plotly_bundle_url, 'get'); - - % handle response - if ~extras.isGood - error(['Whoops! There was an error attempting to ', ... - 'download the MATLAB offline Plotly ', ... - 'bundle. Status: %s %s.'], ... - num2str(extras.status.value), extras.status.msg); + try + % download bundle + plotly_bundle = webread(plotly_bundle_url); + catch exception + disp("Whoops! There was an error attempting to download the " ... + + "MATLAB offline Plotly bundle"); + rethrow(exception); end % create Plotly config folder