jersey
  1. jersey
  2. JERSEY-925

Exception Mapper Not Used When Exception in EntityMessageWriter

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.12
    • Fix Version/s: 2.0
    • Component/s: core
    • Labels:
      None

      Description

      Having IOException mapper
      @Provider
      public class IOExceptionExceptionMapper implements ExceptionMapper<IOException>{

      @Override
      public Response toResponse(IOException exception)

      { return Response.status(Status.ACCEPTED).build(); }

      }
      and Servlet

      @Path("MyServlet")
      public class MyServlet(){
      @GET
      @Produces(MediaType.TEXT_XML)
      @Path("writeIOExceptionUsingWriter")
      public Response writeIOExceptionUsingWriter() throws IOException

      { throw new IOException("123 exception"); }

      }
      Status.ACCEPTED is returned, as expected; But having:

      public class ReadableWritableEntity {
      private String entity;

      public ReadableWritableEntity(String entity)

      { this.entity = entity; }

      @Override
      public String toString()

      { return entity; }

      }

      @Provider
      public class EntityMessageWriter implements
      MessageBodyWriter<ReadableWritableEntity> {

      @Override
      public long getSize(ReadableWritableEntity t, Class<?> type,
      Type genericType, Annotation[] annotations, MediaType mediaType)

      { boolean writeable = isWriteable(type, genericType, annotations, mediaType); return writeable ? t.toString().length() : -1; }

      @Override
      public boolean isWriteable(Class<?> type, Type genericType,
      Annotation[] annotations, MediaType mediaType)

      { return MediaType.TEXT_XML_TYPE.isCompatible(mediaType) && ReadableWritableEntity.class.isAssignableFrom(type); }

      @Override
      public void writeTo(ReadableWritableEntity t, Class<?> type,
      Type genericType, Annotation[] annotations, MediaType mediaType,
      MultivaluedMap<String, Object> httpHeaders,
      OutputStream entityStream) throws IOException,
      WebApplicationException

      { throw new IOException("Test IOException"); }

      }

      @Path("MyServlet")
      public class MyServlet(){
      @GET
      @Produces(MediaType.TEXT_XML)
      @Path("writeIOExceptionUsingWriter")
      public Response writeIOExceptionUsingWriter() throws IOException

      { ReadableWritableEntity rwe = new ReadableWritableEntity(""); return Response.ok(rwe).build(); }

      }

      The IOExceptionExceptionMapper is not used and Status 500 is returned.

        Activity

        Hide
        Jakub Podlesak added a comment -

        Reproduced the issue. I think we should fix this in 2.0. Please let me know if you have any objections.

        Show
        Jakub Podlesak added a comment - Reproduced the issue. I think we should fix this in 2.0. Please let me know if you have any objections.
        Hide
        Jakub Podlesak added a comment -

        This is a duplicate of JERSEY-920

        Show
        Jakub Podlesak added a comment - This is a duplicate of JERSEY-920

          People

          • Assignee:
            Jakub Podlesak
            Reporter:
            jan.supol
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: