From c003a9e3b0fac732f746a99774cdfcd887546f75 Mon Sep 17 00:00:00 2001 From: "rayw%netscape.com" Date: Thu, 29 Nov 2001 03:07:37 +0000 Subject: [PATCH] More bug fixes to SOAP implementation. Not part of default build. --- .../soap/src/nsHTTPSOAPTransport.cpp | 77 +++++++++++-------- .../webservices/soap/tests/soapcall.html | 20 +++-- .../soap/src/nsHTTPSOAPTransport.cpp | 77 +++++++++++-------- extensions/xmlextras/tests/soapcall.html | 20 +++-- 4 files changed, 114 insertions(+), 80 deletions(-) diff --git a/extensions/webservices/soap/src/nsHTTPSOAPTransport.cpp b/extensions/webservices/soap/src/nsHTTPSOAPTransport.cpp index 9ca2e0f4fe45..ee16d823f473 100644 --- a/extensions/webservices/soap/src/nsHTTPSOAPTransport.cpp +++ b/extensions/webservices/soap/src/nsHTTPSOAPTransport.cpp @@ -49,9 +49,22 @@ NS_IMETHODIMP nsHTTPSOAPTransport::SyncCall(nsISOAPCall *aCall, nsISOAPResponse nsresult rv; nsCOMPtr request; + nsCOMPtr messageDocument; + rv = aCall->GetMessage(getter_AddRefs(messageDocument)); + if (NS_FAILED(rv)) return rv; + if (!messageDocument) return NS_ERROR_NOT_INITIALIZED; + request = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; + nsAutoString uri; + rv = aCall->GetTransportURI(uri); + if (NS_FAILED(rv)) return rv; + if (AStringIsNull(uri)) return NS_ERROR_NOT_INITIALIZED; + + rv = request->OpenRequest("POST", NS_ConvertUCS2toUTF8(uri).get(), PR_FALSE, nsnull, nsnull); + if (NS_FAILED(rv)) return rv; + nsAutoString action; rv = aCall->GetActionURI(action); if (NS_FAILED(rv)) return rv; @@ -60,19 +73,6 @@ NS_IMETHODIMP nsHTTPSOAPTransport::SyncCall(nsISOAPCall *aCall, nsISOAPResponse if (NS_FAILED(rv)) return rv; } - nsAutoString uri; - rv = aCall->GetTransportURI(uri); - if (NS_FAILED(rv)) return rv; - if (!AStringIsNull(uri)) return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr messageDocument; - rv = aCall->GetMessage(getter_AddRefs(messageDocument)); - if (NS_FAILED(rv)) return rv; - if (!messageDocument) return NS_ERROR_NOT_INITIALIZED; - - rv = request->OpenRequest("POST", NS_ConvertUCS2toUTF8(uri).get(), PR_FALSE, nsnull, nsnull); - if (NS_FAILED(rv)) return rv; - nsCOMPtr variant = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; @@ -100,6 +100,7 @@ class nsHTTPSOAPTransportCompletion : public nsIDOMEventListener { public: nsHTTPSOAPTransportCompletion(); + nsHTTPSOAPTransportCompletion(nsISOAPCall *call, nsISOAPResponse *response, nsIXMLHttpRequest *request, nsISOAPResponseListener *listener); virtual ~nsHTTPSOAPTransportCompletion(); NS_DECL_ISUPPORTS @@ -120,6 +121,13 @@ nsHTTPSOAPTransportCompletion::nsHTTPSOAPTransportCompletion() { NS_INIT_ISUPPORTS(); } +nsHTTPSOAPTransportCompletion::nsHTTPSOAPTransportCompletion( + nsISOAPCall *call, + nsISOAPResponse *response, + nsIXMLHttpRequest *request, + nsISOAPResponseListener *listener): + mCall(call), mResponse(response), mRequest(request), mListener(listener) {} + nsHTTPSOAPTransportCompletion::~nsHTTPSOAPTransportCompletion() { } @@ -128,7 +136,7 @@ nsHTTPSOAPTransportCompletion::HandleEvent(nsIDOMEvent* aEvent) { nsresult rv; mRequest->GetStatus(&rv); - if (NS_SUCCEEDED(rv)) { + if (mResponse && NS_SUCCEEDED(rv)) { nsCOMPtr document; rv = mRequest->GetResponseXML(getter_AddRefs(document)); if (NS_SUCCEEDED(rv)) { @@ -148,12 +156,25 @@ NS_IMETHODIMP nsHTTPSOAPTransport::AsyncCall(nsISOAPCall *aCall, nsISOAPResponse nsresult rv; nsCOMPtr request; - nsCOMPtr eventTarget = do_QueryInterface(request, &rv); + nsCOMPtr messageDocument; + rv = aCall->GetMessage(getter_AddRefs(messageDocument)); if (NS_FAILED(rv)) return rv; + if (!messageDocument) return NS_ERROR_NOT_INITIALIZED; request = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; + nsCOMPtr eventTarget = do_QueryInterface(request, &rv); + if (NS_FAILED(rv)) return rv; + + nsAutoString uri; + rv = aCall->GetTransportURI(uri); + if (NS_FAILED(rv)) return rv; + if (AStringIsNull(uri)) return NS_ERROR_NOT_INITIALIZED; + + rv = request->OpenRequest("POST", NS_ConvertUCS2toUTF8(uri).get(), PR_TRUE, nsnull, nsnull); + if (NS_FAILED(rv)) return rv; + nsAutoString action; rv = aCall->GetActionURI(action); if (NS_FAILED(rv)) return rv; @@ -161,24 +182,16 @@ NS_IMETHODIMP nsHTTPSOAPTransport::AsyncCall(nsISOAPCall *aCall, nsISOAPResponse rv = request->SetRequestHeader("SOAPAction", NS_ConvertUCS2toUTF8(action).get()); if (NS_FAILED(rv)) return rv; } - nsCOMPtr listener = new nsHTTPSOAPTransportCompletion(); - if (!listener) return NS_ERROR_OUT_OF_MEMORY; - nsAutoString uri; - rv = aCall->GetTransportURI(uri); - if (NS_FAILED(rv)) return rv; - if (!AStringIsNull(uri)) return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr messageDocument; - rv = aCall->GetMessage(getter_AddRefs(messageDocument)); - if (NS_FAILED(rv)) return rv; - if (!messageDocument) return NS_ERROR_NOT_INITIALIZED; - - rv = request->OpenRequest("POST", NS_ConvertUCS2toUTF8(uri).get(), PR_TRUE, nsnull, nsnull); - if (NS_FAILED(rv)) return rv; - - eventTarget->AddEventListener(NS_LITERAL_STRING("load"), listener, PR_FALSE); - eventTarget->AddEventListener(NS_LITERAL_STRING("error"), listener, PR_FALSE); + if (aListener) { + nsCOMPtr listener; + listener = new nsHTTPSOAPTransportCompletion(aCall, aResponse, request, aListener); + if (!listener) return NS_ERROR_OUT_OF_MEMORY; + rv = eventTarget->AddEventListener(NS_LITERAL_STRING("load"), listener, PR_FALSE); + if (NS_FAILED(rv)) return rv; + rv = eventTarget->AddEventListener(NS_LITERAL_STRING("error"), listener, PR_FALSE); + if (NS_FAILED(rv)) return rv; + } nsCOMPtr variant = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; diff --git a/extensions/webservices/soap/tests/soapcall.html b/extensions/webservices/soap/tests/soapcall.html index 6af85713d88e..2094467f2d9b 100644 --- a/extensions/webservices/soap/tests/soapcall.html +++ b/extensions/webservices/soap/tests/soapcall.html @@ -7,13 +7,13 @@ // Passed in as the response handler in the asynchronous case // and called directly (see below) in the synchronous case -function onresponse(resp, call) { +function handleResponse(resp, call, status, end) { if (resp == null) { - return; + return true; } // Was there a SOAP fault in the response? - if (resp.generatedFault()) { + if (resp.fault != null) { var f = resp.fault; var detail = f.detail; var ds = new XMLSerializer(); @@ -21,8 +21,11 @@ function onresponse(resp, call) { alert("Fault:\nFault code: " + f.faultCode + "\nFault string: " + f.faultString + "\nFault actor: " + f.faultActor + "\nDetail: " + detailStr); } else { - var ret = resp.returnValue; - var val = ret.value; + function Count() { + } + var count = new Count(); + var ret = resp.getParameters(false, count); + var val = ret[0].value; var retStr = "Success:\nName: " + ret.name + "\nValue: " + val; // In this case, we happen to know that the result value is an array // and the 5th parameter is a struct. @@ -33,6 +36,7 @@ function onresponse(resp, call) { } alert(retStr); } + return true; } function makeCall(syncCall, faultCall) { @@ -70,14 +74,14 @@ function makeCall(syncCall, faultCall) { // the last parameter is an object that will be serialized into // a struct parameter. It does not have a parameter wrapper because // we don't need it to be named - s.encode("GetLastTradePrice", "uri:some-namespace", 0, null, 5, new Array(5, p1, p2, p3, p4, new SOAPParameter(new Dog("Fido", "Lab", "Black")))); + s.encode("GetLastTradePrice", "uri:some-namespace", 0, null, 3, new Array(p1, p2, p3, p4, new SOAPParameter(new Dog("Fido", "Lab", "Black")))); if (syncCall) { var r = s.invoke(); - onresponse(r, s); + handleResponse(r, s, 0, true); } else { - s.asyncInvoke(onresponse); + s.asyncInvoke(handleResponse); } } diff --git a/extensions/xmlextras/soap/src/nsHTTPSOAPTransport.cpp b/extensions/xmlextras/soap/src/nsHTTPSOAPTransport.cpp index 9ca2e0f4fe45..ee16d823f473 100644 --- a/extensions/xmlextras/soap/src/nsHTTPSOAPTransport.cpp +++ b/extensions/xmlextras/soap/src/nsHTTPSOAPTransport.cpp @@ -49,9 +49,22 @@ NS_IMETHODIMP nsHTTPSOAPTransport::SyncCall(nsISOAPCall *aCall, nsISOAPResponse nsresult rv; nsCOMPtr request; + nsCOMPtr messageDocument; + rv = aCall->GetMessage(getter_AddRefs(messageDocument)); + if (NS_FAILED(rv)) return rv; + if (!messageDocument) return NS_ERROR_NOT_INITIALIZED; + request = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; + nsAutoString uri; + rv = aCall->GetTransportURI(uri); + if (NS_FAILED(rv)) return rv; + if (AStringIsNull(uri)) return NS_ERROR_NOT_INITIALIZED; + + rv = request->OpenRequest("POST", NS_ConvertUCS2toUTF8(uri).get(), PR_FALSE, nsnull, nsnull); + if (NS_FAILED(rv)) return rv; + nsAutoString action; rv = aCall->GetActionURI(action); if (NS_FAILED(rv)) return rv; @@ -60,19 +73,6 @@ NS_IMETHODIMP nsHTTPSOAPTransport::SyncCall(nsISOAPCall *aCall, nsISOAPResponse if (NS_FAILED(rv)) return rv; } - nsAutoString uri; - rv = aCall->GetTransportURI(uri); - if (NS_FAILED(rv)) return rv; - if (!AStringIsNull(uri)) return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr messageDocument; - rv = aCall->GetMessage(getter_AddRefs(messageDocument)); - if (NS_FAILED(rv)) return rv; - if (!messageDocument) return NS_ERROR_NOT_INITIALIZED; - - rv = request->OpenRequest("POST", NS_ConvertUCS2toUTF8(uri).get(), PR_FALSE, nsnull, nsnull); - if (NS_FAILED(rv)) return rv; - nsCOMPtr variant = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; @@ -100,6 +100,7 @@ class nsHTTPSOAPTransportCompletion : public nsIDOMEventListener { public: nsHTTPSOAPTransportCompletion(); + nsHTTPSOAPTransportCompletion(nsISOAPCall *call, nsISOAPResponse *response, nsIXMLHttpRequest *request, nsISOAPResponseListener *listener); virtual ~nsHTTPSOAPTransportCompletion(); NS_DECL_ISUPPORTS @@ -120,6 +121,13 @@ nsHTTPSOAPTransportCompletion::nsHTTPSOAPTransportCompletion() { NS_INIT_ISUPPORTS(); } +nsHTTPSOAPTransportCompletion::nsHTTPSOAPTransportCompletion( + nsISOAPCall *call, + nsISOAPResponse *response, + nsIXMLHttpRequest *request, + nsISOAPResponseListener *listener): + mCall(call), mResponse(response), mRequest(request), mListener(listener) {} + nsHTTPSOAPTransportCompletion::~nsHTTPSOAPTransportCompletion() { } @@ -128,7 +136,7 @@ nsHTTPSOAPTransportCompletion::HandleEvent(nsIDOMEvent* aEvent) { nsresult rv; mRequest->GetStatus(&rv); - if (NS_SUCCEEDED(rv)) { + if (mResponse && NS_SUCCEEDED(rv)) { nsCOMPtr document; rv = mRequest->GetResponseXML(getter_AddRefs(document)); if (NS_SUCCEEDED(rv)) { @@ -148,12 +156,25 @@ NS_IMETHODIMP nsHTTPSOAPTransport::AsyncCall(nsISOAPCall *aCall, nsISOAPResponse nsresult rv; nsCOMPtr request; - nsCOMPtr eventTarget = do_QueryInterface(request, &rv); + nsCOMPtr messageDocument; + rv = aCall->GetMessage(getter_AddRefs(messageDocument)); if (NS_FAILED(rv)) return rv; + if (!messageDocument) return NS_ERROR_NOT_INITIALIZED; request = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; + nsCOMPtr eventTarget = do_QueryInterface(request, &rv); + if (NS_FAILED(rv)) return rv; + + nsAutoString uri; + rv = aCall->GetTransportURI(uri); + if (NS_FAILED(rv)) return rv; + if (AStringIsNull(uri)) return NS_ERROR_NOT_INITIALIZED; + + rv = request->OpenRequest("POST", NS_ConvertUCS2toUTF8(uri).get(), PR_TRUE, nsnull, nsnull); + if (NS_FAILED(rv)) return rv; + nsAutoString action; rv = aCall->GetActionURI(action); if (NS_FAILED(rv)) return rv; @@ -161,24 +182,16 @@ NS_IMETHODIMP nsHTTPSOAPTransport::AsyncCall(nsISOAPCall *aCall, nsISOAPResponse rv = request->SetRequestHeader("SOAPAction", NS_ConvertUCS2toUTF8(action).get()); if (NS_FAILED(rv)) return rv; } - nsCOMPtr listener = new nsHTTPSOAPTransportCompletion(); - if (!listener) return NS_ERROR_OUT_OF_MEMORY; - nsAutoString uri; - rv = aCall->GetTransportURI(uri); - if (NS_FAILED(rv)) return rv; - if (!AStringIsNull(uri)) return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr messageDocument; - rv = aCall->GetMessage(getter_AddRefs(messageDocument)); - if (NS_FAILED(rv)) return rv; - if (!messageDocument) return NS_ERROR_NOT_INITIALIZED; - - rv = request->OpenRequest("POST", NS_ConvertUCS2toUTF8(uri).get(), PR_TRUE, nsnull, nsnull); - if (NS_FAILED(rv)) return rv; - - eventTarget->AddEventListener(NS_LITERAL_STRING("load"), listener, PR_FALSE); - eventTarget->AddEventListener(NS_LITERAL_STRING("error"), listener, PR_FALSE); + if (aListener) { + nsCOMPtr listener; + listener = new nsHTTPSOAPTransportCompletion(aCall, aResponse, request, aListener); + if (!listener) return NS_ERROR_OUT_OF_MEMORY; + rv = eventTarget->AddEventListener(NS_LITERAL_STRING("load"), listener, PR_FALSE); + if (NS_FAILED(rv)) return rv; + rv = eventTarget->AddEventListener(NS_LITERAL_STRING("error"), listener, PR_FALSE); + if (NS_FAILED(rv)) return rv; + } nsCOMPtr variant = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; diff --git a/extensions/xmlextras/tests/soapcall.html b/extensions/xmlextras/tests/soapcall.html index 6af85713d88e..2094467f2d9b 100644 --- a/extensions/xmlextras/tests/soapcall.html +++ b/extensions/xmlextras/tests/soapcall.html @@ -7,13 +7,13 @@ // Passed in as the response handler in the asynchronous case // and called directly (see below) in the synchronous case -function onresponse(resp, call) { +function handleResponse(resp, call, status, end) { if (resp == null) { - return; + return true; } // Was there a SOAP fault in the response? - if (resp.generatedFault()) { + if (resp.fault != null) { var f = resp.fault; var detail = f.detail; var ds = new XMLSerializer(); @@ -21,8 +21,11 @@ function onresponse(resp, call) { alert("Fault:\nFault code: " + f.faultCode + "\nFault string: " + f.faultString + "\nFault actor: " + f.faultActor + "\nDetail: " + detailStr); } else { - var ret = resp.returnValue; - var val = ret.value; + function Count() { + } + var count = new Count(); + var ret = resp.getParameters(false, count); + var val = ret[0].value; var retStr = "Success:\nName: " + ret.name + "\nValue: " + val; // In this case, we happen to know that the result value is an array // and the 5th parameter is a struct. @@ -33,6 +36,7 @@ function onresponse(resp, call) { } alert(retStr); } + return true; } function makeCall(syncCall, faultCall) { @@ -70,14 +74,14 @@ function makeCall(syncCall, faultCall) { // the last parameter is an object that will be serialized into // a struct parameter. It does not have a parameter wrapper because // we don't need it to be named - s.encode("GetLastTradePrice", "uri:some-namespace", 0, null, 5, new Array(5, p1, p2, p3, p4, new SOAPParameter(new Dog("Fido", "Lab", "Black")))); + s.encode("GetLastTradePrice", "uri:some-namespace", 0, null, 3, new Array(p1, p2, p3, p4, new SOAPParameter(new Dog("Fido", "Lab", "Black")))); if (syncCall) { var r = s.invoke(); - onresponse(r, s); + handleResponse(r, s, 0, true); } else { - s.asyncInvoke(onresponse); + s.asyncInvoke(handleResponse); } }