我使用的Restlet版本2.0.15MyStatusService拋出異常
我採取的是在飛行中產生潛在的巨大的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) - > calls
MyRepresentation(延伸OutputRepresentation).WRITE(OutputStream中)
指找到(如預期)的一個問題與(有意壞用於測試的原因)請求, 並想給所述客戶端的有意義的反應。所以,它拋出一個異常(它應該是一個ResourceException,或任何異常?),這是陷入
ServerAdapter.commit(HttpResponse)
,但在這之後,則不會調用在MyStatusService任何方法制成的,所以客戶端不 得到一個有意義的消息,只有500個狀態。
有沒有一種方法可以控制客戶的狀態(理想情況下提供信息性消息)?
感謝任何信息,
- 吉姆