Commit 30ef6714ab770d6dfc07855cc226bc8aab8cada4

Authored by Thierry Louge
1 parent 4f7282d6

GVOHub send url containing get_fits method. It detects http get_fits method call…

… and returning is ont he way
Showing 1 changed file with 35 additions and 28 deletions
src/vo/GVOHub.cpp
@@ -430,11 +430,33 @@ void GVOHub::handle_request(const socklen_t& sock) @@ -430,11 +430,33 @@ void GVOHub::handle_request(const socklen_t& sock)
430 430
431 // Extract response into an XML object 431 // Extract response into an XML object
432 GXml xml; 432 GXml xml;
  433 + size_t start_html = message.find("GET /get_fits");
  434 + if (start_html != std::string::npos) {
  435 + #if defined(G_CONSOLE_DUMP)
  436 + std::cout << "get_fits called " << std::endl;
  437 + #endif
  438 + //Form and send here the html message containing fits file data
  439 + std::string msg ="";
  440 + msg.append("HTTP/1.1 200 OK\n");
  441 + msg.append("Connection: open\n");
  442 + msg.append("Content-Type: multipart/form-data\n");
  443 + //Fixed length for tests
  444 + msg.append("Content-Length: 364\n");
  445 + //Fixed filename for tests
  446 + msg.append("Content-Disposition: form-data; name=\"Gammalib_fits\";filename=\"/root/Skw+_Fermi_5.fits\"\n");
  447 + post_string(msg, sock);
  448 + #if defined(G_CONSOLE_DUMP)
  449 + std::cout <<msg << std::endl;
  450 + #endif
  451 + // Return
  452 + return;
  453 + }
  454 +
