Invoking an HTTP GET request through MySQL by executing native operating system's commands like curl

ぐ巨炮叔叔 提交于 2019-12-24 03:35:49

问题


I am using MySQL 5.6.11 running on 32-bit Microsoft Windows XP (Professional Version 2002 Service Pack 3). I installed the MySQL sys_exec UDF. Since I am running on 32-bit Windows, I used this lib_mysqludf_sys.dll (placed under C:\Program Files\MySQL\MySQL Server 5.6\lib\plugin\ as it is the default installation).

Afterwards, the following command was executed (after logging in into an already created database).

mysql> CREATE FUNCTION sys_exec RETURNS INT SONAME 'lib_mysqludf_sys.dll';
Query OK, 0 rows affected (0.02 sec)

I had already created a PL/SQL stored procedure as follows.

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `country_push`()
BEGIN 
    SET @result=sys_exec('curl http://localhost:8080/ContextPath/push-update-country'); 
END

This procedure is supposed to be invoked by database triggers (which is adequately done) and accordingly, it should raise an HTTP GET request on the said URL but no HTTP GET request is raised on the URL, when this stored procedure is executed by a trigger on a certain event.


Manually executing the procedure on the command line succeeds as well, as follows.

mysql> CALL country_push();
Query OK, 0 rows affected (0.08 sec)

The sys_exec() function returns 1 as follows which is a success flag.

mysql> SELECT sys_exec('curl http://localhost:8080/ContextPath/push-update-country')
AS result;
+--------+
| result |
+--------+
|      1 |
+--------+
1 row in set (0.06 sec)

There is already a Java Servlet running on GlassFish (4.1) application server which is supposed to listen to this HTTP GET request as follows.

@WebServlet(name = "PushCountry", urlPatterns = {"/push-update-country"})
public class PushCountry extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("PushCountry called.");
    }
}

The line System.out.println("PushCountry called."); in the doGet() method produces nothing on the server terminal (because it is not executed/invoked), when the above-mentioned MySQL stuff is put into practice.

Is it not practical to do this using MySQL, is there something else I might be missing or is it the old EOL dinosaur : Windows XP?


The shared Dynamic Link Library I am using might not be suitable. Please clarify, if such is a case as this is beyond me.


EDIT:

When entering,

mysql> SELECT sys_eval('id');

MySQL terminates/crashes with the following error report.

On closing this dialog, MySQL leaves the following error message.

ERROR 2013 (HY000): Lost connection to MySQL server during query

It fails to reconnect until/unless the system itself is restarted.

Perhaps, I will think of reinstalling the operating system itself later on.


回答1:


seems that 'id' is a Linux command not existing under Windows... anyway i also get trouble with sys_exec() under windows that return a number but no process is launched. For info it works well under linux.



来源:https://stackoverflow.com/questions/28665934/invoking-an-http-get-request-through-mysql-by-executing-native-operating-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!