I accidentally posted a question to the GitHub issue list. Sorry Restlet team. I closed it. Here is my question to the mailing list…
I've come across a situation where the default behavior of the StatusService is
not kicking in. I think it probably has to do with a combination of using an
anonymous inner class and Variants but I'm not sure. Hopefully I can get a hint
or two as to a better design pattern so that I don't end up hacking a
solution...
Let's say I have a ServerResource with only one GET that returns a PDF. When it
fails I want the vanilla Restlet HTML error pages to be returned to the client
via the StatusService but the way the code is set up below the browser expects
a PDF and so the HTML error pages don't come back nor does the actual error
status code (401, 500, etc.) come back to the client whenever there is an
exception.
@Get("pdf")
public Representation getMethod() {
Representation representation = null;
representation = new OutputRepresentation(MediaType.APPLICATION_PDF) {
@Override
public void write(OutputStream os) {
try {
//Call a ClientResource that can throw a
ResourceException back to us.
//Use the returned data to write my PDF.
} catch (ResourceException e) {
setStatus(e.getStatus(), e.getMessage());
LOGGER.error(getStatus().toString()); //This shows the
error status but the client gets a 200 back with an empty application/pdf
"envelope"
} catch (IOException e) {
setStatus(Status.SERVER_ERROR_INTERNAL,
e.getMessage());
}
}
};
return representation;
}
Paul Morris, Software Developer
Northwestern Memorial Physicians Group<http://www.nmpg.com>
773.469.4330 | 312.926.6674 | [email protected]
[cid:28D3237A-4BA3-4098-9CF0-EB776799E47D]
This message and any included attachments are intended only for the addressee.
The information contained in this message is confidential and may constitute
proprietary or non-public information under international, federal, or state
laws. Unauthorized forwarding, printing, copying, distribution, or use of such
information is strictly prohibited and may be unlawful. If you are not the
addressee, please promptly delete this message and notify the sender of the
delivery error by e-mail.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3045797<<inline: OCP_JavaSE6Programmer_clr[2].png>>

