本文介绍了使用 RESTEasy 抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RESTEasy 开发一个简单的 WS 客户端

I'm using RESTEasy to develop a simple WS client

所以这是我的 POM.XML

so this my POM.XML

              <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jackson-provider</artifactId>
                <version>2.2.1.GA</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
                <version>2.2.1.GA</version>
            </dependency>

这是我的测试代码

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.logging.Level;

import javax.ws.rs.core.MediaType;

import org.compiere.framework.PO;
import org.compiere.model.X_I_Order;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.Ctx;
import org.compiere.util.DB;
import org.compiere.util.Trx;
import org.jboss.resteasy.client.ClientRequest;

import ru.compiere.report.RusReportStarter;

import com.audaxis.compiere.laserloylty.util.Carte;
import com.audaxis.compiere.laserloylty.util.IOrderRequest;
import com.audaxis.compiere.laserloylty.util.OrderHeader;
import com.audaxis.compiere.laserloylty.util.OrderLine;
import com.audaxis.compiere.model.MPInstanceProxy;

    ClientRequest request = new ClientRequest("http:/MyURL"); //Error here

当我尝试创建一个新的 ClientRequest 时出现此异常

when i try to create a new ClientRequest a get this Exception

java.lang.ClassCastException: com.sun.jersey.impl.provider.RuntimeDelegateImpl cannot be cast to org.jboss.resteasy.spi.ResteasyProviderFactory
    at org.jboss.resteasy.spi.ResteasyProviderFactory.getInstance(ResteasyProviderFactory.java:351)
    at org.jboss.resteasy.client.ClientRequest.<init>(ClientRequest.java:137)
    at org.jboss.resteasy.client.ClientRequest.<init>(ClientRequest.java:132)
    at org.jboss.resteasy.client.ClientRequest.<init>(ClientRequest.java:127)
    at GetOrdersFromCardibox.getOrders(GetOrdersFromCardibox.java:109)
    at GetOrdersFromCardibox.main(GetOrdersFromCardibox.java:226)

谁能告诉我问题出在哪里?!

Can any one tell me where's the problem ?!

推荐答案

如果您查看当前版本中的 org.jboss.resteasy.client.ClientRequest,您会发现它已被弃用,并带有以下注释:

If you look at the org.jboss.resteasy.client.ClientRequest in a current version, you can see that it is deprecated with the following comment:

>

resteasy-jaxrs 中的 Resteasy 客户端框架被替换为符合 JAX-RS 2.0 的 resteasy-client 模块.

因此您应该考虑使用带有 RestEasy 作为提供程序的 Jax-RS 客户端 API.有关一些文档,请查看:http://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html/RESTEasy_Client_Framework.html#d4e2141

So you should consider to use the Jax-RS Client API with RestEasy as provider. For some documentation look at:http://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html/RESTEasy_Client_Framework.html#d4e2141

文档包含以下示例代码:

The documentation contains the following example-code:

Client client = ClientBuilder.newClient();
        ... or...
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target("http://foo.com/resource");
Response response = target.request().get();
String value = response.readEntity(String.class);
response.close();  // You should close connections!

您可能需要将依赖项更新到较新版本的 RestEasy.你可以在这里找到一些帮助:http://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html/Maven_and_RESTEasy.html

You might need to update your dependencies to a newer version of RestEasy. You can find some help here:http://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html/Maven_and_RESTEasy.html

核心库是:

   <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <version>3.0.16.Final</version>
   </dependency>
   <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-client</artifactId>
      <version>3.0.16.Final</version>
   </dependency>

这篇关于使用 RESTEasy 抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 07:06