Error Invoke a BPMN REST Endpoint from the wso2 business process server

1.2k views Asked by At

I want to send a message to the proxy service of ESB from BPMN REST of business process server but when i invoke a process, an exception is thrown.

TID: [-1234] [] [2017-08-30 18:22:15,504] ERROR {org.wso2.carbon.bpmn.extensions.rest.RESTTask} -  Failed to execute POST http://localhost:8280/services/bpmnProxy within task servicetask1:REST Task in process instance 7501 {org.wso2.carbon.bpmn.extensions.rest.RESTTask}
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('C' (code 67)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: java.io.StringReader@5dbc3edb; line: 1, column: 2]
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1369)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:532)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:453)
    at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleUnexpectedValue(ReaderBasedJsonParser.java:1386)
    at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:669)
    at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:2926)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2873)
    at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1750)
    at org.wso2.carbon.bpmn.core.types.datatypes.json.JSONUtils.parse(JSONUtils.java:42)
    at org.wso2.carbon.bpmn.extensions.rest.RESTTask.execute(RESTTask.java:210)
    at org.activiti.engine.impl.delegate.JavaDelegateInvocation.invoke(JavaDelegateInvocation.java:34)


TID: [-1234] [] [2017-08-30 18:22:15,525] ERROR {org.wso2.carbon.bpmn.rest.common.provider.ExceptionMapper.BPMNExceptionHandler} -  Activiti Exception Occured  {org.wso2.carbon.bpmn.rest.common.provider.ExceptionMapper.BPMNExceptionHandler}
org.activiti.engine.delegate.BpmnError: No catching boundary event found for error with errorCode 'REST_CLIENT_INVOKE_ERROR', neither in same process nor in parent process (errorCode='REST_CLIENT_INVOKE_ERROR') (errorCode='REST_CLIENT_INVOKE_ERROR')
    at org.activiti.engine.impl.bpmn.helper.ErrorPropagation.propagateError(ErrorPropagation.java:82)
    at org.activiti.engine.impl.bpmn.helper.ErrorPropagation.propagateError(ErrorPropagation.java:60)
    at org.activiti.engine.impl.bpmn.helper.ClassDelegate.execute(ClassDelegate.java:160)
    at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60)
    at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97)
    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:644)
    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:637)
    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:97)

What i do wrong?

The call scheme: Client->proxy service of esb->Business process->Invoke Rest API->Proxy service of esb

1.Proxy service of esb->business process:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="processProxy" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
   <target>
      <inSequence>
         <payloadFactory media-type="json">
            <format>
            {
              "processDefinitionKey":"myProcess",
              "tenantId": "-1234",
              "variables": [
                {
                  "name":"Name",
                  "value":"$1"
                }]
            }
            </format>
            <args>
               <arg evaluator="xml" expression="//req/name/text()"/>
            </args>
         </payloadFactory>
         <header expression="fn:concat('Basic ', base64Encode('admin:admin'))" name="Authorization" scope="transport"/>
         <header name="Content-Type" scope="transport" value="application/json"/>
         <header name="Accept" scope="transport" value="application/json"/>
         <log level="full"/>
         <send>
            <endpoint>
               <http method="POST"
                     uri-template="https://localhost:9445/bpmn/runtime/process-instances"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="full"/>
      </outSequence>
      <faultSequence/>
   </target>
   <description/>
</proxy>

2.Business process->invoke Rest API:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start">
      <extensionElements>
        <activiti:formProperty id="vName" name="vName" type="string" variable="vName" required="true"></activiti:formProperty>
      </extensionElements>
    </startEvent>
    <serviceTask id="servicetask1" name="REST Task" activiti:class="org.wso2.carbon.bpmn.extensions.rest.RESTTask" activiti:extensionId="org.wso2.developerstudio.bpmn.extensions.restTask.RESTTask">
      <extensionElements>
        <activiti:field name="serviceURL">
          <activiti:string>http://localhost:8280/services/bpmnProxy</activiti:string>
        </activiti:field>
        <activiti:field name="method">
          <activiti:string>POST</activiti:string>
        </activiti:field>
        <activiti:field name="input">
          <activiti:expression>{
 "Name":"${vName}"
}</activiti:expression>
        </activiti:field>
        <activiti:field name="headers">
          <activiti:string>Content-Type:application/json</activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
  </process>
</definitions>

3.Invoke Rest API->proxy service of esb

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="bpmnProxy" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
   <target>
      <inSequence>
         <property expression="json-eval($.Name)" name="vName" scope="default" type="STRING"/>
         <payloadFactory media-type="xml">
            <format>
               <req>
                  <name>$1</name>
               </req>
            </format>
            <args>
               <arg evaluator="xml" expression="get-property('vName')"/>
            </args>
         </payloadFactory>
         <property name="HTTP_METHOD" scope="axis2" type="STRING" value="POST"/>
         <property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
         <send>
            <endpoint>
               <address uri="http://192.168.18.1:8740"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
            <format>
        {
          "result":"success"
        } 
            </format>
            <args/>
         </payloadFactory>
         <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
         <send/>
      </outSequence>
      <faultSequence/>
   </target>
   <description/>
</proxy>
1

There are 1 answers

0
Dvortsevoy Eugene On

i found in what was the reason.

in sources org.wso2.carbon.bpmn.extensions.rest the class RESTTask, headers are trying to parse as JSON object

if (headers != null) {
    String headerContent = headers.getValue(execution).toString();
    jsonHeaders = JSONUtils.parse(headerContent);
}

but all the examples that I have found, headers passed as a string:

"Content-Type:application/json, ....."

made the headers JSON objects and all worked

{"Accept":"application/json","Content-Type":"application/json"}