<commit_before>#include <Poco/Exception.h>
#include <Poco/FIFOBuffer.h>
#include <Poco/Net/NetException.h>

#include "Debug.h"
#include "server/XmlRequestHandler.h"

using namespace std;
using namespace Poco;
using namespace Poco::Net;
using namespace Poco::XML;
using namespace BeeeOn;

XmlRequestHandler::XmlRequestHandler(
		const StreamSocket &socket,
		const AutoPtr<Document> input):
	TCPServerConnection(socket),
	m_logger(LOGGER_CLASS(this)),
	m_input(input),
	m_stream(socket),
	m_output(m_stream, XMLWriter::Options::CANONICAL_XML)
{
}

void XmlRequestHandler::run()
{
	_TRACE_METHOD(m_logger);

	try {
		m_output.startDocument();
		handleInput();
		m_output.endDocument();
	} catch (const Exception &e) {
		m_logger.log(e, __FILE__, __LINE__);
	}
}

XmlRequestHandlerFactory::XmlRequestHandlerFactory():
	m_logger(LOGGER_CLASS(this)),
	m_maxLength(4096)
{
	init();
}

XmlRequestHandlerFactory::XmlRequestHandlerFactory(size_t maxLength):
	m_logger(LOGGER_CLASS(this)),
	m_maxLength(maxLength)
{
	init();
}

void XmlRequestHandlerFactory::init()
{
	injector<XmlRequestHandlerFactory, XmlRequestHandlerResolver>
		("resolvers", &XmlRequestHandlerFactory::registerResolver);
	numberInjector("maxBuffer", (NumberSetter)
			&XmlRequestHandlerFactory::setMaxLength);
}

TCPServerConnection *XmlRequestHandlerFactory::createConnection(
	const StreamSocket &socket)
{
	try {
		StreamSocket readableSocket(socket);
		return resolveRequest(socket, parseDocument(readableSocket));
	}
	catch (const Exception &e) {
		m_logger.log(e, __FILE__, __LINE__);
	}
	catch (const exception &e) {
		m_logger.critical(e.what(), __FILE__, __LINE__);
	}

	return NULL;
}

XmlRequestHandler *XmlRequestHandlerFactory::resolveRequest(
		const StreamSocket &socket,
		const AutoPtr<Document> input)
{
	for (auto resolver : m_resolvers) {<commit_msg>XmlRequestHandler: debug log parsed input document<commit_after>#include <sstream>

#include <Poco/Exception.h>
#include <Poco/FIFOBuffer.h>
#include <Poco/Net/NetException.h>
#include <Poco/DOM/DOMWriter.h>

#include "Debug.h"
#include "server/XmlRequestHandler.h"

using namespace std;
using namespace Poco;
using namespace Poco::Net;
using namespace Poco::XML;
using namespace BeeeOn;

XmlRequestHandler::XmlRequestHandler(
		const StreamSocket &socket,
		const AutoPtr<Document> input):
	TCPServerConnection(socket),
	m_logger(LOGGER_CLASS(this)),
	m_input(input),
	m_stream(socket),
	m_output(m_stream, XMLWriter::Options::CANONICAL_XML)
{
}

void XmlRequestHandler::run()
{
	_TRACE_METHOD(m_logger);

	try {
		m_output.startDocument();
		handleInput();
		m_output.endDocument();
	} catch (const Exception &e) {
		m_logger.log(e, __FILE__, __LINE__);
	}
}

XmlRequestHandlerFactory::XmlRequestHandlerFactory():
	m_logger(LOGGER_CLASS(this)),
	m_maxLength(4096)
{
	init();
}

XmlRequestHandlerFactory::XmlRequestHandlerFactory(size_t maxLength):
	m_logger(LOGGER_CLASS(this)),
	m_maxLength(maxLength)
{
	init();
}

void XmlRequestHandlerFactory::init()
{
	injector<XmlRequestHandlerFactory, XmlRequestHandlerResolver>
		("resolvers", &XmlRequestHandlerFactory::registerResolver);
	numberInjector("maxBuffer", (NumberSetter)
			&XmlRequestHandlerFactory::setMaxLength);
}

TCPServerConnection *XmlRequestHandlerFactory::createConnection(
	const StreamSocket &socket)
{
	try {
		StreamSocket readableSocket(socket);
		return resolveRequest(socket, parseDocument(readableSocket));
	}
	catch (const Exception &e) {
		m_logger.log(e, __FILE__, __LINE__);
	}
	catch (const exception &e) {
		m_logger.critical(e.what(), __FILE__, __LINE__);
	}

	return NULL;
}

static string documentToString(const AutoPtr<Document> doc)
{
	DOMWriter writer;
	ostringstream s;
	writer.writeNode(s, doc);
	return s.str();
}

XmlRequestHandler *XmlRequestHandlerFactory::resolveRequest(
		const StreamSocket &socket,
		const AutoPtr<Document> input)
{
	if (m_logger.debug()) {
		m_logger.debug("document: " + documentToString(input),
				__FILE__, __LINE__);
	}

	for (auto resolver : m_resolvers) {
{'fraction_non_alphanumeric': 0.12319201995012469, 'fraction_numerical': 0.00199501246882793, 'mean_word_length': 7.236139630390143, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '512304', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1346, 'n_words': 246}