09-04-2015 09:29 AM
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;
}
}
09-07-2015 07:46 AM
09-08-2015 01:00 PM
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.