Tuesday 9 September 2008

Oracle HTTP request

SET serveroutput ON
CREATE OR REPLACE PACKAGE hello_soap AS
TYPE response IS RECORD (
doc xmltype);
PROCEDURE invoke(hello varchar2);
END;
/
CREATE OR REPLACE PACKAGE BODY hello_soap AS

PROCEDURE invoke(hello varchar2) AS
env VARCHAR2(32767);
http_req utl_http.req;
http_resp utl_http.resp;
resp response;
BEGIN
env := ;dataset><record><clientId>123</clientId><addressId>987</addressId><addressLineId>456</addressLineId><address1>1305 mainst</address1><address2></address2><address3></address3><address4></address4><city></city><state></state><postalCode>54650</postalCode><postalCode2></postalCode2><country>US</country></record></dataset>';
http_req := utl_http.begin_request( 'http://localhost:8080/Service', 'POST','HTTP/1.0');
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(env));
utl_http.set_header(http_req, 'SOAPAction', 'http://localhost:8080/Service');
utl_http.write_text(http_req, env);
http_resp := utl_http.get_response(http_req);
utl_http.read_text(http_resp, env);
utl_http.end_response(http_resp);
resp.doc := xmltype.createxml(env);
--resp.doc := resp.doc.extract('/soap:Envelope/soap:Body/child::node()',
-- 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
put_line(resp.doc.getStringVal(),20);
END;
END;
/

No comments: