1 2 Previous Next 21 Replies Latest reply on Nov 4, 2013 10:43 AM by bennixview Go to original post
      • 15. Re: Process Parameters through REST API?
        Thomas Setiabudi Expert

        Hi Mai A. S,

         

        Sorry it took so long time to reply, here are the requestGetService and authenticate functions

         

        public String authenticate(String address, String username, String password) {
          String responseString = "";
          List<NameValuePair> formparams = new ArrayList<NameValuePair>();
          formparams.add(new BasicNameValuePair(KEY_USERNAME, username));
          formparams.add(new BasicNameValuePair(KEY_PASSWORD, password));

          HttpPost httpPost = new HttpPost("http://" + address
            + "/gwt-console-server/rs/process/j_security_check");
          InputStreamReader inputStreamReader = null;
          BufferedReader bufferedReader = null;

          try {
           UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams,
             "UTF-8");// UrlEncodedFormEntity(formparams,
                // "multipart/form-data");
           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);
          } finally {
           if (inputStreamReader != null) {
            try {
             inputStreamReader.close();
            } catch (Exception e) {
             throw new RuntimeException(e);
            }
           }
           if (bufferedReader != null) {
            try {
             bufferedReader.close();
            } catch (Exception e) {
             throw new RuntimeException(e);
            }
           }
          }

          return responseString;
        }

         

        public String requestGetService(String url, Map<String, Object> parameters,
           boolean multipart) {
          String responseString = "";
          MultipartEntity multiPartEntity = new MultipartEntity(
            HttpMultipartMode.BROWSER_COMPATIBLE);
          List<NameValuePair> formparams = new ArrayList<NameValuePair>();
          if (parameters == null) {
           parameters = new HashMap<String, Object>();
          }
          Set<String> keys = parameters.keySet();
          for (Iterator<String> keysIterator = keys.iterator(); keysIterator
            .hasNext();) {
           String keyString = keysIterator.next();
           String value = parameters.get(keyString).toString();
           formparams.add(new BasicNameValuePair(keyString, value));
           if (multipart) {
            try {
             StringBody stringBody = new StringBody(value, "text/plain",
               Charset.forName("UTF-8"));
             multiPartEntity
               .addPart(keyString, (ContentBody) stringBody);
            } catch (Exception e) {
             throw new RuntimeException(e);
            }
           }
          }

          HttpGet httpPost = new HttpGet(url);

          InputStreamReader inputStreamReader = null;
          BufferedReader bufferedReader = null;
          try {
           if (multipart) {
            // httpPost.setEntity(multiPartEntity);
           } else {
            // UrlEncodedFormEntity entity = new UrlEncodedFormEntity(
            // formparams, "UTF-8");// UrlEncodedFormEntity(formparams,
            // "multipart/form-data");
            // 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);
          } finally {
           if (inputStreamReader != null) {
            try {
             inputStreamReader.close();
            } catch (Exception e) {
             throw new RuntimeException(e);
            }
           }
           if (bufferedReader != null) {
            try {
             bufferedReader.close();
            } catch (Exception e) {
             throw new RuntimeException(e);
            }
           }
          }
          return responseString;

        }

         

         

        • 16. Re: Process Parameters through REST API?
          satish babu Newbie

          Hi Thomas,

           

          I am trying with ur code to pass parameters to the process

           

          Rnder URL working fine.

           

          "http://localhost:8080/gwt-console-server/rs/form/process/{id}/render"

           

          when i am hitting the Authentication URL it is showing the problem like this

           

          The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser

           

          Following is the console Log

           

          <html><head><title>Apache Tomcat/6.0.35 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 408 - The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser</u></p><p><b>description</b> <u>The client did not produce a request within the time that the server was prepared to wait (The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser).</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.35</h3></body></html>

           

           

          My Authendication URL is

           

          "http://localhost:8080/gwt-console-server/rs/identity/secure/j_security_check"

           

          Can u help on this.

           

          Regards

          Satish

          • 17. Re: Process Parameters through REST API?
            bennixview Newbie

            I have got the following error (HTTP Status 415 - Cannot consume content type):

             

            <html><head><title>JBoss Web/7.0.17.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 415 - Cannot consume content type</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Cannot consume content type</u></p><p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Cannot consume content type).</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.17.Final</h3></body></html>

             

            Any suggestion?

            • 18. Re: Process Parameters through REST API?
              Thomas Setiabudi Expert

              HI Benjamin Wirtz,

               

              What version of JBPM5 are you using?

               

              Maybe its better to make a new forum post about this?

               

              Regards,

              Thomas Setiabudi

              • 19. Re: Process Parameters through REST API?
                bennixview Newbie

                JBoss 7.1.3. / jbpm 5.4

                 

                It works now!

                 

                I exactly do what you said in your post :

                 

                1.

                requestGetService(urlRender, null, false);

                  if (responseString.contains("<html>")) {
                   responseString = authenticate(authUrl, "krisv", "krisv");

                   responseString = requestGetService(urlRender, null, false);
                  }

                 

                  Map<String, Object> map = new HashMap<String, Object>();
                  map.put("employee", "thomas");
                  map.put("reason", "theReason");

                 

                responseString = requestPostMultipartService(urlComplete, map);
                  if (responseString.contains("<html>")) {
                   responseString = authenticate(authUrl, "krisv", "krisv");
                   responseString = requestPostMultipartService(urlComplete, map);
                  }

                 

                :-) THX

                 

                p.s.: In you code example you used "address" for a authentication and complete but that different urls.

                 

                 


                • 20. Re: Process Parameters through REST API?
                  ayman shahrour Newbie

                  Hello ,

                   

                  I have the same issue here,

                   

                  Any Idea in how to start a process with parameters and getting the instance ID?

                   

                  Please Help.

                   

                  Thanks,

                  • 21. Re: Process Parameters through REST API?
                    bennixview Newbie

                    org.jbpm.integration.console.ProcessManagement ->

                      ProcessInstanceRef newInstance(String definitionId, Map<String, Object> processVars);

                    1 2 Previous Next