How to evaluate URL string for HTTP connector in service task?

1,521 views
Skip to first unread message

andrei....@gmail.com

unread,
Nov 15, 2015, 2:26:25 PM11/15/15
to camunda BPM users
Hi

I have to start rest service from camunda with URL which contains process variables.

I tried this

Set url =
type text
value "http://localhost/request/" + {$requestid} + "/clientform"

But this string copied by engine as is without evaluation.

Please suggest how to generate custom url string for http connector.

Sebastian Menski

unread,
Nov 16, 2015, 4:40:54 AM11/16/15
to camunda BPM users, andrei....@gmail.com
Hi,

could you shortly explain where you want to set the url? I'm not sure what this code snippet is?

Set url =
type text
value "http://localhost/request/" + {$requestid} + "/clientform"

Cheers,
Sebastian

andrei....@gmail.com

unread,
Nov 16, 2015, 1:25:54 PM11/16/15
to camunda BPM users, andrei....@gmail.com
Hi, Sebastian.

I have process variable requestid.

In service task I would like to start rest service with URL evaluated in camunda.

I'm using http-connector


<bpmn2:extensionElements>
<camunda:connector>
<camunda:connectorId>http-connector</camunda:connectorId>
<camunda:inputOutput>
<camunda:inputParameter name="url">
<camunda:script scriptFormat="Groovy"><![CDATA[$url = "http://localhost/request/$requestid/clientform"]]></camunda:script>
</camunda:inputParameter>
<camunda:inputParameter name="method">GET</camunda:inputParameter>
<camunda:outputParameter name="res">
<camunda:script scriptFormat="Javascript" resource="parseEO.js"/>
</camunda:outputParameter>
</camunda:inputOutput>
</camunda:connector>
</bpmn2:extensionElements>

But I couldn't evaluate string. Getting errors.

andrei....@gmail.com

unread,
Nov 16, 2015, 1:46:39 PM11/16/15
to camunda BPM users, andrei....@gmail.com
воскресенье, 15 ноября 2015 г., 22:26:25 UTC+3 пользователь andrei....@gmail.com написал:
21:20:23,297 INFO [org.camunda.bpm.application.impl.DefaultElResolverLookup] (http-/127.0.0.1:8080-4) ElResolvers found for Process Applica
tion extendedAppSEBAgreementClass org.camunda.bpm.engine.cdi.impl.CdiProcessApplicationElResolver
21:20:30,833 INFO [org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher] (http-/127.0.0.1:8080-1) Deploying javax.ws.rs.cor
e.Application: class org.camunda.bpm.tasklist.impl.web.TasklistApplication
21:20:34,705 SEVERE [org.camunda.bpm.engine.impl.interceptor.CommandContext] (http-/127.0.0.1:8080-1) Error while closing command context: j
ava.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
at org.camunda.connect.httpclient.impl.AbstractHttpRequest.getUrl(AbstractHttpRequest.java:47)
at org.camunda.connect.httpclient.impl.AbstractHttpConnector.createHttpRequestBase(AbstractHttpConnector.java:99)
at org.camunda.connect.httpclient.impl.AbstractHttpConnector.createHttpRequest(AbstractHttpConnector.java:88)

Sebastian Menski

unread,
Nov 17, 2015, 5:00:43 AM11/17/15
to camunda BPM users, andrei....@gmail.com
Hi,

assuming 'restquestid' is a process variable you should be able to do this:

<bpmn2:extensionElements>
    <camunda:connector>
        <camunda:connectorId>http-connector</camunda:connectorId>
        <camunda:inputOutput>
            <camunda:inputParameter name="url">
                <camunda:script scriptFormat="Groovy">"http://localhost/request/${requestid}/clientform".toString()></camunda:script>
            </camunda:inputParameter>
            <camunda:inputParameter name="method">GET</camunda:inputParameter>
            <camunda:outputParameter name="res">
                <camunda:script scriptFormat="Javascript" resource="parseEO.js"/>
            </camunda:outputParameter>
        </camunda:inputOutput>
    </camunda:connector>
</bpmn2:extensionElements>

