exception from REST controller in syncope-client

9 views
Skip to first unread message

renemulder

unread,
Dec 16, 2011, 5:13:03 AM12/16/11
to syncope-users
Hi All,

I would very much like to know to which extent any exception thrown by
Syncope Core is visible in the REST client.

For example, from the UserController i can see that the create action
can throw a number of exceptions:

public UserTO create(HttpServletResponse response,
@RequestBody UserTO userTO,
@RequestParam(value = "mandatoryRoles",
required = false) Set<Long> mandatoryRoles,
@RequestParam(value = "mandatoryResources",
required = false) Set<String> mandatoryResources)
throws SyncopeClientCompositeErrorException,
DataIntegrityViolationException, WorkflowException,
PropagationException, NotFoundException,
UnauthorizedRoleException

Are these exceptions visible at the REST client? If not, when is the
implementation of detailed exception handling planned?

Thanks,
René

Francesco Chicchiriccò

unread,
Dec 16, 2011, 5:49:58 AM12/16/11
to syncop...@googlegroups.com
Hi Rene,
as you probably know, REST does not provide a standard way to handle exceptions, so Syncope provide its own method, essentially based on HTTP headers.

Basically, any uncaught exception thrown by  REST controllers is sent to a dedicated JSP page by the following declaration in web.xml:

    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/syncopeClientError.jsp</location>
    </error-page>

If you take a look at such JSP page (see [1] for the trunk), you will see that basically some HTTP headers are generated using some classes from syncope-client.

From a REST client point of view, an exception handler is provided that parses HTTP headers and re-generates correspondent exceptions on client-side.
For this, you can take Syncope console Spring configuration [2] as reference, since console is nothing more than a REST client for Syncope core. Look at definition of bean "restTemplate".

Finally, once you've set Sycope custom error handler, you can just catch exceptions in the usual way (this example is from [3]):

        try {
            validators = restTemplate.getForObject(
                    baseURL + "task/jobClasses.json", Set.class);
        } catch (SyncopeClientCompositeErrorException e) {
            LOG.error("While getting all job classes", e);
        }

Of course you can do more with exception than just log, look at SyncopeClientCompositeErrorException [4] for more information.

Regards.

[1] http://syncope.googlecode.com/svn/trunk/core/src/main/webapp/syncopeClientError.jsp
[2] http://syncope.googlecode.com/svn/trunk/console/src/main/resources/applicationContext.xml
[3] http://syncope.googlecode.com/svn/trunk/console/src/main/java/org/syncope/console/rest/TaskRestClient.java
[4] http://syncope.googlecode.com/svn/trunk/client/src/main/java/org/syncope/client/validation/SyncopeClientCompositeErrorException.java
-- 
Francesco Chicchiriccò

"Computer Science is no more about computers than astronomy
is about telescopes." (E. W. Dijkstra)
Reply all
Reply to author
Forward
0 new messages