/*
- * Copyright 2001-2005 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.
#include <shibsp/SPConfig.h>
#include <xmltooling/util/NDC.h>
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
+#ifndef WIN32
+# include <netinet/in.h>
#endif
using namespace shibsp;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
using xercesc::DOMElement;
private:
SocketListener::ShibSocket connect();
-
+
+ Category& m_log;
const SocketListener* m_listener;
- Category& m_log;
auto_ptr<Mutex> m_lock;
stack<SocketListener::ShibSocket> m_pool;
};
}
SocketListener::SocketListener(const DOMElement* e) : log(&Category::getInstance(SHIBSP_LOGCAT".Listener")),
- m_shutdown(NULL), m_child_lock(NULL), m_child_wait(NULL), m_socketpool(NULL), m_socket((ShibSocket)0)
+ m_socketpool(NULL), m_shutdown(NULL), m_child_lock(NULL), m_child_wait(NULL), m_socket((ShibSocket)0)
{
// Are we a client?
if (SPConfig::getConfig().isEnabled(SPConfig::InProcess)) {
#ifdef _DEBUG
NDC ndc("run");
#endif
+ log->info("listener service starting");
// Save flag to monitor for shutdown request.
m_shutdown=shutdown;
NDC ndc("send");
#endif
- log->debug("sending message: %s", in.name());
+ log->debug("sending message (%s)", in.name() ? in.name() : "unnamed");
// Serialize data for transmission.
ostringstream os;
XMLToolingException* except=NULL;
try {
except=XMLToolingException::fromString(out.string());
+ log->error("remoted message returned an error: %s", except->what());
}
catch (XMLToolingException& e) {
log->error("caught XMLToolingException while building the XMLToolingException: %s", e.what());
{
Category& log = Category::getInstance("shibd.Listener");
- DDF out;
- DDFJanitor jout(out);
+ bool incomingError = true; // set false once incoming message is received
+ ostringstream sink;
#ifdef WIN32
u_long len;
#else
DDFJanitor jin(in);
is >> in;
+ log.debug("dispatching message (%s)", in.name() ? in.name() : "unnamed");
+
+ incomingError = false;
+
// Dispatch the message.
- out=m_listener->receive(in);
+ m_listener->receive(in, sink);
}
catch (XMLToolingException& e) {
- log.error("error processing incoming message: %s", e.what());
- out=DDF("exception").string(e.toString().c_str());
+ if (incomingError)
+ log.error("error processing incoming message: %s", e.what());
+ DDF out=DDF("exception").string(e.toString().c_str());
+ DDFJanitor jout(out);
+ sink << out;
}
catch (exception& e) {
- log.error("error processing incoming message: %s", e.what());
+ if (incomingError)
+ log.error("error processing incoming message: %s", e.what());
ListenerException ex(e.what());
- out=DDF("exception").string(ex.toString().c_str());
+ DDF out=DDF("exception").string(ex.toString().c_str());
+ DDFJanitor jout(out);
+ sink << out;
}
#ifndef _DEBUG
catch (...) {
- log.error("unexpected error processing incoming message");
+ if (incomingError)
+ log.error("unexpected error processing incoming message");
ListenerException ex("An unexpected error occurred while processing an incoming message.");
- out=DDF("exception").string(ex.toString().c_str());
+ DDF out=DDF("exception").string(ex.toString().c_str());
+ DDFJanitor jout(out);
+ sink << out;
}
#endif
// Return whatever's available.
- ostringstream xmlout;
- xmlout << out;
- string response(xmlout.str());
+ string response(sink.str());
int outlen = response.length();
len = htonl(outlen);
if (m_listener->send(m_sock,(char*)&len,sizeof(len)) != sizeof(len)) {