예제 #1
0
int CSoapServerApplication::ProcessRequest(CCgiContext& ctx)
{
    const CCgiRequest& request  = ctx.GetRequest();
    CCgiResponse&      response = ctx.GetResponse();
    response.SetContentType("text/xml");
    if (!x_ProcessWsdlRequest(response, request)) {
        x_ProcessSoapRequest(response, request);
    }
    response.Flush();
    return 0;
}
예제 #2
0
int CNetCacheBlobFetchApp::ProcessRequest(CCgiContext& ctx)
{
    const CCgiRequest& request = ctx.GetRequest();
    CCgiResponse&      reply   = ctx.GetResponse();

    bool is_found;

    string key = request.GetEntry("key", &is_found);
    if (key.empty() || !is_found) {
        NCBI_THROW(CArgException, eNoArg, "CGI entry 'key' is missing");
    }

    string fmt = request.GetEntry("fmt", &is_found);
    if (fmt.empty() || !is_found)
        fmt = "image/png";

    string filename(request.GetEntry("filename", &is_found));
    if (is_found && !filename.empty()) {
        string is_inline(request.GetEntry("inline", &is_found));

        reply.SetHeaderValue("Content-Disposition",
                (is_found && NStr::StringToBool(is_inline) ?
                        "inline; filename=" : "attachment; filename=") +
                filename);
    }

    reply.SetContentType(fmt);

    reply.WriteHeader();

    CNetStorageObject netstorage_object(m_NetStorage.Open(key));

    char buffer[NETSTORAGE_IO_BUFFER_SIZE];

    size_t total_bytes_written = 0;

    while (!netstorage_object.Eof()) {
        size_t bytes_read = netstorage_object.Read(buffer, sizeof(buffer));

        reply.out().write(buffer, bytes_read);
        total_bytes_written += bytes_read;

        if (bytes_read < sizeof(buffer))
            break;
    }

    netstorage_object.Close();

    LOG_POST(Info << "retrieved data: " << total_bytes_written << " bytes");

    return 0;
}
예제 #3
0
void CSeqBasicCommand::Execute( CCgiContext& ctx )
{
    const CNcbiRegistry& reg = ctx.GetConfig();
    
    /* load in the html template file */
    string baseFile = reg.Get( "filesystem", "HtmlBaseFile" );
    auto_ptr<CHTMLPage> page( new CHTMLPage( NcbiEmptyString, baseFile ) );
    
    /* set up to replace <@VIEW@> in template file with html returned
       from CreateView */
    page->AddTagMap( "QUICKSEARCH", CreateQuickSearch(ctx) );
    page->AddTagMap( "VIEW", CreateView( ctx ) );
    /* actual page output */
    ctx.GetResponse().WriteHeader();
    page->Print(ctx.GetResponse().out(), CNCBINode::eHTML );
}
예제 #4
0
void CHelloCommand::Execute( CCgiContext& ctx )
{
    const CNcbiRegistry& reg = ctx.GetConfig();
    
    // load in the html template file
    string baseFile = reg.Get( "filesystem", "HtmlBaseFile" );
	auto_ptr<CHTMLPage> page( new CHTMLPage( NcbiEmptyString, baseFile ) );
    
    // set up to replace <@VIEW@> in template file with html returned
    // from CreateView
	page->AddTagMap( "VIEW", CreateView( ctx ) );

	// actual page output
    ctx.GetResponse().WriteHeader();
    page->Print(ctx.GetResponse().out(), CNCBINode::eHTML );
}
예제 #5
0
void CNcbiResource::HandleRequest( CCgiContext& ctx )
{
    bool defCom = false;
	
	try {
	    TCmdList::iterator it = find_if( m_cmd.begin(), m_cmd.end(), 
										 PRequested<CNcbiCommand>( ctx ) );
    
		unique_ptr<CNcbiCommand> cmd( ( it == m_cmd.end() ) 
									? ( defCom = true, GetDefaultCommand() )
									: (*it)->Clone() );
		cmd->Execute( ctx );
#if !defined(NCBI_COMPILER_GCC)  ||  NCBI_COMPILER_VERSION >= 300  ||  defined(_IO_THROW)
    } catch( IOS_BASE::failure& /* e */  ) {
        throw;
#endif
    } catch( std::exception& e ) {
	    _TRACE( e.what() );
		ctx.PutMsg( string("Error handling request: ") + e.what() );
		if( !defCom ) {
		  unique_ptr<CNcbiCommand> cmd( GetDefaultCommand() );
		  cmd->Execute( ctx );
		}
    }
}
예제 #6
0
bool CNcbiCommand::IsRequested( const CCgiContext& ctx ) const
{ 
    const string value = GetName();
  
    TCgiEntries& entries =
        const_cast<TCgiEntries&>(ctx.GetRequest().GetEntries());

    pair<TCgiEntriesI,TCgiEntriesI> p = entries.equal_range( GetEntry() );
    for ( TCgiEntriesI itEntr = p.first; itEntr != p.second; ++itEntr ) {
        if( AStrEquiv( value, itEntr->second, PNocase() ) ) {
            return true;
        } // if
    } // for

    // if there is no 'cmd' entry
    // check the same for IMAGE value
    p = entries.equal_range( NcbiEmptyString );
    for ( TCgiEntriesI iti = p.first; iti != p.second; ++iti ) {
        if( AStrEquiv( value, iti->second, PNocase() ) ) {
            return true;
        } // if
    }
    
    return false;
}
예제 #7
0
int CVAApp::ProcessRequest(CCgiContext& ctx)
{

    // execute request
    ctx.GetResource().HandleRequest(ctx);
    return(0);
}
예제 #8
0
/* carries out the construction of the webpage when the 
 * cmd=advanced is set in the query string. */
