users@jersey.java.net

[Jersey] Re: How to force empty response on error

From: ManiKanta G <go4mani_at_gmail.com>
Date: Mon, 10 Sep 2012 20:09:41 +0530

Hi,

I've faced the same issue once and here is the better solution, that worked
for me.

http://stackoverflow.com/questions/794329/disable-all-default-http-error-response-content-in-tomcat/7580792#7580792



ManiKanta G
twitter.com/ManiKantaG


On Mon, Sep 10, 2012 at 8:02 PM, Pavel Bucek <pavel.bucek_at_oracle.com> wrote:

> Hello,
>
> I'm not a tomcat configuration expert, but I'm pretty sure that this is
> container related thing and it is configurable.
>
> See: http://stackoverflow.com/**questions/3856145/empty-page-**
> instead-of-custom-tomcat-**error-page<http://stackoverflow.com/questions/3856145/empty-page-instead-of-custom-tomcat-error-page>
> or look into tomcat documentation.
>
> Regards,
> Pavel
>
>
> On 8/30/12 10:13 PM, Vinicius Carvalho wrote:
>
>> Hello there! This is bugging me for a couple of hours now.
>>
>> We are running jersey 1.1.13 inside tomcat.
>>
>> We don't want to have tomcat exposing those error pages as content body
>> whenever an error happens. Even using ExceptionMappers I found out that
>> jersey uses response.sendError instead of response.setStatus at the
>> WebComponent class:
>>
>> if (cResponse.getStatus() >= 400) {
>>
>> if (useSetStatusOn404 && cResponse.getStatus() == 404) {
>>
>> response.setStatus(cResponse.**getStatus());
>>
>> } else {
>>
>> final String reason = cResponse.getStatusType().**getReasonPhrase();
>>
>> if (reason == null || reason.isEmpty()) {
>>
>> response.sendError(cResponse.**getStatus());
>>
>> } else {
>>
>> response.sendError(cResponse.**getStatus(), reason);
>>
>> }
>>
>> }
>>
>> } else {
>>
>> response.setStatus(cResponse.**getStatus());
>>
>> }
>>
>>
>> I really would like to avoid having to configure empty html pages at
>> <error> section of my web.xml. Isn't there a way to just force the Response
>> to be empty?
>>
>>
>> I "fixed" this by making this call inside my Mapper:
>>
>>
>> return Response.status(Status.NOT_**FOUND).type(MediaType.TEXT_**PLAIN).entity("
>> ").build();
>>
>>
>> But it feels so ugly to me, I really would love if:
>>
>> return Response.status(Status.NOT_**FOUND).build();
>>
>> Could just work with empty response bodies and not default to container
>> specific error pages.
>>
>>
>> Any way to fix this?
>>
>>
>> Regards
>>
>>
>>
>