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
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
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 }
00185