/
People Service Consumption
People Service Consumption
Amit Poddar (Unlicensed)
Owned by Amit Poddar (Unlicensed)
Oracle
People Service Expand source
create user wc identified by wc default tablespace users temporary tablespace temp; grant create procedure to wc; grant execute on utl_http to wc; grant create session to wc; grant create type to wc; BEGIN DBMS_NETWORK_ACL_ADMIN.create_acl ( acl => 'Layer7_Dev.xml', description => 'A test of the Web Service functionality', principal => 'WC', is_grant => TRUE, privilege => 'connect', start_date => SYSTIMESTAMP, end_date => NULL); end; begin DBMS_NETWORK_ACL_ADMIN.assign_acl ( acl => 'Layer7_Dev.xml', host => 'gw-dev.its.yale.edu', lower_port => 443, upper_port => NULL); end; connect wc/wc create type person_type as object ( UPI varchar2(20), NETID varchar2(20), AFFILIATION varchar2(200), PRIMARY_AFFILIATION varchar2(60), LEGAL_FIRST_NAME varchar2(60), LEGAL_LAST_NAME varchar2(60) ); create type people as table of person_type; create or replace package ws_consumer_pkg as function get_web_request(p_uri varchar2, p_user_name varchar2, p_password varchar2) return clob; function post_web_request(p_uri varchar2, p_post_body varchar2, p_user_name varchar2, p_password varchar2) return clob; function get_people_data(p_uri varchar2, p_post_body varchar2, p_user_name varchar2, p_password varchar2) return people pipelined; end ws_consumer_pkg; create or replace package body ws_consumer_pkg as function get_web_request(p_uri varchar2, p_user_name varchar2, p_password varchar2) return clob as l_request utl_http.req; l_response utl_http.resp; l_buffer varchar2(32767); l_clob clob; begin dbms_lob.createtemporary(l_clob,false); utl_http.set_detailed_excp_support(true); utl_http.set_wallet('file:/etc/ORACLE/WALLETS/oracle', 'oracle007'); l_request := utl_http.begin_request(p_uri, 'GET', 'HTTP/1.1'); if ( p_user_name is not null and p_password is not null ) then utl_http.set_authentication(l_request, p_user_name, p_password); end if; utl_http.set_header(l_request, 'user-agent', 'mozilla/4.0'); l_response := utl_http.get_response(l_request); begin loop utl_http.read_text(l_response, l_buffer, length(l_buffer)); dbms_lob.writeappend(l_clob, length(l_buffer), l_buffer); end loop; exception when utl_http.end_of_body then utl_http.end_response(l_response); end; return l_clob; end get_web_request; function post_web_request(p_uri varchar2, p_post_body varchar2, p_user_name varchar2, p_password varchar2) return clob as l_request utl_http.req; l_response utl_http.resp; l_buffer varchar2(32767); l_clob clob; begin dbms_lob.createtemporary(l_clob,false); utl_http.set_detailed_excp_support(true); utl_http.set_wallet('file:/etc/ORACLE/WALLETS/oracle', 'oracle007'); utl_http.set_transfer_timeout(600); l_request := utl_http.begin_request(p_uri, 'POST', 'HTTP/1.1'); if ( p_user_name is not null and p_password is not null ) then utl_http.set_authentication(l_request, p_user_name, p_password); end if; utl_http.set_header(l_request, 'user-agent', 'mozilla/4.0'); utl_http.set_header(l_request, 'Content-Type', 'text/xml'); utl_http.set_header(l_request, 'Content-Length', length(p_post_body)); utl_http.write_text(l_request, p_post_body); l_response := utl_http.get_response(l_request); begin loop utl_http.read_text(l_response, l_buffer, length(l_buffer)); dbms_lob.writeappend(l_clob, length(l_buffer), l_buffer); end loop; exception when utl_http.end_of_body then utl_http.end_response(l_response); end; return l_clob; end post_web_request; function get_people_data(p_uri varchar2, p_post_body varchar2, p_user_name varchar2, p_password varchar2) return people pipelined as l_clob clob; begin l_clob := post_web_request(p_uri, p_post_body, p_user_name, p_password); for i in ( with xdata as ( select xmltype(l_clob) as data from dual ) SELECT t.* FROM xdata, XMLTABLE(xmlnamespaces ('urn:edu.yale/people' as "ph"), '/ph:People/ph:Person' PASSING xdata.data COLUMNS UPI VARCHAR2(30) PATH './ph:Identifiers/ph:Upi', NETID VARCHAR2(30) PATH './ph:Identifiers/ph:NetId', AFFILIATION VARCHAR2(200) PATH './ph:Identifiers/ph:Affiliation', PRIMARYAFFILIATION VARCHAR2(60) PATH './ph:Identifiers/ph:PrimaryAffiliation', LEGAL_FIRST_NAME VARCHAR2(60) PATH './ph:Names/ph:LegalName/ph:FirstName', LEGAL_LAST_NAME VARCHAR2(60) PATH './ph:Names/ph:LegalName/ph:LastName' ) t ) loop pipe row(person_type(i.UPI, i.NETID, i.AFFILIATION, i.PRIMARYAFFILIATION,i.LEGAL_FIRST_NAME, i.LEGAL_LAST_NAME)); end loop; end; end ws_consumer_pkg; select * from table(ws_consumer_pkg.get_people_data( 'https://gw-dev.its.yale.edu/soa-gateway/PeopleHub/PeopleService', '<Request> <Header> <PageNumber>1</PageNumber> <RecordsPerPage>50</RecordsPerPage> </Header> <AttributeFilter> <Contact>Y</Contact> <Demographic>Y</Demographic> <Position>Y</Position> <Appointment>Y</Appointment> <Enrollment>Y</Enrollment> <Organization>Y</Organization> <Status>Y</Status> </AttributeFilter> <!--<PopulationFilter> <Operator>AND</Operator> <Primary_EDU_Person_Affiliation cmp="IN">EMPLOYEE</Primary_EDU_Person_Affiliation> <Department_Code cmp="in">HPC111,HPC222</Department_Code> <Planning_Unit_Code cmp="in">HPCC4003,HPCC4001</Planning_Unit_Code> </PopulationFilter>--> </Request>','s_ph_ybt_fin','xxxxxxxxx' ) ) select * from table(ws_consumer_pkg.get_people_data( 'https://gw-dev.its.yale.edu/soa-gateway/PeopleHub/PeopleService', '<Request> <Header> <PageNumber>1</PageNumber> <RecordsPerPage>50</RecordsPerPage> </Header> <AttributeFilter> <Contact>Y</Contact> <Demographic>Y</Demographic> <Position>Y</Position> <Appointment>Y</Appointment> <Enrollment>Y</Enrollment> <Organization>Y</Organization> <Status>Y</Status> </AttributeFilter> <!--<PopulationFilter> <Operator>AND</Operator> <Primary_EDU_Person_Affiliation cmp="IN">EMPLOYEE</Primary_EDU_Person_Affiliation> <Department_Code cmp="in">HPC111,HPC222</Department_Code> <Planning_Unit_Code cmp="in">HPCC4003,HPCC4001</Planning_Unit_Code> </PopulationFilter>--> </Request>','s_ph_ybt_fin','xxxxxxxxxx' ) ) where Upi='10000051'
MS SQL
People Service Expand source
using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Collections; using System.Globalization; using Microsoft.SqlServer.Server; using System.Net; using System.Text; using System.IO; public partial class UserDefinedFunctions { public static SqlXml ConvertString2SqlXml(string xmlData) { UTF8Encoding encoding = new UTF8Encoding(); MemoryStream m = new MemoryStream(encoding.GetBytes(xmlData)); return new SqlXml(m); } [return: SqlFacet(MaxSize = -1)] [Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.Read)] public static SqlXml PostWebRequest(SqlString uri, SqlString postData, SqlString username, SqlString password) { SqlString document = null; byte[] postBytes = Encoding.UTF8.GetBytes(Convert.ToString(postData)); WebRequest request = null; WebResponse response = null; Stream datastream = null; StreamReader reader = null; try { request = WebRequest.Create(Convert.ToString(uri)); if (Convert.ToString(username) != null && Convert.ToString(password) != null) { request.Credentials = new NetworkCredential(Convert.ToString(username), Convert.ToString(password)); } ((HttpWebRequest)request).UserAgent = "CLR web client on SQL Server"; request.Method = "POST"; request.ContentType = "text/xml"; Stream requestStream = request.GetRequestStream(); requestStream.Write(postBytes, 0, postBytes.Length); requestStream.Close(); response = request.GetResponse(); datastream = response.GetResponseStream(); reader = new StreamReader(datastream); document = (SqlString)reader.ReadToEnd(); reader.Close(); datastream.Close(); response.Close(); } finally { reader.Close(); datastream.Close(); response.Close(); } return (ConvertString2SqlXml(document.ToString())); } [return: SqlFacet(MaxSize = -1)] [Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.Read)] public static SqlXml GetWebRequest(SqlString uri, SqlString username, SqlString password) { SqlString document = null; WebRequest request = null; WebResponse response = null; Stream datastream = null; StreamReader reader = null; try { request = WebRequest.Create(Convert.ToString(uri)); if (Convert.ToString(username) != null && Convert.ToString(password) != null) { request.Credentials = new NetworkCredential(Convert.ToString(username), Convert.ToString(password)); } ((HttpWebRequest)request).UserAgent = "CLR web client on SQL Server"; response = request.GetResponse(); datastream = response.GetResponseStream(); reader = new StreamReader(datastream); document = (SqlString)reader.ReadToEnd(); reader.Close(); datastream.Close(); response.Close(); } finally { reader.Close(); datastream.Close(); response.Close(); } return (ConvertString2SqlXml(document.ToString())); } }
People Service Expand source
create ASSEMBLY WsConsumer FROM0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C01030035FF08580000000000000000E00002210B010B00000E000000060000000000006E2C0000002000000040000000000010002000000002000004000000000000000600000000000000008000000002000000000000030060850000100000100000000010000010000000000000100000000000000000000000182C00005300000000400000B002000000000000000000000000000000000000006000000C000000E02A00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000740C000000200000000E000000020000000000000000000000000000200000602E72737263000000B0020000004000000004000000100000000000000000000000000000400000402E72656C6F6300000C0000000060000000020000001400000000000000000000000000004000004200000000000000000000000000000000502C0000000000004800000002000500E4220000FC0700000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000133002001F0000000100001100730500000A0A06026F0600000A730700000A0B07730800000A0C2B00082A001B3004003C010000020000110014280A00000A0A280B00000A038C03000001280C00000A6F0600000A0B140C140D14130414130500028C03000001280C00000A280D00000A0C048C03000001280C00000A2C10058C03000001280C00000A14FE012B011700130811082D240008048C03000001280C00000A058C03000001280C00000A730E00000A6F0F00000A000008741200000172010000706F1000000A0008723B0000706F1100000A000872450000706F1200000A00086F1300000A130611060716078E696F1400000A0011066F1500000A00086F1600000A0D096F1700000A13041104731800000A130511056F1900000A280A00000A0A11056F1A00000A0011046F1500000A00096F1B00000A0000DE1A0011056F1A00000A0011046F1500000A00096F1B00000A0000DC001200FE16030000016F1C00000A280100000613072B0011072A0110000002002800E008011A000000001B300300EC000000030000110014280A00000A0A140B140C140D14130400028C03000001280C00000A280D00000A0B038C03000001280C00000A2C10048C03000001280C00000A14FE012B011700130611062D240007038C03000001280C00000A048C03000001280C00000A730E00000A6F0F00000A000007741200000172010000706F1000000A00076F1600000A0C086F1700000A0D09731800000A130411046F1900000A280A00000A0A11046F1A00000A00096F1500000A00086F1B00000A0000DE190011046F1A00000A00096F1500000A00086F1B00000A0000DC001200FE16030000016F1C00000A280100000613052B0011052A0110000002001100A8B90019000000001E02281D00000A2A42534A4201000100000000000C00000076342E302E33303331390000000005006C0000008C020000237E0000F80200001403000023537472696E6773000000000C060000580000002355530064060000100000002347554944000000740600008801000023426C6F620000000000000002000001471502000900000000FA253300160000010000001500000002000000040000000A0000001D0000000700000003000000010000000300000000000A0001000000000006003E0037000A00660051000A00820051000A00D200B70006001601030117002A0100000600590139010600790139010600AE01A2010600BB01A2010600D701CD010600E401CD010A00EB01B7000600150237000E00310226020E00430226020E00550226020E00720226020E00C70226020600F102CD010600FE02CD010000000001000000000001000100010010001900000005000100010050200000000096006D000A0001007C200000000096008C0010000200D4210000000096009B001D000700DC22000000008618A90028000B0000000100AF0000000000000000000100E40000000200E80000000300F10000000400FA0000000000000000000100E40000000200F10000000300FA002100A90028002900A9003F003900A90045004100A90028004900A90028005100C4014A005900A90050001100A90056006900A900280019000002F60051000C02FC0071001D02010179003C0206018100A9000C0179006202120191008102180179008F02180179009A0218017900AA021D016100BB0222016100C10228007900D3022A019900DF021D01A100A9005600A90009032F01A900C10228009900C102280009001D022F010900A90028002E00130057012E001B0060012E002300690140004B00650044000B002C0060004B006500E4000B002C005C00330147010480000000000000000000000000000000009701000004000000000000000000000001002E00000000000400000000000000000000000100450000000000040000000000000000000000010037000000000000000000003C4D6F64756C653E005753436F6E73756D65722E646C6C0055736572446566696E656446756E6374696F6E73006D73636F726C69620053797374656D004F626A6563740053797374656D2E446174610053797374656D2E446174612E53716C54797065730053716C586D6C00436F6E76657274537472696E673253716C586D6C0053716C537472696E6700506F7374576562526571756573740047657457656252657175657374002E63746F7200786D6C44617461004D6963726F736F66742E53716C5365727665722E5365727665720053716C46616365744174747269627574650075726900706F73744461746100757365726E616D650070617373776F72640053797374656D2E446961676E6F73746963730044656275676761626C6541747472696275746500446562756767696E674D6F6465730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465005753436F6E73756D65720053797374656D2E546578740055544638456E636F64696E6700456E636F64696E670047657442797465730053797374656D2E494F004D656D6F727953747265616D0053747265616D0053716C46756E6374696F6E417474726962757465006F705F496D706C69636974006765745F5554463800436F6E7665727400546F537472696E670053797374656D2E4E6574005765625265717565737400437265617465004E6574776F726B43726564656E7469616C004943726564656E7469616C73007365745F43726564656E7469616C73004874747057656252657175657374007365745F557365724167656E74007365745F4D6574686F64007365745F436F6E74656E7454797065004765745265717565737453747265616D00577269746500436C6F736500576562526573706F6E736500476574526573706F6E736500476574526573706F6E736553747265616D0053747265616D52656164657200546578745265616465720052656164546F456E640000003943004C0052002000770065006200200063006C00690065006E00740020006F006E002000530051004C002000530065007200760065007200000950004F0053005400001174006500780074002F0078006D006C000000D6A73C8775060A4AABEB2834E0764D5A0008B77A5C561934E08905000112090E0C00041209110D110D110D110D0A00031209110D110D110D0320000112010001005408074D617853697A65FFFFFFFF05200101111904200101080520011D050E052001011D050520010112310807031225122D1209808F010001005455794D6963726F736F66742E53716C5365727665722E5365727665722E446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D342E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038390A4461746141636365737301000000050001110D0E04000012290400010E1C050001123D0E052002010E0E052001011245042001010E0420001231072003011D050808042000124D0320000E130709110D1D05123D124D1231125112311209020F0707110D123D124D123112511209020801000701000000000801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F7773010000000035FF085800000000020000001C010000FC2A0000FC0C00005253445377463E1FA28E45489C09260F74A2533404000000633A5C565350726F6A656374735C5753436F6E73756D65725C5753436F6E73756D65725C6F626A5C44656275675C5753436F6E73756D65722E7064620000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000402C000000000000000000005E2C0000002000000000000000000000000000000000000000000000502C000000000000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001800008000000000000000000000000000000100010000003000008000000000000000000000000000000100000000004800000058400000540200000000000000000000540234000000560053005F00560045005200530049004F004E005F0049004E0046004F0000000000BD04EFFE00000100000000000000000000000000000000003F000000000000000400000002000000000000000000000000000000440000000100560061007200460069006C00650049006E0066006F00000000002400040000005400720061006E0073006C006100740069006F006E00000000000000B004B4010000010053007400720069006E006700460069006C00650049006E0066006F0000009001000001003000300030003000300034006200300000002C0002000100460069006C0065004400650073006300720069007000740069006F006E000000000020000000300008000100460069006C006500560065007200730069006F006E000000000030002E0030002E0030002E003000000040000F00010049006E007400650072006E0061006C004E0061006D00650000005700530043006F006E00730075006D00650072002E0064006C006C00000000002800020001004C006500670061006C0043006F00700079007200690067006800740000002000000048000F0001004F0072006900670069006E0061006C00460069006C0065006E0061006D00650000005700530043006F006E00730075006D00650072002E0064006C006C0000000000340008000100500072006F006400750063007400560065007200730069006F006E00000030002E0030002E0030002E003000000038000800010041007300730065006D0062006C0079002000560065007200730069006F006E00000030002E0030002E0030002E003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000703C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 WITH PERMISSION_SET=EXTERNAL_ACCESS; GO create FUNCTION dbo.fn_get_webrequest( @uri nvarchar(max), @user nvarchar(255)=NULL, @passwd nvarchar(255)=NULL ) RETURNS xml AS EXTERNAL NAME WsConsumer.UserDefinedFunctions.GetWebRequest; GO create FUNCTION dbo.fn_post_webrequest( @uri nvarchar(max), @postdata nvarchar(max), @user nvarchar(255)=NULL, @passwd nvarchar(255)=NULL ) RETURNS xml AS EXTERNAL NAME WsConsumer.UserDefinedFunctions.PostWebRequest; GO CREATE FUNCTION [dbo].[PeopleHubService](@puri nvarchar(max), @PostData nvarchar(max), @pusername nvarchar(60), @ppassword nvarchar(60)) RETURNS @returnPeopleInformation TABLE ( Upi nvarchar(20), NetId nvarchar(10), Affiliation nvarchar(100), PrimaryAffiliation nvarchar(50) NULL, LegalFirstName nvarchar(50) NULL, LegalLastName nvarchar(50) NULL ) AS -- Returns the first name, last name, job title, and contact type for the specified contact. BEGIN DECLARE @username nvarchar(60) = @pusername, --N's_ph_msgIII_its', @password nvarchar(60) = @ppassword, --xxxxxxxx', @retvar xml, @uri nvarchar(max) = @puri --N'https://gw-dev.its.yale.edu/soa-gateway/PeopleHub/PeopleService' set @retvar = dbo.fn_post_webrequest(@uri, @postdata, @username, @password) insert into @returnPeopleInformation --;WITH XMLNAMESPACES ('urn:edu.yale/people' AS ph) select a.b.value('(./*:Identifiers/*:Upi)[1]','nvarchar(100)') as Upi ,a.b.value('(./*:Identifiers/*:NetId)[1]','nvarchar(100)') as NetId ,a.b.value('(./*:Affiliations/*:Affiliation)[1]','nvarchar(100)') as Affiliation ,a.b.value('(./*:Affiliations/*:PrimaryAffiliation)[1]', 'nvarchar(100)') as PrimaryAffiliation ,a.b.value('(./*:Names/*:LegalName/*:FirstName)[1]', 'nvarchar(100)') as LegalFirstName ,a.b.value('(./*:Names/*:LegalName/*:LastName)[1]', 'nvarchar(100)') as LegalLastName from @retvar.nodes('(/*:People/*:Person)') as a(b) return END: GO declare @uri nvarchar(max) = N'https://gw-dev.its.yale.edu/soa-gateway/PeopleHub/PeopleService', @postdata nvarchar(max) = N'<Request> <Header> <PageNumber>2</PageNumber> <RecordsPerPage>100</RecordsPerPage> </Header> <AttributeFilter> <Contact>Y</Contact> <Demographic>Y</Demographic> <Position>Y</Position> <Appointment>Y</Appointment> <Enrollment>Y</Enrollment> <Organization>Y</Organization> <Status>Y</Status> </AttributeFilter> <PopulationFilter> <Operator>AND</Operator> <Primary_EDU_Person_Affiliation cmp="IN">EMPLOYEE</Primary_EDU_Person_Affiliation> <!--<Department_Code cmp="in">HPC111,HPC222</Department_Code> <Planning_Unit_Code cmp="in">HPCC4003,HPCC4001</Planning_Unit_Code>--> </PopulationFilter> </Request>', @username nvarchar(60) = N's_ph_ybt_fin', @password nvarchar(60) = N'xxxxxxxxxx' select * from dbo.PeopleHubService(@uri, @postdata, @username, @password)
, multiple selections available,
Related content
PeopleService Connection via Database
PeopleService Connection via Database
More like this
PeopleHub Services Troubleshooting
PeopleHub Services Troubleshooting
More like this
PeopleService Connection via Talend
PeopleService Connection via Talend
More like this