måndag, mars 19, 2007

Exposing a Java Service Facade for an EJB 3.0 Entity as a Web Service

A few days ago I tried to expose a Java Service Facade for an EJB 3.0 entity as a Web Service using JDeveloper. At first, I had a problem with this, however, once I found the culprit, it was quite obvious. Here are the steps I took:

  1. Created Entity Objects - by using the Wizards in JDeveloper, this went very smooth.
  2. Created the JavaServiceFacade Exposing the Entity, no problems here either.
  3. Expose the Java Service Facade as a Web Service using the Wizards. So far so good.
  4. Configure the persistence.xml file.
Now I got a problem, I did not get the expected results back, instead I ended up with a java.lang.NullPointerException, and when browsing the log files I found:

2007-03-07 13:46:35.434 ERROR OWS-04046 Caught exception while handling request:
java.lang.NullPointerException java.lang.NullPointerException

So, what was the problem? This problem occurs when the persistance.xml file point to a datasource rather than a direct JDBC connection. Since the JavaServiceFacade class is plain J2SE class, using a datasource in the persistance.xml can be used with EJB application only. For example you can create a EJB SessionFacade and publish this as a Web Service. Once I had re-defined the persistance.xml to point to a direct JDBC connection, it worked, like:

...
<persistence-unit name="WebServicesMetaData">
<class>webservicesmetadata.Countries</class>
<properties>
<property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="toplink.jdbc.url"
value="jdbc:oracle:thin:@myHost:myPort:mySID"/>
<property name="toplink.jdbc.user" value="hr"/>
<property name="toplink.jdbc.password" value="hr_password"/>
<property name="toplink.target-database" value="Oracle"/>
<property name="toplink.logging.level" value="FINER"/>
</properties>
</persistence-unit>
...


onsdag, februari 28, 2007

Recursion in Rules

Long time since I wrote something about Rules, so, here is a small sample for using recursion in Rules. Implementing recursion in Rules is fairly easy, just assert a new fact in the action-block of a rule, that's it. By asserting a new fact to the system, the system will re-evaluate, and recursion has taken place.

Below is an example that will illustrate this, it will find and print all ancestor relationships that are the result of three parent relationships. Andy is a parent of Betty, Betty is a parent of Charlie and Charlie is a parent of Donna. Which are the resulting ancestor relationships?

Running this program will reveal the result...

ruleset main {

class Parent {
String a;
String b;
}

class Ancestor {
String a;
String b;
}

// Convert a Parent relationship to an Ancestor relationship
rule parentToAncestor {
if ( (fact Parent p) ) {
assert(new Ancestor(a: p.a, b: p.b));
}
}

// If A is parent of B and B is an Ancestor of C, then A is an Ancestor of C
rule parentAndAncestorToAncestor {
if (
(fact Parent p) &&
(fact Ancestor a) &&
p.b.equals(a.a)
) {
assert(new Ancestor(a: p.a , b: a.b));
}
}

// Printout all Ancestors relationships
rule printAncestors {
if (fact Ancestor a) {
println(a.a + " is an ancestor of " + a.b);
}
}

// Setup some parent relations...
{
assert(new Parent(a: "Andy" , b: "Betty"));
assert(new Parent(a: "Betty" , b: "Charlie"));
assert(new Parent(a: "Charlie", b: "Donna"));
}

// Evaluate the ruleset
run();
}


below is the result:

Andy is an ancestor of Donna
Betty is an ancestor of Donna
Charlie is an ancestor of Donna
Andy is an ancestor of Charlie
Betty is an ancestor of Charlie
Andy is an ancestor of Betty

fredag, februari 23, 2007

Using the JDeveloper HTTP Analyser to Trace Web Services Calls from the RDBMS

As you know, you can use the HTTP Analyser within JDeveloper to examine the network traffic of a client connecting to a Web Service. Usually one uses the HTTP Analyser from within JDeveloper, but it can also be used to track calls from a Web Services client residing within the RDBMS.

This is the approach to take to do this:

First, you start the HTTP Analyser normally by selecting View Http Analyser within JDeveloper. It then opens in its own window inside JDeveloper, run the HTTP Analyser by clicking > '(the small green button...)'.

Next, you need to tell the RDBMS Web Service client to use this instance of the HTTP Analyser as a proxy, this can be done with the following line:

sys.utl_dbws.set_http_proxy('<host>:<port>');

and here you specify the host where JDeveloper is running as the host, the port is by default 8099, so unless you know that this has been changed, use this.

Now it's time to run the call to the Web Service. The request/response packet pairs will now be listed in the HTTP Analyser. To examine the content of a request/response pair highlight it in the History tab and then click the Data tab.

The should give you further details about the exact request / response sequence taking place.


fredag, februari 16, 2007

Changed the Connection for a JDeveloper Generated PL/SQL Web Service

Have you ever been annoyed that the JDeveloper PL/SQL Wizard is not able to change the Connection? Once you have created the Web Service, the field for the Connection is not editable. At least I have.

