cancel
Showing results for 
Search instead for 
Did you mean: 

different error response body from REST API since upgrade from 5.16.3 to 5.17

spille
Champ in-the-making
Champ in-the-making
Hi,

I throw exceptions from a (groovy)scripttask when userform input in a usertask is not valid.

Since i'm running activiti 5.17 (with jetty) the error response body no longer returns jsonobjects when I throw an exception from a scripttask to a usertask.

Anybody else has this problem?

thanks in advance Smiley Happy ,

grts,

Yannick
7 REPLIES 7

jbarrez
Star Contributor
Star Contributor
Can you give an example of what was working in 5.16.3 and now isn't anymore?  The groovy script is probably the most interesting, and then which call you typically do to get that exception as json object.

spille
Champ in-the-making
Champ in-the-making
I made a simple example (see exampleprocess.bpmn20.xml)

This is the script:

if (var1 !=  'ok'){throw new Exception ('<error>correct value for var1 is: ok</error>')}

And the task is completed witht the REST API:

POST /activiti-rest/service/form/form-data

{
  "taskId" : "${taskid}",
  "properties" : [
    {
      "id" : "var1",
      "value" : "notok"
    }
  ]
}


thanks Smiley Happy

jbarrez
Star Contributor
Star Contributor
Ok, tried it here. The stacktrace was pretty clear:

<code>
rg.activiti.engine.ActivitiException: Can't find scripting engine for 'Groovy'
at org.activiti.engine.impl.scripting.ScriptingEngines.getEngineByName(ScriptingEngines.java:124)
at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:85)
at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:73)
at org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.execute(ScriptTaskActivityBehavior.java:62)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:633)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:626)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:633)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:626)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:633)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:626)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
</code>

The 5.17 does NOT ship with Groovy-all (which is needed to have the scripting engine). I don't recall why we removed it, but there would have been some thought in that. Or not, I'll follow up on that. Anyway,  add the groovy-all jar to your Jetty classpath (see http://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all/2.4.3) and you should be fine.

spille
Champ in-the-making
Champ in-the-making
Well I have the Groovy-all in my classpath.
I think my question was a little unclear. Allow me to explain it more elaborate:

The thing is that I want to create a stacktrace/exception. In this example it looks like this:

10:40:19,292 [qtp966396367-12] WARN  org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior  - Exception while executing sid-01B97437-D665-477F-B56A-BF4DF2BF5EF4 : problem evaluating script: javax.script.ScriptException: java.lang.Exception: correct value for var1 is: ok
2015-07-03 10:40:19.332:WARNSmiley Surprisedejs.ServletHandler:qtp966396367-12:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.activiti.engine.ActivitiException: problem evaluating script: javax.script.ScriptException: java.lang.Exception: correct value for var1 is: ok

This is what I actually want because I use this exception message to communicate the result of the inputvalidation to the frontend.

I used to get a JSON respons that looked like this:
{
  "statusCode" :500 ,
  "errorMessage" : "correct value for var1 is: ok'."
}

Now I still get the exception which is great, but instead of  a jsonstring I get a html blob with the stacktrace.

thanks again for all your help Smiley Happy

jbarrez
Star Contributor
Star Contributor
Ah, now I understand.

That's indeed currently not happening. I've fixed it on master: https://github.com/Activiti/Activiti/commit/2e0d0b3b23945e86e2f11f7a98540e750fdfad6e

You could work around it with the current release, by having a ControllerAdvice (in the org.activiti.rest.exceptio package) on your classpath with the method I added:

<code>
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)  // 500
  @ExceptionHandler(Exception.class)
  @ResponseBody
  public ErrorInfo handleOtherException(Exception e) {
   return new ErrorInfo("Internal server error", e);
  }
</code>

It's my hope Spring would pick up multiple advices…. but haven't tried it.

spille
Champ in-the-making
Champ in-the-making
Thanks a lot!

We will try it out and post the results here. Smiley Happy keep u posted!

spille
Champ in-the-making
Champ in-the-making
works in 5.18!

thanks again Smiley Happy