Back to index

lightning-sunbird  0.9+nobinonly
nsSOAPCall.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsSOAPCall.h"
00039 #include "nsSOAPResponse.h"
00040 #include "nsSOAPUtils.h"
00041 #include "nsISOAPTransport.h"
00042 #include "nsIServiceManager.h"
00043 #include "nsIComponentManager.h"
00044 #include "nsIURI.h"
00045 #include "nsNetUtil.h"
00046 #include "nsSOAPException.h"
00047 
00049 //
00050 //
00052 
00053 nsSOAPCall::nsSOAPCall() : mVerifySourceHeader(PR_FALSE)
00054 {
00055 }
00056 
00057 nsSOAPCall::~nsSOAPCall()
00058 {
00059 }
00060 
00061 NS_IMPL_CI_INTERFACE_GETTER2(nsSOAPCall, nsISOAPMessage, nsISOAPCall)
00062     NS_IMPL_ADDREF_INHERITED(nsSOAPCall, nsSOAPMessage)
00063     NS_IMPL_RELEASE_INHERITED(nsSOAPCall, nsSOAPMessage)
00064     NS_INTERFACE_MAP_BEGIN(nsSOAPCall)
00065     NS_INTERFACE_MAP_ENTRY(nsISOAPCall)
00066     NS_IMPL_QUERY_CLASSINFO(nsSOAPCall)
00067     NS_INTERFACE_MAP_END_INHERITING(nsSOAPMessage)
00068 /* attribute boolean verifySourceHeader; */
00069 NS_IMETHODIMP nsSOAPCall::GetVerifySourceHeader(PRBool * aVerifySourceHeader)
00070 {
00071   NS_ENSURE_ARG_POINTER(aVerifySourceHeader);
00072   *aVerifySourceHeader = mVerifySourceHeader;
00073   return NS_OK;
00074 }
00075 
00076 NS_IMETHODIMP nsSOAPCall::SetVerifySourceHeader(PRBool aVerifySourceHeader)
00077 {
00078   mVerifySourceHeader = aVerifySourceHeader;
00079   return NS_OK;
00080 }
00081 
00082 /* attribute DOMString transportURI; */
00083 NS_IMETHODIMP nsSOAPCall::GetTransportURI(nsAString & aTransportURI)
00084 {
00085   aTransportURI.Assign(mTransportURI);
00086   return NS_OK;
00087 }
00088 
00089 NS_IMETHODIMP nsSOAPCall::SetTransportURI(const nsAString & aTransportURI)
00090 {
00091   mTransportURI.Assign(aTransportURI);
00092   return NS_OK;
00093 }
00094 
00095 nsresult nsSOAPCall::GetTransport(nsISOAPTransport ** aTransport)
00096 {
00097   NS_ENSURE_ARG_POINTER(aTransport);
00098   *aTransport = nsnull;
00099 
00100   nsresult rv;
00101   nsCOMPtr<nsIURI> uri;
00102 
00103   rv = NS_NewURI(getter_AddRefs(uri), mTransportURI);
00104   if (NS_FAILED(rv))
00105     return rv;
00106 
00107   nsCAutoString protocol;
00108   uri->GetScheme(protocol);
00109 
00110   nsCAutoString transportContractid;
00111   transportContractid.Assign(NS_SOAPTRANSPORT_CONTRACTID_PREFIX);
00112   transportContractid.Append(protocol);
00113 
00114   return CallGetService(transportContractid.get(), aTransport);
00115 }
00116 
00117 /* nsISOAPResponse invoke (); */
00118 NS_IMETHODIMP nsSOAPCall::Invoke(nsISOAPResponse ** _retval)
00119 {
00120   NS_ENSURE_ARG_POINTER(_retval);
00121   nsresult rv;
00122   nsCOMPtr<nsISOAPTransport> transport;
00123 
00124   if (mTransportURI.IsEmpty()) {
00125     return SOAP_EXCEPTION(NS_ERROR_NOT_INITIALIZED,"SOAP_TRANSPORT_URI", "No transport URI was specified.");
00126   }
00127 
00128   rv = GetTransport(getter_AddRefs(transport));
00129   if (NS_FAILED(rv))
00130     return rv;
00131 
00132   nsCOMPtr<nsISOAPResponse>
00133       response(do_CreateInstance(NS_SOAPRESPONSE_CONTRACTID, &rv));
00134   if (NS_FAILED(rv))
00135     return rv;
00136   rv = response->SetEncoding(mEncoding);
00137   if (NS_FAILED(rv))
00138     return rv;
00139 
00140   rv = transport->SyncCall(this, response);
00141   if (NS_FAILED(rv))
00142     return rv;
00143 
00144   nsCOMPtr<nsIDOMDocument> document;
00145   rv = response->GetMessage(getter_AddRefs(document));        //  No XML response.
00146   if (NS_FAILED(rv))
00147     return rv;
00148   if (!document) {
00149     *_retval = nsnull;
00150     return NS_OK;
00151   }
00152 
00153   return response->QueryInterface(NS_GET_IID(nsISOAPResponse),
00154                                   (void **) _retval);
00155 }
00156 
00157 /* void asyncInvoke (in nsISOAPResponseListener listener); */
00158 NS_IMETHODIMP
00159     nsSOAPCall::AsyncInvoke(nsISOAPResponseListener * listener,
00160                             nsISOAPCallCompletion ** aCompletion)
00161 {
00162   NS_ENSURE_ARG_POINTER(aCompletion);
00163   nsresult rv;
00164   nsCOMPtr<nsISOAPTransport> transport;
00165 
00166   if (mTransportURI.IsEmpty()) {
00167     return SOAP_EXCEPTION(NS_ERROR_NOT_INITIALIZED,"SOAP_TRANSPORT_URI", "No transport URI was specified.");
00168   }
00169 
00170   rv = GetTransport(getter_AddRefs(transport));
00171   if (NS_FAILED(rv))
00172     return rv;
00173 
00174   nsCOMPtr<nsISOAPResponse>
00175       response(do_CreateInstance(NS_SOAPRESPONSE_CONTRACTID, &rv));
00176   if (NS_FAILED(rv))
00177     return rv;
00178   rv = response->SetEncoding(mEncoding);
00179   if (NS_FAILED(rv))
00180     return rv;
00181 
00182   rv = transport->AsyncCall(this, listener, response, aCompletion);
00183   return rv;
00184 }