X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fsoap%2Fimpl%2FSOAPClient.cpp;h=2a569797e7d3f38ad6c24284f1dec088e275a73d;hb=6505807a62569ce65803b448b07a6872c6af2512;hp=dc2f6d1e9a77cda51ab48516d6765d504179499c;hpb=b2d74dde6a375aca444cdddbc354ddeeb32c80bf;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/soap/impl/SOAPClient.cpp b/xmltooling/soap/impl/SOAPClient.cpp index dc2f6d1..2a56979 100644 --- a/xmltooling/soap/impl/SOAPClient.cpp +++ b/xmltooling/soap/impl/SOAPClient.cpp @@ -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. @@ -24,9 +24,8 @@ #include "exceptions.h" #include "soap/SOAP.h" #include "soap/SOAPClient.h" -#include "util/NDC.h" #include "util/XMLHelper.h" -#include "validation/ValidatorSuite.h" +#include "validation/ValidatorSuite.h" #include #include @@ -38,7 +37,7 @@ using namespace std; SOAPClient::~SOAPClient() { - reset(); + delete m_transport; } void SOAPClient::reset() @@ -47,19 +46,19 @@ 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 char* peerName, const char* endpoint) { // Prepare a transport object. const char* pch = strchr(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)); + m_transport = XMLToolingConfig::getConfig().SOAPTransportManager.newPlugin(scheme.c_str(), make_pair(peerName,endpoint)); prepareTransport(*m_transport); // Serialize envelope. stringstream s; - s << *env; + s << env; // Send to peer. m_transport->send(s); @@ -75,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 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) @@ -91,7 +95,7 @@ Envelope* SOAPClient::receive() Body* body = env->getBody(); if (body && body->hasChildren()) { //Check for a Fault. - const Fault* fault = dynamic_cast(body->getXMLObjects().front()); + const Fault* fault = dynamic_cast(body->getUnknownXMLObjects().front()); if (fault && handleFault(*fault)) throw IOException("SOAP client detected a Fault."); } @@ -102,10 +106,7 @@ Envelope* SOAPClient::receive() bool SOAPClient::handleFault(const Fault& fault) { -#ifdef _DEBUG - xmltooling::NDC ndc("receiveSAML"); -#endif - 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)",