Jump to content
Sign in to follow this  
field

TW3HttpRequest.ResponseXML buggy

Recommended Posts

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)?! 


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×