330 likes | 340 Views
Kuassi Mensah Java Products Group Stephen Jones Oracle University. Build Your First Database Web Services. Agenda. Web Services Concepts Database as Service Provider Database as Service Consumer Conclusions. Web Browser. Applications. Applications.
E N D
Kuassi Mensah Java Products Group Stephen Jones Oracle University
Agenda • Web Services Concepts • Database as Service Provider • Database as Service Consumer • Conclusions
Web Browser Applications Applications Traditional Web versus Web Services Firewall Web Site HTTP (HTML) JSP, Servlets RMI EJBs SOAP Web Services Web Services provide a way for applications to publish and invoke functionality across the internet in a language independent manner
Web Services -- The Basic Ingredients • SOAP - Simple Object Access Protocol • Transport-independent XML messaging protocol • WSDL - Web Services Definition Language • Declares in an XML document everything you need to know to use a web service • UDDI - Universal Description, Discovery, and Integration • A directory to publish and find web services
SOAP, WSDL, UDDI Together Web ServiceConsumer UDDIRepository 2. Find 3. Bind 4. Invoke 1. Publish SOAP Servlet Service WSDL Document Web Service Supplier
J2EE-based Web Services Oracle Application Server Containers for J2EE SSB MDB or Java Class OC4J Web Services Servlet HTTP Decoding Endpoint implicitly specifies the type of service provided by the server Encoding HTTP SOAP response per WSDL SOAP Libraries XML Parser
Database Web Service OC4J Web Services Servlet JPub Generated Java Classes HTTP Decoding Endpoint implicitly specifies the type of service provided by the server JDBC Encoding HTTP SOAP response per WSDL SOAP Libraries XML Parser
Using a Web Service • Static Binding • Use the WSDL to get the proxy jar http://host:port/StatelessTest?proxy.jar • Jar contains proxy class that communicates via SOAP to the server • Write client code to use the proxy • Dynamic Binding • Set up Service and Call objects at Runtime • Invoke Operations through a Generic list of input argument • Get a return value as well as a list of output values
Agenda • Web Services Concepts • Database as Service Provider • Setting Up OC4J • The Web Service Assembler • Building your First Query and DML Web Services • Build your First PL/SQL and DB-Java Web Services • Database as Service Consumer • Conclusions
Database as Web Services Provider J2EE (Business Logic) Oracle Database 10g Oracle9iAS Web Services Framework Web Service Client PL/SQL Java Oracle Application Server 10g SOAP JDBC Data Data Logic SQL/DML SQL/Query
Setting Up OC4J • Modify data-sources.xml to point to the running instance <data-source class="com.evermind.sql.DriverManagerDataSource" name="OracleDS" location="jdbc/OracleCoreDS" xa-location="jdbc/xa/OracleXADS" ejb-location="jdbc/OracleDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="scott" password="tiger" url="jdbc:oracle:thin:@<host>:<port>:<sid>" inactivity-timeout="30" />
The Web Service Assembler • Utility for creating Web Services as J2EE EAR • Uses JPublisher for generating Java code corresponding to the Web Service • Takes input from XML-based config files • Service-config.xml • Client-config.xml • Invoked as follow % java -jar wsa.jar -config config.xml
The Web Service Assembler -- Service Config file <db-port> <uri> how it is invoked </uri> <schema>scott/tiger</schema> <db-conn>jdbc:oracle:thin:@localhost:5521:sqlj</db-conn> <datasource-location>jdbc/OracleDS</datasource-location> <jpub-input> directives for JPublisher processing flags (optional) </jpub-input> … the database resource to be published as a Web Service … … </db-port>
Building your first Query Web Services • Motivations • Step#1 – Assembling your Query Web Service <output>./build/query.ear</output> <uri>/query</uri> <sql-statement> <operation> <name>getEmp</name> <statement> select ename from emp where ename=:{myname VARCHAR} </statement> </operation> </sql-statement>
Building your first Query Web Services (II) • Step#2 - Generating an ear file containing the Java wrapper % java -jar <OC4J_HOME>/webservices/lib/wsa.jar -config service-config.xml The following files will be generated • build/query.ear - the webservices application • build/src - subdirectory holding client proxy source code • build/classes - subdirectory holder client proxy .class files.
Building your first Query Web Services (III) • Step#3 – Deploy the Generated EAR to OC4J % java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://<hostname>:<port> admin <admin-password> -deploy -file build/query.ear -deploymentName query • Step#4 – Binding the Deployed Application % java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://<hostname>:<port> admin <admin-password> -bindWebApp query query-web http-web-site query At this stage, the Web Service has been deployed!
Building your first Query Web Services (IV) • Step#5 – Generating the Client Application <web-services> <web-service> <wsdl-input url="http://localhost:8888/query/query?WSDL"/> <jaxrpc-mapping-file>mapping.xml</jaxrpc-mapping-file> <source-output-dir>build/src/client</source-output-dir> <proxy-gen> <package-name> oracle.demo.db.query.stub</package-name> <output>build/classes/client</output> </proxy-gen> </web-service> </web-services> % java -jar $ORACLE_HOME/webservices/wsa.jar -config client-config.xml • Step#6 – Binding the Deployed Application % java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://<hostname>:<port> admin <admin-password> -bindWebApp query query-web http-web-site query At this stage, the Web Service has been deployed!
Building your first Query Web Services (V) • Step#6 – Compiling and Running the Client Application Compile and run the sample client program in src/client/oracle/demo/db/query/QueryClient.java % ant compile-client % ant run-client [java] *** Query Emp Rows by ID returns 1 rows [java] *** Query Emp Rows by ID returns <7900,JAMES> • Step#7 – Accessing the Service via Browser http://localhost:8888/query/query
Building your First PL/SQL Web Services • Step#1 – Assemble PL/SQL Web Services <plsql-package> <!-- The database package to be exposed. --> <name>Company</name> <!-- A list of methods to expose (optional). --> <method>method1</method> <method>method2</method> </plsql-package> • Step#2-7 Same as Query Web Services
Building your First DB-Java Web Services • Step#1 – Assemble DB-Java Web Services <db-java> <!-- Server-side Java class to be exposed --> <name>foo.bar.Baz</name> <!-- List of methods to be exposed (optional) --> <method>method1</method> <method>method2</method> </db-java> • Step#2-7 Same as Query Web Services
Agenda • Introduction – Web Services Concepts • Database as Service Provider • Database as Service Consumer • Conclusions
Database as Web Services Consumer Web Service Provider Oracle9iAS Web Services Framework PL/SQL SOAP Message SQL Java Data Data Logic XML Batch Jobs Service WSDL
Building your First “Database as Web Service Consumer” • Motivations • Step#1 – Setting up the Database for Call-out • For Oracle Database 10g Production: sqljutl.jar, utl_dbws_jserver.jar, as well as the SYS.UTL_DBWS packages are loaded at install time • For 10g Beta databases, run initdbws.sqlSQL>conn / as sysdba SQL>@initdbws SQL>@sqljutl.sql • For 9i databases run initdbws9.sql SQL>conn / as sysdba SQL>@initdbws9 SQL>@sqljutl.sql
Reminder -- Using a Web Service • Dynamic Binding • Set up Service and Call objects at Runtime • Invoke Operations through a Generic list of input argument • Get a return value as well as a list of output values Load the Java client in OracleJVM and you are done! • Static Binding – see Step#2 • Use the WSDL to get the proxy jar http://host:port/StatelessTest?proxy.jar • Jar contains proxy class that communicates via SOAP to the server • Write client code to use the proxy See Step#2-4
Building your First “Database as Web Service Consumer” (II) • Step#2 – Generating the required files New JPublisher options automates • The generation of the client proxy, Compiling it, JARing it, and Loading it in the database % jpub -proxywsdl= URL_of_Web_Service_WSDL -dir=genproxy -package=javacallout -user=username/password -endpoint=external_Web_Services_URL [-url=JDBC_database_URL ] JPublisher will generate the Java proxy classes, the PL/SQL wrappers and load the appropriate files
Building your First “Database as Web Service Consumer” (III) • Step#3 – Granting Privileges Run plsql_grant.sql as SYS to grant necessary privileges for SCOTT to execute the loaded client proxy SQL> conn / as sysdba SQL> @genproxy/plsql_grant.sql
Building your First “Database as Web Service Consumer” (IV) • Step#4 – Calling-out the Web Service Declare and Run the sql/run-plsql-proxy.sql script or run the PL/SQL block below SQL> conn / as sysdba SQL>SQL> set serveroutput on SQL> declare x varchar2(100); begin x:=JPUB_PLSQL_WRAPPER.sayHello('Hello from database'); dbms_output.put_line(x); end; /
Agenda • Introduction – Web Services Concepts • Database as Service Provider • Database as Service Consumer • Conclusions
Summary • The Combination of Database and Web Services allows simple but powerful applications • JPublisher simplifies and automates the process • JDeveloper will make it even simpler • More Details on the Database Web Service center http://otn.oracle.com/tech/webservices/database.html • All codes samples posted on OTN http://otn.oracle.com/sample_code/tech/java/jsp/dbwebservices.html
Q & Q U E S T I O N S A N S W E R S A