0

我正在使用下面的代码通过 Oracle DB 触发器进行 http 调用

create or replace TRIGGER TEST_TABLE_TRIGGER 
AFTER INSERT OR UPDATE OF VALUE ON TEST_TABLE 

for each row
DECLARE

  req utl_http.req;
  res utl_http.resp;
  buffer varchar2(4000); 
  url varchar2(4000) := 'http://localhost:8086/testMethod';

BEGIN
  req := utl_http.begin_request(url, 'GET',' HTTP/1.1');
  utl_http.set_header(req, 'content-type', 'application/json');
  res := utl_http.get_response(req);
  -- process the response from the HTTP call
  begin
    loop
      utl_http.read_line(res, buffer);
      dbms_output.put_line(buffer);
    end loop;
    utl_http.end_response(res);
  exception
    when utl_http.end_of_body 
    then
      utl_http.end_response(res);
  end;
END;

DBA 团队已向 DB 用户授予 http 权限(SQL> grant execute on UTL_HTTP to userName;)。但是我的应用程序日志中出现以下错误(Springboot)

java.sql.SQLException: ORA-29273: HTTP request failed
ORA-12541: TNS:no listener
ORA-06512: at "SYS.UTL_HTTP", line 368
ORA-06512: at "SYS.UTL_HTTP", line 1118
ORA-06512: at "userName.TEST_TABLE_TRIGGER", line 9
ORA-04088: error during execution of trigger 'userName.TEST_TABLE_TRIGGER '

我尝试在 linux 服务器中运行应用程序并使用有效的 IP 地址而不是 localhost ( 'http://localhost:8086/testMethod') 并得到相同的错误。

当我询问 DBA 团队时,他们说数据库侦听器已启动并在端口15251791上运行。如何/在哪里使用数据库侦听器端口来使此代码工作?

4

1 回答 1

0

当我在数据库触发器中使用http://localhost:8086/testMethod URL 在STS(Spring 工具站点)中运行代码时,它在本地不起作用。但是,在我在 Linux 服务器中部署代码并使用 linux 服务器的 IP 地址(http://{serverIP}:8086/testMethod)更新 localhost 之后,它就可以工作了!我的错 !我一开始使用了错误的 URL。当我在 STS 中运行代码时,如果您知道如何使其在本地工作,请告诉我。

于 2020-04-28T15:58:25.997 回答