Title: Corporate PPT Template
1(No Transcript)
2Kuassi Mensah Java Products Group Stephen
Jones Oracle University
3Build Your First Database Web Services
4Agenda
- Web Services Concepts
- Database as Service Provider
- Database as Service Consumer
- Conclusions
5Traditional 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
6Web 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
7SOAP, WSDL, UDDI Together
Web ServiceConsumer
UDDIRepository
2. Find
4. Invoke
3. Bind
1. Publish
SOAP
Servlet
Service
WSDL Document
Web Service Supplier
8J2EE-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
HTTP
Encoding
SOAP response per WSDL
XML Parser
SOAP Libraries
9Database 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
XML Parser
SOAP Libraries
10Using a Web Service
- Static Binding
- Use the WSDL to get the proxy jar
- http//hostport/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
11Example - Stateless Java Class
ltservletgt ltservlet-namegtStateless
Java Web Servicelt/servlet-namegt
ltservlet-classgtoracle.j2ee.ws.StatelessJavaRpcWebS
ervicelt/servlet-classgt ltinit-paramgt
ltparam-namegtclass-namelt/param
-namegt ltparam-valuegtmyJavaCla
ss.classlt/param-valuegt lt/init-paramgt
ltinit-paramgt
ltparam-namegtinterface-namelt/param-namegt
ltparam-valuegtmyJavaInterface.classlt/par
am-valuegt lt/init-paramgt lt/servletgt
ltservlet-mappinggt
ltservlet-namegtStateless Java Web
Servicelt/servlet-namegt
lturl-patterngt/StatelessTestlt/url-patterngt
lt/servlet-mappinggt
Web Services servlet
Class you wrote
Methods to expose
How it is invoked
12Agenda
- 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
13Database as Web Services Provider
J2EE (Business Logic)
Oracle Database 10g
Oracle9iAS Web Services Framework
Web Service Client
Java
PL/SQL
Oracle Application Server 10g
SOAP
JDBC
Data Data Logic
SQL/DML
SQL/Query
14Setting Up OC4J
- Modify data-sources.xml to point to the running
instance - ltdata-source class"com.evermind.sql.DriverManage
rDataSource" name"OracleDS" location"jdbc/Orac
leCoreDS" xa-location"jdbc/xa/OracleXADS"
ejb-location"jdbc/OracleDS" connection-driver"
oracle.jdbc.driver.OracleDriver"
username"scott" password"tiger"
url"jdbcoraclethin_at_lthostgtltportgtltsidgt"
inactivity-timeout"30" - /gt
15The 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
16The Web Service Assembler -- Service Config file
- ltdb-portgt
- lturigt how it is invoked lt/urigt
- ltschemagtscott/tigerlt/schemagtÂ
- ltdb-conngtjdbcoraclethin_at_localhost5521sqljlt/db
-conngt - ltdatasource-locationgtjdbc/OracleDSlt/datasource-loc
ationgt - ltjpub-inputgt
- directives for JPublisher processing flags
(optional) - lt/jpub-inputgt
-
- the database resource to be published as a Web
Service  -
- lt/db-portgt
17Building your first Query Web Services
- Motivations
- Step1 Assembling your Query Web Service
- ltoutputgt./build/query.earlt/outputgtÂ
- lturigt/querylt/urigt
- ltsql-statementgt
- ltoperationgt
- ltnamegtgetEmplt/namegt
- ltstatementgt
- select ename from emp where
enamemyname VARCHAR - lt/statementgt
- lt/operationgt
- lt/sql-statementgt
18Building your first Query Web Services (II)
- Step2 - Generating an ear file containing the
Java wrapper - java -jar ltOC4J_HOMEgt/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.
19Building your first Query Web Services (III)
- Step3 Deploy the Generated EAR to OC4J
- java -jar ltOC4J_HOMEgt/j2ee/home/admin.jar
ormi//lthostnamegtltportgt admin ltadmin-passwordgt
-deploy -file build/query.ear -deploymentName
query - Step4 Binding the Deployed Application
- java -jar ltOC4J_HOMEgt/j2ee/home/admin.jar
ormi//lthostnamegtltportgt admin ltadmin-passwordgt
-bindWebApp query - query-web http-web-site query
- At this stage, the Web Service has been deployed!
20Building your first Query Web Services (IV)
- Step5 Generating the Client Application
- ltweb-servicesgt
- ltweb-servicegt
- ltwsdl-input url"http//localhost8888/que
ry/query?WSDL"/gt - ltjaxrpc-mapping-filegtmapping.xmllt/jaxrpc-m
apping-filegt - ltsource-output-dirgtbuild/src/clientlt/source-outp
ut-dirgt - ltproxy-gengt
- ltpackage-namegt oracle.demo.db.query.st
ublt/package-namegt - ltoutputgtbuild/classes/clientlt/outputgt
- lt/proxy-gengt
- lt/web-servicegt
- lt/web-servicesgt
- java -jar ORACLE_HOME/webservices/wsa.jar
- -config client-config.xml
- Step6 Binding the Deployed Application
- java -jar ltOC4J_HOMEgt/j2ee/home/admin.jar
ormi//lthostnamegtltportgt admin ltadmin-passwordgt
-bindWebApp query - query-web http-web-site query
21Building your first Query Web Services (V)
- Step6 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
lt7900,JAMESgt - Step7 Accessing the Service via Browser
- http//localhost8888/query/query
22Building your First PL/SQL Web Services
- Step1 Assemble PL/SQL Web Services
- ltplsql-packagegt
- lt!-- The database package to be exposed. --gt
- ltnamegtCompanylt/namegt
- lt!-- A list of methods to expose (optional). --gt
- ltmethodgtmethod1lt/methodgt
- ltmethodgtmethod2lt/methodgt
- lt/plsql-packagegt
- Step2-7 Same as Query Web Services
23Building your First DB-Java Web Services
- Step1 Assemble DB-Java Web Services
- ltdb-javagt
- lt!-- Server-side Java class to be exposed --gt
- ltnamegtfoo.bar.Bazlt/namegt
- lt!-- List of methods to be exposed (optional) --gt
- ltmethodgtmethod1lt/methodgt
- ltmethodgtmethod2lt/methodgt
- lt/db-javagt
-
- Step2-7 Same as Query Web Services
24Agenda
- Introduction Web Services Concepts
- Database as Service Provider
- Database as Service Consumer
- Conclusions
25Database 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
26Building your First Database as Web Service
Consumer
- Motivations
- Step1 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.sql
SQLgtconn / as sysdba SQLgt_at_initdbws - SQLgt_at_sqljutl.sql
- For 9i databases run initdbws9.sql
- SQLgtconn / as sysdba
- SQLgt_at_initdbws9
- SQLgt_at_sqljutl.sql
27Reminder -- 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 Step2
- Use the WSDL to get the proxy jar
- http//hostport/StatelessTest?proxy.jar
- Jar contains proxy class that communicates via
SOAP to the server - Write client code to use the proxy
- See Step2-4
28Building your First Database as Web Service
Consumer (II)
- Step2 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
- -dirgenproxy -packagejavacallout
- -userusername/password
- -endpointexternal_Web_Services_URL
- -urlJDBC_database_URL
- JPublisher will generate the Java proxy classes,
the - PL/SQL wrappers and load the appropriate files
29Building your First Database as Web Service
Consumer (III)
- Step3 Granting Privileges
- Run plsql_grant.sql as SYS to grant necessary
- privileges for SCOTT to execute the loaded
client - proxy
- SQLgt conn / as sysdba
- SQLgt _at_genproxy/plsql_grant.sql
30Building your First Database as Web Service
Consumer (IV)
- Step4 Calling-out the Web Service
- Declare and Run the sql/run-plsql-proxy.sql
- script or run the PL/SQL block below
- SQLgt conn / as sysdba
- SQLgtSQLgt set serveroutput on
- SQLgt declare x varchar2(100) begin
xJPUB_PLSQL_WRAPPER.sayHello('Hello from
database') dbms_output.put_line(x) end / - Â
31Agenda
- Introduction Web Services Concepts
- Database as Service Provider
- Database as Service Consumer
- Conclusions
32Summary
- 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/databas
e.html - All codes samples posted on OTN
http//otn.oracle.com/sample_code/tech/java/jsp/db
webservices.html -
33A
34(No Transcript)