84 UINT8 *pPiName = NULL;
90 if(pPiServerConfig==NULL)
92 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface: could not configure PI interface: no proper configuration given.\n");
97 pPiName = pPiServerConfig->getHostName();
98 pPiCert = pPiServerConfig->getCertificate();
99 piPort = (
UINT16)pPiServerConfig->getPortNumber();
103 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface: could not configure PI interface: no PI name specified.\n");
109 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface: could not configure PI interface: no PI certificate specified.\n");
118 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface: no server address initialized while trying to configure PI interface.\n");
143 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface: no address initialized while trying to connect. Connect aborted.\n");
153 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface: no socket initialized while trying to connect. Creating new one.\n");
160 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface: no PI server certificate specified. Connect aborted.\n");
172 "CAAccountingBIInterface: Could not connect to BI at %s:%i. Reason: %i\n",
199 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface: no socket initialized while trying to close connection.\n");
216 DOMNodeList *errorMsgList = NULL;
217 UINT8 *allCCsAsString = NULL, *response = NULL;
218 UINT32 contentLength = 0, nrOfErrorMessages = 0, i = 0;
220 SINT32 transmitStatus = 0, domStatus;
221 bool settleSuccessful =
false;
229 allCCsEnvelopeDoc->appendChild(allCCsEnvelope);
231 for (i = 0; i < nrOfCCs; i++)
233 allCCsEnvelope->appendChild(allCCsEnvelopeDoc->importNode(
234 ccs[i]->getXMLDocument()->getDocumentElement(),
true));
238 transmitStatus = (allCCsAsString != NULL) ?
240 allCCsAsString, contentLength) :
E_UNKNOWN;
242 allCCsEnvelopeDoc->release();
243 allCCsEnvelopeDoc = NULL;
244 allCCsEnvelope = NULL;
246 delete [] allCCsAsString;
247 allCCsAsString = NULL;
256 if( (transmitStatus !=
E_SUCCESS) || (status != 200) || (contentLength == 0))
260 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface::settle: timeout while receiving response!\n");
264 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface::settle: received bad response from PI: %u!\n", status);
269 CAMsg::printMsg(LOG_DEBUG,
"CAAccountingBIInterface::settle: got response header [Status,content-Length]=[%i,%i]!\n",
270 status, contentLength);
272 response =
new UINT8[contentLength+1];
279 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface::settle: timeout while receiving settle message!\n");
283 CAMsg::printMsg(LOG_DEBUG,
"CAAccountingBIInterface::settle: error\n");
292 response[contentLength]=
'\0';
294 CAMsg::printMsg(LOG_DEBUG,
"CAAccountingBIInterface::settle: response body received: %s\n", response);
298 if(allCCsEnvelopeDoc != NULL)
306 settleSuccessful =
false;
309 nrOfErrorMessages = errorMsgList->getLength();
312 if(nrOfErrorMessages == nrOfCCs)
315 for (i = 0; i < nrOfErrorMessages; i++)
322 CAMsg::printMsg(LOG_WARNING,
"CAAccountingBIInterface::settle: BUG: number of messages != number of cost confirmations!\n");
332 CAMsg::printMsg(LOG_WARNING,
"CAAccountingBIInterface::settle: PI exception raised.\n");
333 *settleException = (nrOfErrorMessages > 0) ?
342 if(allCCsEnvelopeDoc != NULL)
344 allCCsEnvelopeDoc->release();
345 allCCsEnvelopeDoc = NULL;
348 return (settleException != NULL) ? resultMessages : NULL;
357 UINT8* response=NULL;
358 UINT32 contentLen=0, status=0;
363 pStrCC = cc.dumpToMem(&contentLen);
378 if( ret !=
E_SUCCESS || (status!=200) || (contentLen==0))
382 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface::settle: timeout while receiving response!\n");
386 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface::settle: received bad response from PI!\n");
392 CAMsg::printMsg(LOG_DEBUG,
"CAAccountingBIInterface::settle: got response header [Status,content-Lenght]=[%i,%i]!\n",status,contentLen);
394 response =
new UINT8[contentLen+1];
401 CAMsg::printMsg(LOG_ERR,
"CAAccountingBIInterface::settle: timeout while receiving settle message!\n");
405 CAMsg::printMsg(LOG_DEBUG,
"CAAccountingBIInterface::settle: error\n");
413 CAMsg::printMsg(LOG_DEBUG,
"CAAccountingBIInterface::settle: response body received!\n");
415 response[contentLen]=
'\0';
#define XML_ATTR_SETTLE_SUCCESSFUL
#define POST_CMD_SETTLEALL
#define PI_CONNECT_TIMEOUT
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument(const UINT8 *const buff, UINT32 len)
Parses a buffer containing an XML document and returns this document.
DOMNodeList * getElementsByTagName(DOMElement *pElem, const char *const name)
XERCES_CPP_NAMESPACE::DOMDocument * createDOMDocument()
Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in...
DOMElement * createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.
SINT32 getDOMElementAttribute(const DOMNode *const elem, const char *attrName, UINT8 *value, UINT32 *len)
#define XML_ELEMENT_ERROR_MSG
CAHttpClient * m_phttpClient
CAAccountingBIInterface()
private constructor just initializes fields, server configuration is done separately
SINT32 terminateBIConnection()
Terminate HTTP(s) connection to the BI (JPI)
CASocketAddrINet * m_pPiServerAddress
SINT32 initBIConnection()
Establishes HTTP(s) connection to the BI (JPI)
CAXMLErrorMessage ** settleAll(CAXMLCostConfirmation **CCs, UINT32 nrOfCCs, CAXMLErrorMessage **settleException)
SINT32 setPIServerConfiguration(CAXMLBI *pPiServerConfig)
~CAAccountingBIInterface()
private destructor
CACertificate * m_pPiServerCertificate
CAXMLErrorMessage * settle(CAXMLCostConfirmation &cc)
Send a cost confirmation to the JPI.
CATLSClientSocket * m_pSocket
SINT32 sendPostRequest(const UINT8 *url, const UINT8 *data, const UINT32 dataLen)
Sends a HTTP POST request to the server.
SINT32 parseHTTPHeader(UINT32 *contentLength, UINT32 *statusCode=NULL, UINT32 msTimeOut=3000)
receives the HTTP header and parses the content length
SINT32 setSocket(CASocket *pSocket)
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
This class represents a socket address for Internet (IP) connections.
SINT32 setAddr(const UINT8 *szIP, UINT16 port)
Sets the address to szIP and port.
SINT32 getHostName(UINT8 *buff, UINT32 len) const
Returns the hostname for this address.
UINT16 getPort() const
Returns the port value of the address.
virtual SINT32 receiveFullyT(UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Trys to receive all bytes.
virtual SINT32 setNonBlocking(bool b)
SINT32 close()
Shuts down the socket.
SINT32 connect(const CASocketAddr &psa, UINT32 msTimeout)
Establishes the actual TCP/IP connection and performs the TLS handshake.
SINT32 setServerCertificate(CACertificate *pCert)
Sets the Certifcate we accept as server identification.
This class encapsulates an error or success message.
static const UINT32 ERR_INTERNAL_SERVER_ERROR
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.