Accessing HTTPS Web Service (REST) using UTL_HTTP and SET_AUTHENTICATION
Hi,
I'm trying to access a web service built using REST architecture (not SOAP), and which runs in a secure mode (HTTPS) from my PL/SQL code. The website that I'm trying to access uses Oracle Corp-SSO and is an external site used by external Oracle users (e.g. https://somesite.oracle.com).
I've got the certificate imported into the wallet, and I can access the wallet without any issues. I'm also passing a valid username and password to utl_http.set_authentication. However, the output that I get it not the HTML code of the site I'm calling, but of the SSO login page where the site redirects me to.
Following is my code:
DECLARE
req utl_http.req;
resp utl_http.resp;
name VARCHAR2(255);
value VARCHAR2(1023);
v_msg VARCHAR2(80);
v_url VARCHAR2(32767) := 'https://somesite.oracle.com/web_service/123';
begin
dbms_output.put_line('Enabling Error Check');
-- request that exceptions are raised for error status codes
utl_http.set_response_error_check(enable => TRUE);
dbms_output.put_line('Enabling Exception Support');
-- allow testing for exceptions like Utl_Http.Http_Server_Error
utl_http.set_detailed_excp_support(enable => TRUE);
dbms_output.put_line('Setting proxy');
utl_http.set_proxy(
proxy=>'proxy-server-name', no_proxy_domains=>'us.oracle.com');
dbms_output.put_line('Setting SSL Wallet');
utl_http.set_wallet(
path=>'file:some_path',
password=>'some_password');
dbms_output.put_line('Begin request');
req := utl_http.begin_request(url => v_url, method => 'GET');
-- Or use method => 'POST' and utl_http.write_text
-- to create an arbitrarily long msg
dbms_output.put_line('Authenticate');
utl_http.set_authentication(r => req, username => '<<valid_sso_username>>',
password => '<<valid_password>>', scheme => 'Basic', for_proxy => FALSE);
dbms_output.put_line('Set Header');
utl_http.set_header(r=>req,name=>'User-Agent',value=>'Mozilla/4.0');
dbms_output.put_line('Get Response');
resp := utl_http.get_response(r => req);
dbms_output.put_line('Status code: ' || resp.status_code);
dbms_output.put_line('Reason phrase: ' || resp.reason_phrase);
FOR i IN 1..utl_http.get_header_count(r => resp)
LOOP
utl_http.get_header(r=>resp, n=>i, name=>name, value=>value);
dbms_output.put_line(name || ': ' || value);
END LOOP;
dbms_output.put_line('======OUTPUT======');
BEGIN
LOOP
utl_http.read_text(r => resp, data => v_msg);
dbms_output.put_line(v_msg);
END LOOP;
EXCEPTION
WHEN utl_http.end_of_body THEN
NULL;
END;
utl_http.end_response(r => resp);
EXCEPTION
WHEN utl_http.request_failed THEN
dbms_output.put_line('Request Failed: ' || utl_http.get_detailed_sqlerrm);
WHEN utl_http.http_server_error THEN
dbms_output.put_line('Server Error: ' || utl_http.get_detailed_sqlerrm);
WHEN utl_http.http_client_error THEN
dbms_output.put_line('Client Error: ' || utl_http.get_detailed_sqlerrm);
WHEN OTHERS THEN
dbms_output.put_line(SQLERRM);
END;
/
Any idea where I'm going wrong?
Thanks,
A