kuassi mensah java products group stephen jones oracle university

33

Upload: mabel-lynch

Post on 03-Jan-2016

225 views

Category:

Documents


3 download

TRANSCRIPT

Kuassi MensahJava Products Group

Stephen JonesOracle University

Build Your First Database Web Services

Agenda

Web Services Concepts Database as Service Provider Database as Service Consumer Conclusions

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

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

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

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

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

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

SOAP

J2EE(Business Logic)

Oracle9iASWebServicesFramework

Web ServiceWeb ServiceClientClient Data

Data LogicSQL/QuerySQL/DML

JavaPL/SQLOracle Oracle ApplicationApplicationServer 10Server 10g

JDBC

OracleOracleDatabase 10Database 10g

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 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

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

Oracle9iASWebServicesFramework Data

Data LogicBatch Jobs

XML

SOAP Message

Web ServiceWeb ServiceProviderProvider

Service

SQL Java

PL/SQL

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.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

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

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

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 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; /

 

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

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