Javascripting issues with spin connector

I’m working with service task calling a soap mock server I have setup locally.

The service is based on the github example here
I seem to having a few issues around the spin connector in the javascript.

  <camunda:inputOutput>
    <camunda:inputParameter name="url">http://JJEC-laptop:8088/mockUKLocationSoap12</camunda:inputParameter>
    <camunda:inputParameter name="payload">
      <camunda:script scriptFormat="freemarker" resource="soapEnvelope.ftl" />
    </camunda:inputParameter>
    <camunda:inputParameter name="headers">
      <camunda:map>
        <camunda:entry key="Content-Type">application/soap+xml;charset=UTF-8;action="SurgicalSupportServices"</camunda:entry>
      </camunda:map>
    </camunda:inputParameter>
    <camunda:outputParameter name="fullDetails">
		              <![CDATA[
						${S(response)
						.childElement("Body")
						.childElement("http://www.webserviceX.NET", "GetUKLocationByPostCodeResponse")
						.childElement("GetUKLocationByPostCodeResult")}
					  ]]>
		</camunda:outputParameter>
  </camunda:inputOutput>
</camunda:connector>
	
	<camunda:inputOutput>
    <camunda:outputParameter name="fullPatientName">
        <camunda:script scriptFormat="Javascript" resource="parseAppmt.js" />
    </camunda:outputParameter>
</camunda:inputOutput>

</bpmn:extensionElements>
bpmn:incomingSequenceFlow_09n2x7s</bpmn:incoming>

The Spin connector is able to retrieve the data from the response mock service no problem in the BPMN file. But when I call try to extract a value and assign to a variable from a javascript the process falls over.

This is what parstAppm.js contains:-

// this script parses the appointment time from the response
//Ensures there will be no 'console is undefined' errors

//var logger = java.util.logging.Logger;
//var log = logger.getLogger("MY_JS_LOGGER");

var rawFullDetails  = execution.getVariable('fullDetails');
//log.info("this is rawFullDetails : " + rawFullDetails);

//convert from object to string
//var fullDetails = rawFullDetails.toString();

// remove prologue which cannot be parsed: '<?xml version="1.0" encoding="utf-16"?>'
// see here var fullDetailsEssential = rawFullDetails.substring(rawFullDetails.indexOf("\n" ));

//log.info("this is fullDetails minus topline: " + fullDetailsEssential);

var patientName = S(rawFullDetails).childElement("FullName").textContent();
//log.info("this is  patientName : " + patientName);

//var appmtTime = pL.substr(pL.length - 5);
var regex = /(.....)$/;

//return "11:45" //appmtTime;
regex.exec(pL)[1];

I’m sure it is at line 18 var patientName = S(rawFullDetails).childElement("FullName").textContent() because when I’ve hard-coded the variable, the script is able to work fine.

the message displayed on the tasklist is:-

The process could not be started. : cannot POST /camunda/api/engine/engine/default/process-definition/Process_1:31:037f90f7-d0f7-11e6-aa0e-a0a8cd4879e9/submit-form (500)

There is nothing in the catalina log for this, whilst the local access log has the following:-

127.0.0.1 - - [02/Jan/2017:14:56:00 +0000] "GET /camunda/api/engine/engine/default/process-definition/count?latest=true&active=true&firstResult=0&maxResults=15 HTTP/1.1" 200 21
127.0.0.1 - - [02/Jan/2017:14:56:00 +0000] "GET /camunda/api/engine/engine/default/process-definition?latest=true&active=true&firstResult=0&maxResults=15 HTTP/1.1" 200 1821
127.0.0.1 - - [02/Jan/2017:14:56:01 +0000] "GET /camunda/api/engine/engine/default/process-definition/Process_1:31:037f90f7-d0f7-11e6-aa0e-a0a8cd4879e9/startForm HTTP/1.1" 200 98
127.0.0.1 - - [02/Jan/2017:14:56:01 +0000] "GET /SAU-tomcat-0.1.0-SNAPSHOT/forms/NewPatient.html?noCache=1483368961924 HTTP/1.1" 200 703
127.0.0.1 - - [02/Jan/2017:14:56:01 +0000] "GET /camunda/api/engine/engine/default/process-definition/Process_1:31:037f90f7-d0f7-11e6-aa0e-a0a8cd4879e9/form-variables?deserializeValues=false&variableNames=nhsNumber%2CpatientName%2CpostCode HTTP/1.1" 200 12

the localhost log has the following:-

