Xerces 3 revisions.
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / impl / SOAPClient.cpp
index ba4676d..fb0ff52 100644 (file)
 
 #include "internal.h"
 #include "exceptions.h"
+#include "logging.h"
 #include "soap/SOAP.h"
 #include "soap/SOAPClient.h"
 #include "util/XMLHelper.h"
 #include "validation/ValidatorSuite.h"
 
 #include <sstream>
-#include <log4cpp/Category.hh>
 
 using namespace soap11;
+using namespace xmltooling::logging;
 using namespace xmltooling;
-using namespace log4cpp;
+using namespace xercesc;
 using namespace std;
 
+void SOAPTransport::send(istream* in)
+{
+    if (!in)
+        throw IOException("SOAP transport does not support an empty request body.");
+    return send(*in);
+}
+
 SOAPClient::~SOAPClient()
 {
     delete m_transport;
@@ -46,19 +54,23 @@ void SOAPClient::reset()
     m_transport=NULL;
 }
 
-void SOAPClient::send(const Envelope* env, const KeyInfoSource& peer, const char* endpoint)
+void SOAPClient::send(const Envelope& env, const SOAPTransport::Address& addr)
 {
     // Prepare a transport object.
-    const char* pch = strchr(endpoint,':');
+    const char* pch = strchr(addr.m_endpoint,':');
     if (!pch)
         throw IOException("SOAP endpoint was not a URL.");
-    string scheme(endpoint, pch-endpoint);
-    m_transport = XMLToolingConfig::getConfig().SOAPTransportManager.newPlugin(scheme.c_str(), make_pair(&peer,endpoint));
+    string scheme(addr.m_endpoint, pch-addr.m_endpoint);
+    m_transport = XMLToolingConfig::getConfig().SOAPTransportManager.newPlugin(scheme.c_str(), addr);
     prepareTransport(*m_transport);
     
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".SOAPClient");
+    if (log.isDebugEnabled())
+        log.debugStream() << "marshalled envelope:\n" << env << logging::eol;
+    
     // Serialize envelope.
     stringstream s;
-    s << *env;
+    s << env;
     
     // Send to peer.
     m_transport->send(s);
@@ -83,6 +95,18 @@ Envelope* SOAPClient::receive()
     DOMDocument* doc = (m_validate ? XMLToolingConfig::getConfig().getValidatingParser()
         : XMLToolingConfig::getConfig().getParser()).parse(out); 
     XercesJanitor<DOMDocument> janitor(doc);
+
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".SOAPClient");
+    if (log.isDebugEnabled()) {
+#ifdef XMLTOOLING_LOG4SHIB
+        log.debugStream() << "received XML:\n" << *(doc->getDocumentElement()) << logging::eol;
+#else
+        string buf;
+        XMLHelper::serialize(doc->getDocumentElement(), buf);
+        log.debugStream() << "received XML:\n" << buf << logging::eol;
+#endif
+    }
+    
     auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true));
     janitor.release();
     if (!m_validate)
@@ -106,7 +130,7 @@ Envelope* SOAPClient::receive()
 
 bool SOAPClient::handleFault(const Fault& fault)
 {
-    const QName* code = (fault.getFaultcode() ? fault.getFaultcode()->getCode() : NULL);
+    const xmltooling::QName* code = (fault.getFaultcode() ? fault.getFaultcode()->getCode() : NULL);
     auto_ptr_char str((fault.getFaultstring() ? fault.getFaultstring()->getString() : NULL));
     Category::getInstance(XMLTOOLING_LOGCAT".SOAPClient").error(
         "SOAP client detected a Fault: (%s) (%s)",