2017-10-21 11 views
0

ローカルのXAMPPでホストされているWebサービスからJSONオブジェクトを受け取るためのテストOracleプロシージャを開発しています。以下の手順に従います。PL/SQLでWebサービス経由でJSONオブジェクトを処理する

(01)はprocの

set serveroutput on size 30000; 
BEGIN 
    JSON11(); 
END; 
呼び出されたテスト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)次の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)を作成しました

ただし、以下のエラーで終了します。

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を使用しています。 Webサービスは非常に簡単で、XAMPP経由で実行され、単純なJSONオブジェクトを返します。

ヒントは共有できますか?

よろしく、 LM

+0

なぜこれは 'pljson'とタグ付けされていますか? –

+0

私はPL/JSONプロジェクトのJSONオブジェクトを使ってWebサービスを参照しています。 –

答えて

1

あなたはセッションごとに5つのHTTP要求の最大を持つことができます。 プロシージャを実行するたびに新しい接続を1つ作成していますが、必ずしもその接続を閉じる必要はありません。 接続はwhen utl_http.end_of_body thenでのみ終了しますが、when others thenでも閉じてください。

+0

優れています。それは働いています!アドバイスをありがとうございます。 –

関連する問題