我正在使用Restlet版本2.0.15
我正在实现一个生成可能很大的zip文件的服务 由ReST客户端下载。在生成此文件时,可能会发生错误,以及何时发生错误 我是否愿意向客户提供有意义的错误回复。
我的设置包括:
In the main, an instance of Application is constructed, and the Component.setStatusService(StatusService) and
Application.setStatusSevice(StatusService) are invoked with MyStatusService (Extends StatusService)
and, and MyStatusService overrides:
public Representation getRepresentation(Status status, Request request, Response response) {
public Status getStatus(Throwable throwable, Request request, Response response) {
public Status getStatus(Throwable throwable, UniformResource resource) {
...
When I handle the GET request from the client, I set the entity in the response
(Response.setEntity(Representation) with MyRepresentation which extends OutputRepresentation.
The MyRepresentation class overrides the method:
public void write(WritableByteChannel writableChannel)
which calls the overridden method:
public void write(OutputStream outputStream)
which does the work of generating the zip file.
当我运行它时,会发生以下情况:
ServerCall.sendRespo nse(响应)调用 - >
ServerCall.writeResp onseBody(Representat ion,WritableChannel,OutputStream) - >呼叫
MyRepresentation(扩展OutputRepresentation).write(OutputStream)
发现问题(如预期的那样)与(故意为测试原因不合适)请求, 并希望给客户一个有意义的回应。所以它抛出一个异常(如果它是一个ResourceException,或任何异常?),它被捕获在
中ServerAdapter.commit(HttpResponse)
但在此之后,没有对MyStatusService中的任何方法进行调用,因此客户端没有 获得有意义的消息,只有500状态。
有没有办法控制状态(最好是提供信息性消息)给客户?
感谢您提供任何信息,
答案 0 :(得分:0)
这实际上是Restlet中的一个错误。问题记录在:
https://github.com/restlet/restlet-framework-java/issues/670