cancel
Showing results for 
Search instead for 
Did you mean: 

How to extend Activiti REST now

fisher
Champ in-the-making
Champ in-the-making
There's a great post about extending Activiti REST. http://alfrescoblog.com/2014/05/24/how-to-extend-activiti-rest.  I can follow the post and deploy my own implement. But it's only working before Activiti 5.16.4.

How to extend Activiti REST now. I'm a ROR developer. So I'm not familiar with Spring and Servlet config.  Can you give me some instructions?

thx in advance.
11 REPLIES 11

fisher
Champ in-the-making
Champ in-the-making

soaguy
Champ in-the-making
Champ in-the-making
Hi folks,
            I am trying to build my own REST service to enhance some of the features of the activiti-rest api. I have a maven spring project that has a custom Rest controller (below),
=============================================
<java>
package org.activiti.rest.service.api.dsw;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.Execution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CustomRestController {

@Autowired
private RuntimeService runtimeService;

@RequestMapping(value = "/dsw/sendResponse", method = RequestMethod.PUT, produces = "application/json")
public MessageCorrelationResponse correlate(@RequestBody MessageCorrelationRequest messageRequest,
   HttpServletRequest request) {
  MessageCorrelationResponse messageResponse = new MessageCorrelationResponse();

  if (checkValidString(messageRequest.getMessageName()) && checkValidString(messageRequest.getCorrelationKey())
    && checkValidString(messageRequest.correlationKeyValue)
    && checkValidString(messageRequest.getMessagePayload())) {

   String messageName = messageRequest.getMessageName();
   // Locate the execution using the correlation
   Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName(messageName)
     .variableValueEquals(messageRequest.getCorrelationKey(), messageRequest.correlationKeyValue)
     .singleResult();
   // Set message into map
   Map<String, Object> variableMap = new HashMap<String, Object>();
   variableMap.put("_MessageName", messageName);
   variableMap.put("_MessageContent", messageRequest.getMessagePayload());

   runtimeService.messageEventReceived(messageName, execution.getId(), variableMap);

   messageResponse.setResult("success");
  } else
   messageResponse.setResult("Invalid inputs");

  return messageResponse;

}

private boolean checkValidString(String str) {
  if (str != null && !str.isEmpty())
   return true;
  return false;

}

}
</java>
======================================

Where should I place this class and what do I need to modify to let the DispatchServlet know that I want to use this REST service against the endpt. /dsw/sendResponse? The activiti-rest web.xml file is as below.
<blockcode>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0"
         metadata-complete="true">

  <display-name>Activiti REST</display-name>
    <!– All the Servlets and Filters are configured by this ServletContextListener : –>
    <listener>
        <listener-class>org.activiti.rest.servlet.WebConfigurer</listener-class>
    </listener>
</web-app>
</blockcode>

Thanks