--load java for webservice
--ref: DBWS Callout Utilities User's Guide for RDBMS 10.1 or 10.2 [ID 428775.1]
--http://docs.oracle.com/cd/B19306_01/java.102/b14188/intro.htm#BHCIBFGJ
--download:http://download.oracle.com/technology/sample_code/tech/java/jsp/dbws-callout-utility-10131.zip
--to load java make sure using right java version
export PATH=$ORACLE_HOME/jdk/bin:$PATH
loadjava -u rsong/slb -r -v -f -genmissing dbwsclientws.jar dbwsclientdb11.jar
--test ref: http://www.oracle-base.com/articles/10g/utl_dbws10g.php
CREATE OR REPLACE FUNCTION add_numbers (p_int_1 IN NUMBER,
p_int_2 IN NUMBER)
RETURN NUMBER
AS
l_service RSONG.UTL_DBWS.service;
l_call RSONG.UTL_DBWS.call;
l_wsdl_url VARCHAR2(32767);
l_namespace VARCHAR2(32767);
l_service_qname RSONG.UTL_DBWS.qname;
l_port_qname RSONG.UTL_DBWS.qname;
l_operation_qname RSONG.UTL_DBWS.qname;
l_xmltype_in SYS.XMLTYPE;
l_xmltype_out SYS.XMLTYPE;
l_return NUMBER;
BEGIN
l_wsdl_url := 'http://www.oracle-base.com/webservices/server.php?wsdl';
l_namespace := 'http://www.oracle-base.com/webservices/';
l_service_qname := RSONG.UTL_DBWS.to_qname(l_namespace, 'Calculator');
l_port_qname := RSONG.UTL_DBWS.to_qname(l_namespace, 'CalculatorPort');
l_operation_qname := RSONG.UTL_DBWS.to_qname(l_namespace, 'ws_add');
l_service := RSONG.UTL_DBWS.create_service (
wsdl_document_location => URIFACTORY.getURI(l_wsdl_url),
service_name => l_service_qname);
l_call := RSONG.UTL_DBWS.create_call (
service_handle => l_service,
port_name => l_port_qname,
operation_name => l_operation_qname);
l_xmltype_in := SYS.XMLTYPE('
' || p_int_1 || '
' || p_int_2 || '
');
l_xmltype_out := RSONG.UTL_DBWS.invoke(call_Handle => l_call,
request => l_xmltype_in);
RSONG.UTL_DBWS.release_call (call_handle => l_call);
RSONG.UTL_DBWS.release_service (service_handle => l_service);
l_return := l_xmltype_out.extract('//return/text()').getNumberVal();
RETURN l_return;
END;
/
exec dbms_java.grant_permission( 'RSONG', 'SYS:java.lang.RuntimePermission', 'getClassLoader', '' );
select add_numbers(1,2) from dual;
DBAREPO1 SQL> /
select add_numbers(1,2) from dual
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.IllegalAccessException: java.lang.NoClassDefFoundError
ORA-06512: at "RSONG.UTL_DBWS", line 193
ORA-06512: at "RSONG.UTL_DBWS", line 190
ORA-06512: at "RSONG.ADD_NUMBERS", line 25
--debug
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','shutdownHooks','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','setFactory','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','accessClassInPackage.sun.util.calendar','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','getClassLoader','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','createClassLoader','');
exec dbms_java.grant_permission('RSONG','SYS:java.util.logging.LoggingPermission','control','');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxySet','write' );
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxyHost','write');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxyPort','write');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','*','read,write,resolve,connect');
-- shows true error
DBAREPO1 SQL> select add_numbers(1,2) from dual;
select add_numbers(1,2) from dual
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.IllegalAccessException: error.build.wsdl.model:
oracle.j2ee.ws.common.tools.api.WsdlValidationException: Failed to setup HTTP
Connection to URL: "http://www.oracle-base.com/webservices/server.php?wsdl",
caused by: java.security.AccessControlException. : the Permission
(java.net.SocketPermission www.oracle-base.com resolve) has not been granted to
RSONG. The PL/SQL to grant this is dbms_java.grant_permission( 'RSONG','SYS:java.net.SocketPermission', 'www.oracle-base.com', 'resolve' )
ORA-06512: at "RSONG.UTL_DBWS", line 193
ORA-06512: at "RSONG.UTL_DBWS", line 190
ORA-06512: at "RSONG.ADD_NUMBERS", line 25
exec dbms_java.grant_permission('RSONG', 'SYS:java.net.SocketPermission', '88.208.252.198:80','connect,resolve' );
DBAREPO1 SQL> select add_numbers(1,2) from dual;
select add_numbers(1,2) from dual
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.ExceptionInInitializerError
ORA-06512: at "RSONG.UTL_DBWS", line 404
ORA-06512: at "RSONG.UTL_DBWS", line 401
ORA-06512: at "RSONG.ADD_NUMBERS", line 39
--finally
exec dbms_java.grant_permission( 'RSONG', 'SYS:java.util.PropertyPermission', 'HTTPClient.socket.idleTimeout', 'write' );
DBAREPO2 SQL> select add_numbers(1,2) from dual;
ADD_NUMBERS(1,2)
----------------
3
--overall permissions
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','shutdownHooks','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','setFactory','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','accessClassInPackage.sun.util.calendar','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','getClassLoader','');
exec dbms_java.grant_permission('RSONG','SYS:java.lang.RuntimePermission','createClassLoader','');
exec dbms_java.grant_permission('RSONG','SYS:java.util.logging.LoggingPermission','control','');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxySet','write' );
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxyHost','write');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','http.proxyPort','write');
exec dbms_java.grant_permission('RSONG','SYS:java.util.PropertyPermission','*','read,write,resolve,connect');
exec dbms_java.grant_permission('RSONG', 'SYS:java.net.SocketPermission', '88.208.252.198:80','connect,resolve' );
exec dbms_java.grant_permission( 'RSONG', 'SYS:java.util.PropertyPermission', 'HTTPClient.socket.idleTimeout', 'write' );