jersey
  1. jersey
  2. JERSEY-1513

EJB Exception is not propagated to the container.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0-m09
    • Fix Version/s: 2.0-rc1, 2.0
    • Component/s: core
    • Labels:
      None

      Description

      Spec says:

      If an Exception-Mapper for a EJBException or subclass
      is not included with an application then exceptions
      thrown by an EJB resource class or provider method
      MUST be unwrapped and processed as described in
      Section 3.3.4.

      But only following CONTENT is sent to a client:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head><title>GlassFish Server Open Source Edition  4.0  - Error report</title><style type="text/css">
      <!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}-->
      </style> </head>
      <body><h1>HTTP Status 500 - Internal Server Error</h1>
      <hr/><p><b>type</b> Status report</p><p><b>message</b>Internal Server Error</p>
      <p><b>description</b>The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.</p>
      <hr/><h3>GlassFish Server Open Source Edition  4.0 </h3></body>
      </html>"
      

        Issue Links

          Activity

          Hide
          Jakub Podlesak added a comment -

          Following is what Jersey currently does with EJB exceptions. Jersey is actually unwrapping the encapsulated exception
          and passing it over to the registered mappers. I.e. Jersey runtime should do exactly what is required by the spec.
          Could you please attach your test case, so that i am able to reproduce and see what is going wrong?

          public class EjbExceptionMapper implements ExceptionMapper<EJBException> {
          
              private final Providers providers;
          
              /**
               * Create new EJB exception mapper.
               *
               * @param providers JAX-RS Providers.
               */
              public EjbExceptionMapper(@Context Providers providers) {
                  this.providers = providers;
              }
          
              @Override
              public Response toResponse(EJBException exception) {
                  final Exception cause = exception.getCausedByException();
                  if (cause != null) {
                      final ExceptionMapper mapper = providers.getExceptionMapper(cause.getClass());
                      if (mapper != null) {
                          //noinspection unchecked
                          return mapper.toResponse(cause);
                      } else if (cause instanceof WebApplicationException) {
                          return ((WebApplicationException) cause).getResponse();
                      }
                  }
          
                  // Re-throw so the exception can be passed through to the
                  // servlet container
                  throw new MappableException((cause == null) ? exception : cause);
              }
          }
          
          Show
          Jakub Podlesak added a comment - Following is what Jersey currently does with EJB exceptions. Jersey is actually unwrapping the encapsulated exception and passing it over to the registered mappers. I.e. Jersey runtime should do exactly what is required by the spec. Could you please attach your test case, so that i am able to reproduce and see what is going wrong? public class EjbExceptionMapper implements ExceptionMapper<EJBException> { private final Providers providers; /** * Create new EJB exception mapper. * * @param providers JAX-RS Providers. */ public EjbExceptionMapper(@Context Providers providers) { this .providers = providers; } @Override public Response toResponse(EJBException exception) { final Exception cause = exception.getCausedByException(); if (cause != null ) { final ExceptionMapper mapper = providers.getExceptionMapper(cause.getClass()); if (mapper != null ) { //noinspection unchecked return mapper.toResponse(cause); } else if (cause instanceof WebApplicationException) { return ((WebApplicationException) cause).getResponse(); } } // Re- throw so the exception can be passed through to the // servlet container throw new MappableException((cause == null ) ? exception : cause); } }
          Hide
          jan.supol added a comment -
          @Singleton
          @Path("/sgb")
          public class SingletonRootResource {
              @Path("exception")
              @GET
              public String throwException (){
              	throw new EJBException("exception");
              }
          }
          

          That's it, no exception mapper. Spec says (3.3.4):

          Unchecked exceptions and errors that have not been mapped MUST be re-thrown and allowed to
          propagate to the underlying container.

          In Jersey 1.1, I assume it was the container who sent me response with content with "javax.ejb.EJBException" in it.

          Show
          jan.supol added a comment - @Singleton @Path( "/sgb" ) public class SingletonRootResource { @Path( "exception" ) @GET public String throwException (){ throw new EJBException( "exception" ); } } That's it, no exception mapper. Spec says (3.3.4): Unchecked exceptions and errors that have not been mapped MUST be re-thrown and allowed to propagate to the underlying container. In Jersey 1.1, I assume it was the container who sent me response with content with "javax.ejb.EJBException" in it.
          Hide
          Jakub Podlesak added a comment -

          Thanks for the test case. Then there is nothing to unwrap in this case. Updated the title to better describe the issue.

          Show
          Jakub Podlesak added a comment - Thanks for the test case. Then there is nothing to unwrap in this case. Updated the title to better describe the issue.
          Hide
          Jakub Podlesak added a comment -

          This is a duplicate of JERSEY-1613

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

          Reopening to adjust with updated way to treat exception mappers in jersey.

          Show
          Jakub Podlesak added a comment - Reopening to adjust with updated way to treat exception mappers in jersey.
          Hide
          Jakub Podlesak added a comment -

          fixed in the master branch

          Show
          Jakub Podlesak added a comment - fixed in the master branch

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 3 hours
                3h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours
                3h