cancel
Showing results for 
Search instead for 
Did you mean: 

Call UniversalWorklistService from CAF

Former Member
0 Kudos

<p>I'm having to resort to asking this question after having spent a couple of days trying to figure this out, looking through SDN articles and tutorials, Javadoc, etc.</p>

<p>What I am trying to do is connect to the UWL service from a CAF application service in order to use some of the UWL API calls from within another application. I've seen many other people do this from Web Dynpro, or Portal, or some other way so before people try and point me to articles for those - please don't. I'm looking for anyone who has actually got this working.</p>

<p>The basic code is as follows:</p>

<code>

Hashtable env = new Hashtable();<br>

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sapportals.portal.prt.registry.PortalRegistryFactory");<br>

Context ctx = new InitialContext(env);<br>

IUWLService uwlService = (IUWLService)ctx.lookup("/broker/services/"+IUWLService.ALIAS_KEY);<br>

</code>

<p>I have tried several ways to get this to work with the relevant jar files as dependencies but it comes down to this:<br>

<b>1.</b> Reference the UWLJWF SC from my SC and refer the ejbModule DC to "tc/kmc/bc.uwl/api".<br>

<b>2.</b> Retrieve all required jars (<em>bc.uwl.service.api_api.jar, bc.uwl.service.api_core.jar, com.sap.netweaver.bc.uwl_core.jar, com.sap.portal.runtime.application.rfcengine_api.jar, prtapi.jar, prtconnection.jar</em>) bundle into an External Library type DC and deploy with my composite application.</p>

<p>In the case of <b>1</b>: the error is <em>"<code>java.lang.NoClassDefFoundError: com/sap/netweaver/bc/uwl/IUWLService</code>"</em> which implies to me that the classloader for the server is not picking it up from somewhere yet the project builds fine in NWDS as the reference exists to UWLJWF. That particular SC is also deployed on the server, as I believe is standard.</p>

<p>In the case of <b>2</b>: the error is <em>"<code>java.lang.ClassCastException: class com.sap.netweaver.bc.uwl.core.portal.UWLPortalService:WCE_PRIVATE_CL_sap.com/com.sap.netweaver.bc.uwl[at]com.sap.engine.boot.loader.ResourceMultiParentClassLoader[at]75605aa1[at]alive incompatible with interface com.sap.netweaver.bc.uwl.IUWLService:demo.sap.com/uwltest~ear[at]com.sap.engine.boot.loader.ResourceMultiParentClassLoader[at]27a3bd7[at]alive</code>"</em> which doesn't make much sense to me except that there is some difference between the instances of the classloaders that is causing the issue.</p>

<p>If I modify the code to specifically cast:<br>

<code>UWLPortalService uwlPortalService = (UWLPortalService)ctx.lookup("/broker/services/"+IUWLService.ALIAS_KEY);</code><br>

... I get a similar class cast exception except the error is "can't cast UWLPortalService to UWLPortalService"... pretty much the same.</p>

<hr>

<p>As an alternative I've tried to connect from just a standard Java app within eclipse referencing the appropriate SAP runtime libraries and those mentioned above. Connecting to the context is much the same except to provide a port number:</p>

<code>

Hashtable env = new Hashtable();<br>

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");<br>

env.put(Context.PROVIDER_URL, "*HOST*:50004");<br>

env.put(Context.SECURITY_AUTHENTICATION,"simple");<br>

env.put(Context.SECURITY_CREDENTIALS, "**********");<br>

env.put(Context.SECURITY_PRINCIPAL, "**********");<br>

Context ctx = new InitialContext(env);<br>

</code>

<p>Using this code I can connect to the InitialContextFactory and list all bindings that exist at root level. However, if I change the initial context factory to <em>com.sapportals.portal.prt.registry.PortalRegistryFactory</em> and do a similar search or specifically try to lookup "/broker/services/UniversalWorklistService", I just get NULL.</p>

<p>So I'm not sure the port number is the same for both the factories. Has anyone tried this and can tell me what the port should be? For InitialContextFactoryImpl it appears to work with 50004 but not for the PortalRegistryFactory, although strangely no exceptions are thrown.</p>

<hr>

<p>Thanks in advance to anyone who might be able to shed some light. As I've already said, please don't just point me at snippets of code for WDJ tutorials.</p>

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Tom,

in my case I found out whats wrong. I created a web service which calls the method you mentioned.

I also added "tc/kmc/bc.uwl/api" to the dc of the ejbmodule and got the same error.

The error occurs because I forgot to add the api ALSO TO THE EAR DC. Only the ear is uploaded to the server so it is absolutely correct that the class could not be found.

Hope this helps.

Regards

xinjiang_li
Active Participant
0 Kudos

Hi,Tom,

Have you solved the problem?I have the same scenario:Calling uwl api from NON-SAP J2EE Engine.It gave the error like below:

javax.naming.NoInitialContextException: Cannot instantiate class: com.sapportals

.portal.prt.registry.PortalRegistryFactory [Root exception is java.lang.ClassNot

FoundException: com.sapportals.portal.prt.registry.PortalRegistryFactory]

Thanks in advance.

Former Member
0 Kudos

Hello,

I'm actually going to close this thread as I have come to a conclusion as to why it doesn't work.

The problem stems from the fact that I was attempting to access an instance of an object in a JVM from a separate JVM. The object in this case was stored in the JNDI accessible through one of those JVMs. At runtime when I try to retrieve an instance of the object in one JVM from another they are being loaded by completely separate classloaders and therefore are different physical instances of the same class, hence the class cast fails with the error it does.

With EJBs this obviously isn't a problem because the narrowing of a JNDI object involves remote stubs using RMI.

I think the solution in this case would be to develop a portal based application service that can access the UWL API and provide a facade for external applications to call (i.e. Web Service or some other kind of endpoint).

In your case the ClassNotFoundException is occurring because you have not got the PortalRegistryFactory in your runtime classpath. I am presuming you managed to compile the code in your IDE and must therefore have imported the relevant jar files into your build path. Make sure the same jars are packaged when you deploy the application in your non-SAP application server or runtime environment. Either way you will then run into the same problem I did of different classloaders.

Hope that explanation helps.

Best Regards,

Tom Screen

Former Member
0 Kudos

Hi Tom,

as you I try to generate a URL of a BPM task to call it directly. Therefore I followed the tutorial [How to use UWL API for NetWeaver BPM Tasks|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/16356] [original link is broken] [original link is broken] [original link is broken];

I created a J2EE/EJBModule (basis for web service), referenced the dc to "tc/kmc/bc.uwl/api" as you described as step 1.

When I test the web service in wsnavigator I also got the Error java.lang.NoClassDefFoundError: com/sap/netweaver/bc/uwl/IUWLService

Did you already got the example running? If yes, may you send me your DC to reproduce it?

Regards

xinjiang_li
Active Participant
0 Kudos

Hi,Tom,

Thanks for your reply.Sorry for replying you so late.

We had developed a webdynpro application to call uwl api,and it worked successfully.(We use WDPortalUtils class to get the IUWLService object)

Now we planed to develop a web service in NWDS to call uwl api.As you mentioned,I can develop a portal application which call uwl api and provide a facade (web service) for external applications to call (In this case we can't use WDPortalUtils but have to think another way) . Would you mind telling me how I can expose the portal application to web service?Thanks in advance.