02-Jan-2017 14:56:06.795 SEVERE [http-apr-8080-exec-266] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [Engine Api] in context with path [/camunda] threw exception
 java.lang.RuntimeException: org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: Could not initialize class org.camunda.spin.SpinFactory
	at org.camunda.bpm.webapp.impl.security.auth.AuthenticationFilter$1.execute(AuthenticationFilter.java:61)
	at org.camunda.bpm.webapp.impl.security.auth.AuthenticationFilter$1.execute(AuthenticationFilter.java:56)
	at org.camunda.bpm.webapp.impl.security.SecurityActions.runWithAuthentications(SecurityActions.java:38)
	at org.camunda.bpm.webapp.impl.security.auth.AuthenticationFilter.doFilter(AuthenticationFilter.java:56)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
.
.
.
Caused by: org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: Could not initialize class org.camunda.spin.SpinFactory
	at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:365)
	at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:233)
	at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:209)

There are some other issues as well generally around the scripting side based on the example which maybe based on my understanding of what is being passed back in the github example. I am also getting the error message when I un-comment the line 14 which removes the top-line.

The message on the server is

02-Jan-2017 14:06:32.178 WARNING [http-apr-8080-exec-215] org.camunda.bpm.engine.rest.exception.RestExceptionHandler.toResponse org.camunda.bpm.engine.rest.exception.RestException: Cannot instantiate process definition Process_1:28:c1e52ba5-d0dd-11e6-aa0e-a0a8cd4879e9: Unable to evaluate script: TypeError: null has no such function "substring" in <eval> at line number 14
	at org.camunda.bpm.engine.rest.sub.repository.impl.ProcessDefinitionResourceImpl.submitForm(ProcessDefinitionResourceImpl.java:174)
	at sun.reflect.GeneratedMethodAccessor584.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)

Also to try and understand the example as it seems that the webserviceX site is down. In the getWeather example from the site, they say that the response is the following:-

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetWeatherResponse xmlns="http://www.webserviceX.NET">
      <GetWeatherResult>string</GetWeatherResult>
    </GetWeatherResponse>
  </soap:Body>
</soap:Envelope>

However the github example for the getweather service has the following as I assumed being sent back response.txt

<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
  <Location>Berlin-Tegel, Germany (EDDT) 52-34N 013-19E 37M</Location>
  <Time>Jun 11, 2014 - 08:50 AM EDT / 2014.06.11 1250 UTC</Time>
  <Wind> from the NW (310 degrees) at 6 MPH (5 KT):0</Wind>
  <Visibility> greater than 7 mile(s):0</Visibility>
  <SkyConditions> mostly cloudy</SkyConditions>
  <Temperature> 68 F (20 C)</Temperature>
  <DewPoint> 64 F (18 C)</DewPoint>
  <RelativeHumidity> 88%</RelativeHumidity>
  <Pressure> 30.18 in. Hg (1022 hPa)</Pressure>
  <Status>Success</Status>
</CurrentWeather>

Where does this fit in with the soap response from the webservicex site? Does this go inside of the element GetWeatherResult?

Finally, is the only way to return a value out of the script through using .exec()? It is not possible to just use return()? What if I don’t need to do any regular expression?

Many Thanks

What version of Camunda are you using? I had issues with Spin in earlier versions of Camunda, but these were fixed. I seemed to remember working through some of those same examples over a year ago and I couldn’t make them work (or translate them into something that worked with my implementation), so I ended up writing my own parser/mapper instead of using Spin.

I’m on 7.4.

There is no chance of me writing any parsing anything! How big of a pain is it to migrate to 7.6? I’m using the shared container managed process engine.

It’s really not that difficult. It depends upon how you are running your Camunda instance. Essentially, you do the following:

  1. Shutdown Camunda

  2. Download and install Camunda 7.6 in a separate location from your current instance

  3. Apply any changes to Camunda 7.6 that are specific to the Java container you are using (e.g. if you’re using WildFly, you would update the the standalone.xml and mgmt-users.properties files).

  4. Make a backup of your existing back end database

  5. Find the upgrade SQL script(s) for your particular back end database and execute it against the database. Be aware that you might need to run multiple scripts if your instance is older.

  6. Start Camunda 7.6 and log in

There are more details in the Camunda documentation, but that’s an overview of what you need to do.

1 Like

Thanks, I’ll give it a go soon. It shouldn’t be too difficult I’m only using the H2 database.

Cancelling… apologies