javajax-rsopenejb

Making JAX-RS 2 calls from openejb?


We are running Websphere 9 and openejb 4.7.2 as our application servers. Websphere both hosts REST services and calls REST services.

We would now like to call and host services in openejb. We are starting with calling REST services.

I wonder what jar should we include in our classpath in order for us to load javax.ws.rs.client.Client?

The same class works fine in websphere (without any modifications) but this is the stacktrace we get from openejb when started:

java.lang.NoClassDefFoundError:
Could not fully load class: my.class.RESTClientBean due to:javax.ws.rs.client.Client in classLoader:

org.apache.openejb.core.TempClassLoader@ba08782 at org.apache.xbean.finder.ClassFinder.(ClassFinder.java:136) at org.apache.xbean.finder.ClassFinder.(ClassFinder.java:127) at org.apache.openejb.config.rules.CheckCallbacks.validate(CheckCallbacks.java:85) at org.apache.openejb.config.rules.ValidationBase.validate(ValidationBase.java:50) at org.apache.openejb.config.AppValidator.validate(AppValidator.java:101) at org.apache.openejb.config.ValidateModules.deploy(ValidateModules.java:38) at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:403) at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:971) at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:832) at org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:546) at org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:591) at org.apache.openejb.assembler.classic.Assembler.getOpenEjbConfiguration(Assembler.java:459) at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:438) at org.apache.openejb.OpenEJB$Instance.(OpenEJB.java:150) at org.apache.openejb.OpenEJB$Instance.(OpenEJB.java:67) at org.apache.openejb.OpenEJB.init(OpenEJB.java:298) at org.apache.openejb.OpenEJB.init(OpenEJB.java:278) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) at java.lang.reflect.Method.invoke(Method.java:508) at org.apache.openejb.loader.OpenEJBInstance.init(OpenEJBInstance.java:36) at org.apache.openejb.core.LocalInitialContextFactory.init(LocalInitialContextFactory.java:98) at org.apache.openejb.core.LocalInitialContextFactory.init(LocalInitialContextFactory.java:62) at org.apache.openejb.core.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:46) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:695) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:324) at javax.naming.InitialContext.init(InitialContext.java:255) at javax.naming.InitialContext.(InitialContext.java:227) at my.calling.Util.init(Util.java:199)

Simplified code example:

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
...
private static void start() {
        Client client = ClientBuilder.newClient();
        Response response = client.target(URI + "abc?code=41").request().get();
        int status = response.getStatus();
        System.out.println("Status code: " + status);
    }

Solution

  • EJB and JaxRS are two different specifications. OpenEJB implements EJB spec. To make a RESTFul service call using JaxRS APIs, you would need a library that implements JaxRS specification. Jersey is one such library. Take a look here -

    Jersey Download

    There are other JaxRS implementations you could consider like Resteasy, Restlet etc.,