calling web services from oracle presenter – raymond jones company – intermountain healthcare...

14
Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft) and have decided to do all interfaces using web services. Oracle SOA Suite will be used to develop the web services. My team will be calling these web services from Oracle E-Business Suite.

Upload: branden-davidson

Post on 18-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

Calling Web Services from Oracle

• Presenter – Raymond Jones• Company – Intermountain Healthcare• Background – We are implementing a new

ERP system (Peoplesoft) and have decided to do all interfaces using web services. Oracle SOA Suite will be used to develop the web services. My team will be calling these web services from Oracle E-Business Suite.

Page 2: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

Steps to call a web service

• Get WSDL• Use soapUI to read WSDL• Create Oracle Wallet if calling secure website• Use UTL_HTTP package to call web service• Parse web service response using oracle

functions and xpath

Page 3: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

WSDL

• Web Services Description Language – XML document that is used to describe how a service is called.

• Tools such as soapUI are available that will read the WSDL and provide the details needed to call the service.

• Example: http://www.webservicex.net/stockquote.asmx?WSDL

Page 4: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

soapUI• A tool for processing WSDL’s• Download version 4.5.1 (free version, not Pro version) – www.soapui.org• File -> New soapUI Project• Enter WSDL and click OK• Double click request• Save URL and XML to use when calling the web service• Configure proxy server if needed: File -> Preferences -> Proxy Server• Note: Proxy server did not work for me because soapUI uses NTLMv1

authentication and our proxy is using NTLMv2. A workaround is to access WSDL in browser and then save to local machine and then access that file from soapUI

Page 5: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

Create Oracle Wallet

• On Database server create Oracle Wallet• Need to add a certificate for each secure web

server ie (https connections)• See the following Oracle support Document

for steps needed to setup Wallet: Configuring Wallet Manager To Enable HTTPS Connections Via UTL_HTTP.REQUEST [ID 169768.1]

Page 6: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

Call web service using UTL_HTTPCREATE OR REPLACE PACKAGE ihchr_web AS

PROCEDURE call_service(p_url IN VARCHAR2,p_xml_send_text IN XMLTYPE,p_xml_response OUT XMLTYPE,p_error_message OUT VARCHAR2);

END ihchr_web;

Page 7: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

CREATE OR REPLACE PACKAGE BODY ihchr_web AS

FUNCTION call_service(p_url IN VARCHAR2,p_xml_send_text IN XMLTYPE,p_xml_response OUT XMLTYPE,p_error_message OUT VARCHAR2)IS

v_http_req UTL_HTTP.REQ;v_http_resp UTL_HTTP.RESP;v_response_clob CLOB;v_text VARCHAR2(32767);v_location VARCHAR2(255);

BEGIN

v_location := 'Set Oracle Wallet';UTL_HTTP.SET_WALLET('file:/etc/ORACLE/WALLETS/oracle',‘password');

v_location := 'Set Proxy';UTL_HTTP.SET_PROXY(‘user:password@server:port');

v_location := 'Establish connection to web server';v_http_req := UTL_HTTP.BEGIN_REQUEST(p_url, 'POST', 'HTTP/1.0');

v_location := 'Set http request header';UTL_HTTP.SET_HEADER(v_http_req, 'Content-Type', 'text/xml');UTL_HTTP.SET_HEADER(v_http_req, 'Content-Length',

LENGTH(p_xml_send_text.GETSTRINGVAL()));

Page 8: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

v_location := 'Writes text data in the HTTP request body';UTL_HTTP.WRITE_TEXT(v_http_req, p_xml_send_text.GETSTRINGVAL());

v_location := 'Read the HTTP response';v_http_resp := UTL_HTTP.GET_RESPONSE(v_http_req);

v_location := 'Put HTTP response into CLOB';BEGIN

-- Initialize the CLOB.DBMS_LOB.createtemporary(v_response_clob, FALSE);LOOP --read in a chunk at a time so large responses will be handled properly

UTL_HTTP.READ_TEXT(v_http_resp, v_text, 32766);DBMS_LOB.writeappend(v_response_clob, LENGTH(v_text),

v_text);END LOOP;

EXCEPTIONWHEN UTL_HTTP.end_of_body THEN -- this gets us out of above loop.

NULL;END;v_location := 'closing network connection';UTL_HTTP.END_RESPONSE(v_http_resp);

v_location := 'convert response to XML';IF DBMS_LOB.getlength(v_response_clob) > 0 THEN

p_xml_response := XMLTYPE(v_response_clob);END IF;DBMS_LOB.freetemporary(v_response_clob);

Page 9: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

EXCEPTIONWHEN OTHERS THEN

p_error_message := 'Location=ihchr_web.call_service-'||v_location||chr(10)||SUBSTR(SQLERRM,1,240);

END;

END ihchr_web;

Page 10: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

Parsing XML

• xpath• Namespace• Oracle functions

Page 11: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

XPATH• XML Path Language is a query language for selecting nodes from an XML

document.• http://www.w3.org/TR/xpath has xpath documentation• http://www.w3schools.com/xpath/xpath_syntax.asp has xpath examples• /* selects everything from the root node down• /bookstore/book/* select everything from book node down• /bookstore/book[1]/text() selects the value for the 1st book.• /stockquote/stock/price/text() selects the price value for the stock

Page 12: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

XML namespace• Provide uniquely named elements and attributes in an XML document• Not well documented for Oracle functions but are mandatory if namespaces are

included in XML documents such as SOAP documents.• Example: xmlns:soap="http://www.w3.org/2003/05/soap-envelope"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=http://www.w3.org/2001/XMLSchema

Page 13: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

Oracle functions to Parse XML• EXTRACT• Syntax: xml_doc.EXTRACT(xpath,namespace).getvalue• Example: v_xml_response.EXTRACT(‘/soap:store/book[1]/text()’,’xmlsn:soap=

http://www.w3.org’).getstringval()• XMLSEQUENCE• Syntax: table(xmlsequence(extract(xml_doc,xpath,namespace)))• Example select count(*) from

table(xmlsequence(extract(xml_doc,xpath,namespace))) from dual;• XMLTABLE• Syntax: xmltable(xmlnamespaces(‘url’ as “namespace 1”),’xpath’ PASSING xml_doc

COLUMNS type PATH ‘xpath’

Page 14: Calling Web Services from Oracle Presenter – Raymond Jones Company – Intermountain Healthcare Background – We are implementing a new ERP system (Peoplesoft)

XMLTABLE example: SELECT seq, company,old_dept,bus_unit,new_dept FROM XMLTABLE(XMLNamespaces('http://schemas.xmlsoap.org/soap/envelope/' as "env“

,'http://intermountain.org/soa/utility/v1/IfsCrosswalk' as "ns0") ,'env:Envelope/env:Body/ns0:IfsCrosswalkResponse/ns0:CrosswalkValues'

PASSING v_xml_response COLUMNS seq FOR ORDINALITY , company VARCHAR2(100) PATH 'ns0:Source1' , old_dept VARCHAR2(100) PATH 'ns0:Source2' , bus_unit VARCHAR2(100) PATH 'ns0:Target1' , new_dept VARCHAR2(100) PATH 'ns0:Target2' ) AS my_table WHERE company = '105' ORDER BY old_dept