OW_RequestHandlerIFCXML.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #include "OW_config.h"
00037 #include "OW_RequestHandlerIFCXML.hpp"
00038 #include "OW_Assertion.hpp"
00039 #include "OW_CIMErrorException.hpp"
00040 #include "OW_XMLOperationGeneric.hpp"
00041 #include "OW_Format.hpp"
00042 #include "OW_ConfigOpts.hpp"
00043 #include "OW_ServiceEnvironmentIFC.hpp"
00044 #include "OW_ThreadCancelledException.hpp"
00045 #include "OW_XMLParseException.hpp"
00046 #include "OW_Logger.hpp"
00047 #include "OW_OperationContext.hpp"
00048 #include "OW_Array.hpp"
00049 
00050 #define OW_LOGDEBUG(msg) OW_LOG_DEBUG(this->getEnvironment()->getLogger(COMPONENT_NAME), msg)
00051 #define OW_LOGINFO(msg) OW_LOG_INFO(this->getEnvironment()->getLogger(COMPONENT_NAME), msg)
00052 #define OW_LOGERROR(msg) OW_LOG_ERROR(this->getEnvironment()->getLogger(COMPONENT_NAME), msg)
00053 #define OW_LOGFATALERROR(msg) OW_LOG_FATAL_ERROR(this->getEnvironment()->getLogger(COMPONENT_NAME), msg)
00054 
00055 namespace OW_NAMESPACE
00056 {
00057 
00058 namespace
00059 {
00060    const String COMPONENT_NAME("ow.requesthandler.cimxml");
00061 }
00062 using std::istream;
00063 using std::ostream;
00065 RequestHandlerIFCXML::~RequestHandlerIFCXML()
00066 {
00067 }
00069 void
00070 RequestHandlerIFCXML::doProcess(istream* istr, ostream* ostrEntity,
00071    ostream* ostrError, OperationContext& context)
00072 {
00073    OW_ASSERT(ostrEntity);
00074    OW_ASSERT(ostrError);
00075    try
00076    {
00077       setPath(context.getStringData(OperationContext::HTTP_PATH));
00078    }
00079    catch (ContextDataNotFoundException& e)
00080    {
00081       // not found: okay, setPath() won't be called.
00082    }
00083 
00084    try
00085    {
00086       CIMXMLParser parser(*istr);
00087       if (!parser)
00088       {
00089          OW_THROW(CIMErrorException, CIMErrorException::request_not_well_formed);
00090       }
00091       XMLOperationGeneric::XMLGetCIMElement(parser);
00092       if (!parser)
00093       {
00094          OW_THROW(CIMErrorException, CIMErrorException::request_not_loosely_valid);
00095       }
00096       if (!parser.tokenIsId(CIMXMLParser::E_MESSAGE))
00097       {
00098          OW_THROW(CIMErrorException, CIMErrorException::request_not_loosely_valid);
00099       }
00100       try
00101       {
00102          executeXML(parser, ostrEntity, ostrError, context);
00103       }
00104       catch (CIMException& ce)
00105       {
00106          OW_LOGINFO(Format("RequestHandlerIFCXML::doProcess caught CIM "
00107             "exception:\nCode: %1\nFile: %2\n Line: %3\nMessage: %4",
00108             ce.getErrNo(), ce.getFile(), ce.getLine(), ce.getMessage()));
00109          outputError(ce.getErrNo(), ce.getDescription(), *ostrError);
00110       }
00111       catch (CIMErrorException& cee)
00112       {
00113          OW_LOGINFO(Format("RequestHandlerIFCXML::doProcess caught CIMError "
00114             "exception:File: %1\n Line: %2\nMessage: %3",
00115             cee.getFile(), cee.getLine(), cee.getMessage()));
00116          m_cimError = cee.getMessage();
00117          outputError(CIMException::FAILED, cee.getMessage(), *ostrError);
00118       }
00119       catch (Exception& e)
00120       {
00121          OW_LOGINFO(Format("RequestHandlerIFCXML::doProcess caught "
00122             "Exception:%1",   e));
00123          m_cimError = e.getMessage();
00124          outputError(CIMException::FAILED, e.getMessage(), *ostrError);
00125       }
00126       catch (std::exception& e)
00127       {
00128          OW_LOGERROR(Format("RequestHandlerIFCXML::doProcess caught std exception: %1"
00129             , e.what()));
00130          outputError(CIMException::FAILED, e.what(), *ostrError);
00131       }
00132       catch (ThreadCancelledException&)
00133       {
00134          OW_LOGDEBUG("RequestHandlerIFCXML::doProcess caught Thread Cancelled exception.");
00135          outputError(CIMException::FAILED, "thread cancelled", *ostrError);
00136          throw;
00137       }
00138       catch (...)
00139       {
00140          OW_LOGERROR("RequestHandlerIFCXML::doProcess caught unknown exception");
00141          outputError(CIMException::FAILED, "Unknown Exception", *ostrError);
00142       }
00143       if (hasError())
00144       {
00145          (*ostrError) << "</MESSAGE></CIM>\r\n";
00146       }
00147    }
00148    catch (XMLParseException& e)
00149    {
00150       OW_THROW(CIMErrorException, CIMErrorException::request_not_well_formed);
00151    }
00152 }
00154 void
00155 RequestHandlerIFCXML::makeXMLHeader(const String& messageID, ostream& ostr)
00156 {
00157    ostr << XML_CIM_HEADER1;
00158    ostr << XML_CIM_HEADER2;
00159    ostr << "<MESSAGE ID=\"" << messageID << "\" PROTOCOLVERSION=\""
00160       << CIM_PROTOCOL_VERSION << "\">";
00161 }
00163 StringArray
00164 RequestHandlerIFCXML::getSupportedContentTypes() const
00165 {
00166    StringArray rval;
00167    rval.push_back("text/xml");
00168    rval.push_back("application/xml");
00169    return rval;
00170 }
00172 String
00173 RequestHandlerIFCXML::getContentType() const
00174 {
00175    return String("application/xml");
00176 }
00178 void
00179 RequestHandlerIFCXML::setPath(const String& arg)
00180 {
00181    m_path = arg;
00182 }
00183 
00184 } // end namespace OW_NAMESPACE
00185 

Generated on Thu Feb 9 08:48:10 2006 for openwbem by  doxygen 1.4.6