1 2 3 Previous Next 38 Replies Latest reply: Dec 28, 2011 8:32 AM by Ram Biradar Go to original post RSS
  • 15. Re: Connecting to GWT Console by Rest interface, login problem
    priyakpandey Newbie

    Hi,

    I am trying to create a new process using the following url

     

    /gwt-console-server/rs/process/definition/{id}/new_instance

     

    I followed the instructions and it is printing the output similar to

    {"id":"105","definitionId":"yourProcessName","startDate":"2011-06-03 12:43:45","suspended":false,"rootToken":{"id":"2","name":"","currentNodeName":"","children":[],"availableSignals":[],"canBeSignaled":false}}

     

     

    This means a new process instance is created.

     

    The process I using has  Start - > Human Task -> End.

    Human Task has a perfomer which comes from a process variable, lets say MyUser. I am passing the value of this parameter as 'admin' when i execute above mentioned ReST service.

    Problem is, the task does not get assigned to 'admin'. What am i doing wrong?

    Any help would be appreciated?

    Thank You.

  • 16. Re: Connecting to GWT Console by Rest interface, login problem
    priyakpandey Newbie

    Hi,

    I am trying to create a new process using the following url

     

    /gwt-console-server/rs/process/definition/{id}/new_instance

     

    I followed the instructions and it is printing the output similar to

    {"id":"105","definitionId":"yourProcessName","startDate":"2011-06-03 12:43:45","suspended":false,"rootToken":{"id":"2","name":"","currentNodeName":"","children":[],"availableSignals":[],"canBeSignaled":false}}

     

     

    This means a new process instance is created.

     

    The process I using has  Start - > Human Task -> End.

    Human Task has a perfomer which comes from a process variable, lets say MyUser. I am passing the value of this parameter as 'admin' when i execute above mentioned ReST service.

    Problem is, the task does not get assigned to 'admin'. What am i doing wrong?

    Any help would be appreciated?

    Thank You.

  • 17. Re: Connecting to GWT Console by Rest interface, login problem
    priyakpandey Newbie

    Hi,

    I am trying to create a new process using the following url

     

    /gwt-console-server/rs/process/definition/{id}/new_instance

     

    I followed the instructions and it is printing the output similar to

    {"id":"105","definitionId":"yourProcessName","startDate":"2011-06-03 12:43:45","suspended":false,"rootToken":{"id":"2","name":"","currentNodeName":"","children":[],"availableSignals":[],"canBeSignaled":false}}

     

     

    This means a new process instance is created.

     

    The process I using has  Start - > Human Task -> End.

    Human Task has a perfomer which comes from a process variable, lets say MyUser. I am passing the value of this parameter as 'admin' when i execute above mentioned ReST service.

    Problem is, the task does not get assigned to 'admin'. What am i doing wrong?

    Any help would be appreciated?

    Thank You.

  • 18. Re: Connecting to GWT Console by Rest interface, login problem
    Chris Melas Apprentice

    Hello,

    Well unfortunately there is no way at the moment to pass parameters to the process when starting a process from the REST api.

     

    However you can easily add it yourself, to be honest we have created an implementation for supporting such functionality.

     

    The web service is located inside jbpm-gwt-console-server.war in org.jboss.bpm.console.server.ProcessMgmtFacade.java and the method is newInstance(@PathParam("id")....)  you will notice the @Path("definition/{id}/new_instance") .

    So now you can either modify this method or create another one with modified url accepting a string with parameters or even better accepting post parameters via @FormParam .

    The rest of the code is ready since you can use the same method body and instead of calling getProcessManagement().newInstance(definitionId); you will call getProcessManagement().newInstance(definitionId,params); where params would be a Map<String, Object> variable with the parameters prepared as received from the web service call . The method of ProcessManagement for creating newInstance with parameters is already there but currently not used from the REST api.

  • 19. Re: Connecting to GWT Console by Rest interface, login problem
    priyakpandey Newbie

    Thank you for the instructions. I modified the files as instructed by you and it worked.

  • 20. Re: Connecting to GWT Console by Rest interface, login problem
    priyakpandey Newbie

    I have modified a class ProcessMgmtFacade.java present jbpm-gwt-console-server.war for the above requirements and it is working.

    Would you like me to upload it so that it can be used in you framework?

    If yes then do let me know the location where i can upload the modified file(s).

  • 21. Re: Connecting to GWT Console by Rest interface, login problem
    Chris Melas Apprentice

    Hello,

    I'm glad everything worked out nicely for you

    Well certainly, if it is one class you have modified please post the code or post with attachments, for others to use as well

    Thanks

  • 22. Re: Connecting to GWT Console by Rest interface, login problem
    priyakpandey Newbie

    I have added mofified java classes,

    package org.jboss.bpm.console.server.ProcessMgmtFacade

    I added a new method to accept parameters whicle starting the process

    @POST

      @Path("definition/{id}/drms_new_instance")

      @Produces("application/json")

      @Consumes("application/x-www-form-urlencoded")

      public Response drmsNewInstance(

          @PathParam("id") String definitionId,

          MultivaluedMap<String, String> params) {

      System.out.println("ProcessMgmtFacade.drmsNewInstance()<definitionId="+definitionId+", params="+params+">");

      log.info("ProcessMgmtFacade.drmsNewInstance()<definitionId="+definitionId+", params="+params+">");

        ProcessInstanceRef instance = null;

        try {

        Map<String, Object> data = DrmsUtil.self().getParamsAsMap(params);

        System.out.println("ProcessMgmtFacade.drmsNewInstance().data="+data);

        log.info("ProcessMgmtFacade.drmsNewInstance().data="+data);

        if(null == data) {

        instance = getProcessManagement().newInstance(definitionId);

        } else {

        instance = getProcessManagement().newInstance(definitionId, data);

        }

        return createJsonResponse(instance);

        } catch (Throwable t) {

        throw new WebApplicationException(t, 500);

        }

      }

     

    Added method to close task with params in - org.jboss.bpm.console.server.TaskMgmtFacade

    @POST

      @Path("{taskId}/close_with_params")

      @Produces("application/json")

      @Consumes("application/x-www-form-urlencoded")

      public Response closeTaskWithParams(

                  @Context HttpServletRequest request,

                @PathParam("taskId") long taskId,

                MultivaluedMap<String, String> params) {

          System.out.println("TaskMgmtFacade.closeTaskWithParams()<taskId="+taskId+", params="+params+">");

          log.info("TaskMgmtFacade.closeTaskWithParams()<taskId="+taskId+", params="+params+">");

        try {

          Map<String, Object> data = DrmsUtil.self().getParamsAsMap(params);

              System.out.println("TaskMgmtFacade.closeTaskWithParams().data="+data);

          log.info("TaskMgmtFacade.closeTaskWithParams().data="+data);

          if(null == data) {

                getTaskManagement().completeTask(taskId, null, request.getUserPrincipal().getName());

          } else {

                getTaskManagement().completeTask(taskId, null, data, request.getUserPrincipal().getName());

          }

          return Response.ok().build();

        } catch (Throwable t) {

          throw new WebApplicationException(t, 500);

        }

      }

     

    DrmsUtil is the new classes added for manging data.


     

     

  • 23. Re: Connecting to GWT Console by Rest interface, login problem
    victor ma Newbie

    hello priyakpandey,

    i just follow what you said, but the params is still empty, can you give me a copy of client code, thanks a lot!

  • 24. Re: Connecting to GWT Console by Rest interface, login problem
    priyakpandey Newbie

    Not sure how you are setting the parameters?

    I had set using following code snippet and it works

     

    PostMethod myMethod = new PostMethod(REST_URL);

        NameValuePair[] data = {new NameValuePair("name1", "value1"), new NameValuePair("name2", "value2")};

        myMethod .setRequestBody(data);

        httpclient.executeMethod(myMethod );

  • 25. Re: Connecting to GWT Console by Rest interface, login problem
    victor ma Newbie

    i am using httpclient4.1.1 to set the parameters:

            String responseString = "";

            List<NameValuePair> formparams = new ArrayList<NameValuePair>();

            formparams.add(new BasicNameValuePair("name1", "value1"));

            formparams.add(new BasicNameValuePair("name2", "value2"));

            formparams.add(new BasicNameValuePair("name3", "value3"));

            HttpPost httpPost = new HttpPost(url);

            InputStreamReader inputStreamReader = null;

            BufferedReader bufferedReader = null;

            try {

                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");

                httpPost.setEntity(entity);

                HttpResponse response = httpClient.execute(httpPost);

                InputStream inputStream = response.getEntity().getContent();

                inputStreamReader = new InputStreamReader(inputStream);

                bufferedReader = new BufferedReader(inputStreamReader);

                StringBuilder stringBuilder = new StringBuilder();

                String line = bufferedReader.readLine();

                while (line != null) {

                    stringBuilder.append(line);

                    line = bufferedReader.readLine();

                }

                responseString = stringBuilder.toString();

            } catch (Exception e) {

                throw new RuntimeException(e);

            }

     

    i am wondering the server side code " MultivaluedMap<String, String> params " does not work well on jboss rest easy, so i create a Pojo class to pass the parameters like this:

     

    public class DataEntity {

        @FormParam("name1")

        private String name1;

     

        @FormParam("name2")

        private String name2;

     

        @FormParam("name3")

        private String name3;

     

        public String toString(){

            return name1+" - "+name2+" - "+name3;

        }

        public Map<String, Object> getMap(){

            Map<String, Object> map =new HashMap<String, Object>();

            map.put("name1", name1);

            map.put("name2", name2);

            map.put("name3", name3);

            return map;

     

        }

     

    }

     

    @POST

    @Path("definition/{id}/new_instance")

    public Response NewInstance(@PathParam("id") String definitionId, @Form DataEntity form) {

            Map<String, Object> data = form.getMap();

            ..............

    }

     

     

    anyway, it works now,

    thanks a lot!

  • 26. Re: Connecting to GWT Console by Rest interface, login problem
    priyakpandey Newbie

    Great to know it worked !!!

    Fantastic !

  • 27. Re: Connecting to GWT Console by Rest interface, login problem
    npereira Newbie

    Hi forum,

     

    First, let me say great thread, really helped me a lot.

     

    Second, I wanted to ask something. Chris Melas, in his post said:

     

    "3. normally at first i will get an authentication error, so at that point i will run the authenticate method (as posted by me above, i will post it again at the bottom) with the proper credentials"

     

    I'm actually having the same problem.

    Independetly of what I do the first call always throws an error. Even if I do the authentication first, it will always throw an error.

     

    The first thing I have to do is call a Post message and the second action that I do is Authentication. If I don't do this, it throws an error.

     

    Does anybody else have this bizarre behaviour? Anybody knows how to overcome it?

     

    Regards

  • 28. Re: Connecting to GWT Console by Rest interface, login problem
    Chris Melas Apprentice

    Hello,

    Do you get and exception or just a response for no authorisation?

    Can you please post your code, method calls, responses and/or exceptions?

    ( you're using httpclient 4.x right? )

    Thanks

  • 29. Re: Connecting to GWT Console by Rest interface, login problem
    npereira Newbie

    Hello,

     

    The sequence that I'm using is the following:

     

    String address = "localhost:8080";

    String responseString = "";

     

    responseString = requestPostService("http://" + address + "/gwt-console-server/rs/process/definition/MyBPMN/new_instance", null, false);

    System.out.println("start process1:------>"+responseString+"\n\n\n\n");

     

    responseString = authenticate(address, "krisv", "krisv");

    System.out.println("authentication2:------>"+responseString + "\n\n\n\n");

     

    responseString = requestPostService("http://" + address + "/gwt-console-server/rs/process/definition/MyBPMN/new_instance", null, false);

    System.out.println("start process2:------>"+responseString+"\n\n\n\n");

     

    This sequence will result on the first requestPostService throwing an error,

     

    <html><head>  <title>HTTP 401</title> <!-- Do not remove --></head><body><form method="POST" action="j_security_check">  <center/>  <br><br>  <div style="font-family:sans-serif;border:1px solid black; width:270;padding:15px;"><h2>BPM Console Server</h2>    <table with=250><tr>  <td>Username:</td>  <td><input type="text" name="j_username"></td></tr><tr>  <td>Password:</td>  <td><input type="password" name="j_password"></td></tr><tr>  <td></td>  <td align=right><input type="submit"/></td></tr>  </table>  </div></form></body></html>

     

    (This is expected, because I haven't logged in!)

     

    But if I comment the first requestPostService and do the authentication first I  get the follwing error,

     

    <html><header>  <title>HTTP 401</title> <!-- Do not remove --></header><body>  <center/>  <br><br>  <div style="font-family:sans-serif;border:1px solid black; width:270;padding:15px;"><h3>Login failed!</h3>  </div></body></html>

     

    I'm using httpcomponents-client-4.1.2.

    The methods I used are exactly those that you posted previously in this thread, I didn't change anything.

     

    Regards