通过PL/SQL中的Webservice处理JSON对象

问题描述:

我正在开发测试Oracle过程以从本地XAMPP托管的Web服务接收JSON对象。遵循以下步骤。通过PL/SQL中的Webservice处理JSON对象

(01)创建的ACL

set define off; 
BEGIN 
SYS.DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(acl   => 'www.xml', 
            description => 'TEST JSON', 
            principal => 'TEST_USER', 
            is_grant => true, 
            privilege => 'connect', 
            start_date => SYSTIMESTAMP, 
            end_date  => NULL); 

SYS.DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl  => 'www.xml', 
             principal => 'TEST_USER', 
             is_grant => true, 
             privilege => 'resolve'); 

SYS.DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(acl => 'www.xml', 
            host  => 'localhost', 
            lower_port => 8081, 
            upper_port => NULL); 
END; 

(02)以下是测试PROC

create or replace PROCEDURE JSON11 IS 
    l_param_list  VARCHAR2(512); 
    l_http_request UTL_HTTP.req; 
    l_http_response UTL_HTTP.resp; 
    l_response_text VARCHAR2(32767); 
    l_list system.json_list; 
    acl   VARCHAR2(100); 
    url   VARCHAR2(1000) := 
    'http://localhost:8081/PhpProjectFirst/displayValuesSent.php? 
    name=name11&[email protected]&gender=male&course=OCA2&class=2008&s 
    ubject=PL/SQL'; 

BEGIN 
    DBMS_OUTPUT.put_line('start'); 
    l_http_request := utl_http.begin_request(url, 'POST','HTTP/1.1'); 
    DBMS_OUTPUT.put_line('aa'); 
    --utl_http.set_header(l_http_request, 'user-agent', 'mozilla/4.0'); 
    utl_http.set_header(l_http_request, 'Content-Type', 'application/json'); 
    --utl_http.set_header(l_http_request, 'Content-Length', 
    length(content));  
    --utl_http.write_text(l_http_request, content); 
    DBMS_OUTPUT.put_line('bb'); 
    l_http_response := utl_http.get_response(l_http_request); 
    DBMS_OUTPUT.put_line('cc'); 

    -- process the response from the HTTP call 
    begin 
     loop 
      utl_http.read_line(l_http_response, l_response_text); 
      dbms_output.put_line(l_response_text); 
     end loop; 
     utl_http.end_response(l_http_response); 

    end; 
exception 
    when utl_http.end_of_body then 
     utl_http.end_response(l_http_response); 
    when others then 
     DBMS_OUTPUT.put_line('Error >> '||sqlerrm); 
END JSON11; 

(03)叫PROC

set serveroutput on size 30000; 
BEGIN 
    JSON11(); 
END; 

但以下面的错误结束。

Error >> ORA-29273: HTTP request failed 
ORA-06512: at "SYS.UTL_HTTP", line 1130 
ORA-29270: too many open HTTP requests 

DB是Oracle XE并使用Oracle SQL Developer。 Webservice非常简单,通过XAMPP运行并返回一个简单的JSON对象。

任何提示可以共享?

问候, LM

+0

为什么这个标签为'pljson'? –

+0

我已经使用PL/JSON项目的JSON对象来引用Web服务。 –

你可以有一个最大的每个会话5个HTTP请求。 随着程序的每次运行,您正在创建一个新的连接,但您并不总是关闭它。 您只在when utl_http.end_of_body then中关闭连接,但您也应该在when others then关闭它。

+0

优秀。它已经奏效!非常感谢您的建议。 –