void spep::AttributeProcessor::doAttributeProcessing(spep::PrincipalSession &principalSession)
{
	// Validate the ESOE session identifier
	if( principalSession.getESOESessionID().length() <= 0 )
	{
		_localLogger.error() << "Rejecting attribute processing request for principal session with empty ESOE session identifier.";
		SAML2LIB_INVPARAM_EX( "Principal session had an empty ESOE session identifier. Unable to get attributes." );
	}
	
	_localLogger.debug() << "Building attribute query for new principal session. ESOE Session ID: " << UnicodeStringConversion::toString( principalSession.getESOESessionID() );

	// Build the attribute query
	std::wstring samlID = this->_identifierGenerator->generateSAMLID();
	
	xml_schema::dom::auto_ptr<DOMDocument> requestDocument( this->buildAttributeQuery( principalSession, samlID ) );
	
	if ( requestDocument.get() == NULL )
	{
		throw AttributeException( "The request document was null. Aborting attribute query." );
	}
	
	std::auto_ptr<saml2::protocol::ResponseType> response;
	try
	{
		std::string endpoint( this->_metadata->getAttributeServiceEndpoint() );
		_localLogger.debug() << "Doing attribute query to endpoint: " << endpoint;
		response.reset( this->_wsClient->doWSCall( endpoint, requestDocument.get(), this->_responseUnmarshaller ) );
	}
	catch( std::exception& ex )
	{
		_localLogger.error() << "An exception occurred during the attribute web service call. Unable to continue. "
			"Exception was: " << ex.what();
		throw AttributeException( "An exception occurred during the attribute web service call. Unable to continue." );
	}
	
	_localLogger.debug() << "Got attribute response document. Going to process attribute statements.";
	
	// Process the response
	try
	{
		_localLogger.debug() << "Processing attribute response.";
		this->processAttributeResponse( response.get(), principalSession, samlID );
	}
	catch ( std::exception& ex )
	{
		_localLogger.error() << "An exception occurred while processing the attribute response. Exception was: " << ex.what();
		throw AttributeException( "An exception occurred while processing the attribute response." );
	}
}
    void Wagnis::validateContribution(const QString &contributionKey)
    {
        qDebug() << "Wagnis::validateContribution" << contributionKey;
        QUrl url = QUrl(API_CONTRIBUTION);
        QNetworkRequest request(url);
        request.setHeader(QNetworkRequest::ContentTypeHeader, MIME_TYPE_JSON);

        QJsonObject jsonPayloadObject;
        jsonPayloadObject.insert("wagnis_id", wagnisId);
        jsonPayloadObject.insert("application", this->applicationName);
        jsonPayloadObject.insert("contribution_key", contributionKey);

        QJsonDocument requestDocument(jsonPayloadObject);
        QByteArray jsonAsByteArray = requestDocument.toJson();
        request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(jsonAsByteArray.size()));

        QNetworkReply *reply = manager->post(request, jsonAsByteArray);

        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(handleValidateContributionError(QNetworkReply::NetworkError)));
        connect(reply, SIGNAL(finished()), this, SLOT(handleValidateContributionFinished()));
    }
void spep::StartupProcessorImpl::doStartup()
{
	
	try
	{
		// Generate the request document
		std::wstring samlID( this->_identifierGenerator->generateSAMLID() );
		
		xml_schema::dom::auto_ptr<DOMDocument> requestDocument( this->buildRequest( samlID ) );
		
		std::string endpoint( this->_metadata->getSPEPStartupServiceEndpoint() );
		
		{
			std::stringstream ss;
			ss << "About to send SPEP startup WS query to ESOE endpoint: " << endpoint << std::ends;
			_localLogger.debug() << ss.str();
		}
		
		// Perform the web service call.
		try
		{
			std::auto_ptr<middleware::ESOEProtocolSchema::ValidateInitializationResponseType> response(
				this->_wsClient->doWSCall( endpoint, requestDocument.get(), this->_validateInitializationResponseUnmarshaller )
			);
			
			_localLogger.debug() << "Received response from web service endpoint. Going to process.";
			
			// Process the response.
			this->processResponse( response.get(), samlID );
		}
		catch( saml2::UnmarshallerException &ex )
		{
			std::stringstream ss;
			ss << "SPEP startup ERROR. Exception when unmarshalling startup response. Exception was: " << ex.getMessage() << ". Cause was: " << ex.getCause() << std::ends;
			_localLogger.debug() << ss.str();
			throw SPEPStartupException( "Exception occurred while unmarshalling SPEP startup response." );
		}
		catch( std::exception &ex )
		{
			std::stringstream ss;
			ss << "SPEP startup ERROR. Exception when unmarshalling startup response. Exception was: " << ex.what() << std::ends;
			_localLogger.debug() << ss.str();
			throw SPEPStartupException( "Exception occurred while unmarshalling SPEP startup response." );
		}
		
		// If we made it here, startup was successful..
		this->setStartupResult( STARTUP_ALLOW );
		
	}
	catch( saml2::MarshallerException &ex )
	{
		std::stringstream ss;
		ss << "Failed to marshal request document. Error was: " << ex.getMessage() << " .. cause: " << ex.getCause() << std::ends;
		
		// .. otherwise it failed for some reason.
		_localLogger.debug() << ss.str();
		this->setStartupResult( STARTUP_FAIL );
		
	}
	catch( std::exception &ex )
	{
		
		std::stringstream ss;
		ss << "Failed SPEP startup. Exception message was: " << ex.what() << std::ends;
		
		// .. otherwise it failed for some reason.
		_localLogger.debug() << ss.str();
		this->setStartupResult( STARTUP_FAIL );
		
	}
}