示例#1
0
	void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
	{
		response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_OK);

		if (request.getContentType() == "application/soap+xml")
		{
      assert(false);
      //std::string req(std::istreambuf_iterator<char>(request.stream()), std::istreambuf_iterator<char>());

			//tinyxml2::XMLDocument reqDoc;
			//reqDoc.Parse(req.c_str());

			//tinyxml2::XMLDocument respDoc;
			//respDoc.LoadFile(m_wsdl.c_str());

			//cout << "Sending wsdl via soap" << endl << flush;

			//m_outbuf = "";
			//m_soapProtocol.SendResponse(reqDoc, respDoc, respDoc.FirstChildElement(), "http://www.w3.org/2005/08/addressing/anonymous");
			//response.sendBuffer(m_outbuf.c_str(), m_outbuf.size());

			//m_outbuf = "";
		}
		else
		{
			cout << "Sending wsdl via http" << endl << flush;
			response.sendFile(m_wsdl.c_str(), "text/xml");
		}		
	}
示例#2
0
void ShowFilePage::handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response)
{
	m_log->trace("ShowFilePage::handleRequest from "+request.clientAddress().toString());
	m_log->trace("ShowFilePage::handleRequest ContentType="+request.getContentType());
	m_log->trace("ShowFilePage::handleRequest TransferEncoding="+request.getTransferEncoding());
	m_log->trace("ShowFilePage::handleRequest URI="+request.getURI());

	std::map<std::string,QueryVar> queryvars;

	CreateQueryVarMap(request,queryvars);

	std::string content="";
	if(queryvars.find("file")!=queryvars.end() && m_filewhitelist.find((*queryvars.find("file")).second.GetData())!=m_filewhitelist.end())
	{
		try
		{
			response.sendFile(global::basepath+(*queryvars.find("file")).second.GetData(),m_filewhitelist[(*queryvars.find("file")).second.GetData()]);
		}
		catch(Poco::FileNotFoundException &fnf)
		{
			m_log->error("ShowFilePage::handleRequest caught FileNotFound exception - "+fnf.message());
		}
		catch(Poco::OpenFileException &of)
		{
			m_log->error("ShowFilePage::handleRequest caught OpenFile exception - "+of.message());
		}
		catch(...)
		{
			m_log->error("ShowFilePage::handleRequest caught other exception");
		}
	}
	else if(request.getURI().size()>0 && request.getURI()[0]=='/' && m_filewhitelist.find(request.getURI().substr(1))!=m_filewhitelist.end())
	{
		try
		{
			response.sendFile(global::basepath+request.getURI().substr(1),m_filewhitelist[request.getURI().substr(1)]);
		}
		catch(Poco::FileNotFoundException &fnf)
		{
			m_log->error("ShowFilePage::handleRequest caught FileNotFound exception - "+fnf.message());
		}
		catch(Poco::OpenFileException &of)
		{
			m_log->error("ShowFilePage::handleRequest caught OpenFile exception - "+of.message());
		}
		catch(...)
		{
			m_log->error("ShowFilePage::handleRequest caught other exception");
		}		
	}
	else if(request.getURI().size()>0 && m_filewhitelist.find(request.getURI())!=m_filewhitelist.end())
	{
		try
		{
			response.sendFile(global::basepath+request.getURI(),m_filewhitelist[request.getURI()]);
		}
		catch(Poco::FileNotFoundException &fnf)
		{
			m_log->error("ShowFilePage::handleRequest caught FileNotFound exception - "+fnf.message());
		}
		catch(Poco::OpenFileException &of)
		{
			m_log->error("ShowFilePage::handleRequest caught OpenFile exception - "+of.message());
		}
		catch(...)
		{
			m_log->error("ShowFilePage::handleRequest caught other exception");
		}	
	}

}
示例#3
0
void Controller::handle(const std::vector<std::string>& parameters, Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
	_parameters = parameters;
	_request = &request;
	_response = &response;

	if ( _parameters.size() > 0 )
	{
		_action = _parameters.front();
		_parameters.erase(_parameters.begin());
	}
	else
	{
		setResponseStatus(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST, "Invalid URI parameters");
		return;
	}

	for(std::vector<std::string>::iterator it = _parameters.begin(); it != _parameters.end(); ++it)
	{
		int pos = it->find_first_of(':');
		if ( pos != std::string::npos )
		{
			std::string name = it->substr(0, pos);
			std::string value = it->substr(pos+1);
			_namedParameters[name] = value;
		}
	}

	std::string contentType = request.getContentType();
	if ( contentType == "application/json" )
	{
		Poco::JSON::Parser parser;
		try
		{
			Poco::Dynamic::Var json = parser.parse(request.stream());
			if ( ! json.isEmpty() && json.type() == typeid(Poco::JSON::Object::Ptr) )
			{
				_data->set("filter", json.extract<Poco::JSON::Object::Ptr>());
			}
		}
		catch(Poco::JSON::JSONException& jsone)
		{
			// Make sure everything is read, otherwise this can result
			// in Bad Request error in the next call.
			Poco::NullOutputStream nos;
			Poco::StreamCopier::copyStream(request.stream(), nos);

			setResponseStatus(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST, "JSON error occurred: " + jsone.displayText());
			return;
		}
	}
	else
	{
		_form.load(request, request.stream(), *this);
	}

	// Make sure everything is read, otherwise this can result
	// in Bad Request error in the next call.
	Poco::NullOutputStream nos;
	Poco::StreamCopier::copyStream(request.stream(), nos);

	beforeAction();

	if ( response.getStatus() != Poco::Net::HTTPResponse::HTTP_OK
		|| _data->has("error") )
	{
		//TODO: return error template file or json error
	}

	const ActionMap& actions = getActions();
	ActionMap::const_iterator it = actions.find(_action);
	if ( it == actions.end() )
	{
		setResponseStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND, "Invalid action '" + _action + "' specified.");
		return;
	}

	ActionFn action = it->second;
	(this->*action)();

	afterAction();
}