https://issues.shibboleth.net/jira/browse/CPPXT-47
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / impl / SOAPClient.cpp
index 260736a..1978e28 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2009 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
 #include "internal.h"
 #include "exceptions.h"
 #include "logging.h"
+#include "soap/HTTPSOAPTransport.h"
 #include "soap/SOAP.h"
 #include "soap/SOAPClient.h"
 #include "util/XMLHelper.h"
 using namespace soap11;
 using namespace xmltooling::logging;
 using namespace xmltooling;
+using namespace xercesc;
 using namespace std;
 
+SOAPTransport::SOAPTransport()
+{
+}
+
+SOAPTransport::~SOAPTransport()
+{
+}
+
+bool SOAPTransport::setProviderOption(const char* provider, const char* option, const char* value)
+{
+    return false;
+}
+
+HTTPSOAPTransport::HTTPSOAPTransport()
+{
+}
+
+HTTPSOAPTransport::~HTTPSOAPTransport()
+{
+}
+
+SOAPClient::SOAPClient(bool validate) : m_validate(validate), m_transport(NULL)
+{
+}
+
 SOAPClient::~SOAPClient()
 {
     delete m_transport;
 }
 
+void SOAPClient::setValidating(bool validate)
+{
+    m_validate = validate;
+}
+
 void SOAPClient::reset()
 {
     delete m_transport;
     m_transport=NULL;
 }
 
+void SOAPTransport::send(istream* in)
+{
+    if (!in)
+        throw IOException("SOAP transport does not support an empty request body.");
+    return send(*in);
+}
+
 void SOAPClient::send(const Envelope& env, const SOAPTransport::Address& addr)
 {
     // Prepare a transport object.
-    const char* pch = strchr(addr.m_endpoint,':');
+    const char* pch = addr.m_endpoint ? strchr(addr.m_endpoint,':') : NULL;
     if (!pch)
         throw IOException("SOAP endpoint was not a URL.");
     string scheme(addr.m_endpoint, pch-addr.m_endpoint);
@@ -58,7 +97,7 @@ void SOAPClient::send(const Envelope& env, const SOAPTransport::Address& addr)
     
     Category& log = Category::getInstance(XMLTOOLING_LOGCAT".SOAPClient");
     if (log.isDebugEnabled())
-        log.debugStream() << "marshalled envelope: " << env << logging::eol;
+        log.debugStream() << "marshalled envelope:\n" << env << logging::eol;
     
     // Serialize envelope.
     stringstream s;
@@ -89,13 +128,20 @@ Envelope* SOAPClient::receive()
     XercesJanitor<DOMDocument> janitor(doc);
 
     Category& log = Category::getInstance(XMLTOOLING_LOGCAT".SOAPClient");
-    if (log.isDebugEnabled())
-        log.debugStream() << "received XML: " << *(doc->getDocumentElement()) << logging::eol;
+    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)
-        SchemaValidators.validate(xmlObject.get());
+
+    SchemaValidators.validate(xmlObject.get());
 
     Envelope* env = dynamic_cast<Envelope*>(xmlObject.get());
     if (!env)
@@ -113,9 +159,13 @@ Envelope* SOAPClient::receive()
     return env;
 }
 
+void SOAPClient::prepareTransport(SOAPTransport& transport)
+{
+}
+
 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)",