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


1 kommentar:

  1. I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

    SvaraRadera