00001
00027
00028
00030 #pragma warning ( disable: 4786 )
00031 #include "SOAPDispatcher.h"
00032 #if !defined(SOAPENCODER_H)
00033 #include "SOAPEncoder.h"
00034 #endif // SOAPENCODER_H
00035 #if !defined(SOAPOBJECT_H)
00036 #include "SOAPObject.h"
00037 #endif // !defined(SOAPOBJECT_H)
00038 #if !defined(SOAPFAULT_H)
00039 #include "SOAPFault.h"
00040 #endif // !defined(SOAPFAULT_H)
00041
00043
00045
00046 SOAPDispatcher::SOAPDispatcher()
00047 {
00048 currentMethodList = NULL;
00049 }
00050
00051 SOAPDispatcher::~SOAPDispatcher()
00052 {
00053 for (CreatorContainer::iterator it = m_creatorContainer.begin();
00054 it != m_creatorContainer.end(); ++it)
00055 {
00056 delete it->second;
00057 }
00058 }
00059
00060 SOAPDispatcher& SOAPDispatcher::Instance()
00061 {
00062 return Singleton<SOAPDispatcher>::Instance();
00063 }
00064
00065 bool SOAPDispatcher::registerObject( SOAPObjectCreator* pCreator )
00066 {
00067
00068 CreatorContainer::iterator it = m_creatorContainer.find( pCreator->createdObjectName() );
00069 bool retval = false;
00070 if ( it == m_creatorContainer.end() )
00071 {
00072
00073
00074 retval = true;
00075 m_creatorContainer.insert( CreatorContainer::value_type(
00076 pCreator->createdObjectName(), pCreator ) );
00077 }
00078 return retval;
00079 }
00080
00081 SOAPMethod * SOAPDispatcher::GetMethod( const char* methodName )
00082 {
00083
00084 if ( currentMethodList )
00085 for ( SOAPObject::MethodList::iterator it = currentMethodList->begin(); it != currentMethodList->end(); ++it )
00086 if ( (*it)->methodName() == methodName )
00087 {
00088 return (*it);
00089 }
00090
00091 return NULL;
00092 }
00093
00094 std::string SOAPDispatcher::processMessage(
00095 const std::string& KszObjectName,
00096 const std::string& KszMethodName,
00097 SOAPElement& theCall,
00098 bool& bContainsFault)
00099 {
00100 std::string retval;
00101 SOAPEncoder theEncoder;
00102 SOAPFault soapFault;
00103 CreatorContainer::iterator it = m_creatorContainer.find( KszObjectName );
00104
00105 if ( it != m_creatorContainer.end() )
00106 {
00107 std::auto_ptr<SOAPObject> pObject = std::auto_ptr<SOAPObject>( it->second->newSOAPObject() );
00108 if ( NULL != pObject.get() )
00109 {
00110
00111 SOAPObject::MethodList& methodList = pObject->getMethodList();
00112 currentMethodList = &methodList;
00113 bool bFoundMethod = false;
00114 for ( SOAPObject::MethodList::iterator it = methodList.begin(); it != methodList.end(); ++it )
00115 {
00116 if ( (*it)->methodName() == KszMethodName )
00117 {
00118 SOAPElement theMethod;
00119 bFoundMethod = true;
00120
00121
00122
00123 if ( ( !(*it)->mustIUnderstand( theCall ) ) &&
00124 ( (*it)->extractMethod( theCall, theMethod ) ) &&
00125 ( (*it)->execute( theMethod ) ) )
00126 {
00127 retval = theEncoder.encodeMethodResponse( **it );
00128 }
00129 else
00130 {
00131 retval = theEncoder.encodeFault( *((*it)->getFault()) );
00132 bContainsFault = true;
00133 }
00134 break;
00135 }
00136 }
00137 if ( !bFoundMethod )
00138 {
00139
00140 soapFault.setSpecificFault( "CouldNotLocateMethod", SOAPFault::Client );
00141 soapFault.faultString() =
00142 std::string( "Requested object exists but does not "
00143 "implement the requested method: " ) +
00144 KszObjectName + std::string(".") +
00145 KszMethodName;
00146 retval = theEncoder.encodeFault( soapFault );
00147 bContainsFault = true;
00148 }
00149 }
00150 else
00151 {
00152
00153 soapFault.setSpecificFault( "CouldNotCreateObject", SOAPFault::Server );
00154 soapFault.faultString() =
00155 "Requested object exists but could not be created.";
00156 retval = theEncoder.encodeFault( soapFault );
00157 bContainsFault = true;
00158 }
00159 }
00160 else
00161 {
00162
00163
00164 soapFault.setSpecificFault( "ObjectNotFound" );
00165 soapFault.faultString() = "Object: " + KszObjectName +
00166 " Method: " + KszObjectName +
00167 " The requested server context object does not exist on this server.";
00168 retval = theEncoder.encodeFault( soapFault );
00169 bContainsFault = true;
00170 }
00171 currentMethodList = NULL;
00172
00173
00174 return retval;
00175 }