X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fsoap%2Fimpl%2FSOAPClient.cpp;h=01a178982294dbaa71fad000b111749fed3eb692;hb=88d66de2aa06a8ad04c94b4f5ae792eb22dd98d1;hp=2b330550da484bec6e0721564b730c1deadc6f3e;hpb=58257405aacb2e9fbf1b288f319d69594584d8d3;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/soap/impl/SOAPClient.cpp b/xmltooling/soap/impl/SOAPClient.cpp index 2b33055..01a1789 100644 --- a/xmltooling/soap/impl/SOAPClient.cpp +++ b/xmltooling/soap/impl/SOAPClient.cpp @@ -1,17 +1,21 @@ -/* - * Copyright 2001-2006 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. * - * http://www.apache.org/licenses/LICENSE-2.0 + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** @@ -22,43 +26,138 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" +#include "soap/HTTPSOAPTransport.h" +#include "soap/OpenSSLSOAPTransport.h" #include "soap/SOAP.h" #include "soap/SOAPClient.h" #include "util/XMLHelper.h" #include "validation/ValidatorSuite.h" #include -#include using namespace soap11; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; +using namespace xercesc; using namespace std; +#if !defined(XMLTOOLING_NO_XMLSEC) && !defined(XMLTOOLING_LITE) +namespace xmltooling { + PluginManager::Factory CURLSOAPTransportFactory; +}; +#endif + +void xmltooling::registerSOAPTransports() +{ +#if !defined(XMLTOOLING_NO_XMLSEC) && !defined(XMLTOOLING_LITE) + XMLToolingConfig& conf=XMLToolingConfig::getConfig(); + conf.SOAPTransportManager.registerFactory("http", CURLSOAPTransportFactory); + conf.SOAPTransportManager.registerFactory("https", CURLSOAPTransportFactory); +#endif +} + + +#ifdef XMLTOOLING_NO_XMLSEC +void xmltooling::initSOAPTransports() +{ +} + +void xmltooling::termSOAPTransports() +{ +} +#endif + +SOAPTransport::SOAPTransport() +{ +} + +SOAPTransport::~SOAPTransport() +{ +} + +bool SOAPTransport::setProviderOption(const char* provider, const char* option, const char* value) +{ + return false; +} + +bool SOAPTransport::setCacheTag(string* cacheTag) +{ + return false; +} + +void SOAPTransport::send(istream* in) +{ + if (!in) + throw IOException("SOAP transport does not support an empty request body."); + return send(*in); +} + +long SOAPTransport::getStatusCode() const +{ + return 0; +} + +HTTPSOAPTransport::HTTPSOAPTransport() +{ +} + +HTTPSOAPTransport::~HTTPSOAPTransport() +{ +} + +bool HTTPSOAPTransport::followRedirects(bool follow, unsigned int maxRedirs) +{ + return false; +} + +#ifndef XMLTOOLING_NO_XMLSEC +OpenSSLSOAPTransport::OpenSSLSOAPTransport() +{ +} + +OpenSSLSOAPTransport::~OpenSSLSOAPTransport() +{ +} +#endif + +SOAPClient::SOAPClient(bool validate) : m_validate(validate), m_transport(nullptr) +{ +} + SOAPClient::~SOAPClient() { - reset(); + delete m_transport; +} + +void SOAPClient::setValidating(bool validate) +{ + m_validate = validate; } void SOAPClient::reset() { delete m_transport; - m_transport=NULL; + m_transport=nullptr; } -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 = addr.m_endpoint ? strchr(addr.m_endpoint,':') : nullptr; 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); @@ -72,16 +171,33 @@ Envelope* SOAPClient::receive() // If we can get the stream, then the call is still active. istream& out = m_transport->receive(); if (!out) - return NULL; // nothing yet + return nullptr; // 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); + + 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(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true)); janitor.release(); - if (!m_validate) - SchemaValidators.validate(xmlObject.get()); + + SchemaValidators.validate(xmlObject.get()); Envelope* env = dynamic_cast(xmlObject.get()); if (!env) @@ -90,7 +206,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."); } @@ -99,10 +215,14 @@ 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); - auto_ptr_char str((fault.getFaultstring() ? fault.getFaultstring()->getString() : NULL)); + const xmltooling::QName* code = (fault.getFaultcode() ? fault.getFaultcode()->getCode() : nullptr); + auto_ptr_char str((fault.getFaultstring() ? fault.getFaultstring()->getString() : nullptr)); Category::getInstance(XMLTOOLING_LOGCAT".SOAPClient").error( "SOAP client detected a Fault: (%s) (%s)", (code ? code->toString().c_str() : "no code"),