cancel
Showing results for 
Search instead for 
Did you mean: 

How to Rollback the webscript not using WebScriptException?

kasperba
Champ in-the-making
Champ in-the-making
How do I make Alfresco rollback the transaction when my DeclarativeWebscript discovers an error?

All my REST-calls return an XML (with the Freemaker Template) that has a standard format containing a status-tag. So I am not interested in the error generated when the WebScriptException is thrown.

Can I call a specific function in java or should I override the WebScriptException?
2 REPLIES 2

davidc
Star Contributor
Star Contributor
Are you aware of http://wiki.alfresco.com/wiki/Web_Scripts#Response_Status

I'm not sure exactly of your requirement, but if an exception is thrown, the transaction will roll-back.  And all exceptions are caught by the Web Script runtime and rendered as a response (with a status).

The only possible issue is how to mark rollback within javascript.  Is that your issue?

kasperba
Champ in-the-making
Champ in-the-making
I don't use javascript with Alfresco 🙂

I want to do the following handle an exception in a java class of type DeclarativeWebScript gracefull by doing the following

- catch exception
- rollback the transaction
- set a custom statuscode in the model that I return
- use the Freemaker-template for the method (no exception/error FreeMarker template)
- the FreeMaker-template returns its XML as normal with the statuscode.

@Override
   protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
      
      Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);

      Integer statuscode = Status.STATUS_INTERNAL_ERROR;

      try {
         SuperObject so = null;

         so.thisWillTriggerException();

         statuscode = Status.SUCCESS;
      }
      catch (…) {
         // Rollback transaction and use the same
         // FreeMaker-template as it would if no
         // exception was triggered.
         statuscode = Status.THIS_TOTALLY_FAILED;
      }
       
      model.put("statuscode", statuscode);
       
      return model;
   }

Is this more clear concerning what I want to do?
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.