示例#1
0
HttpResponse * 
EHS::RouteRequest ( HttpRequest * ipoHttpRequest ///< request info for service
	)
{

	// get the next path from the URI
	std::string sNextPathPart = GetNextPathPart ( ipoHttpRequest->sUri );


	EHS_TRACE ( "Info: Trying to route: '%s'\n", sNextPathPart.c_str ( ) );


	// if there is no more path, call HandleRequest on this EHS object with
	//   whatever's left - or if we're not routing
	if ( sNextPathPart.empty ( ) ||
		 m_oEHSServerParameters.find ( "norouterequest" ) !=
		 m_oEHSServerParameters.end ( ) ) {

		// create an HttpRespose object for the client
		HttpResponse * poHttpResponse = 
			new HttpResponse ( ipoHttpRequest->m_nRequestId,
							   ipoHttpRequest->m_poSourceEHSConnection );
		
		// get the actual response and return code
		poHttpResponse->m_nResponseCode = 
			HandleRequest ( ipoHttpRequest, poHttpResponse );

		return poHttpResponse;

	}

	// if the path exists, check it against the map of EHSs
	if ( oEHSMap [ sNextPathPart ] ) {

		// if it exists, call RouteRequest with that EHS and the
		//   new shortened path

		return oEHSMap [ sNextPathPart ]->RouteRequest ( ipoHttpRequest );

	}
	// if it doesn't exist, send an error back up saying resource doesn't exist
	else {

		
		EHS_TRACE ( "Info: Routing failed.  Most likely caused by an invalid URL, not internal error\n" );


		// send back a 404 response
		HttpResponse * poHttpResponse = new HttpResponse ( ipoHttpRequest->m_nRequestId,
														   ipoHttpRequest->m_poSourceEHSConnection );

		poHttpResponse->m_nResponseCode = HTTPRESPONSECODE_404_NOTFOUND;
		poHttpResponse->SetBody ( "404 - Not Found", strlen ( "404 - Not Found" ) );

		return poHttpResponse;
		
	}

}
示例#2
0
 HttpResponse *HandleThreadException(ehs_threadid_t, HttpRequest *request, exception &ex)
 {
     HttpResponse *ret = NULL;
     string msg(ex.what());
     cerr << "##################### Catched " << msg << endl;
     cerr << "request: " << hex << request << dec << endl;
     tracing::exception *btx =
         dynamic_cast<tracing::exception*>(&ex);
     if (NULL != btx) {
         string tmsg = btx->where();
         cerr << "Backtrace:" << endl << tmsg;
         if (0 != msg.compare("fatal")) {
             ret = HttpResponse::Error(HTTPRESPONSECODE_500_INTERNALSERVERERROR, request);
             string body(ret->GetBody());
             tmsg.insert(0, "<br>\n<pre>").append(msg).append("</pre><p><a href=\"/\">Back to main page</a>");
             body.insert(body.find("</body>"), tmsg);
             ret->SetBody(body.c_str(), body.length());
         }
     }
     return ret;
 }