00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #include "OW_config.h"
00036 #include "OW_CppIndicationExportXMLHTTPProvider.hpp"
00037 #include "OW_HTTPClient.hpp"
00038 #include "OW_ConfigOpts.hpp"
00039 #include "OW_IndicationExporter.hpp"
00040 #include "OW_Format.hpp"
00041 #include "OW_CIMInstance.hpp"
00042 #include "OW_CIMProperty.hpp"
00043 #include "OW_CIMValue.hpp"
00044 #include "OW_MutexLock.hpp"
00045 #include "OW_Logger.hpp"
00046
00047 namespace OW_NAMESPACE
00048 {
00049
00050 using namespace WBEMFlags;
00051
00052 namespace
00053 {
00054 const String COMPONENT_NAME("ow.provider.CppIndicationExportXMLHTTP");
00055
00056 class HTTPClientListJanitor
00057 {
00058 public:
00059 HTTPClientListJanitor(std::list<HTTPClientRef>::iterator httpClient, std::list<HTTPClientRef>& list, Mutex& guard)
00060 : m_httpClient(httpClient)
00061 , m_list(list)
00062 , m_guard(guard)
00063 {
00064 }
00065
00066 ~HTTPClientListJanitor()
00067 {
00068 MutexLock lock(m_guard);
00069 m_list.erase(m_httpClient);
00070 }
00071 private:
00072 std::list<HTTPClientRef>::iterator m_httpClient;
00073 std::list<HTTPClientRef>& m_list;
00074 Mutex& m_guard;
00075 };
00076 }
00077
00079 CppIndicationExportXMLHTTPProvider::CppIndicationExportXMLHTTPProvider()
00080 : m_cancelled(false)
00081 {
00082 }
00083
00085 CppIndicationExportXMLHTTPProvider::~CppIndicationExportXMLHTTPProvider()
00086 {
00087 }
00088
00090
00091 void
00092 CppIndicationExportXMLHTTPProvider::exportIndication(
00093 const ProviderEnvironmentIFCRef& env,
00094 const String& ns,
00095 const CIMInstance &indHandlerInst,
00096 const CIMInstance &indicationInst_)
00097 {
00098
00099 CIMInstance indicationInst(indicationInst_.clone(E_NOT_LOCAL_ONLY, E_EXCLUDE_QUALIFIERS, E_INCLUDE_CLASS_ORIGIN));
00100
00101 LoggerRef logger = env->getLogger(COMPONENT_NAME);
00102 OW_LOG_DEBUG(logger, Format("CppIndicationExportXMLHTTPProvider "
00103 "exporting indication. Handler = %1, Indication = %2",
00104 indHandlerInst.toString(), indicationInst.toString()));
00105
00106 String listenerUrl;
00107 indHandlerInst.getProperty("Destination").getValue().get(listenerUrl);
00108
00109
00110 URL url(listenerUrl);
00111
00112 if (indHandlerInst.getClassName().equalsIgnoreCase("CIM_IndicationHandlerXMLHTTPS"))
00113 {
00114 if (!url.scheme.equals(URL::CIMXML_WBEMS))
00115 {
00116 url.scheme = URL::CIMXML_WBEMS;
00117 listenerUrl = url.toString();
00118 }
00119 }
00120
00121 HTTPClientRef httpClient = new HTTPClient(listenerUrl);
00122 IndicationExporter exporter = IndicationExporter(httpClient);
00123
00124
00125
00126 if (!url.namespaceName.empty())
00127 {
00128 httpClient->setHTTPPath('/' + url.namespaceName);
00129 }
00130
00131
00132 MutexLock lock(m_guard);
00133 if (m_cancelled)
00134 {
00135 return;
00136 }
00137 m_httpClients.push_back(httpClient);
00138 HTTPClientListJanitor janitor(--m_httpClients.end(), m_httpClients, m_guard);
00139 lock.release();
00140
00141 exporter.exportIndication(ns, indicationInst);
00142 }
00144
00145
00146 StringArray
00147 CppIndicationExportXMLHTTPProvider::getHandlerClassNames()
00148 {
00149 StringArray rv;
00150 rv.append("CIM_IndicationHandlerXMLHTTP");
00151 rv.append("CIM_IndicationHandlerXMLHTTPS");
00152 rv.append("CIM_IndicationHandlerCIMXML");
00153
00154 rv.append("CIM_ListenerDestinationCIMXML");
00155
00156 return rv;
00157 }
00158
00160 void
00161 CppIndicationExportXMLHTTPProvider::doCooperativeCancel()
00162 {
00163 MutexLock lock(m_guard);
00164 m_cancelled = true;
00165 for (std::list<HTTPClientRef>::iterator iter = m_httpClients.begin(); iter != m_httpClients.end(); ++iter)
00166 {
00167 (*iter)->close();
00168 }
00169 }
00170
00171
00172 }
00173
00175 OW_PROVIDERFACTORY(OpenWBEM::CppIndicationExportXMLHTTPProvider, cppindicationexportxmlhttpprovider);
00176