isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andi Huber <ahu...@apache.org>
Subject Re: How to configure the ExceptionRecognizer in Isis + how to return different HTTP status codes
Date Thu, 16 Nov 2017 22:52:11 GMT
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
View raw message