Please note the ".toString()" call as the GStringImpl of groovy is lazy and will only evaluate if transformed to String which has to be done explicitly in this case.

Cheers,
Sebastian

andrei....@gmail.com

unread,
Nov 17, 2015, 7:24:16 AM11/17/15
to camunda BPM users, andrei....@gmail.com
вторник, 17 ноября 2015 г., 13:00:43 UTC+3 пользователь Sebastian Menski написал:
Hi Sebastian. It's working. Thanks.

Another question with response now.

I have JSON in response like this

"sebCheck": {
"approveF5201": true,
"residesOnActualAddressF5202": true,
"rejectF5203": false,
"absenceOfPermanentExecutiveBodyF5204": false,
"failureToProvideDocumentsByArticle7F5205": false,
"questionableTransactionsAnnex1211F5206": false,
"fakeActualCompanyAddressF5207": false,
"clientInTerroristsListF5208": false,
"unreliabilityOfForeignEconomicActivityF5209": false,
"companyWasClosedByFNSsiteInfoF5210": false,
"legalizationOfIncomeFromCriminalF5211": false,
"financingOfTerrorismF5212": false,
"refusalToProvideInfoOfBeneficiariesF5213": false,
"refuseCommentF5214": "Empty comment",
"clientRefusedToAccountF5215": false,
"doSendToReworkWithCommentF5216": false,
"reworkCommentF5217": "rework comment",
"reponsibleSurnameF5218": "Кирпичёв",
"responsibleNameF5219": "Игорь",
"responsibleMiddleNameF5220": "Борисович",
"dateTimeF5221": "2015-10-16T17:00:03",
"commentTypeF5222": "commentType"

I have to access some fields, check them and perform next activities in BPM based on these values.

I created next http-connector:

<camunda:connector>
<camunda:connectorId>http-connector</camunda:connectorId>
<camunda:inputOutput>
<camunda:inputParameter name="url">
<camunda:script scriptFormat="Groovy"><![CDATA[url = "http://localhost:8088/request/$requestid/clientform"

url.toString()]]></camunda:script>
</camunda:inputParameter>
<camunda:inputParameter name="method">GET</camunda:inputParameter>
<camunda:outputParameter name="res">
<camunda:script scriptFormat="JavaScript" resource="parseEO.js"/>
</camunda:outputParameter>
</camunda:inputOutput>
</camunda:connector>

and content of parseEO.js


// fetch execution variables
var response = connector.getVariable("response");
var json = S(response);

var res;

//var query = "$.[?(@.datum=='" + date + "')]";

//!holidays.jsonPath(query).elementList().isEmpty();


if ((json.jsonPath("$.rejectF5203").value() == "true")||(json.jsonPath("$.clientRefusedToAccountF5215").value() == "true"))
res = "reject";


if (json.jsonPath("$.doSendToReworkWithCommentF5216").value() == "true")
res = "rework";

if (json.jsonPath("$.approveF5201").value() == "true")
res = "confirm";




Getting error:
An error happend while submitting the task form : Cannot submit task form 0bc8ca0f-8d26-11e5-b2d7-a45d36bee6d1: Unable to evaluate script: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function value in object org.camunda.spin.impl.json.jackson.query.JacksonJsonPathQuery@24cace19. (#12) in at line number 12

Sebastian Menski

unread,
Nov 17, 2015, 11:43:08 AM11/17/15
to camunda BPM users, andrei....@gmail.com
Hi,

you can find the available methods in the javadoc [1]. If you want to have the value of a json path expression you can use stringValue(), boolValue() or numberValue().

Cheers,
Sebastian

andrei....@gmail.com

unread,
Nov 18, 2015, 3:02:32 AM11/18/15
to camunda BPM users, andrei....@gmail.com
вторник, 17 ноября 2015 г., 19:43:08 UTC+3 пользователь Sebastian Menski написал:
Hi Sebastian. Problem was with jsonPath. I tested with jsonPath evaluator and found that jsonPath returns [] array of values even with single structure in json.

Changed search argument to
jsonPath("$..approveF5201[0]") and all working now.
Reply all
Reply to author
Forward
0 new messages