VirtualBox

Changeset 44414 in vbox for trunk


Ignore:
Timestamp:
Jan 28, 2013 11:09:48 AM (12 years ago)
Author:
vboxsync
Message:

Main/webservice: improve API fault handling, provide exact method name information and complete error message details in the single error string, even with multiple errors

Location:
trunk/src/VBox/Main/webservice
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/webservice/vboxweb.cpp

    r43136 r44414  
    66 *      server, to which clients can connect.
    77 *
    8  * Copyright (C) 2007-2012 Oracle Corporation
     8 * Copyright (C) 2007-2013 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    14371437    return aStr.c_str();
    14381438}
    1439 #define DECODE_STR_MAX 0x100000
    1440 void Base64DecodeByteArray(struct soap *soap, std::string& aStr, ComSafeArrayOut(BYTE, aData))
     1439
     1440#define DECODE_STR_MAX _1M
     1441void Base64DecodeByteArray(struct soap *soap, std::string& aStr, ComSafeArrayOut(BYTE, aData), const char *pszMethodName, IUnknown *pObj, const com::Guid &iid)
    14411442{
    14421443    const char* pszStr = aStr.c_str();
     
    14461447    {
    14471448        WebLog("Decode string too long.\n");
    1448         RaiseSoapRuntimeFault(soap, VERR_BUFFER_OVERFLOW, (ComPtr<IUnknown>)NULL);
     1449        RaiseSoapRuntimeFault(soap, pszMethodName, E_INVALIDARG, pObj, iid);
    14491450    }
    14501451
     
    14531454    if (FAILED(rc))
    14541455    {
    1455         WebLog("String Decoding Failed. ERROR: 0x%lX\n", rc);
    1456         RaiseSoapRuntimeFault(soap, rc, (ComPtr<IUnknown>)NULL);
     1456        WebLog("String Decoding Failed. Error code: %Rrc\n", rc);
     1457        RaiseSoapRuntimeFault(soap, pszMethodName, E_INVALIDARG, pObj, iid);
    14571458    }
    14581459
     
    14611462
    14621463/**
    1463  * Raises a SOAP runtime fault. Implementation for the RaiseSoapRuntimeFault template
    1464  * function in vboxweb.h.
    1465  *
     1464 * Raises a SOAP runtime fault.
     1465 *
     1466 * @param soap
     1467 * @param pcszMethodName
     1468 * @param apirc
    14661469 * @param pObj
    1467  */
    1468 void RaiseSoapRuntimeFault2(struct soap *soap,
    1469                             HRESULT apirc,
    1470                             IUnknown *pObj,
    1471                             const com::Guid &iid)
     1470 * @param iid
     1471 */
     1472void RaiseSoapRuntimeFault(struct soap *soap,
     1473                           const char *pcszMethodName,
     1474                           HRESULT apirc,
     1475                           IUnknown *pObj,
     1476                           const com::Guid &iid)
    14721477{
    14731478    com::ErrorInfo info(pObj, iid.ref());
     
    14751480    WEBDEBUG(("   error, raising SOAP exception\n"));
    14761481
    1477     WebLog("API return code:            0x%08X (%Rhrc)\n", apirc, apirc);
    1478     WebLog("COM error info result code: 0x%lX\n", info.getResultCode());
    1479     WebLog("COM error info text:        %ls\n", info.getText().raw());
    1480 
    1481     // allocated our own soap fault struct
     1482    WebLog("API method name:            %s\n", pcszMethodName);
     1483    WebLog("API return code:            %#10lx (%Rhrc)\n", apirc, apirc);
     1484    if (info.isFullAvailable() || info.isBasicAvailable())
     1485    {
     1486        const com::ErrorInfo *pInfo = &info;
     1487        do
     1488        {
     1489            WebLog("COM error info result code: %#10lx (%Rhrc)\n", pInfo->getResultCode(), pInfo->getResultCode());
     1490            WebLog("COM error info text:        %ls\n", pInfo->getText().raw());
     1491
     1492            pInfo = pInfo->getNext();
     1493        }
     1494        while (pInfo);
     1495    }
     1496
     1497    // compose descriptive message
     1498    com::Utf8Str str = com::Utf8StrFmt("VirtualBox error: rc=%#lx", apirc);
     1499    if (info.isFullAvailable() || info.isBasicAvailable())
     1500    {
     1501        const com::ErrorInfo *pInfo = &info;
     1502        do
     1503        {
     1504            str += com::Utf8StrFmt(" %ls (%#lx)", pInfo->getText().raw(), pInfo->getResultCode());
     1505            pInfo = pInfo->getNext();
     1506        }
     1507        while (pInfo);
     1508    }
     1509
     1510    // allocate our own soap fault struct
    14821511    _vbox__RuntimeFault *ex = soap_new__vbox__RuntimeFault(soap, 1);
    14831512    // some old vbox methods return errors without setting an error in the error info,
     
    14881517    ex->component = ConvertComString(info.getComponent());
    14891518    ex->interfaceID = ConvertComString(info.getInterfaceID());
    1490 
    1491     // compose descriptive message
    1492     com::Utf8StrFmt str("VirtualBox error: %s (0x%lX)", ex->text.c_str(), ex->resultCode);
    14931519
    14941520    RaiseSoapFault(soap,
     
    17661792            {
    17671793                ISession *p = session;
    1768                 WEBDEBUG(("   * %s: created session object with comptr 0x%lX, MOR = %s\n", __FUNCTION__, p, _pISession->getWSDLID().c_str()));
     1794                WEBDEBUG(("   * %s: created session object with comptr %#p, MOR = %s\n", __FUNCTION__, p, _pISession->getWSDLID().c_str()));
    17691795            }
    17701796        } while (0);
     
    17941820
    17951821    uintptr_t ulp = (uintptr_t)pObject;
    1796     // WEBDEBUG(("   %s: looking up 0x%lX\n", __FUNCTION__, ulp));
     1822    // WEBDEBUG(("   %s: looking up %#lx\n", __FUNCTION__, ulp));
    17971823    ManagedObjectsMapByPtr::iterator it = _pp->_mapManagedObjectsByPtr.find(ulp);
    17981824    if (it != _pp->_mapManagedObjectsByPtr.end())
    17991825    {
    18001826        ManagedObjectRef *pRef = it->second;
    1801         WEBDEBUG(("   %s: found existing ref %s (%s) for COM obj 0x%lX\n", __FUNCTION__, pRef->getWSDLID().c_str(), pRef->getInterfaceName(), ulp));
     1827        WEBDEBUG(("   %s: found existing ref %s (%s) for COM obj %#lx\n", __FUNCTION__, pRef->getWSDLID().c_str(), pRef->getInterfaceName(), ulp));
    18021828        return pRef;
    18031829    }
     
    19341960    session.touch();
    19351961
    1936     WEBDEBUG(("   * %s: MOR created for %s*=0x%lX (IUnknown*=0x%lX; COM refcount now %RI32/%RI32), new ID is %llX; now %lld objects total\n",
     1962    WEBDEBUG(("   * %s: MOR created for %s*=%#p (IUnknown*=%#p; COM refcount now %RI32/%RI32), new ID is %llX; now %lld objects total\n",
    19371963              __FUNCTION__,
    19381964              pcszInterface,
     
    20832109    } while (0);
    20842110
    2085     WEBDEBUG(("-- leaving %s, rc: 0x%lX\n", __FUNCTION__, rc));
     2111    WEBDEBUG(("-- leaving %s, rc: %#lx\n", __FUNCTION__, rc));
    20862112    if (FAILED(rc))
    20872113        return SOAP_FAULT;
     
    21272153    } while (0);
    21282154
    2129     WEBDEBUG(("-- leaving %s, rc: 0x%lX\n", __FUNCTION__, rc));
     2155    WEBDEBUG(("-- leaving %s, rc: %#lx\n", __FUNCTION__, rc));
    21302156    if (FAILED(rc))
    21312157        return SOAP_FAULT;
     
    22152241    } while (0);
    22162242
    2217     WEBDEBUG(("-- leaving %s, rc: 0x%lX\n", __FUNCTION__, rc));
     2243    WEBDEBUG(("-- leaving %s, rc: %#lx\n", __FUNCTION__, rc));
    22182244    if (FAILED(rc))
    22192245        return SOAP_FAULT;
     
    22442270    } while (0);
    22452271
    2246     WEBDEBUG(("-- leaving %s, rc: 0x%lX\n", __FUNCTION__, rc));
     2272    WEBDEBUG(("-- leaving %s, rc: %#lx\n", __FUNCTION__, rc));
    22472273    if (FAILED(rc))
    22482274        return SOAP_FAULT;
     
    22812307    } while (0);
    22822308
    2283     WEBDEBUG(("-- leaving %s, rc: 0x%lX\n", __FUNCTION__, rc));
     2309    WEBDEBUG(("-- leaving %s, rc: %#lx\n", __FUNCTION__, rc));
    22842310    if (FAILED(rc))
    22852311        return SOAP_FAULT;
  • trunk/src/VBox/Main/webservice/vboxweb.h

    r43136 r44414  
    33 *      header file for "real" web server code.
    44 *
    5  * Copyright (C) 2006-2011 Oracle Corporation
     5 * Copyright (C) 2006-2013 Oracle Corporation
    66 *
    77 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    7272void RaiseSoapInvalidObjectFault(struct soap *soap, WSDLT_ID obj);
    7373
    74 void RaiseSoapRuntimeFault2(struct soap *soap, HRESULT apirc, IUnknown *pObj, const com::Guid &iid);
    75 
    76 /**
    77  * Template function called everywhere from methodmaps.cpp which calls
    78  * RaiseSoapRuntimeFault2() with the correct COM interface ID.
    79  * @param soap
    80  * @param apirc
    81  * @param pObj
    82  */
    83 template <class T>
    84 void RaiseSoapRuntimeFault(struct soap *soap, HRESULT apirc, const ComPtr<T> &pObj)
    85 {
    86     RaiseSoapRuntimeFault2(soap, apirc, pObj, COM_IIDOF(T));
    87 }
     74void RaiseSoapRuntimeFault(struct soap *soap, const char *pcszMethodName, HRESULT apirc, IUnknown *pObj, const com::Guid &iid);
    8875
    8976/****************************************************************************
     
    9986std::string Base64EncodeByteArray(ComSafeArrayIn(BYTE, aData));
    10087
    101 void Base64DecodeByteArray(struct soap *soap, std::string& aStr, ComSafeArrayOut(BYTE, aData));
     88void Base64DecodeByteArray(struct soap *soap, std::string& aStr, ComSafeArrayOut(BYTE, aData), const char *pszMethodName, IUnknown *pObj, const com::Guid &iid);
    10289/****************************************************************************
    10390 *
  • trunk/src/VBox/Main/webservice/websrv-cpp.xsl

    r43136 r44414  
    1212        generated for the webservice.
    1313
    14     Copyright (C) 2007-2012 Oracle Corporation
     14    Copyright (C) 2007-2013 Oracle Corporation
    1515
    1616    This file is part of VirtualBox Open Source Edition (OSE), as
     
    8787const char *g_pcszDoneConvertingComOutputBack = "   done converting COM output \"%s\" back to caller format\n";
    8888const char *g_pcszEntering = "-- entering %s\n";
    89 const char *g_pcszLeaving = "-- leaving %s, rc: 0x%lX (%d)\n";
     89const char *g_pcszLeaving = "-- leaving %s, rc: %#lx (%d)\n";
    9090
    9191// generated string constants for all interface names
     
    534534-->
    535535<xsl:template name="emitInputArgConverter">
     536  <xsl:param name="ifname" />
     537  <xsl:param name="object" />       <!-- normally "pObj" -->
    536538  <xsl:param name="method" />
     539  <xsl:param name="methodname" />
    537540  <xsl:param name="structprefix" />   <!-- with WSDL document style: req element prefix, like "vbox__IVirtualBox_USCOREcreateMachineRequestElement->" -->
    538541  <xsl:param name="name" />
     
    547550       <xsl:value-of select="concat('com::SafeArray&lt;BYTE&gt; comcall_',$name, ';')" />
    548551       <xsl:call-template name="emitNewlineIndent8" />
    549        <xsl:value-of select="concat('Base64DecodeByteArray(soap, ',$structprefix,$name,', ComSafeArrayAsOutParam(comcall_',$name, '));')" />
     552       <xsl:value-of select="concat('Base64DecodeByteArray(soap, ',$structprefix,$name,', ComSafeArrayAsOutParam(comcall_',$name, '), &quot;', $ifname, '::', $methodname, '&quot;, ', $object, ', COM_IIDOF(', $ifname, '));')" />
    550553    </xsl:when>
    551554
     
    779782-->
    780783<xsl:template name="emitComCall">
    781   <xsl:param name="object" />       <!-- normally "pObj->" -->
     784  <xsl:param name="ifname" />
     785  <xsl:param name="object" />       <!-- normally "pObj" -->
    782786  <xsl:param name="methodname" />
    783787  <xsl:param name="attrname" />     <!-- with attributes only -->
     
    787791  <xsl:param name="varprefix" />      <!-- only with nested get-attribute calls -->
    788792
    789   <xsl:variable name="comMethodName">
    790     <xsl:call-template name="capitalize"><xsl:with-param name="str" select="$methodname" /></xsl:call-template>
    791   </xsl:variable>
    792 
    793793  <xsl:call-template name="emitNewlineIndent8" />
    794   <xsl:value-of select="concat('WEBDEBUG((g_pcszCallingComMethod, &quot;', $comMethodName, '&quot;));')" />
     794  <xsl:value-of select="concat('WEBDEBUG((g_pcszCallingComMethod, &quot;', $methodname, '&quot;));')" />
    795795  <xsl:call-template name="emitNewlineIndent8" />
    796   <xsl:value-of select="concat('rc = ', $object, '-&gt;', $comMethodName, '(')" />
     796  <xsl:value-of select="concat('rc = ', $object, '-&gt;', $methodname, '(')" />
    797797  <xsl:if test="$attrtype">
    798798    <xsl:choose>
     
    857857  <xsl:text>{</xsl:text>
    858858  <xsl:call-template name="emitNewlineIndent8" />
    859   <xsl:value-of select="concat('    RaiseSoapRuntimeFault(soap, rc, ', $object, ');')" />
     859  <xsl:value-of select="concat('    RaiseSoapRuntimeFault(soap, &quot;', $ifname, '::', $methodname,'&quot;, rc, ', $object, ', COM_IIDOF(', $ifname, '));')" />
    860860  <xsl:call-template name="emitNewlineIndent8" />
    861861  <xsl:text>    break;</xsl:text>
     
    10681068  <!-- actual COM method call -->
    10691069  <xsl:call-template name="emitComCall">
     1070    <xsl:with-param name="ifname" select="$ifname" />
    10701071    <xsl:with-param name="methodname" select="concat('COMGETTER(', $upperattrname, ')')" />
    10711072    <xsl:with-param name="object" select="$object" />
     
    11031104
    11041105  <xsl:call-template name="emitInputArgConverter">
     1106    <xsl:with-param name="ifname" select="$ifname" />
    11051107    <xsl:with-param name="method" select="concat($ifname, '::', $settername)" />
     1108    <xsl:with-param name="methodname" select="concat('COMSETTER(', $upperattrname, ')')" />
     1109    <xsl:with-param name="object" select="$object" />
    11061110    <xsl:with-param name="name" select="$attrname" />
    11071111    <xsl:with-param name="structprefix" select="concat($G_requestElementVarName, '-&gt;')" />
     
    11101114  </xsl:call-template>
    11111115  <xsl:call-template name="emitComCall">
     1116    <xsl:with-param name="ifname" select="$ifname" />
    11121117    <xsl:with-param name="methodname" select="concat('COMSETTER(', $upperattrname, ')')" />
    11131118    <xsl:with-param name="object" select="$object" />
     
    13781383                  <xsl:when test="$dir='in'">
    13791384                    <xsl:call-template name="emitInputArgConverter">
     1385                      <xsl:with-param name="ifname" select="$ifname" />
    13801386                      <xsl:with-param name="method" select="concat($ifname, '::', $methodname)" />
     1387                      <xsl:with-param name="methodname">
     1388                        <xsl:call-template name="capitalize">
     1389                          <xsl:with-param name="str" select="$methodname" />
     1390                        </xsl:call-template>
     1391                      </xsl:with-param>
     1392                      <xsl:with-param name="object" select='"pObj"' />
    13811393                      <xsl:with-param name="structprefix" select="concat($G_requestElementVarName, '-&gt;')" />
    13821394                      <xsl:with-param name="name" select="@name" />
     
    14051417              <!-- actual COM method call -->
    14061418              <xsl:call-template name="emitComCall">
     1419                <xsl:with-param name="ifname" select="$ifname" />
    14071420                <xsl:with-param name="object" select='"pObj"' />
    14081421                <xsl:with-param name="methodname">
  • trunk/src/VBox/Main/webservice/websrv-wsdl2gsoapH.xsl

    r43103 r44414  
    1010        generated for the webservice.
    1111
    12     Copyright (C) 2006-2010 Oracle Corporation
     12    Copyright (C) 2006-2013 Oracle Corporation
    1313
    1414    This file is part of VirtualBox Open Source Edition (OSE), as
     
    8282
    8383// forward declarations
    84  class _vbox__InvalidObjectFault;
     84class _vbox__InvalidObjectFault;
    8585class _vbox__RuntimeFault;
    8686
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette