从 openejb 进行 JAX-RS 2 调用?
Making JAX-RS 2 calls from openejb?
我们的应用服务器是运行Websphere 9 和openejb 4.7.2。 Websphere 既承载 REST 服务又调用 REST 服务。
我们现在想在 openejb 中调用和托管服务。我们从调用 REST 服务开始。
我想知道我们应该在 class 路径中包含什么 jar 以便我们加载 javax.ws.rs.client.Client?
相同的 class 在 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
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)
简化代码示例:
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 规范的库。
泽西岛就是这样一个图书馆。看这里 -
您可以考虑其他 JaxRS 实现,例如 Resteasy、Restlet 等,
我们的应用服务器是运行Websphere 9 和openejb 4.7.2。 Websphere 既承载 REST 服务又调用 REST 服务。
我们现在想在 openejb 中调用和托管服务。我们从调用 REST 服务开始。
我想知道我们应该在 class 路径中包含什么 jar 以便我们加载 javax.ws.rs.client.Client?
相同的 class 在 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 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)
简化代码示例:
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 规范的库。 泽西岛就是这样一个图书馆。看这里 -
您可以考虑其他 JaxRS 实现,例如 Resteasy、Restlet 等,