编程语言
首页 > 编程语言> > REST JAX-RS javax.ws.rs.ProcessingException:

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

作者:互联网

每当我的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");
    }

例外:

: 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$1.call(JerseyInvocation.java:667)
    at org.glassfish.jersey.client.JerseyInvocation$1.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

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

当我将客户端作为独立的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.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.13</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.13</version>
</dependency>

我也尝试按此链接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"/>

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

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

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

请建议还能做些什么.

谢谢

解决方法:

我最近碰到了这个问题.它是由一个提供旧的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>

标签:java,rest,jboss,jersey-2-0,jersey-client
来源: https://codeday.me/bug/20191005/1857191.html