bool CLogThread::queueLog(IEspContext & context,const char* serviceName, const char* request, const char* response) { IProperties* pProperties = context.queryRequestParameters(); StringBuffer UserID, UserRealm, UserReference, peer; if(pProperties != NULL && pProperties->hasProp("userid_")) UserID.appendf("%s",pProperties->queryProp("userid_")); else context.getUserID(UserID); if(pProperties != NULL && pProperties->hasProp("fqdn_")) UserRealm.appendf("%s",pProperties->queryProp("fqdn_")); else context.getRealm(UserRealm); Owned<IPropertyTree> pLogTreeInfo = createPTreeFromXMLString(request, ipt_none, ptr_none); IArrayOf<IEspLogInfo> LogArray; addLogInfo(LogArray, *pLogTreeInfo.get()); if(pProperties != NULL && pProperties->hasProp("referencecode_")) { //lets manually add the reference number.... IClientLogInfo& LogInfoTransaction = addLogInfoElement(LogArray); LogInfoTransaction.setName("referencenumber"); LogInfoTransaction.setValue(pProperties->queryProp("referencecode_")); } LOG_INFO _LogStruct(serviceName,-1,false); return queueLog(UserID.str(), UserRealm.str() , context.getPeer(peer).str(),_LogStruct, LogArray ); }
int CSoapService::processRequest(ISoapMessage &req, ISoapMessage& resp) { ESP_TIME_SECTION("CSoapService::processRequest()"); CSoapRequest& request = *(dynamic_cast<CSoapRequest*>(&req)); CSoapResponse& response = *(dynamic_cast<CSoapResponse*>(&resp)); IEspContext* ctx = req.queryContext(); StringBuffer requeststr; Owned<CMimeMultiPart> multipart; if(Utils::strncasecmp(request.get_content_type(), HTTP_TYPE_SOAP, strlen(HTTP_TYPE_SOAP))==0 || Utils::strncasecmp(request.get_content_type(), HTTP_TYPE_TEXT_XML, strlen(HTTP_TYPE_TEXT_XML))==0) { requeststr.append(request.get_text()); } else if(!Utils::strncasecmp(request.get_content_type(), HTTP_TYPE_MULTIPART_RELATED, strlen(HTTP_TYPE_MULTIPART_RELATED))) { multipart.setown(LINK(request.queryMultiPart())); CMimeBodyPart* rootpart = multipart->queryRootPart(); if(rootpart != NULL) rootpart->getContent(requeststr); else throw MakeStringException(-1, "MultiPart root is NULL"); } else { throw MakeStringException(-1, "Request type %s not supported", request.get_content_type()); } //Parse the content auto_ptr<XmlPullParser> xpp(new XmlPullParser()); int bufSize = requeststr.length(); xpp->setSupportNamespaces(true); xpp->setInput(requeststr.str(), bufSize); int type; StartTag stag; EndTag etag; Owned<CEnvelope> req_envelope; req_envelope.setown(new CEnvelope); while((type = xpp->next()) != XmlPullParser::END_DOCUMENT) { if(type == XmlPullParser::START_TAG) { xpp->readStartTag(stag); if(!stricmp(stag.getLocalName(), SOAP_ENVELOPE_NAME)) { req_envelope->unmarshall(xpp.get()); break; } } } CHeader* req_header = req_envelope->get_header(); if(req_header != NULL) { // As headers are normally for common uses like authentication and routing, let's process it here // instead of in binding. int ret = processHeader(req_header, ctx); if(ret != 0 ) { response.set_status(ret); return 0; } } StringBuffer peerStr; ctx->getPeer(peerStr); const char* userId = ctx->queryUserId(); CBody* req_body = req_envelope->get_body(); Owned<CRpcResponse> rpc_response; rpc_response.setown(new CRpcResponse); rpc_response->setContext(req.queryContext()); Owned<CRpcCall>rpc_call; rpc_call.setown(new CRpcCall); rpc_call->setContext(req.queryContext()); try { req_body->nextRpcMessage(rpc_call.get()); rpc_call->unmarshall(xpp.get(), multipart.get()); } catch (XmlPullParserException& e) { response.set_status(SOAP_CLIENT_ERROR); response.set_err(e.getMessage().c_str()); DBGLOG("SOAP request from %s@%s. Parsing xml error: %s. Offending XML: [%s]", (userId&&*userId)?userId:"unknown", (peerStr.length()>0)?peerStr.str():"unknown", e.getMessage().c_str(), requeststr.str()); return 0; } catch (...) { response.set_status(SOAP_CLIENT_ERROR); response.set_err("Unknown error when parsing soap body XML"); ERRLOG("SOAP request from %s@%s. Unknown error when parsing: %s", (userId&&*userId)?userId:"unknown", (peerStr.length()>0)?peerStr.str():"unknown", requeststr.str()); return 0; } DBGLOG("SOAP method <%s> from %s@%s.", rpc_call->get_name(), (userId&&*userId)?userId:"unknown", (peerStr.length()>0)?peerStr.str():"unknown"); // call the rpc and set the response if(m_soapbinding != NULL) m_soapbinding->processRequest(rpc_call, rpc_response); response.set_status(rpc_response->get_status()); response.set_err(rpc_response->get_err()); Owned<CBody> res_body = new CBody; res_body->add_rpcmessage(rpc_response.get()); Owned<CEnvelope> res_envelope; res_envelope.setown(new CEnvelope(NULL, res_body.getLink())); Owned<CMimeMultiPart> resp_multipart; resp_multipart.setown(new CMimeMultiPart("1.0", "", "MIME_boundary", "text/xml", "soaproot")); res_envelope->marshall(resp_multipart); StringBuffer contenttype; StringBuffer responsestr; resp_multipart->serialize(contenttype, responsestr); response.set_content_type(contenttype.str()); response.set_text(responsestr.str()); return 0; }
bool CLogThread::queueLog(IEspContext & context,LOG_INFO& _LogStruct, IArrayOf<IEspLogInfo>& LogArray, IConstModelLogInformation* pModelLogInfo) { if(!m_pLoggingService.get()) return false; //Owned<IClientLOGServiceUpdateRequest> pRequest = m_pLoggingService->createUpdateLogServiceRequest(); IClientLOGServiceUpdateRequest* tptrRequest; if( m_bModelRequest ) { IClientLOGServiceUpdateModelRequest* pUpdateModelRequest = m_pLoggingService->createUpdateModelLogServiceRequest(); if(pModelLogInfo!=0) { pUpdateModelRequest->setModelLogInformation(*pModelLogInfo); } tptrRequest = dynamic_cast<IClientLOGServiceUpdateRequest*>(pUpdateModelRequest); } else { tptrRequest = m_pLoggingService->createUpdateLogServiceRequest(); } Owned<IClientLOGServiceUpdateRequest> pRequest( tptrRequest ); if (pRequest == 0) return false; StringBuffer UserID,realm,peer; pRequest->setUserName(context.getUserID(UserID).str()); pRequest->setDomainName(context.getRealm(realm).str()); pRequest->setRecordCount(_LogStruct.recordsReturned); pRequest->setServiceName(_LogStruct.serviceName); pRequest->setIP(context.getPeer(peer).str()); bool bBlind = _LogStruct.Blind; bool bEncrypt = _LogStruct.Encrypt; ISecPropertyList* properties = context.querySecuritySettings(); if( properties !=NULL) { if(bBlind==false) { if(properties->findProperty("blind")!=NULL) strncmp(properties->findProperty("blind")->getValue(),"1",1) == 0 ? bBlind=true : bBlind=false; } if(bEncrypt==false && properties->findProperty("encryptedlogging")!=NULL) { if(strncmp(properties->findProperty("encryptedlogging")->getValue(),"1",1) == 0) bEncrypt=true; } } if(bEncrypt==true) { //need to do encrpyted logging pRequest->setEncryptedLogging(true); pRequest->setRawLogInformation(_LogStruct.RequestStr.str()); } pRequest->setBlindLogging(bBlind); pRequest->setLogInformation(LogArray); return queueLog(pRequest,_LogStruct); }