AnsweredAssumed Answered

Error during the execution of service task

Question asked by sagarieduri on Aug 9, 2016
   I am using the activiti in my application,when i'm using the service task,it is exiting the service task before the logic inside the class is executed,in that class after the logic execution i'm setting the variable to activiti execution and using it in the next step of workflow process,as it is exiting before it throwing the exception as
     org.activiti.engine.ActivitiException: problem evaluating script: ReferenceError: "response" is not defined in <eval> at line number 1

Here is the code in my service task related class:

     class WebServiceInvocation extends JavaDelegate {
      override def execute(execution: DelegateExecution): Unit = {
      val variables = execution.getVariables
      val serviceRegistryId = variables.get(REST_ID).asInstanceOf[String].toLong
      val apiKey = variables.get(API_KEY).asInstanceOf[String]
       if (serviceRegistryId != 0L) {
      /**I am getting the error in this case,where i'm doing some logic before calling the webservice **/
      //Get required data from service registry table and invoke webServiceCall method
       retrieveDataFromServiceRegistry(execution, serviceRegistryId, apiKey)
      } else {
       /**No error..goes smoothly **/
       val restUrl = variables.get(REST_URL).asInstanceOf[String]
       val restMethod = variables.get(REST_METHOD).asInstanceOf[String].toLowerCase
       webServiceCall(restUrl, restMethod, apiKey, execution)
    private def retrieveDataFromServiceRegistry(execution: DelegateExecution, serviceRegistryId: Long, apiKey: String) = {
    ImplServiceRegistryRepository.findById(serviceRegistryId, false) map { serviceRegistry =>
      val restUrl = serviceRegistry.url
      val regex = "\\{([^}]*)\\}" // regex for curly braces
     val pattern = Pattern.compile(regex)
      val matcher = pattern.matcher(restUrl)
      val stringBuffer = new StringBuffer()
      while (matcher.find()) {
        val activitiVariable =
        val replace = execution.getVariable(activitiVariable).asInstanceOf[String]
        matcher.appendReplacement(stringBuffer, replace)
      val modifiedRestUrl = stringBuffer.toString
      val restMethod = serviceRegistry.httpRequestType.toLowerCase
      webServiceCall(modifiedRestUrl, restMethod, apiKey, execution)
    private def webServiceCall(restUrl: String, restMethod: String, apiKey: String, execution: DelegateExecution): Unit = {
    val client = new DefaultHttpClient
    restMethod match {
      case "get" => invokeGetRequest
    def invokeGetRequest= {
        val getRequest = new HttpGet(restUrl)
        getRequest.setHeader(API_KEY, apiKey)
        val response = client.execute(getRequest)
        val content = IOUtils.toString(response.getEntity.getContent)
        println("response = "+content)
        execution.setVariable("response", content)
      }catch {
        case ex: Exception => ex.printStackTrace();throw ex