我们正在运行Websphere 9和openejb 4.7.2作为我们的应用程序服务器。 Websphere既托管REST服务,又调用REST服务。

我们现在想在openejb中调用和托管服务。我们从调用REST服务开始。

我想知道我们应该在类路径中包括哪个jar以便加载javax.ws.rs.client.Client?

相同的类在websphere中可以正常工作(无需任何修改),但这是我们在启动时从openejb获得的堆栈跟踪:

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


简化的代码示例:

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);
    }

最佳答案

EJB和JaxRS是两个不同的规范。 OpenEJB实现EJB规范。要使用JaxRS API进行RESTFul服务调用,您需要一个实现JaxRS规范的库。
泽西岛就是这样一个图书馆。在这里看看-

Jersey Download

您还可以考虑使用其他JaxRS实现,例如Resteasy,Restlet等,

10-08 01:32