An Oracle JDeveloper How To Document
Written by Susan Duncan
March, 2004
Web services allow applications to programatically access remote content and application functionality using industry-standard mechanisms, without any dependency on the provider's platform, the location, the service implementation, or the data format.
Database Web services work in two directions: database as service provider, i.e. calling from the outside in, which lets client applications access the database via Web services mechanisms; and database as service consumer, i.e. calling from the inside out, which lets a SQL query or an application module in a database session consume an external Web Service.
This How To document describes the steps to create the files necessary to consume a Java web service in the database. It gives step by step instructions for loading these files into the database and testing the call out to a web service running in Oracle Containers for Java (OC4J). It uses a very simple HelloWorld service as an example. It gives tips on testing and debugging the service.
Full details of all the features of JDeveloper discussed in this article can be found in the JDeveloper Help documentation
This is a one-off install to enable calls from the database to web services. If you have already installed SOAP Client Stack, skip this section. For detailed instructions on installing the stack see Install JAR Files In the Database
Your schema needs the correct Java 2 Permissions. See Chapter9 (Security) of the Database Java Developer's Guide for a detailed explanation. You can check whether the correct permissions already exist using the table browser (see step 4). The example in this HowTo uses the HR schema, you might set the permissions as follows.
dbms_java.grant_permission('HR','SYS:java.util.PropertyPermission','*','read,write') dbms_java.grant_permission( 'HR', 'SYS:java.lang.RuntimePermission', 'getClassLoader', '' )To disable a permission you can use dbms_java.disable_permission(164) where '164' is the Key column from the table (see above example). To permanently delete a permission first disable and then delete dbms_java.delete_permission(164)
This HowTo does not go into the detail of these steps. However, to follow this HowTo here are some tips to create and deploy a web service based on the HelloWorld Java class
public class HelloWorld { public HelloWorld() { } public String sayHello(String name) { return "Hello" + name; } }
public static String callWS(String s) { HelloWorldServiceStub stub = new HelloWorldServiceStub(); try { String result= stub.sayHello(s); return result; } catch (Exception ex) { String error = ex.toString(); return error; } }
Create a deployment profile to load the calling classes into the database
Use the context menu of your deployment profile to deploy the profile and the callWS function to your database
FUNCTION "TEST" RETURN VARCHAR2 AS mystring varchar2(2000); BEGIN mystring := HR.CALLWS(' tester'); RETURN(mystring); END;
Problem | Possible Solution |
---|---|
ORA-29541: class HR.mypackage/MyHelloStub could not be resolved
ORA-06512: at "HR.CALLWS", line 0 ORA-06512: at "HR.TEST", line 6 ORA-06512: at line 5 Process exited. Disconnecting from the database hr16179. |
SOAP stack not loaded |
|
Ensure that the OC4J instance where your web service is deployed is up and running with your web and that the stub reflects that in its endpoint
|
Check that your database schema has all necessary permissions granted. See Grant Java Permissions to HR Schema |
Although the initial release of JDeveloper 10g does not seamlessly support the creation and loading of files required to call web services from the database, it provides tools to achieve these tasks with little hand coding needed from the developer.
Further Information