Uploaded image for project: 'Errai'
  1. Errai
  2. ERRAI-557

Errai JAX-RS Application-Exception mapping

    Details

      Description

      I'm requesting Errai to perform automatic maping of Application Exceptions across the JAX-WS service boundary. Have a quick look below:

      The service definition is like this:

      ---------------------------------------------

      @Path("blah")
      public interface BlahService {

      @POST
      @Consumes("application/json")
      @Produces("application/json")
      public MyResult fooOperation(MyRequest myRequest) throws myException;
      ---------------------------------------------

      The ServiceImpl class would look like this:

      ---------------------------------------------
      public classBlahServiceImpl implements BlahService{

      @Override
      public MyResult fooOperation(MyRequest myRequest) throws myException{
      If (happy days)

      { // Do something return new MyResult(); }

      else

      { throw new MyException("myException"); }

      }

      ---------------------------------------------

      The client would look like this

      ---------------------------------------------

      private void letsDoIt(){
      MyRequest myRequest = new MyRequest();
      try

      { blahService.call(blahCallback).fooOperation(myRequest); System.out.println("Success"); }

      catch (MyException e)

      { System.out.println("Error [" + e.getMessage() + "]"); }

      }

      final RemoteCallback<MyResult> blahCallback = new RemoteCallback<MyResult>() {
      @Override
      public void callback(MyResult myResult)

      { // Do something here with myResult System.out.println("Doing something useful with the result"); }

      };

      -------------------------------------------

      When I call "letsDoIt" from the client, The sever gets invoked correctly and the result is returned and everything is great.

      If however, I throw an exception in the Impl class, the "catch (MyException e)" code in "letsDoIt" does not get called. As far as "letsDoIt" is concerned, the operation was a success (the console even prints out "success". However, when the method completes, the underlying Erria error handling notices that an exception has occurred and proceeds to produce stack traces etc. I've tried including an errorHandler callback like this: "blahService.call(blahCallback, myErrorCallback).fooOperation(myRequest);", but this seems to aimed at more cataclysmic communication errors rather than simple application exceptions.

      After discussing things with Christian I understand some of the constraints that apply to an asynchronous solution, but I feel that if manual mapping is possible (it is), then automatic mapping should also be possible as this is largely a problem that should exist in the framework arena and not an application programmer should have to concern themselves with.

      Rather than using the "errorCallback" (reserved for nasty non-application, server-type errors), it would be really nice to somehow have the exception handled in "letsDoIt" or "blahCallback".

      I'm not an errai design guru, but an at a certain level, an application exception is just another java class that can mapped just like the expected return type already is. Maybe the errai framework just needs an indicator that the returning mapped-class is in fact an exception, then serve it up to the application client in a familiar "thrown exception" syntax?

      Anyway, thanks for your consideration,

      Mark Badorrek

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  csa Christian Sadilek
                  Reporter:
                  yagerhard Mark Badorrek
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: