cancel
Showing results for 
Search instead for 
Did you mean: 

Loading JDO in a web service endpoint

Former Member
0 Kudos

I have a web service endpoint (Java class exposed as a web service) I'm developing in NW04-sp9, and I'm having trouble getting access to JDO in my web service. I have an object class I'd like to persist using JDO, and I've developed them and run the build helper utility to make them persistable. I believe that this works, because I can look at the .class file in a text editor and see references to javax/jdo/spi/PersistenceCapable.

In my WSE, I try to get the default PersistenceManagerFactory doing a JNDI lookup with:

_pmf=(PersistenceManagerFactory)ctx.lookup("java:comp/env/jdo/defaultPMF");

which fails with a NamingException. Based on another forum posting, I tried:

_pmf=(PersistenceManagerFactory)ctx.lookup("deployedAdapters/jdo/defaultPMF/shareable/jdo/defaultPMF");

Which actually seems to work, but when I do this, I get a NoClassDefFoundError on javax/jdo/PersistenceManagerFactory from the web service endpoint.

I have added the com.sap.jdo application to my WSE's application-j2ee-engine.xml file, as described in the JDO chapter of the NW04 documentation.

Any clues what I'm missing?

Thanks,

- Bill

Accepted Solutions (0)

Answers (1)

Answers (1)

katarzyna_fecht
Explorer
0 Kudos

Hi Bill,

how have you deployed the affected Java class?

Is it part of a web- or an ejb application or possibly a library?

Former Member
0 Kudos

Hi, Katarzyna,

Thanks for your reply. I actually met you in Waldorf about this time last year, when I was visiting with Dieter Babutzka (whose name I have almost certainly misspelled).

I'm creating the WSE using the instructions described at http://help.sap.com/saphelp_nw04/helpdata/en/2b/a6888f335a6d48b968ffdd59a25d1b/content.htm

Since this is a web service endpoint, it is getting deployed as an EAR, but it's an EAR containing a WSAR file, instead of a WAR. It contains an application.xml, a ???-j2ee-application.xml, and a web service configuration xml file (I forget the name of the file).

What the EAR does not contain is a web.xml, which in a web application (as opposed to a web service endpoint), would tell the web container to map the JDO service to a container resource (javax.resource.cci.ConnectionFactory), nor can I find a way in Visual Admin to load the JDO service.

Any idea what I'm missing?

Thanks,

- Bill

0 Kudos

Hi Bill,

Let me give you some technical background on the JDO PMF. In order to acquire the JDO PMF and work with JDO, one has to declare a resource reference to the JDO PMF in the J2EE deployment descriptors (web.xml or ejb-jar.xml) and lookup the JDO PMF from the local environmental naming context java:comp/env. You cannot lookup the JDO PMF in the global JNDI context by means of an absolute JNDI path name. This is due to the fact that JDO is a JCA resource adapter which are all treated in this way.

When you want to use JDO in a web service endpoint, you should use a stateless session bean as endpoint. Then you have full control on the EJB components, and you can simply declare a resource reference to the JDO PMF and look it up in the setSessionContext method of the bean.

When the web service endpoint is a simple Java class, then it is much more difficult to use JDO. To my knowledge such a Java class endpoint is automatically wrapped by a generated web application having one servlet for this endpoint. Since the web application and its web.xml file are generated, you have no real access to the web.xml file. You could use a simple stateless session bean whose only purpose is to hand out a JDO PMF. The local home interface of this session bean can be looked up in the global JNDI context without requiring a ejb reference. Technically this is possible, albeit pretty much ugly.

I would recommend you to use a stateless session bean as web service endpoint. This is the best and cleanest way to enter the server.

Kind Regards,

Christian

Former Member
0 Kudos

Christian,

Thanks for the information. So, do I understand that there's no way to declare a resource reference for a web service endpoint (Java class exposed as a web service)? We would prefer not to go through the EJB container, because our application will need to do several things (notably file i/o and thread creation) which are not legal within the EJB container. Running as a web service endpoint seemed a better choice for us.

We could fall back to OpenSQL accessed through JDBC, or use your JDO PMF sesion bean solution, but surely there needs to be some way to declare a resource reference for the web service?

Do you think that was a bug or oversight? Or was it an intentional design decision?

Thanks,

- Bill

0 Kudos

Hi Bill,

I will check if it is possible to declare resource references for web services and tell you.

By the way, I have just found out that one can lookup JCA connection factories in the global JNDI context without having to declare resource references. I don't like this. In my opinion, applications should never access the global JNDI context directly, but only the local java:comp/env context.

You can find the JDO PMF at the following location in the global JNDI context:

deployedAdapters/jdo/defaultPMF/shareable/jdo/defaultPMF

I don't know when this deployedAdapters directory was introduced, but I can imagine why. Most likely, there are runtime environments like Web Dynpro or Web Services where one needs to access JCA adapters, but where resource references are not available.

Kind Regards,

Christian

Former Member
0 Kudos

>

> I will check if it is possible to declare resource

> references for web services and tell you.

>

Thanks very much

>

> By the way, I have just found out that one can lookup

> JCA connection factories in the global JNDI context

> without having to declare resource references. I

> don't like this. In my opinion, applications should

> never access the global JNDI context directly, but

> only the local java:comp/env context.

>

> You can find the JDO PMF at the following location in

> the global JNDI context:

>

> deployedAdapters/jdo/defaultPMF/shareable/jdo/default

> PMF

>

I did this (see my initial post), and I agree that it's a bad idea. I didn't have much choice, though When I did this, and I tried to cast the returned object to a PersistenceManagerFactory, I received a NoClassDefFoundError, which led me to believe that the JDO classes were not loaded into the web service container. This is what led me down the resource reference path.

>

> I don't know when this deployedAdapters directory was

> introduced, but I can imagine why. Most likely, there

> are runtime environments like Web Dynpro or Web

> Services where one needs to access JCA adapters, but

> where resource references are not available.

>

Thanks again,

- Bill