isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Manasingarao Shitole <shit...@prime-research.com>
Subject Re: How to configure the ExceptionRecognizer in Isis + how to return different HTTP status codes
Date Fri, 17 Nov 2017 10:13:30 GMT
Hi all,


@Andi Huber<mailto:ahuber@apache.org>:  Thanks for the assistance, will try your version
as well.

Mean time, we have figured out the resolution for the issue. Here are the details with respect
to the earlier reported version.



Resolution for the first case - How to configure the ExceptionRecognizer in Isis


Step 1: Commented the below property in "isis.properties", which is no more needed and registered
the service via DomainAppAppManifest

#isis.services=com.isis.application.services.ServiceExceptionRecognizer
isis.appManifest=com.isis.application.manifest.DomainAppAppManifest


Step 2: Registered the additional service (ServiceExceptionRecognizer), by overriding getAdditionalServices
method of DomainAppAppManifest class.

@Override
public List<Class<?>> getAdditionalServices() {
return Arrays.asList(ServiceExceptionRecognizer.class);
}

Note:
Earlier this method was returning an empty list. ie return Collections.emptyList();. In effect,
this was overridden the registered isis.service (ServiceExceptionRecognizer).
And this was the root cause for not recognizing the service.

Now it works as expected! Wicket viewer shows the error message and not the stack trace for
this recoverable exception.


Resolution for the second case - how to return different HTTP status codes


Step 1: Implemented our own custom ServiceExceptionMapper for the known ServiceException of
ServiceExceptionRecognizer

Step 2:  Registered the new ExceptionMapper by extending RestfulObjectsApplication

public class RestfulObjectsApplicationV1 extends RestfulObjectsApplication {

    public RestfulObjectsApplicationV1() {
        super();
        this.addSingleton(new ServiceExceptionMapper());
    }
}

Step 3: same has been updated in web.xml


Note :

This also helps our clients (like wicket-viewer) to recognize and handle the service exception
recognizers based on HTTP status codes 400/500 with readable error messages.

No more exception stack trace is populated in the response for these recoverable exceptions.


We hope this experience and learning will help others. Thank you all!


P. S:

@Dan<mailto:dan@haywood-associates.co.uk>:

Here is the link for the document which talks about the isis.services property with respect
to isis.appManifest property and its dependency

 - Section 5.5 Services under https://isis.apache.org/guides/rgcfg/rgcfg.html#_rgcfg_configuring-core<https://isis.apache.org/guides/rgcfg/rgcfg.html#_rgcfg_configuring-core>

 - I assume, here document is correct and somewhere I have misunderstood the concept. If such
a case then my sincere apologize for the same.

 - In our case, it worked when we have both the properties (isis.services and isis.appManifest).

- I think, it worked because the Recognizer has been returned in getAdditionalServices() and
might be putting into DomainAppAppManifest package helped here.



Thank you.


Kind regards,

- Mansingh




________________________________
From: Dan Haywood <dan@haywood-associates.co.uk>
Sent: 17 November 2017 07:35:50
To: users@isis.apache.org
Subject: Re: How to configure the ExceptionRecognizer in Isis + how to return different HTTP
status codes

Hi Mansingh,

can you provide a link to any docs that you read that were misleading ...
I'd like to improve them if possible?

thx
Dan


On Thu, 16 Nov 2017 at 22:52 Andi Huber <ahuber@apache.org> wrote:

> In order for the framework to recognize classes as domain-services you
> need to
>
> (1) annotate your ServiceExceptionRecognizer class with
> @DomainService(nature = NatureOfService.DOMAIN)
>
> (2) make sure your ServiceExceptionRecognizer class resides in a Java
> package, that is scanned by the framework.
> To include Java packages for scanning, you have to register a module
> class in your DomainAppAppManifest class.
>
> public class DomainAppAppManifest implements AppManifest {
>
>     /**
>      * Load all services and entities found in (the packages and
> subpackages within) these modules
>      */
>     @Override
>     public List<Class<?>> getModules() {
>         final List<Class<?>> modules = new ArrayList<>();
>         modules.addAll(Arrays.asList(
>                 ...
>                 MyModul.class
>         ));
>         return modules;
>     }
>
> }
>
> Service scanning will be done in the package where MyModul class resides
> (and in any sub-packages recursively).
>
>
> Regards, Andi
>
> On 2017-11-16 11:48, Manasingarao Shitole <shitole@prime-research.com>
> wrote:
> > Hi all,
> >
> >
> > We would like to define our own ServiceExceptionRecognizer for
> following exceptions, ex:
> >
> > - BadRequestException : map to HTTP 400 with the validation message
> >
> > - RuntimeException : map to HTTP 500 with the appropriate message.
> >
> >
> > This will help our clients and wicket viewer as well. Instead of
> propagating entire stack trace for the expected recoverable errors.
> >
> >
> > To do that, here is the exception recognizer
> >
> >
> > public class ServiceExceptionRecognizer extends
> ExceptionRecognizerForType {
> > public ServiceExceptionRecognizer(){
> > super(Category.CLIENT_ERROR,
> ofTypeIncluding(BadRequestException.class, new String[]{"Only long comma
> separated values allowed"}), prefix("Bad Request"));
> > }
> > }
> >
> > Now the question is how to configure the same, tried setting below
> property in isis.properties but it doesn't recognize:
> >
>
> isis.services=com.isis.modules.source.dom.exception.ServiceExceptionRecognizer
> >
> > Where as Isis document says you cant put "isis.services" along with
> "isis.appManifest"
> > isis.appManifest=com.isis.application.manifest.DomainAppAppManifest
> >
> > If we remove the "isis.appManifest" then application will fail to
> bootstrap.
> >
> > Of-course I havn't understood correctly and going somewhere wrong. I
> dont find any clue in docs nor there are any examples on that.
> > Could someone guide us with examples, that will be of great help.
> >
> > Thank you in anticipation.
> >
> > Kind regards,
> > -Mansingh
> >
> >
> >
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message