void CSeqAdvancedGOCommand::Execute( CCgiContext& ctx )
{
    const CNcbiRegistry& reg = ctx.GetConfig();
    
    /* load in the html template file */
    string baseFile = reg.Get( "filesystem", "HtmlBaseFile" );
    auto_ptr<CHTMLPage> page( new CHTMLPage( NcbiEmptyString, baseFile ) );

    page->AddTagMap("QUICKSEARCH", CreateSpacer( ctx ));

    /* calls parent (CSeqBasicCommand) CreateViewi,
     * to add the "Advanced Search" table: allows
     * user to enter parameters for search. */
    page->AddTagMap( "VIEW", CreateView( ctx ) );

    /* actual page output */
    ctx.GetResponse().WriteHeader();
    page->Print(ctx.GetResponse().out(), CNCBINode::eHTML );
}
예제 #9
0
/* returns the string 'value' portion of the 'key=value' pairing 
 * in the querystring. */
inline string CSeqCommand::GetQueryStringValue(CCgiContext& ctx, const string &key)
{
   TCgiEntries& entries = const_cast<TCgiEntries&> (ctx.GetRequest().GetEntries());
   pair<TCgiEntriesI, TCgiEntriesI> Map = entries.equal_range(key);
   string value = kEmptyStr; 
   for(TCgiEntriesI i = Map.first; i != Map.second; ++i)
   {
      value = i->second;
   }
   return value;
}
예제 #10
0
void CNcbiRelocateCommand::Execute( CCgiContext& ctx )
{
    try {
        string url = GetLink(ctx);
        _TRACE("CNcbiRelocateCommand::Execute changing location to:" << url);
        // Theoretically, the status should be set, but...
        // Commented temporarily to avoid the redirection to go out of
        // NCBI and confuse some not-so-smart clients.
        // It can be restored later when (and if) the NCBI internal HTTP
        // servers are tuned to intercept the redirections and resolve these
        // internally.
        //
        //        ctx.GetResponse().SetStatus(301, "Moved");
        ctx.GetResponse().SetHeaderValue("Location", url);
        ctx.GetResponse().WriteHeader();
    }
    catch (exception&) {
        ERR_POST_X(1, "CNcbiRelocateCommand::Execute error getting url");
        throw;
    }
}
예제 #11
0
void CBlastHitMatrixCGIApplication::x_GetCGIContextParams(CCgiContext &ctx)
{
    const CCgiRequest& request  = ctx.GetRequest();
    const TCgiEntries& entries = request.GetEntries();

    m_RID = s_GetRequestParam(entries,"rid");

    string paramVal = s_GetRequestParam(entries,"width");    
    
    m_Width = !paramVal.empty() ? NStr::StringToInt(paramVal) : 800;
    
    paramVal = s_GetRequestParam(entries,"height");    
    
    m_Height = !paramVal.empty() ? NStr::StringToInt(paramVal) : 600;
      
    //Indicates that image should output in the file
    m_File = s_GetRequestParam(entries,"file");        

    m_Thumbnail = s_GetRequestParam(entries,"thumbnail");    
}
예제 #12
0
void CBlastHitMatrixCGIApplication::x_GetSeqAnnot(CCgiContext& ctx)
{
        const CNcbiRegistry & reg = ctx.GetConfig();
        string blastURL = reg.Get("NetParams", "BlastURL");
        string url = (string)blastURL + "?CMD=Get&RID=" + m_RID + "&FORMAT_TYPE=ASN.1&FORMAT_OBJECT=Alignment";
        
        SConnNetInfo* net_info = ConnNetInfo_Create(NULL);
        // create HTTP connection
        CConn_HttpStream inHttp(url,net_info);   

        try {
            m_Annot.Reset(new CSeq_annot);
            auto_ptr<CObjectIStream> is
                    (CObjectIStream::Open(eSerial_AsnText, inHttp));
            *is >> *m_Annot;                                    
        }
         catch (CException& e) {
              m_Annot.Reset();              
              NCBI_THROW(CBlastHitMatrixCGIException, eInvalidSeqAnnot, "Exception reading SeqAnnot via url " + url + ", exception message: " + e.GetMsg());              
        }               
}
예제 #13
0
int CBlastHitMatrixCGIApplication::ProcessRequest(CCgiContext &ctx)
{
    // retrieve our CGI rendering params
    x_GetCGIContextParams(ctx);            
    x_InitAppData(ctx);        
        
    bool success = true;       
    if(m_BlastHitMatrix->IsFileOut()) {
        success = m_BlastHitMatrix->WriteToFile();
    }
    else {        
        string encoding("image/png");
        CCgiResponse& response = ctx.GetResponse();
        response.SetContentType(encoding);
        response.WriteHeader();        
        success = m_BlastHitMatrix->Display(response.out());
    }
    if(!success) {
        NCBI_THROW(CBlastHitMatrixCGIException, eImageRenderError, "Exception occured, exception message: " + m_BlastHitMatrix->GetErrorMessage()); 
    }
    return 0;
}
예제 #14
0
int CTestMultipartCgiApplication::ProcessRequest(CCgiContext& ctx)
{
    const CArgs& args = GetArgs();
    CCgiResponse& response = ctx.GetResponse();
    string mode = args["mode"].AsString();

    if (mode == "mixed") {
        response.SetMultipartMode(CCgiResponse::eMultipart_mixed);
    } else if (mode == "related") {
        response.SetMultipartMode(CCgiResponse::eMultipart_related);
    } else if (mode == "replace") {
        response.SetMultipartMode(CCgiResponse::eMultipart_replace);
    }

    response.WriteHeader();

    response.out() << "main document" << endl;

    if (mode == "mixed") {
        response.BeginPart("attachment.foo", "application/x-foo-bar");
        response.out() << "attachment" << endl;
    } else if (mode == "related") {
        response.BeginPart("more-content.foo", "application/x-foo-bar");
        response.out() << "more content" << endl;
    } else if (mode == "replace") {
        response.EndPart();
        SleepSec(1);
        response.BeginPart(kEmptyStr, "text/html");
        response.out() << "updated document" << endl;
    }
    if (mode != "none") {
        response.EndLastPart();
    }

    return 0;
}
예제 #15
0
int CCgiSampleApplication::ProcessRequest(CCgiContext& ctx)
{
    // Parse, verify, and look at cmd-line and CGI parameters via "CArgs"
    // (optional)
    x_LookAtArgs();

    // Given "CGI context", get access to its "HTTP request" and
    // "HTTP response" sub-objects
    const CCgiRequest& request  = ctx.GetRequest();
    const CCgiCookies& cookies  = request.GetCookies();
    CCgiResponse&      response = ctx.GetResponse();
     
    const CCgiCookie* cookie = cookies.Find(kSessionId, "", "" );
    string message = "<EMPTY>";
    string session_id;
    if (cookie) {
        session_id = cookie->GetValue();
        m_NetCacheAPI.ReadData(session_id, message);
        if (!message.empty()) 
            message = "'" + message + "'";
        else
            message = "<EMPTY>";
    }

    bool is_message = false;
    string new_message = request.GetEntry("Message", &is_message);
    if ( is_message && !new_message.empty() ) {       
        auto_ptr<CNcbiOstream> os(m_NetCacheAPI.CreateOStream(session_id));
        *os << new_message;
        os.reset();
        CCgiCookies& rcookies = response.Cookies();
        rcookies.Add(kSessionId, session_id);
        new_message = "'" +  new_message + "'";
    } else 
        new_message = "<HAS NOT BEEN CHANGED>";

    // Create a HTML page (using template HTML file "cgi_sample.html")
    auto_ptr<CHTMLPage> page;
    try {
        page.reset(new CHTMLPage("Sample CGI with NetCache Session", m_HtmlTempl));
    } catch (exception& e) {
        ERR_POST("Failed to create Sample CGI HTML page: " << e.what());
        return 2;
    }

    // Register substitution for the template parameters <@MESSAGE@> and
    // <@SELF_URL@>
    try {
        CHTMLPlainText* text = new CHTMLPlainText(message);
        page->AddTagMap("MESSAGE", text);

        text = new CHTMLPlainText(new_message);
        page->AddTagMap("NEW_MESSAGE", text);

        CHTMLPlainText* self_url = new CHTMLPlainText(ctx.GetSelfURL());
        page->AddTagMap("SELF_URL", self_url);
    }
    catch (exception& e) {
        ERR_POST("Failed to populate Sample CGI HTML page: " << e.what());
        return 3;
    }

    // Compose and flush the resultant HTML page
    try {
        response.WriteHeader();
        page->Print(response.out(), CNCBINode::eHTML);
    } catch (exception& e) {
        ERR_POST("Failed to compose/send Sample CGI HTML page: " << e.what());
        return 4;
    }

    return 0;
}
예제 #16
0
int CCgiSampleApplication::ProcessRequest(CCgiContext& ctx)
{
    // Parse, verify, and look at cmd-line and CGI parameters via "CArgs"
    // (optional)
    x_LookAtArgs();

    // Given "CGI context", get access to its "HTTP request" and
    // "HTTP response" sub-objects
    const CCgiRequest& request  = ctx.GetRequest();
    CCgiResponse&      response = ctx.GetResponse();

 
    // Try to retrieve the message ('message=...') from the HTTP request.
    // NOTE:  the case sensitivity was turned off in Init().
    bool is_message = false;
    string message    = request.GetEntry("message", &is_message);
    if ( is_message ) {
        message = "'" + message + "'";
    } else {
        message = "<NONE>";
    }

    int iters = 5;
    for(int i = 0; i < iters; ++i) {
        PutProgressMessage( "Iteration " + NStr::IntToString(i) 
                            + " of " + NStr::IntToString(iters));
        SleepSec(5);
    }
    
    string this_host = CSocketAPI::gethostname();

    // Create a HTML page (using template HTML file "cgi_sample.html")
    auto_ptr<CHTMLPage> page;
    try {
        page.reset(new CHTMLPage("Sample Remote CGI", "rcgi_sample.html"));
    } catch (exception& e) {
        ERR_POST("Failed to create Sample CGI HTML page: " << e.what());
        return 2;
    }
    

    // Register substitution for the template parameters <@MESSAGE@> and
    // <@SELF_URL@>
    try {
        CHTMLPlainText* host = new CHTMLPlainText(this_host);
        page->AddTagMap("HOST", host);

        CHTMLPlainText* text = new CHTMLPlainText(message);
        page->AddTagMap("MESSAGE", text);

        CHTMLPlainText* self_url = new CHTMLPlainText(ctx.GetSelfURL());
        page->AddTagMap("SELF_URL", self_url);

        CHTMLPlainText* date = new CHTMLPlainText(
            GetFastLocalTime().AsString("D B Y, h:m:s"));
        page->AddTagMap("DATE", date);
    }
    catch (exception& e) {
        ERR_POST("Failed to populate Sample CGI HTML page: " << e.what());
        return 3;
    }

    // Compose and flush the resultant HTML page
    try {
        response.SetHeaderValue("Pragma", "no-cache");
        response.SetHeaderValue("Cache-Control", "no-cache");
        response.WriteHeader();
        page->Print(response.out(), CNCBINode::eHTML);

    } catch (exception& e) {
        ERR_POST("Failed to compose/send Sample CGI HTML page: " << e.what());
        return 4;
    }

    return 0;
}
예제 #17
0
void CVACommand :: Execute(CCgiContext& ctx)
{

	CCgiRequest&  req = ctx.GetRequest();
   	CCgiResponse& resp = ctx.GetResponse();
	
	string mst = req.GetEntry("master").GetValue();
	if ( mst.empty() ) {
	
		PrtMes::PrintErrorHeader(&resp, "VastAlign", 1);
      		PrtMes::PrintMsgWithTail(&resp,
            		"<h3>No master privided. </h3>n");
 	}

	if ( 4 == mst.size() ) mst += ' ';
	if ( 6 <= mst.size() ) {
		mst[4] = mst[5];
		if ( 6 == mst.size() ) mst[5] = '\0';
	}
	if ( 'x' == mst[4] ) mst[4] = ' ';
	unsigned i;
	for (i=0; i< mst.size(); i++) mst[i]  = toupper(mst[i]);

	string slv = req.GetEntry("slave").GetValue();
	if ( slv.empty() ) {

	     PrtMes::PrintErrorHeader(&resp, "VastAlign", 1);
	     PrtMes::PrintMsgWithTail(&resp, "<h3>No slave privided. </h3>n");
        }

	if ( 4 == slv.size() ) slv += ' ';
	if ( 6 <= slv.size() ) {
		slv[4] = slv[5];
		if ( 6 == slv.size()) slv[5] = '\0';
	}
	
        if ( 'x' == slv[4] ) slv[4] = ' ';
	for (i=0; i< slv.size(); i++) slv[i] = toupper(slv[i]);

	
	string value = req.GetEntry("from").GetValue();
	unsigned from = 0;
	if ( !value.empty() ) from = atoi(value.c_str());

	value = req.GetEntry("to").GetValue();
	unsigned to = 0;
	if ( !value.empty() ) to = atoi(value.c_str());

	VastPageDataPtr vpp = NewDataType <VastPageData> (1);
  	unsigned row_count =
      		constructTopNBestAlignedVastRows(vpp,1, (char *)mst.c_str(),
					(char *)slv.c_str(), from, to, 0, 0,1);

  	if (!row_count) vpp[0].IpdpLen = 0;
  	BiostrucAnnotSetPtr pbsa = constructBASPFromVastPagePtr(vpp, 1);

{AsnIoPtr aip;
aip = AsnIoOpen("pbsa.out", "w");
BiostrucAnnotSetAsnWrite(pbsa, aip, NULL);
AsnIoClose(aip);
}

	auto_ptr <CObjectOStream> oos
	      ( CObjectOStream::Open( eSerial_AsnBinary, resp.out() ) ); //Cn3D
	CObjectOStream::AsnIo aip(*oos, "Biostruc-annot-set");

	//  printf("Content-type: chemical/ncbi-asn1-binary\n\n"); launch Cn3D 
	//  printf("Content-type: text/html\n\n"); for test

/*
   auto_ptr <CObjectOStream> oos
              ( CObjectOStream::Open( eSerial_AsnText, resp.out() ) );
   aip = AsnIoOpen("pbsa.out", "w");  
*/

	resp.SetContentType("application/octet-stream"); 	// Cn3D
	resp.WriteHeader();
  	BiostrucAnnotSetAsnWrite(pbsa, aip, NULL);
	aip.End();

  	BiostrucAnnotSetFree(pbsa);
	delete [] vpp;

  	return;
}
예제 #18
0
int CCgiSampleApplication::ProcessRequest(CCgiContext& ctx)
{
    // Parse, verify, and look at cmd-line and CGI parameters via "CArgs"
    // (optional)
    x_LookAtArgs();

    // Given "CGI context", get access to its "HTTP request" and
    // "HTTP response" sub-objects
    const CCgiRequest& request  = ctx.GetRequest();
    CCgiResponse&      response = ctx.GetResponse();

    /*
    // To get CGI client API (in-house only, optional)
    const char* const* client_tracking_env = request.GetClientTrackingEnv();
    unsigned int client_ip = NcbiGetCgiClientIP(eCgiClientIP_TryAll,
                                                client_tracking_env);
    int is_local_client = NcbiIsLocalCgiClient(client_tracking_env);
    */
   

    // Try to retrieve the message ('message=...') from the HTTP request.
    // NOTE:  the case sensitivity was turned off in Init().
    bool is_message = false;
    string message    = request.GetEntry("Message", &is_message);
    if ( is_message ) {
        message = "'" + message + "'";
    } else {
        message = "<NONE>";
    }

    // NOTE:  While this sample uses the CHTML* classes for generating HTML,
    // you are encouraged to use XML/XSLT and the NCBI port of XmlWrapp.
    // For more info:
    //  http://www.ncbi.nlm.nih.gov/books/NBK8829/
    //  http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/namespacexml.html

    // Create a HTML page (using template HTML file "cgi_sample.html")
    auto_ptr<CHTMLPage> page;
    try {
        page.reset(new CHTMLPage("Sample CGI", "cgi_sample.html"));
    } catch (exception& e) {
        ERR_POST("Failed to create Sample CGI HTML page: " << e.what());
        return 2;
    }

    // Register substitution for the template parameters <@MESSAGE@> and
    // <@SELF_URL@>
    try {
        CHTMLPlainText* text = new CHTMLPlainText(message);
        _TRACE("foo");
        page->AddTagMap("MESSAGE", text);

        CHTMLPlainText* self_url = new CHTMLPlainText(ctx.GetSelfURL());
        page->AddTagMap("SELF_URL", self_url);
    }
    catch (exception& e) {
        ERR_POST("Failed to populate Sample CGI HTML page: " << e.what());
        return 3;
    }

    // Compose and flush the resultant HTML page
    try {
        _TRACE("stream status: " << ctx.GetStreamStatus());
        response.WriteHeader();
        page->Print(response.out(), CNCBINode::eHTML);
    } catch (exception& e) {
        ERR_POST("Failed to compose/send Sample CGI HTML page: " << e.what());
        return 4;
    }

    return 0;
}