500 error from "create case" REST API call

1
0
-1

Having read this quick guide I've created a simple process and deployed it locally using the Bonita UI version 6.2.5 - I can login, create a new case of my process navigating to localhost:8080 in my browser. However when I attempt to create a new case using the REST api I get a HTTP 500 error and the following response returned:

{"exception":"class java.lang.NullPointerException","message":"","stacktrace":[ < massive stack trace here > ]}

To do this I'm navigating to http://localhost:8080/bonita/API/bpm/process?p=0 to obtain the process ID, which I believe is the highlighted portion of the response below:

[{"id":"7163253574217604033","icon":"","displayDescription":"","deploymentDate":"2014-04-14 16:00:54.369","description":"","activationState":"ENABLED","name":"AuthoriseBankAccountChange","deployedBy":"4","displayName":"AuthoriseBankAccountChange","last_update_date":"2014-04-14 16:00:54.553","configurationState":"RESOLVED","version":"1.0"}]

Then I'm creating the POST request as follows - I'm just putting together a quick POC\evaluation first, which is why I'm hacking a quick test together using js in my browser:

// authenticate. verified correct by logging in with these credentials using the
//web UI, logging out + clearing cookies, unsuccessfully navigating to
// http://localhost:8080/bonita, then issuing the command and successfully
//navigating to http://localhost:8080/bonita
var loginURL = "http://localhost:8080/bonita/loginservice"
$.post(url, { username: "walter.bates", password: "bpm", redirect: false })

// create a new case. returns http 500 error
var processURL = "http://localhost:8080/bonita/API/bpm/case/"
var processData = { "processDefinitionId": 7163253574217604033,  "variables": [{"name":"claccountid", "value":"123456"},{"name":"datemodified", "value":"2014-04-14"},{"name":"modifiedby", "value":"404404"},{"name":"fieldname", "value":"SortCode"},{"name":"oldvalue" , "value":"123456"},{"name":"newvalue" , "value":"123455"},{"name":"approved","value":"false"}]}
$.post(processURL, processData)

For each of the elements in "variables" the "name" field corresponds to a variable in the main swimlane of my BPM diagram. When I change the processDefinitionId to something random I get the same error, so I'm thinking that I might be using the wrong value - is this the case?

Edit: full stack trace is as follows...

{"exception":"class java.lang.NullPointerException","message":"","stacktrace":["org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:212)","org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:198)","org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:188)","org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:168)","org.bonitasoft.web.rest.server.framework.APIServletCall.getJSonStreamAsItem(APIServletCall.java:84)","org.bonitasoft.web.rest.server.framework.APIServletCall.doPost(APIServletCall.java:169)","org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.doPost(ToolkitHttpServlet.java:184)","javax.servlet.http.HttpServlet.service(HttpServlet.java:643)","org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:71)","javax.servlet.http.HttpServlet.service(HttpServlet.java:723)","org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:222)","org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)","org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)","org.bonitasoft.console.common.server.login.filter.FilterManager.pageRedirect(FilterManager.java:88)","org.bonitasoft.console.common.server.login.filter.FilterManager.doFilter(FilterManager.java:68)","org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)","org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)","org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)","org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)","org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)","org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)","org.bonitasoft.console.security.SessionFixationValve.invoke(SessionFixationValve.java:77)","org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)","org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)","org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)","org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)","org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)","java.lang.Thread.run(Unknown Source)"]}

Comments

Submitted by rlg on Tue, 04/15/2014 - 07:32

Hi,

Could you share the stacktrace that you can find in the server log file?

Submitted by sean.mclemon on Tue, 04/15/2014 - 09:47

Yep, just updated the question with this data

2 answers

1
0
-1
This one is the BEST answer!

This was 100% user error and caused by my use of the jquery's $.post() which sets the contentType to application/x-www-form-urlencoded for POST data by default. I rearranged my code to use $.ajax() instead and I was able to create a new case successfully. For posterity I've included the solution below (I restarted my laptop and deployed a new instance of my process so the processDefinitionID has changed):

// authenticate. verified correct by logging in with these credentials using the
//web UI, logging out + clearing cookies, unsuccessfully navigating to
// http://localhost:8080/bonita, then issuing the command and successfully
//navigating to http://localhost:8080/bonita
var loginURL = "http://localhost:8080/bonita/loginservice"
$.post(loginURL, { username: "walter.bates", password: "bpm", redirect: false })
 
// now issue a GET to the i18ntranslation resource to set the locale
$.get("http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3Den")

// create a new case.
var processURL = "http://localhost:8080/bonita/API/bpm/case/"
var processData = { "processDefinitionId": 6481676728838404000, "variables": [{"name":"claccountid", "value":"123456"},{"name":"datemodified", "value":"2014-04-14"},{"name":"modifiedby", "value":"404404"},{"name":"fieldname", "value":"SortCode"},{"name":"oldvalue" , "value":"123456"},{"name":"newvalue" , "value":"123455"},{"name":"approved","value":"false"}]}

$.ajax({
        url: processURL,
        type: "POST",
        dataType: "xml/html/script/json", // expected format for response
        contentType: "application/json", // send as JSON
        data: processData
        complete: function() {
                console.log("complete");
        },
        success: function() {
                console.log("success()");
        },
        error: function() {
                console.log("error()")
        },
});

1
0
-1

Hello,

it seems that you forget to set the language you want to use. See: http://documentation.bonitasoft.com/web-rest-api-details#authentication

Extract from the documentation:

After you log in, get the translation resource for the current locale. This is used to return the appropriate language strings in subsequent calls.

Request URL : http://host:port/bonita/API/system/i18ntranslation?f=locale%3dlocale-id Request Method : GET In the request URL, locale-id is the two-letter code identifiying the locale. For example, to get the French-language resources, use a GET request with the URL http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3dfr.

See more at: http://documentation.bonitasoft.com/web-rest-api-details#authentication

Note that this step could be not mandatory in the future ;)

Regards,

Comments

Submitted by sean.mclemon on Tue, 04/15/2014 - 16:10

OK I may be misunderstanding the documentation but it seems to imply that I just need to issue a GET to that resource with the appropriate locale string (in my case it'd be http://localhost:8080/bonita/API/system/i18ntranslation?f=locale%3den), and then proceed with the API call. The example makes no mention of using the locale data returned - which is a giant JSON array of translated strings - which seems a little weird.

Anyway, after I do this I still get the same HTTP 500 error, so this cannot be the cause. Are you sure I am obtaining the processDefinitionId correctly? I get this same error regardless of whether or not I use a valid or invalid one.

Notifications