Don't call virtual method from d'tor.
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / impl / SOAPClient.cpp
index e5acc04..ba4676d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  Copyright 2001-2007 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
 #include "soap/SOAP.h"
 #include "soap/SOAPClient.h"
 #include "util/XMLHelper.h"
-#include "validation/ValidatorSuite.h"\r
+#include "validation/ValidatorSuite.h"
 
 #include <sstream>
 #include <log4cpp/Category.hh>
@@ -37,7 +37,7 @@ using namespace std;
 
 SOAPClient::~SOAPClient()
 {
-    reset();
+    delete m_transport;
 }
 
 void SOAPClient::reset()
@@ -74,14 +74,19 @@ Envelope* SOAPClient::receive()
     if (!out)
         return NULL;    // nothing yet
     
+    // Check content type.
+    string s = m_transport->getContentType();
+    if (s.find("text/xml") == string::npos)
+        throw IOException("Incorrect content type ($1) for SOAP response.", params(1,s.c_str() ? s.c_str() : "none"));
+    
     // Parse and bind the document into an XMLObject.
     DOMDocument* doc = (m_validate ? XMLToolingConfig::getConfig().getValidatingParser()
         : XMLToolingConfig::getConfig().getParser()).parse(out); 
     XercesJanitor<DOMDocument> janitor(doc);
     auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true));
     janitor.release();
-    if (!m_validate)\r
-        SchemaValidators.validate(xmlObject.get());\r
+    if (!m_validate)
+        SchemaValidators.validate(xmlObject.get());
 
     Envelope* env = dynamic_cast<Envelope*>(xmlObject.get());
     if (!env)
@@ -90,7 +95,7 @@ Envelope* SOAPClient::receive()
     Body* body = env->getBody();
     if (body && body->hasChildren()) {
         //Check for a Fault.
-        const Fault* fault = dynamic_cast<Fault*>(body->getXMLObjects().front());
+        const Fault* fault = dynamic_cast<Fault*>(body->getUnknownXMLObjects().front());
         if (fault && handleFault(*fault))
             throw IOException("SOAP client detected a Fault.");
     }
@@ -101,7 +106,7 @@ Envelope* SOAPClient::receive()
 
 bool SOAPClient::handleFault(const Fault& fault)
 {
-    QName* code = (fault.getFaultcode() ? fault.getFaultcode()->getCode() : NULL);
+    const 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)",