Unfortunately doesn't the Wizard support switching the Connection. However, it is possible to do this in another way, this has not been tested to 100%, but I have used on several occasions and it seems to do the trick. So, if you want a 100% safe solution, you should re-create the Web Services. If you do not want to do that, and want to test this approach, you should ensure to have a backup of your project before progressing. Here is how you do it:


1. Close the JDeveloper project.
2. Open the file myProject\src\mypackage\MyWebService.jaxrpc
3. Edit the entry:

<value n="PT_PLSQL_CONNECTION" v="MyConnectionName"/>

and change that to your new Connection and save the file.

4. Open the Project

5. Double click on the Web Service to open the Wizard. The new connection should now appear in the dialog. Click OK, this will re-generate the service to work towards the new connection.

torsdag, februari 01, 2007

Strange ADF Problem, Timepart of a Date Lost

Today I have been working on an issue that has intrigued me for a while. One of our customer has an application (ADF BC - Struts w. JSP) that first inserts some data into an Oracle DB by creating a new row in the corresponding ViewObject, then fetches some additional data from another DB, and updates the newly created ViewObject with this data, however, this process has failed. While debugging this problem I noticed that one of the parts of the Primary Key was a Date column, and in the log files there were entries like:

oracle.jbo.RowAlreadyDeletedException: JBO-25019: Riga entit? della chiave oracle.jbo.Key[1 2006-12-27 aaa] non trovata in MyTable.

I also noticed the following a bit further down in the log:

06/12/27 12:22:31 [515] Original value :2006-12-27 12:22:28.0
06/12/27 12:22:31 [516] Target value :2006-12-27

so, it seems quite obvious why the error occurs, the only question now would be why. Now, I wanted to have the error messages in English, so I then added -Duser.lang=en_US, and restarted the Application. Obviously I expected to get the error messages in English, but instead, it worked fine. Strange... I hope to find some explanation for this...

fredag, januari 12, 2007

Fix for Bug ADF JClient bug 5642176 Available

In the OTN thread:

http://forums.oracle.com/forums/thread.jspa?threadID=297913&start=15&tstart=0


there is a discusssion about a problem related to the ADF JClient bug 5642176. The patch for this bug is now available for download on MetaLink. To download it:

1) In MetaLink, click tab "Patches & Updates"
2) Click "Simple Search"
3) Select "Search By" "Patch Number"
4) Enter the patch number: 5642176
5) Select Microsoft Win-32 bit as the Platform (the patch is still Generic)
6) Click "Go"
7) Click "View Readme" and follow instructions to install the patch.

The patch is available for JDeveloper 10.1.2.2 and 10.1.3.1. Please also refer to the MetaLink Note 406050.1 for further details.

onsdag, november 01, 2006

JDeveloper 10.1.3.1 Released

No updates in a long time... It's been busy times... Anyway, this is probably well known by now, but I add it for reference:

The new JDeveloper 10.1.3.1.0 (Build 3984) is available from OTN:
http://www.oracle.com/technology/software/products/jdev/htdocs/soft10131.html

torsdag, september 14, 2006

Hierarchical Questions Using TopLink

A colleague asked about how one can implement hierarchical questions using TopLink. There is a section in the manual describing this nicely.

The URL to the section is:
http://www.oracle.com/technology/products/ias/toplink/doc/1013/MAIN/_html/qryadv008.htm#i1134801

The following code snippet is an excerpt from it:

ReadAllQuery raq = new ReadAllQuery(Employee.class);
Expression startExpr = expressionBuilder.get("id").equal(new Integer(1));
Expression connectBy = expressionBuilder.get("managedEmployees");
Vector order = new Vector();
order.addElement(expressionBuilder.get("lastName"));
order.addElement(expressionBuilder.get("firstName"));
raq.setHierarchicalQueryClause(startExpr, connectBy, order);
Vector employees = uow.executeQuery(raq);


this will generate the following SQL:

SELECT * FROM EMPLOYEE START WITH ID=1 CONNECT BY PRIOR ID=MANAGER_ID ORDER SIBLINGS BY LAST_NAME, FIRST_NAME

onsdag, september 13, 2006

JDeveloper 10.1.3 ServiceUpdate 5 Available

A new Service Update for JDeveloper 10.1.3 is available via "Check for Updates".

Please note that this is not applicable for the JDeveloper 10.1.3.1 Developer Preview.

This is the fifth Service Update (SU5) for JDeveloper 10.1.3.0.4. It fixes some commonly-encountered critical issues. We recommend that all customers apply this Service Update. This Service Update requires that Service Update 1 has been installed. Please ensure that JDeveloper Service Update 1 is already installed before installing Service Update 5.

torsdag, augusti 24, 2006

Keep the 'home' Instance Clean

We sometimes sees people deploying applications to the default 'home' OC4J instance within the Oracle Application Server. Even though this will work, it is a better practice not deploying any Applications to this Instance, and leave this one alone. We have some internal use of this instance, and it is not ment for regular Application deployments. Therefore; please create a new OC4J instance and use this for your own Application deplyoments.