Kuassi Mensah Rajkumar Irudayaraj Java Products Group Oracle Corporation.
Kuassi Mensah Java Products Group Stephen Jones Oracle University
description
Transcript of Kuassi Mensah Java Products Group Stephen Jones Oracle University
![Page 1: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/1.jpg)
![Page 2: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/2.jpg)
Kuassi MensahJava Products Group
Stephen JonesOracle University
![Page 3: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/3.jpg)
Build Your First Database Web Services
![Page 4: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/4.jpg)
Agenda
Web Services Concepts Database as Service Provider Database as Service Consumer Conclusions
![Page 5: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/5.jpg)
Traditional Web versus Web Services
Web Site
HTTP (HTML)
SOAP
RMI
FirewallWebBrowser
Applications
JSP, ServletsJSP, Servlets
EJBsEJBs
Web ServicesWeb Services
Applications
Web Services provide a way for applications to publish and invoke functionality across the internet in a language independent manner
![Page 6: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/6.jpg)
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
![Page 7: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/7.jpg)
SOAP, WSDL, UDDI Together
WSDL DocumentWSDL Document
Web Service SupplierWeb Service Supplier
4. Invoke4. Invoke
SO
AP
UDDIUDDIRepositoryRepository
1. Publish1. Publish
2. Find2. Find
3. Bind3. Bind
Web ServiceWeb ServiceConsumerConsumer
ServiceServletServlet
![Page 8: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/8.jpg)
J2EE-based Web Services
Endpoint implicitlyspecifies the type of service provided by
the server
SSBSSB
MDBMDB
oror
JavaJava
ClassClassSOAP responseper WSDL
Oracle Application Server Containers for J2EE
HTTP
HTTP
XML ParserXML ParserSOAPSOAPLibrariesLibraries
OC4JOC4JWebWeb
ServicesServicesServletServlet
DecodingDecoding
EncodingEncoding
![Page 9: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/9.jpg)
Database Web Service
Endpoint implicitlyspecifies the type of service provided by
the server
XML ParserXML ParserSOAPSOAPLibrariesLibraries
OC4JOC4JWebWeb
ServicesServicesServletServlet
DecodingDecoding
EncodingEncoding
JPubJPub
GeneratedGenerated
JavaJava
ClassesClassesSOAP response
per WSDL
HTTP
HTTP JDBC
![Page 10: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/10.jpg)
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
![Page 11: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/11.jpg)
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
![Page 12: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/12.jpg)
Database as Web Services Provider
SOAP
J2EE(Business Logic)
Oracle9iASWebServicesFramework
Web ServiceWeb ServiceClientClient Data
Data LogicSQL/QuerySQL/DML
JavaPL/SQLOracle Oracle ApplicationApplicationServer 10Server 10g
JDBC
OracleOracleDatabase 10Database 10g
![Page 13: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/13.jpg)
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"
/>
![Page 14: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/14.jpg)
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
![Page 15: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/15.jpg)
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>
![Page 16: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/16.jpg)
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>
![Page 17: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/17.jpg)
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.
![Page 18: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/18.jpg)
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!
![Page 19: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/19.jpg)
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!
![Page 20: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/20.jpg)
Building your first Query Web Services (V)
Step#6 – Compiling and Running the Client Application
Compile and run the sample client program insrc/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 Browserhttp://localhost:8888/query/query
![Page 21: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/21.jpg)
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
![Page 22: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/22.jpg)
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
![Page 23: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/23.jpg)
Agenda
Introduction – Web Services Concepts Database as Service Provider Database as Service Consumer Conclusions
![Page 24: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/24.jpg)
Database as Web Services Consumer
Oracle9iASWebServicesFramework Data
Data LogicBatch Jobs
XML
SOAP Message
Web ServiceWeb ServiceProviderProvider
Service
SQL Java
PL/SQL
WSDL
![Page 25: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/25.jpg)
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.sql SQL>conn / as sysdba SQL>@initdbws
SQL>@sqljutl.sql
– For 9i databases run initdbws9.sql SQL>conn / as sysdba SQL>@initdbws9 SQL>@sqljutl.sql
![Page 26: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/26.jpg)
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 aredone!
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
![Page 27: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/27.jpg)
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, thePL/SQL wrappers and load the appropriate files
![Page 28: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/28.jpg)
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
![Page 29: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/29.jpg)
Building your First “Database as Web Service Consumer” (IV)
Step#4 – Calling-out the Web ServiceDeclare 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; /
![Page 30: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/30.jpg)
Agenda
Introduction – Web Services Concepts Database as Service Provider Database as Service Consumer Conclusions
![Page 31: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/31.jpg)
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
![Page 32: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/32.jpg)
AQ&Q U E S T I O N SQ U E S T I O N S
A N S W E R SA N S W E R S
![Page 33: Kuassi Mensah Java Products Group Stephen Jones Oracle University](https://reader031.fdocuments.net/reader031/viewer/2022033022/568146f2550346895db42827/html5/thumbnails/33.jpg)