Hi Richard,
In fact, when the connector writes the response entity, the response status
code should already be sent on the wire as it is written in the first line
of the HTTP response.
So it seems that the only feasible thing for the connector is to end the
response (chunked encoding) or close the socket/stream/channel. Any other
idea?
Best,
Jerome
2007/8/1, Richard Wallace <[EMAIL PROTECTED]>:
>
> Hello,
>
> I'm messing around with using the SaxRepresentation and the XmlWriter to
> create a XHTML representation of my resources similar to how they're
> created in "RESTful Web Services". So, in my resource I have
>
> @Override
> public Representation getRepresentation (Variant variant) {
> Representation result = null;
> if (variant.getMediaType().equals
> (MediaType.APPLICATION_XHTML_XML)) {
> result = new SaxRepresentation
> (MediaType.APPLICATION_XHTML_XML) {
> public void write (XmlWriter writer) throws IOException {
> // serialize accounts
> try {
> writer.startDocument ();
> writer.startElement ("html");
>
> writer.endElement ("html");
> writer.endDocument ();
> } catch (SAXException e) {
> throw new IOException (e.getMessage ());
> }
> }
> };
> }
> return result;
> }
>
> I had to catch the SAXException and throw it as an IOException because
> that is all that is allowed by the API for the write() method. The
> thing is, I tried throwing a SAXException in the middle of the try
> statement, which caused the IOException to be thrown, but Restlet still
> sent a 200 to the client saying that everything was ok. If I throw the
> SAXException before endDocument() is called, nothing seems to be sent to
> the client but it gets a 200. I also tried wrapping it in a
> RuntimeException and saw the same behavior.
>
> Shouldn't the caller of the write() method try and catch exceptions and
> send a 500 to the client? It might even be better to give the write()
> method the ability to do this, since it is the one that is probably best
> suited to deciding what kind of error should be sent to the client.
>
> Rich
>