从一个 Web 应用程序抛出 WebapplicationException 并在另一个 Web 应用程序上获取 UniformInterfaceException
我看到一个奇怪的问题。我有两个网络应用程序。其中之一是我们使用 Jersey 公开的其余 Web 服务。另一个具有 JSF 前端实现,它调用上述 Web 服务来获取详细信息。我们使用 Tomcat 作为容器。
我面临的问题是,当我调用休息Web服务时,我像这样抛出WebApplicationException
catch (CustomExceptions e) {
ResponseBuilder response = new ResponseBuilderImpl();
response.status(500);
response.entity(e.getStackTrace());
throw new WebApplicationException(e, response.build());
}
另一方面,在FE Web应用程序上,我执行以下操作:
try {
r.get(MyClass.class);
return "SUCCESS";
} catch (WebApplicationException wae) {
return "FAILURE";
} catch (UniformInterfaceException wae) {
return "FAILURE";
}
在catch块中,我期待WebApplicationException,但它抛出UniformInterfaceException,这很奇怪。此外,如果它抛出 UniformInterfaceException,它不会维护堆栈跟踪。甚至我从休息呼叫中传递的响应也丢失了。有人可以帮助我如何从其余调用中获取原始堆栈跟踪吗?
提前致谢。
I see a weird issue. I have two webapps. One for the rest webservice that we exposed using Jersey. Another has the JSF Front End implementation which calls above webservice to fetch the details. We are using Tomcat as a container.
The issue that i am facing is when i call a rest webservice, i throw WebApplicationException like this
catch (CustomExceptions e) {
ResponseBuilder response = new ResponseBuilderImpl();
response.status(500);
response.entity(e.getStackTrace());
throw new WebApplicationException(e, response.build());
}
And on the other hand on FE webapps, i do the following:
try {
r.get(MyClass.class);
return "SUCCESS";
} catch (WebApplicationException wae) {
return "FAILURE";
} catch (UniformInterfaceException wae) {
return "FAILURE";
}
Here in the catch block i was expecting the WebApplicationException but its throwing UniformInterfaceException which is weird. Also if it throws UniformInterfaceException, It does not maintain the stacktrace. Even the response that i passed in from rest call is lost. Can somebody help me how can i get the original stacktrace from the rest call?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如用户指南和api 文档,当您尝试检索一个 UniformInterfaceException 时,预期结果是按类型指定实体,但收到非 200 系列响应。 WebApplicationException 是一个方便的异常,供您在服务器端使用以在异常中嵌入自定义响应。
没有什么是“丢失”的。请记住,您正在此处发出 HTTP 请求。如果您想自己检查状态代码和响应,请使用
Alternately,假设一切都会顺利,并且仅检查异常的响应:
As specified in both the user guide and the api documentation, a UniformInterfaceException is the expected result when you attempt to retrieve a specific entity by type but receive a non-200-series response. The WebApplicationException is a convenience exception for your use on the server side to embed custom responses in an exception.
Nothing is "lost". Keep in mind you're making an HTTP request here. If you want to inspect the status code and response yourself, use
Alternately, assume everything will go well, and only check the response on exceptions:
我之前也遇到过同样的问题。我认为这是因为 Jersey
WebResource.get
方法仅抛出UniformInterfaceException
,它不在WebApplicationExcpetion
的继承层次结构中。我所做的就是放弃 Jersey 客户端 api,而是使用普通的 ApacheHttpClient。将能够在 httpResponse 内容中获得正确的堆栈跟踪。希望这有帮助。
谢谢,瑞安。我尝试了你的解决方案。很不错。
I had same issue before. I think it's because Jersey
WebResource.get
method throws onlyUniformInterfaceException
which is not in the inheritance hierarchy ofWebApplicationExcpetion
. What I did is to abandon Jersey client side api but use plainApacheHttpClient
. Will be able to get the right stacktrace in the httpResponse contents.Hope this helps.
Thanks, Ryan. I tried your solution. Very nice.