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 430  
431 431 // Extract response into an XML object
432 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 455 size_t start = message.find("<?xml");
434 456 if (start != std::string::npos) {
435 457 xml = GXml(message.substr(start, std::string::npos));
436 458 }
437   -
  459 +
438 460 // Get methodName value
439 461 std::string method_called;
440 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 1168 // Get message mtype
1147 1169 std::string mtype = get_mtype(xml);
1148 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 1172 #endif
1151 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 1175 // Post void message
1157 1176 post_samp_void(sock);
1158 1177 if (mtype == "image.load.fits") {
... ... @@ -1169,7 +1188,7 @@ void GVOHub::broadcast(const GXml&amp; xml, const socklen_t&amp; sock)
1169 1188 m_clients[i].reference,xml);
1170 1189 }
1171 1190  
1172   - } // endif: valid client found
  1191 + //} // endif: valid client found
1173 1192 #if defined(G_CONSOLE_DUMP)
1174 1193 std::cout<<"Returning from broadcast function"<<std::endl;
1175 1194 #endif
... ... @@ -1720,15 +1739,9 @@ void GVOHub::send_notifications(const std::string&amp; method,
1720 1739 std::string msg = "";
1721 1740  
1722 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 1745 // Set response for image.load.fits
1733 1746 msg.append("<?xml version=\"1.0\"?>\n");
1734 1747 msg.append("<methodCall>\n");
... ... @@ -1750,30 +1763,24 @@ void GVOHub::send_notifications(const std::string&amp; method,
1750 1763 msg.append(" <value><struct>\n");
1751 1764 msg.append(" <member>\n");
1752 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 1767 msg.append(" </member>\n");
1763 1768 msg.append(" <member>\n");
1764 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 1771 msg.append(" </member>\n");
1767 1772 msg.append(" <member>\n");
1768 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 1775 msg.append(" </member>\n");
1771 1776 msg.append(" </struct></value>\n");
1772 1777 msg.append(" </member>\n");
1773 1778 msg.append(" </struct></value></param>\n");
1774 1779 msg.append("</params>\n");
1775 1780 msg.append("</methodCall>\n");
1776   -
  1781 + #if defined(G_CONSOLE_DUMP)
  1782 + std::cout << msg << std::endl;
  1783 + #endif
1777 1784 // Post notification
1778 1785 notify(m_clients[i].url, msg);
1779 1786  
... ...