433 size_t start = message.find("<?xml"); 455 size_t start = message.find("<?xml");
434 if (start != std::string::npos) { 456 if (start != std::string::npos) {
435 xml = GXml(message.substr(start, std::string::npos)); 457 xml = GXml(message.substr(start, std::string::npos));
436 } 458 }
437 - 459 +
438 // Get methodName value 460 // Get methodName value
439 std::string method_called; 461 std::string method_called;
440 const GXmlNode* node = xml.element("methodCall > methodName"); 462 const GXmlNode* node = xml.element("methodCall > methodName");
@@ -1146,13 +1168,10 @@ void GVOHub::broadcast(const GXml&amp; xml, const socklen_t&amp; sock) @@ -1146,13 +1168,10 @@ void GVOHub::broadcast(const GXml&amp; xml, const socklen_t&amp; sock)
1146 // Get message mtype 1168 // Get message mtype
1147 std::string mtype = get_mtype(xml); 1169 std::string mtype = get_mtype(xml);
1148 #if defined(G_CONSOLE_DUMP) 1170 #if defined(G_CONSOLE_DUMP)
1149 - std::cout<<"mtype is: " +mtype + "i value: " + gammalib::str(i)<<std::endl; 1171 + std::cout<<"mtype is: " +mtype + " i value: " + gammalib::str(i)<<std::endl;
1150 #endif 1172 #endif
1151 // Continue only if index is valid 1173 // Continue only if index is valid
1152 - if (i != -1) {  
1153 - #if defined(G_CONSOLE_DUMP)  
1154 - std::cout<<"i not negative"<<std::endl;  
1155 - #endif 1174 + //if (i != -1) {
1156 // Post void message 1175 // Post void message
1157 post_samp_void(sock); 1176 post_samp_void(sock);
1158 if (mtype == "image.load.fits") { 1177 if (mtype == "image.load.fits") {
@@ -1169,7 +1188,7 @@ void GVOHub::broadcast(const GXml&amp; xml, const socklen_t&amp; sock) @@ -1169,7 +1188,7 @@ void GVOHub::broadcast(const GXml&amp; xml, const socklen_t&amp; sock)
1169 m_clients[i].reference,xml); 1188 m_clients[i].reference,xml);
1170 } 1189 }
1171 1190
1172 - } // endif: valid client found 1191 + //} // endif: valid client found
1173 #if defined(G_CONSOLE_DUMP) 1192 #if defined(G_CONSOLE_DUMP)
1174 std::cout<<"Returning from broadcast function"<<std::endl; 1193 std::cout<<"Returning from broadcast function"<<std::endl;
1175 #endif 1194 #endif
@@ -1720,15 +1739,9 @@ void GVOHub::send_notifications(const std::string&amp; method, @@ -1720,15 +1739,9 @@ void GVOHub::send_notifications(const std::string&amp; method,
1720 std::string msg = ""; 1739 std::string msg = "";
1721 1740
1722 if (method == "image.load.fits") { 1741 if (method == "image.load.fits") {
1723 - /*  
1724 - Example of message to send for VOTABLE message  
1725 - { "samp.mtype": "table.load.votable",  
1726 - "samp.params": {  
1727 - "name": "SDSS DR7",  
1728 - "table-id": "http://alasky.u-strasbg.fr/cats/SDSS-DR7",  
1729 - "url": "file://localhost/root/.aladin/.aladin.28999/sampSDSSDR71446626818775.xml" } }  
1730 - */  
1731 - 1742 + #if defined(G_CONSOLE_DUMP)
  1743 + std::cout << "GVOHub:: Preparing broadcast message" << std::endl;
  1744 + #endif
1732 // Set response for image.load.fits 1745 // Set response for image.load.fits
1733 msg.append("<?xml version=\"1.0\"?>\n"); 1746 msg.append("<?xml version=\"1.0\"?>\n");
1734 msg.append("<methodCall>\n"); 1747 msg.append("<methodCall>\n");
@@ -1750,30 +1763,24 @@ void GVOHub::send_notifications(const std::string&amp; method, @@ -1750,30 +1763,24 @@ void GVOHub::send_notifications(const std::string&amp; method,
1750 msg.append(" <value><struct>\n"); 1763 msg.append(" <value><struct>\n");
1751 msg.append(" <member>\n"); 1764 msg.append(" <member>\n");
1752 msg.append(" <name>name</name>\n"); 1765 msg.append(" <name>name</name>\n");
1753 - msg.append(" <value>");  
1754 - const GXmlNode* node = xml.element("methodCall > params > param[1] > value > struct > member[1] > value");  
1755 - if (node != NULL) {  
1756 - const GXmlText* text = static_cast<const GXmlText*>((*node)[0]);  
1757 - if (text != NULL) {  
1758 - msg.append(text->text());  
1759 - }  
1760 - }  
1761 - msg.append("</value>\n"); 1766 + msg.append(" <value>Gammalib_shared_fits</value>\n");
1762 msg.append(" </member>\n"); 1767 msg.append(" </member>\n");
1763 msg.append(" <member>\n"); 1768 msg.append(" <member>\n");
1764 msg.append(" <name>image-id</name>\n"); 1769 msg.append(" <name>image-id</name>\n");
1765 - msg.append(" <value>IMAGE_ID</value>\n"); 1770 + msg.append(" <value>Gammalib_shared_fits_id</value>\n");
1766 msg.append(" </member>\n"); 1771 msg.append(" </member>\n");
1767 msg.append(" <member>\n"); 1772 msg.append(" <member>\n");
1768 msg.append(" <name>url</name>\n"); 1773 msg.append(" <name>url</name>\n");
1769 - msg.append(" <value>http://127.0.0.1:2526/</value>\n"); 1774 + msg.append(" <value>http://127.0.0.1:2526/get_fits</value>\n");
1770 msg.append(" </member>\n"); 1775 msg.append(" </member>\n");
1771 msg.append(" </struct></value>\n"); 1776 msg.append(" </struct></value>\n");
1772 msg.append(" </member>\n"); 1777 msg.append(" </member>\n");
1773 msg.append(" </struct></value></param>\n"); 1778 msg.append(" </struct></value></param>\n");
1774 msg.append("</params>\n"); 1779 msg.append("</params>\n");
1775 msg.append("</methodCall>\n"); 1780 msg.append("</methodCall>\n");
1776 - 1781 + #if defined(G_CONSOLE_DUMP)
  1782 + std::cout << msg << std::endl;
  1783 + #endif
1777 // Post notification 1784 // Post notification
1778 notify(m_clients[i].url, msg); 1785 notify(m_clients[i].url, msg);
1779 1786