7 Replies Latest reply on Mar 24, 2015 2:32 AM by swiderski.maciej

    call jBPM6 webservice using REST API

    pandyajayn

      Hi,

       

      We have developed some workflows on jBPM6 which is deployed on one server, now we want to access the methods using rest client from our JAVA program, can anybody please guide us how to start.

       

      Regards,

      Jay

        • 1. Re: call jBPM6 webservice using REST API
          swiderski.maciej

          look at usage of RestWorkItemHandler, here you can find test cases for it. Check out service repository sections in doc to learn on how to use rest work item handler.

           

          HTH

          • 2. Re: call jBPM6 webservice using REST API
            pandyajayn

            when i am executing following method, i am getting 401 return code only which means authentication failed. can anyone please help me to understand where i am doing wrong

             

            String url = "http://serverutl:8080/business-central/rest/runtime/";

             

            HttpClient httpclient = new HttpClient();

            httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(60000);

            httpclient.getHttpConnectionManager().getParams().setSoTimeout(60000);

            HttpMethod theMethod = null;

            theMethod = new GetMethod(str);

            doAuthorization(httpclient, theMethod);

            theMethod.setDoAuthentication(true);

            int responseCode = httpclient.executeMethod(theMethod);

            public static void doAuthorization(HttpClient httpclient, HttpMethod method)

              {

              httpclient.getState().setCredentials(

                  new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM),

                  new UsernamePasswordCredentials("bpmuser", "bpmuser123$")

                      );

                      method.setDoAuthentication(true);

                    

                    

              }

            • 3. Re: call jBPM6 webservice using REST API
              mateuszadamiak

              I am not an expert, but I also struggle with calling a REST API. In your case it is probably because you use BASIC authentication, and you should authenticate by FORM one (j_security_check).

               

              In my case using kie-services-client works, but only in standalone application. When I execute the same piece of code in web application deployed on JBoss, I've got the java.lang.LinkageException as the implementation of org.apache.httpcomponents in kie-services-client is different than provided in the container (at least I think that's the reason) and so far I did not resolve the problem.

              • 4. Re: call jBPM6 webservice using REST API
                swiderski.maciej

                to be able to use the REST api please make sure that you set preemptive authentication on your http client, that means that client will send authentication data before it gets challenged to do so and that should solve the issue.

                 

                HTH

                • 5. Re: call jBPM6 webservice using REST API
                  swiderski.maciej

                  have you tried to exclude one of these libraries? Either exclude it from your web application or use jboss-deployment-structure.xml to exclude module provided by container. This has been recently reported to be an issue when using JBoss modules and should be addressed for next version which I believe will be excluding one of the dependencies.

                   

                  HTH

                  • 6. Re: call jBPM6 webservice using REST API
                    enriquezrene

                    Hi Maciej

                     

                    I was trying to use the REST API in jBPM6 from an angular.js application, however I'm near a month working on it and I have a mistake with the authentication

                    Do you how I can invoke a REST service, for example http://IP:8080/business-central/rest/task/query using this approach

                     

                    My code snnipet is here:

                     

                        $http.defaults.headers.common.Authorization = 'Basic bXNpdDptc2l0LTIwMTQ=';

                     

                        $http.get("http://localhost:8080/business-central/rest/task/query").success(function(data){

                            $scope.tasks = data;

                        }).error(function(data, status, headers, config){

                            alert('error');

                        });

                     

                    I'm always receiving an error message

                     

                    Exist a way to use this approach or is not possible to use angular to create the front end, thanks

                    • 7. Re: call jBPM6 webservice using REST API
                      swiderski.maciej

                      it is certainly possible, the most important is that jBPM rest api requires preemptive authentication. meaning header info must be present in the first request, there is no negotiation involved.

                      If you have any sample app to try out I could take a look.

                       

                      HTH