简体   繁体   English

JBoss6与RestEasy客户端

[英]JBoss6 with RestEasy client

I want to consume a REST service in my web app (.war with 6.0.0.Final), and recently switched from jersey to resteasy (because of JBoss6 with REST client (jersey-client) ). 我想在我的网络应用程序中使用REST服务(.war与6.0.0.Final),最近从jersey转为resteasy(因为JBoss6带有REST客户端(jersey-client) )。

My client code is this simple example (perfectly working when called from the console): 我的客户端代码就是这个简单的例子(从控制台调用时非常有效):

ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
RegisterBuiltin.register(providerFactory);

ClientRequest request = new ClientRequest(restUrl);
request.accept(MediaType.APPLICATION_XML);

ClientResponse<MyJaxbClass> response = request.get(MyJaxbClass.class);

At the beginning I hoped that everything for RESTeasy is available in JBoss, but while accessing the method I get this error: 一开始我希望在JBoss中可以使用RESTeasy的所有东西,但是在访问该方法时我得到了这个错误:

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethod
  at java.lang.Class.getDeclaredConstructors0(Native Method)
  at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
  at java.lang.Class.getConstructor0(Class.java:2699)
  at java.lang.Class.newInstance0(Class.java:326)
  at java.lang.Class.newInstance(Class.java:308)
  at org.jboss.resteasy.client.ClientRequest.createDefaultExecutorInstance(ClientRequest.java:115)
  at org.jboss.resteasy.client.ClientRequest.getDefaultExecutor(ClientRequest.java:94)
  at org.jboss.resteasy.client.ClientRequest.<init>(ClientRequest.java:125)
  at my.own.MyRestEasyClient.members(MyRestEasyClient.java:42)

Well, not a big deal! 好吧,没什么大不了的! Although I'm wondering why the deprecated commons-httpcomponents is used, I added commons-httpclient:commons-httpclient:3.1 to my .war. 虽然我想知道为什么使用已弃用的commons-httpcomponents ,但我将commons-httpclient:commons-httpclient:3.1到我的.war中。 But the error did not disappeared. 但错误并没有消失。 I double-checked that commons-httpclient-3.1.jar is in the war. 我仔细检查了commons-httpclient-3.1.jar是否在战争中。 Then I removed commons-httpcomponents and added org.jboss.resteasy:resteasy-jaxrs:2.1.0.GA and org.jboss.resteasy:resteasy-jaxb-provider:2.1.0.GA`. 然后我删除了commons-httpcomponents and added org.jboss.resteasy:resteasy-jaxrs:2.1.0.GA and org.jboss.resteasy:resteasy-jaxb-provider:2.1.0.GA`。 To avoid (maybe I'm already in) jar-hell I used the resteasy-version which is bundled with JBoss6, but now I'm getting this error: 为了避免(也许我已经在)jar-hell我使用了与JBoss6捆绑在一起的resteasy-version,但是现在我收到了这个错误:

Caused by: java.lang.annotation.AnnotationTypeMismatchException: Incorrectly
  typed data found for annotation element public abstract
  javax.xml.bind.annotation.XmlNsForm
  org.jboss.xb.annotations.JBossXmlSchema.elementFormDefault()
  (Found data of type Ljavax/xml/bind/annotation/XmlNsForm;.QUALIFIED)

This is not really specifict but I got similar errors if I bundle jars into my .war which are already available in JBoss. 这不是真正的具体但如果我把罐子捆绑到我的.war中已经可以在JBoss中使用,我也会遇到类似的错误。 I've found ClassNotFound Exception when configuring RestEasy , but this seems not to be related to my issue. 在配置RestEasy时发现了ClassNotFound异常 ,但这似乎与我的问题没有关系。

We had the same problem a few days ago, but found this bug report that helped us https://issues.jboss.org/browse/JBAS-8841 我们几天前遇到了同样的问题,但发现了这个帮助我们的错误报告https://issues.jboss.org/browse/JBAS-8841

To fix (As mentioned in the bug report): 修复(如错误报告中所述):

I added commons-httpclient-3.1.jar in deployers/resteasy.deployer to correct the exception. 我在deployers / resteasy.deployer中添加了commons-httpclient-3.1.jar来更正异常。 Adding the jar to my webapp didn't worked 将jar添加到我的webapp无效

And this worked for us. 这对我们有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM