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

Reply via email to