cancel
Showing results for 
Search instead for 
Did you mean: 

Integrate CAF into jersey and produce JSON

bernd_speckmann
Contributor
0 Kudos

Hi everybody,

I'm testing some stuff with jersey to generate JSON output. Everything seems to be fine.

Now I want to access an operation of an existing CAF application (NW 7.3) from my jersey java servlet and generate JSON... Is this possible? If yes, is there any tutorial how to access caf from my java servlet to generate JSON using jersey?

Thanks ahead

Accepted Solutions (0)

Answers (1)

Answers (1)

hofmann
Active Contributor
0 Kudos

Yes, this is possible. Did this for my blog: http://scn.sap.com/community/netweaver-gateway/blog/2012/06/27/performance-of-sap-gateway

Just take the EJB, encapsulate it into a Java object with Jersey annotations.

bernd_speckmann
Contributor
0 Kudos

Hi Tobias,

could you please give me an example how to do this?

Thanks ahead

hofmann
Active Contributor
0 Kudos

Theoretically yes, somewhere on my HD the files are still saved. Wanted to bring them to github for easy sharing, but I wanted to first make the project run on 7.3.

The actual code is really simple. As states, just create a CAF project and take the EJB created there (JNDI lookup) and expose it via Jersey in a separate Java EAR project.

bernd_speckmann
Contributor
0 Kudos

Would be great if you can share the code (files) or some snippets...

I've created a very simple CAF application service and a simple stand-alone application.

Application:

public class MyMain {

               public static void main(String[] args) throws NamingException {

                              Properties props = new Properties();

                              props.put(Context.INITIAL_CONTEXT_FACTORY,

                                 "com.sap.engine.services.jndi.InitialContextFactoryImpl");

                              props.put(Context.PROVIDER_URL, "sapsrv.comp.loc:50004");

                              props.put(Context.SECURITY_PRINCIPAL, "admin");

                              props.put(Context.SECURITY_CREDENTIALS, "adminpass"); 

                              props.put(Context.URL_PKG_PREFIXES, "com.sap.engine.services");   

                              InitialContext ctx = new InitialContext(props);

 

                              Object obj = ctx.lookup("ejb:/appName=test.comp.de/remote~ear, jarName=test.comp.de~remote~ejbmodule.jar, beanName=de.comp.test.remote.modeled.appsrv.remoteservice.remoteService, interfaceName=de.comp.test.remote.modeled.appsrv.remoteservice.remoteServiceServiceRemote");

 

                              TestEJBLocal test = (TestEJBLocal)obj;

                              System.out.println(obj);

               }

}

Starting this I get the following error message:

Exception in thread "main" javax.naming.NamingException: Error occurs while the EJB Scheme Context Factory trying to resolve an EJB with scheme ejb:/appName=test.comp.de/remote~ear, jarName=test.comp.de~remote~ejbmodule.jar, beanName=de.comp.test.remote.modeled.appsrv.remoteservice.remoteService, interfaceName=de.comp.test.remote.modeled.appsrv.remoteservice.remoteServiceServiceRemote. Check server's trace files for more details. javax.naming.NamingException: Error occurs while the EJB Object Factory trying to resolve JNDI reference Reference Class Name: EJB Reference

and

java.lang.IllegalArgumentException: interface de.comp.test.remote.modeled.appsrv.remoteservice.remoteServiceServiceRemote is not visible from class loader

Any ideas?

Thanks ahead

bernd_speckmann
Contributor
0 Kudos

Hi Tobias,

did you already publish your code on github and make the project run on 7.3?

I'm still searching after the problem described above...

Thank you

ch_loos
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Bernd,

I just posted a blog with full code samples:

http://scn.sap.com/community/bpm/blog/2013/05/08/make-your-caf-service-web-ready-by-giving-it-a-rest...

Hope this helps,

Christian