X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fsoap%2Fimpl%2FSOAPClient.cpp;h=d785b63abcd62430899890b1ce1decfed37dcd11;hb=1f87cef41f9948492e13d3d9dc1495652606c441;hp=f8a84b543e5ae7df616697cc62e22ab858bef8cd;hpb=05af072aa6fd513edaaff7d94ab4afcd308bfceb;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/soap/impl/SOAPClient.cpp b/xmltooling/soap/impl/SOAPClient.cpp index f8a84b5..d785b63 100644 --- a/xmltooling/soap/impl/SOAPClient.cpp +++ b/xmltooling/soap/impl/SOAPClient.cpp @@ -25,12 +25,14 @@ #include "soap/SOAP.h" #include "soap/SOAPClient.h" #include "util/XMLHelper.h" -#include "validation/ValidatorSuite.h" +#include "validation/ValidatorSuite.h" #include +#include using namespace soap11; using namespace xmltooling; +using namespace log4cpp; using namespace std; SOAPClient::~SOAPClient() @@ -56,7 +58,7 @@ void SOAPClient::send(const Envelope* env, const KeyInfoSource& peer, const char // Serialize envelope. stringstream s; - XMLHelper::serialize(env->marshall(), s); + s << *env; // Send to peer. m_transport->send(s); @@ -78,14 +80,33 @@ Envelope* SOAPClient::receive() XercesJanitor janitor(doc); auto_ptr xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true)); janitor.release(); - if (!m_validate) - SchemaValidators.validate(xmlObject.get()); + if (!m_validate) + SchemaValidators.validate(xmlObject.get()); Envelope* env = dynamic_cast(xmlObject.get()); if (!env) throw IOException("Response was not a SOAP 1.1 Envelope."); - reset(); + Body* body = env->getBody(); + if (body && body->hasChildren()) { + //Check for a Fault. + const Fault* fault = dynamic_cast(body->getUnknownXMLObjects().front()); + if (fault && handleFault(*fault)) + throw IOException("SOAP client detected a Fault."); + } + xmlObject.release(); return env; } + +bool SOAPClient::handleFault(const Fault& fault) +{ + 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)", + (code ? code->toString().c_str() : "no code"), + (str.get() ? str.get() : "no message") + ); + return true; +}