[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] setStatus() vs. sendError(), custom error feedback

Greg,

thanks for your feedback. I'll first dump the (expected) error
feedback for a given REST request in our system:

$ curl -i "http://admin:admin@localhost:8984/rest?query=
HTTP/1.1 400 Bad Request
Content-Length: 53
Server: Jetty(6.1.26)

Stopped at line 1, column 1:
[XPST0003] Empty query.


The same request leads to an exception when called from a browser
(Chrome, Opera, etc):

java.lang.IllegalStateException
  at org.mortbay.servlet.GzipFilter$GzipStream.doNotGzip(GzipFilter.java:544)
  at org.mortbay.servlet.GzipFilter$GZIPResponseWrapper.noGzip(GzipFilter.java:372)
  at org.mortbay.servlet.GzipFilter$GZIPResponseWrapper.setStatus(GzipFilter.java:216)
  at org.basex.http.HTTPContext.status(HTTPContext.java:209)
  at org.basex.http.BaseXServlet.service(BaseXServlet.java:43)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  ...

This is how

a) we currently set up Jetty (the relevant line is currently commented
out in the source code):
  https://github.com/BaseXdb/basex-api/blob/master/src/main/java/org/basex/BaseXHTTP.java#L121

b) we send the status code:
  https://github.com/BaseXdb/basex-api/blob/master/src/main/java/org/basex/http/HTTPContext.java#L201

c) the .setStatus() call is triggered:
  https://github.com/BaseXdb/basex-api/blob/master/src/main/java/org/basex/http/BaseXServlet.java#L27

Do you think there's any clear mistake we've made? I'll be glad to
provide you with for more details,
Christian


> On 22 April 2012 23:34, Christian Grün <christian.gruen@xxxxxxxxx> wrote:
>> Hi all,
>>
>> in our project, we are using Jetty for various HTTP services. If
>> anything goes wrong, we are currently using the following code to set
>> the status code and send a plain error message:
>>
>>  HttpServletResponse res = ... (Jetty  response)
>>  res.setStatus(code);
>>  res.getOutputStream().write(message);
>>
>> This approach fails if we add a GzipFilter to the Jetty context. I
>> have read that sendError() should be used for all kinds of error
>> messages, but it returns a pre-formatted HTML page, while we'd prefer
>> a plain text message (as e.g. our REST services doesn't return HTML
>> by default). I assume that attaching a custom error message is the
>> correct way of dealing with the issue, but I wanted to ask if there is
>> a more convenient way you would recommend? If no, how should such
>> an error handler look like? Is it the best approach to just copy and
>> paste the original Jetty sources of sendError() and modify the
>> contents?
>>
>> Thanks for the attention,
>>
>> Christian
>> BaseX Team
>> _______________________________________________
>> jetty-dev mailing list
>> jetty-dev@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/jetty-dev
> _______________________________________________
> jetty-dev mailing list
> jetty-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jetty-dev