处理 CXF JAX-RS 客户端中的异常

发布于 2025-01-05 17:11:08 字数 644 浏览 6 评论 0原文

我想在 CXF Rest 客户端中将 HTTP 状态代码转换为 Java 异常。根据 官方文档 我需要使用 ResponseExceptionMapper,但没有示例使其工作。我的理解是我需要将其注册为提供者,但是如何使用代理类型的客户端来做到这一点?我尝试了以下代码,

//create a proxy client     
locationService = JAXRSClientFactory.create(applicationURI + "/rest/", LocationService.class);

//registering my ResponseExceptionMapper
ProviderFactory.getSharedInstance().registerUserProvider(LocationResponseExceptionMapper.getInstance());

但它不起作用,因为 ProviderFactory.getSharedInstance() 返回与我的客户端使用的实例不同的 ProviderFactory 实例。

I want to convert HTTP status codes to Java Exceptions in my CXF rest client. According to the official documentation I need to use ResponseExceptionMapper, but there is no example to make it work. My understanding is that I need to register it as a provider, but how can I do that with a proxy type of client? I tried the following code

//create a proxy client     
locationService = JAXRSClientFactory.create(applicationURI + "/rest/", LocationService.class);

//registering my ResponseExceptionMapper
ProviderFactory.getSharedInstance().registerUserProvider(LocationResponseExceptionMapper.getInstance());

but it is not working, because ProviderFactory.getSharedInstance() returns a different ProviderFactory instance then the instance used by my client.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿看小鸭子会跑 2025-01-12 17:11:08

使用 此签名

//create a proxy client with specified exception mapping provider
List<Object> providers = new ArrayList<Object>();
providers.add(LocationResponseExceptionMapper.getInstance());
locationService = JAXRSClientFactory.create(applicationURI + "/rest/", LocationService.class, providers);

Supply exception mapper to proxy factory using this signature:

//create a proxy client with specified exception mapping provider
List<Object> providers = new ArrayList<Object>();
providers.add(LocationResponseExceptionMapper.getInstance());
locationService = JAXRSClientFactory.create(applicationURI + "/rest/", LocationService.class, providers);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文