AnsweredAssumed Answered

Create Process Instance Rest API Exception

Question asked by kartikmavani on Oct 24, 2014
Latest reply on Nov 3, 2014 by jbarrez
Hello,
Greeting !.


I am writing a restful API for starting a process instance. I am using springTemplate.

The following is the code.



        private static String HOST = "localhost";
   private static String PORT = "8080";
   private static String PROTOCOL = "http";
   public static String BASE_URL = PROTOCOL+"://"+HOST+":"+PORT+"/activiti-rest/";

                 TreeMap<String, Object> mainParams = new TreeMap<String, Object>();
            mainParams.put("processDefinitionId", "TestingProcess:1:121704");



         RestTemplate restTemplate = new RestTemplate(getAuthenticatedHeader());
         URI uri = restTemplate.postForLocation(BASE_URL+"service/runtime/process-instances", null ,mainParams);

private SimpleClientHttpRequestFactory getAuthenticatedHeader() {
      SimpleClientHttpRequestFactory connectionFactory = new SimpleClientHttpRequestFactory() {
         @Override
         protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
            super.prepareConnection(connection, httpMethod);
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);

            String authorisation =   "gonzo:gonzo";
            byte[] encodedAuthorisation = Base64.encodeBase64(authorisation.getBytes());
            connection.setRequestProperty("Authorization", "Basic "+new String(encodedAuthorisation));
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Accept", "application/json");
         }
      };
      return connectionFactory;
   }



The following is the exception that I am getting.
09:01:09,768 [http-8080-1] DEBUG org.activiti.engine.impl.interceptor.LogInterceptor  -
09:01:09,769 [http-8080-1] DEBUG org.activiti.engine.impl.interceptor.LogInterceptor  - — starting CheckPassword ——————————————————–
09:01:09,769 [http-8080-1] DEBUG org.activiti.spring.SpringTransactionInterceptor  - Running command with propagation REQUIRED
09:01:10,140 [http-8080-1] DEBUG org.activiti.engine.impl.persistence.entity.UserEntity.selectUserById  - ooo Using Connection [Transaction-aware proxy for target Connection  from DataSource [org.springframework.jdbc.datasource.SimpleDriverDataSource@2754de0b]]
09:01:10,141 [http-8080-1] DEBUG org.activiti.engine.impl.persistence.entity.UserEntity.selectUserById  - ==>  Preparing: select * from ACT_ID_USER where ID_ = ?
09:01:10,143 [http-8080-1] DEBUG org.activiti.engine.impl.persistence.entity.UserEntity.selectUserById  - ==> Parameters: gonzo(String)
09:01:10,171 [http-8080-1] DEBUG org.activiti.engine.impl.db.DbSqlSession  - flush summary: 0 insert, 0 update, 0 delete.
09:01:10,171 [http-8080-1] DEBUG org.activiti.engine.impl.db.DbSqlSession  - now executing flush…
09:01:10,244 [http-8080-1] DEBUG org.activiti.engine.impl.interceptor.LogInterceptor  - — CheckPassword finished ——————————————————–
09:01:10,244 [http-8080-1] DEBUG org.activiti.engine.impl.interceptor.LogInterceptor  -
Oct 24, 2014 9:01:10 PM org.restlet.resource.UniformResource doCatch
WARNING: Exception or error caught in resource
java.lang.NullPointerException
        at org.activiti.rest.service.api.runtime.process.ProcessInstanceCollectionResource.createProcessInstance(ProcessInstanceCollectionResource.java:100)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.restlet.resource.ServerResource.doHandle(ServerResource.java:449)
        at org.restlet.resource.ServerResource.post(ServerResource.java:1114)
        at org.restlet.resource.ServerResource.doHandle(ServerResource.java:533)
        at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:590)
        at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:302)
        at org.restlet.resource.ServerResource.handle(ServerResource.java:849)
        at org.restlet.resource.Finder.handle(Finder.java:513)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Router.doHandle(Router.java:500)
        at org.restlet.routing.Router.handle(Router.java:740)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:155)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.engine.ChainHelper.handle(ChainHelper.java:114)
        at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:75)
        at org.restlet.Application.handle(Application.java:391)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Router.doHandle(Router.java:500)
        at org.restlet.routing.Router.handle(Router.java:740)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Router.doHandle(Router.java:500)
        at org.restlet.routing.Router.handle(Router.java:740)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.engine.ChainHelper.handle(ChainHelper.java:114)
        at org.restlet.Component.handle(Component.java:391)
        at org.restlet.Server.handle(Server.java:491)
        at org.restlet.engine.ServerHelper.handle(ServerHelper.java:74)
        at org.restlet.engine.http.HttpServerHelper.handle(HttpServerHelper.java:153)
        at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1031)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        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.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:662)
Oct 24, 2014 9:01:10 PM org.restlet.engine.log.LogFilter afterHandle
INFO: 2014-10-24        21:01:10        127.0.0.1       gonzo   127.0.0.1       8080    POST    /activiti-rest/service/runtime/process-instances        -       500     -       0       483     http://localhost:8080   Java/1.6.0_45   -

Kindly advise…..

Outcomes