REST JAX-RS javax.ws.rs.ProcessingException:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27312491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:09:15  来源:igfitidea点击:

REST JAX-RS javax.ws.rs.ProcessingException:

javarestjbossjersey-2.0jersey-client

提问by user3275095

I am getting below exception whenever my REST client code makes a call to the REST service using below code: Code:

每当我的 REST 客户端代码使用以下代码调用 REST 服务时,我都会遇到异常: 代码:

public void putWatcher(Watcher watcher)
    {
        System.out.println("In REST Client putWatcher.***********");

        target = target.path(RESOURCE_WATCHERS).path(watcher.getWatcheruri());
        System.out.println(target.getUri());
        Invocation.Builder builder = target.request();
        builder.put(Entity.json(watcher));
//      Response response = target.request().put(Entity.json(watcher));
        System.out.println("Returned from REST Call");
    }

Exception:

例外:

: javax.ws.rs.ProcessingException: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family;
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
    at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:667)
    at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:664)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:664)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:424)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.put(JerseyInvocation.java:318)

Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family;
    at org.glassfish.jersey.message.internal.Statuses$StatusImpl.<init>(Statuses.java:63)
    at org.glassfish.jersey.message.internal.Statuses$StatusImpl.<init>(Statuses.java:54)
    at org.glassfish.jersey.message.internal.Statuses.from(Statuses.java:93)
    at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:323)
    at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
    ... 29 more

My REST service is deployed on Tomcat 8server and the client code is deployed on JBoss 7.2.The client application is SIP-Servlets application which also bundles REST client.

我的REST 服务部署在 Tomcat 8服务器上,客户端代码部署在 JBoss 7.2 上。客户端应用程序是 SIP-Servlets 应用程序,它也捆绑了 REST 客户端。

When I test the client as a standalone Java Application it works but when deployed on JBoss it gives the error. My POM file is:

当我将客户端作为独立的 Java 应用程序进行测试时,它可以工作,但是在 JBoss 上部署时却出现错误。 我的 POM 文件是:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
</dependency>
<!-- logging dependency -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging-api</artifactId>
    <version>1.0.4</version>
    <scope>provided</scope>
</dependency>
<!-- web j2ee dependencies -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>
<!-- sip dependencies -->
<dependency>
    <groupId>org.mobicents.servlet.sip</groupId>
    <artifactId>sip-servlets-spec</artifactId>
    <version>1.7.0.FINAL</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.13</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-common</artifactId>
    <version>2.13</version>
</dependency>
<dependency>
    <groupId>org.codehaus.Hymanson</groupId>
    <artifactId>Hymanson-mapper-asl</artifactId>
    <version>1.9.13</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-Hymanson</artifactId>
    <version>2.13</version>
</dependency>

I also try to do as suggested on this link https://github.com/gondor/openstack4j/issues/30It says to disable JAX-RS from JBOSS config standalone.xml. I am using standalone-sip.xml while starting the server so I modified that only. Removed these two lines:

我也尝试按照此链接https://github.com/gondor/openstack4j/issues/30上的建议进行操作, 它说要从 JBOSS config standalone.xml 禁用 JAX-RS。我在启动服务器时使用了 standalone-sip.xml 所以我只修改了它。删除了这两行:

<subsystem xmlns="urn:jboss:domain:jaxrs:1.0"/>
<extension module="org.jboss.as.jaxrs"/>

This also is not working. I don't know how to disable, just searched for JAX-RS and deleted those lines where I found those.

这也行不通。我不知道如何禁用,只是搜索了 JAX-RS 并删除了我找到的那些行。

In one SO post there was a suggestion to use javax.ws.rs.core.Response responeinstead of Response responsetried that also but no luck.

在一篇 SO 帖子中,有一个建议使用javax.ws.rs.core.Response respone而不是Response response尝试,但也没有运气。

One more info: the REST call itself is successful, that I can see on tomcat server.

还有一个信息:REST 调用本身是成功的,我可以在 tomcat 服务器上看到。

Please suggest what else can be done.

请建议还能做什么。

Thanks

谢谢

回答by Kristjan Veskim?e

Can you take a look at libraries catalogue of your JBoss instance and remove all implementations of JAX-WS? To me it seems they conflict with the Jersey you bundle in your WAR-file.

您能否查看 JBoss 实例的库目录并删除 JAX-WS 的所有实现?对我来说,它们似乎与您捆绑在 WAR 文件中的 Jersey 冲突。

Edit:

编辑:

Actually I guess you need to resolve JAX-WS version conflict between your server and web application. Method familyOfyou are missing in Response.Status.Familywas introduced in Java 7but is missing from Java EE 6. So find Java EE 6 compatible Jersey version or upgrade the server.

实际上,我猜您需要解决服务器和 Web 应用程序之间的 JAX-WS 版本冲突。Response.Status.Family中缺少方法familyOfJava 7中引入,但在Java EE 6 中缺少。所以找Java EE 6兼容的Jersey版本或者升级服务器。

And if later Maven will cause problems, then for the real kick, there's also

如果稍后 Maven 会引起问题,那么对于真正的踢,还有

mvn dependency:tree

and

<dependency>
...
        <exclusions>
            <exclusion>...</exclusion>

回答by user1202136

I recently bumped into this problem. It was caused by a library providing an old implementation of javax.ws.rs.core. I fixed it as follows:

我最近遇到了这个问题。这是由一个提供旧实现的库引起的javax.ws.rs.core。我将其修复如下:

    <dependency>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-jaxws</artifactId>
        <version>1.6.2</version>
        <scope>runtime</scope>
        <exclusions>
            <!-- Causes java.lang.NoSuchMethodError: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family; -->
            <exclusion>
                <groupId>javax.ws.rs</groupId>
                <artifactId>jsr311-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

回答by Feng Zhang

I encountered a similar error. "java.lang.NoSuchMethodError: javax/ws/rs/ClientErrorException.validate(Ljavax/ws/rs/core/Response;Ljavax/ws/rs/core/Response$Status$Family;"

我遇到了类似的错误。"java.lang.NoSuchMethodError: javax/ws/rs/ClientErrorException.validate(Ljavax/ws/rs/core/Response;Ljavax/ws/rs/core/Response$Status$Family;"

Root cause: web service performance tester invoke the web service using script without passing in correct request body. missing a "/" in the path url of web service call is another case.

根本原因:Web 服务性能测试人员使用脚本调用 Web 服务,但未传入正确的请求正文。在 Web 服务调用的路径 url 中缺少“/”是另一种情况。

when you see this validation error, that means some major error already happened, this noSuchMethodError is only a minor byproduct when handling the major error.

当您看到此验证错误时,表示已经发生了一些主要错误,此 noSuchMethodError 只是处理主要错误时的次要副产品。