Jump to content


Photo

TW3HttpRequest.ResponseXML buggy


  • Please log in to reply
No replies to this topic

#1 field

field
  • Members
  • 10 posts

Posted 12 January 2017 - 05:00 PM

Hi,

 

SMS 2.2.2.4543:

 

sorry to say, but the TW3HttpRequest / TW3Storage combination seems to be rather untested (see also my other post concerning LoadBinary below)...

 

unit SmartCL.Inet;

 

TW3HttpRequest

...

 property  ResponseXML:string read (handle.responseXML);

end;

 

is wrong > it should be

 

 property  ResponseXML: JDocument read (handle.responseXML);

 

because otherwise we'll never get the Document-Object back (only ever a string)...

 

 

One more suggestion: 

class procedure TW3Storage.LoadXML()

fails to "force" the request to always be loaded as XML/Document > only if the server sends Content-Type header as "text/xml" or "application/xml" ResponseXML (see above) will be filled at all (not, if the server fails to detect the type (e.g. if served with a different extension)?

Therefore class procedure TW3Storage.LoadXML() should get a line:

...

mLoader:=TW3HttpRequest.Create;

  mLoader.Handle.responseType:= 'document';

 

next potential problem is that ResponseXML is of type JDocument - not of type JXMLDocument (which seems to be unsupported anyway everywhere)!

 

Therefore I'd suggest to add/replace (for /in SmartCL.FileUtils):

 

TW3XMLDocumentReadyEvent = procedure(Sender:TW3HttpRequest; ADocument: JDocument);

 

class procedure TW3StorageHelper.LoadXMLDocument(aFilename:String; const OnComplete: TW3XMLDocumentReadyEvent);
var
  mLoader:  TW3HttpRequest;
Begin
  mLoader:=TW3HttpRequest.Create;
  mLoader.Handle.responseType:= 'document';
  mLoader.OnDataReady:=Procedure (sender:TW3HttpRequest)
  Begin
    try
      try
        if assigned(OnComplete) then
        OnComplete(mLoader,sender.ResponseXML);
      except
        on e: exception do;
      end;
    finally
      mLoader.free;
      mLoader:= nil;
    end;
  end;
  mLoader.OnError:=procedure (sender:TW3HttpRequest)
    Begin
      try
        if assigned(OnComplete) then
        OnComplete(mLoader,NIL);
      finally
        mLoader.free;
        mLoader:= nil;
      end;
    end;
 
  try
    mLoader.Get(aFilename);
  except
    on e: exception do
    Raise EW3Storage.CreateFmt(CNT_ERR_IO_FailedLoadStream,[aFilename]);
  end;
end;
 

 

and deprecate LoadXML!

 

 

 

 

ps: probably for some historic reasons 

 

  property Handle read ( Variant(FReqObj) ) 

AND

 Property  Element:JXMLHttpRequest read FReqObj;

 

 

are both included in TW3HttpRequest...

My 2 cents: I think this should be clarified (remove Element? - where is this name coming from anyway - and retype Handle from THandle(=Variant) to JXMLHttpRequest > (ab)using THandle/ Variant just "serves" to remove all (type-/spelling) checks in this case!).

 

pps: 

class procedure TW3Storage.LoadXML() does NOT include exception handling around mLoader.Get(), class procedure TW3Storage.LoadFile however DOES include it?! ...even more inconsistencies (I don't know which one is right)?! 


  • Nico Wouterse and Darincroft like this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

IPB Skin By Virteq