我尝试将来自Oracle过程(PL / SQL)的JSON消息发送到WSO2 ESB。 所以, 我创建了存储过程TEST_JSON,如下所示:
create or replace PROCEDURE test_json
AS
http_resp utl_http.resp;
req_msg CLOB;
resp_msg CLOB;
TYPE tab_type IS TABLE OF PNLM%ROWTYPE;
t_tab tab_type := tab_type();
v_parser dbms_xmlparser.parser;
v_xmldoc XMLDOM.DOMDocument;
v_node dbms_xmldom.DOMNode;
v_item dbms_xmldom.domnodelist;
v_n dbms_xmldom.DOMNode;
l_pstatus varchar2(20);
v_clob_length binary_integer;
v_amount pls_integer := 16383;
v_offset pls_integer := 1;
v_buffer varchar2(32767);
json_msg CLOB;
BEGIN
json_msg := '{"loc":{"longitude":"30.5","latitude":"20.5"}}';
http_req := utl_http.begin_request('http://test.esb:8280/services/test_json', 'POST');
utl_http.set_body_charset(http_req, 'UTF-8');
utl_http.set_header(http_req, 'Content-Type', 'application/json');
v_clob_length := dbms_lob.getLength(json_msg);
if v_clob_length <= 32767 then
utl_http.write_text(http_req, dbms_lob.substr(json_msg,dbms_lob.getLength(json_msg),1));
elsif v_clob_length > 32767 then
while (v_offset < v_clob_length) loop
dbms_lob.read(lob_loc => json_msg,amount => v_amount,offset => v_offset,buffer => v_buffer);
utl_http.write_text(http_req, v_buffer);
v_offset := v_offset + v_amount;
end loop;
end if;
http_resp := utl_http.get_response(http_req);
utl_http.read_text(http_resp, resp_msg);
dbms_output.put_line(resp_msg);
v_parser := dbms_xmlparser.newParser;
dbms_xmlparser.setValidationMode(v_parser, FALSE);
dbms_xmlparser.parseCLOB(v_parser, resp_msg);
v_xmldoc := dbms_xmlparser.getDocument(v_parser);
dbms_xmlparser.freeParser(v_parser);
v_node := xmldom.makenode(v_xmldoc);
v_item := dbms_xslprocessor.selectNodes(v_node,'//ts_state');
t_tab.EXTEND;
v_n := dbms_xmldom.item(v_item, 0);
dbms_xslprocessor.valueOf(v_n, '//ts_state', l_pstatus);
dbms_output.put_line('l_pstatus=['||l_pstatus||']');
utl_http.end_response(http_resp);
exception when utl_http.end_of_body then utl_http.end_response(http_resp);
when utl_http.request_failed then dbms_output.put_line('Response Failed.'); utl_http.end_response(http_resp);
when others then dbms_output.put_line('Unknown Error!.'); utl_http.end_response(http_resp);
END;
并创建了WSO2 ESB代理服务TEST_JSON(以下内容位于代理服务TEST_JSON的顺序中):
<proxy xmlns="http://ws.apache.org/ns/synapse" name="test_json" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<clone continueParent="true" id="clon1" sequential="true">
<target>
<sequence>
<log level="full">
<property name="text" value="==========in clone=========="/>
</log>
<property name="longitude" expression="//longitude/text()" scope="default" type="STRING"/>
<property name="latitude" expression="//latitude/text()" scope="default" type="STRING"/>
<log level="custom">
<property name="LONGITUDE" expression="get-property('longitude')"/>
<property name="LATITUDE" expression="get-property('latitude')"/>
</log>
</sequence>
</target>
</clone>
<header name="To" action="remove"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="RESPONSE" value="true" scope="default"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
<send/>
<log level="full">
<property name="text" value="==============End=============="/>
</log>
</inSequence>
</target>
<description></description>
</proxy>
但是,Oracle程序总是超时(ORA-29276:传输超时), 虽然WSO2 ESB会收到消息(客户端连接关闭后,ESB控制台中显示日志中介消息)。
当我通过cURL发送JSON消息时:
curl -i \
-H "Content-Type: application/json" \
-X POST \
-d '{"loc":{"longitude":"30.5","latitude":"20.5"}}' \
http://test.esb:8280/services/test_json
很快就会有回应。
任何人都可以帮忙吗?感谢。
答案 0 :(得分:1)
我找到了重点,将'Transfer-Encoding'设置为'chunked', 在utl_http.begin_request之后添加行,
utl_http.set_header(http_req, 'Transfer-Encoding', 'chunked' );