I am using pure java and an HttpUrlConnection with JDK 1.7. I am using Bonita 6.3 with Postgress. I can add more information if it is needed.
I have basic Java code that logs me in as a user. I get the session id, and with that I can get an existing user from the database with no issues.
With that session id, I am not trying to create my first user. I am not stranger to RESTful web-services and have created many of these along with consumers of those services. I can add my basic code here. This is using the same JSON as in their example, I matched it to the letter. I am very aware of how sensitive JSON parsing can be if something is off, but it does look like good JSON when I print out the JSON string.
private long createBonitaUser(String jSessionIdCookie, UserAccount userAccount) throws Exception
{
long userId = 0;
jsonUser = "{\"userName\":\"john.doe\",\"password\":\"bpm\",\"password_confirm\":\"bpm\",\"firstname\":\"John\",\"lastname\":\"Doe\"}";
System.out.println("jsonUser=" + jsonUser);
String link = "http://localhost:8080/bonita/API/identity/user/";
URL url = new URL(link);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Cookie", jSessionIdCookie);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
os.write(jsonUser.getBytes());
os.flush();
System.out.println("conn.getResponseCode()=" + conn.getResponseCode());
if (conn.getResponseCode() != 200)
{
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output = br.readLine();
System.out.println("Output from Server: output=" + output);
return userId;
}
The error I get is as follows:
2014-12-22 15:20:54 org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet
SEVERE: null
java.lang.NullPointerException
at org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:212)
at org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:198)
at org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:188)
at org.bonitasoft.web.toolkit.client.common.json.JSonItemReader.parseItem(JSonItemReader.java:168)
at org.bonitasoft.web.rest.server.framework.APIServletCall.getJSonStreamAsItem(APIServletCall.java:99)
at org.bonitasoft.web.rest.server.framework.APIServletCall.doPost(APIServletCall.java:187)
at org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.doPost(ToolkitHttpServlet.java:188)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
at org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.bonitasoft.web.toolkit.server.servlet.ToolkitHttpServlet.service(ToolkitHttpServlet.java:226)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.bonitasoft.console.common.server.login.filter.AbstractAuthorizationFilter.doFilter(AbstractAuthorizationFilter.java:60)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.bonitasoft.console.common.server.login.filter.AbstractAuthorizationFilter.doFilter(AbstractAuthorizationFilter.java:60)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.bonitasoft.console.common.server.sso.filter.AuthenticationFilter.checkExistingSessionOrFiltering(AuthenticationFilter.java:262)
at org.bonitasoft.console.common.server.sso.filter.AuthenticationFilter.checkExistingSessionOrFilteringAndManageException(AuthenticationFilter.java:144)
at org.bonitasoft.console.common.server.sso.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:120)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.bonitasoft.console.security.SessionFixationValve.invoke(SessionFixationValve.java:77)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
I wish the error message was better to tell me exactly what is missing or what could not be found. In my own code, the Jackson2 JSON mapper is very good at writing out what the error might be.
Any help in this matter would be extremely helpful. Thanks!