9 Replies Latest reply on Jul 7, 2011 6:33 AM by Amit Shah

    deploy a procesee to jboss server suing java code

    Feng Qian Newbie

      Hi all,
      just have a question:
      I am working for importing jboss soa-p esb quick-start samples to eclipse. There is a sample named:bpm_orchestration1. It need call a jbpm process from esb service. Now it can run by ant. From the build.xml, I got this task to deploy a process to a server:

      <target name="deployProcess" description="deploys the process definition" depends="dependencies">
       <echo>Deploy the process definition</echo>
       <taskdef name="deployToServer" classname="org.jbpm.ant.DeployProcessToServerTask">
       <classpath refid="exec-classpath"/>
       </taskdef>
       <deployToServer username="${jbpm.console.username}" password="${jbpm.console.password}" serverDeployer="${org.jboss.esb.jbpm.console.upload.url}">
       <fileset dir="${basedir}/processDefinition" includes="*"/>
       </deployToServer>
      </target>


      Now I need to do this task using java code. I write this method:
      private void deployProcessToServer() {
       DeployProcessToServerTask deployTask = new DeployProcessToServerTask();
       deployTask.setProcess(new File("processdefinition.xml"));
       deployTask.setServerName("localhost");
       deployTask.setServerPort("8080");
       deployTask.setUsername("admin");
       deployTask.setPassword("admin");
       deployTask.setServerDeployer("/jbpm-console/app/upload");
       deployTask.execute();
      
       }


      When I run this method, I got a error:
      Exception in thread "main" couldn't deploy process archives : http://localhost:8080/jbpm-console/app/upload
      at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:179)
      at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.deployProcessToServer(SendTestMessage.java:65)
      at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.sendMessage(SendTestMessage.java:41)
      at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.main(SendTestMessage.java:72)
      Caused by: java.io.FileNotFoundException: http://localhost:8080/jbpm-console/app/upload
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1168)
      at org.jbpm.ant.DeployProcessToServerTask.deployProcess(DeployProcessToServerTask.java:224)
      at org.jbpm.ant.DeployProcessToServerTask.deployProcessWithServlet(DeployProcessToServerTask.java:188)
      at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:142)
      ... 3 more
      --- Nested Exception ---
      java.io.FileNotFoundException: http://localhost:8080/jbpm-console/app/upload
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1168)
      at org.jbpm.ant.DeployProcessToServerTask.deployProcess(DeployProcessToServerTask.java:224)
      at org.jbpm.ant.DeployProcessToServerTask.deployProcessWithServlet(DeployProcessToServerTask.java:188)
      at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:142)
      at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.deployProcessToServer(SendTestMessage.java:65)
      at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.sendMessage(SendTestMessage.java:41)
      at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.main(SendTestMessage.java:72)


        • 1. Re: deploy a procesee to jboss server suing java code
          Mauricio Salatino Master

          My first impresion is that your code have a wrong path to the upload server.. I do not know the SOA platform but i think the correct path is


          /jbpm-console/upload
          


          so try to change this line in your code:

          deployTask.setServerDeployer("/jbpm-console/app/upload");
          

          to
          deployTask.setServerDeployer("/jbpm-console/upload");
          


          if this is not the problem please let me know and we try to solve it together.
          Greetings!

          • 2. Re: deploy a procesee to jboss server suing java code
            Massimiliano Ziccardi Newbie

            If you need to deploy a process by code, you can use something like this:

            byte[] parBytes = readFully("yourfile.par");

            JbpmContext ctx = JbpmConfiguration.getInstance().createJbpmContext();
            new DeployProcessCommand(parBytes).execute(ctx);
            ctx.close();

            If you want to deploy a simple xml process definition, you can replace parBytes with a String containing your XML.

            Hope this helps.

            Massimiliano.

            • 3. Re: deploy a procesee to jboss server using java code
              Feng Qian Newbie

              Thanks. I know I should used /jbpm-console/upload, but if use /jbpm-console/upload, I got another error:

              Exception in thread "main" couldn't deploy process archives : null
              at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:179)
              at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.deployProcessToServer(SendTestMessage.java:65)
              at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.sendMessage(SendTestMessage.java:41)
              at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.main(SendTestMessage.java:72)
              Caused by: java.lang.NullPointerException
              at org.jbpm.ant.DeployProcessToServerTask.tryFormBasedAuthentication(DeployProcessToServerTask.java:276)
              at org.jbpm.ant.DeployProcessToServerTask.deployProcess(DeployProcessToServerTask.java:196)
              at org.jbpm.ant.DeployProcessToServerTask.deployProcessWithServlet(DeployProcessToServerTask.java:188)
              at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:142)
              ... 3 more
              --- Nested Exception ---
              java.lang.NullPointerException
              at org.jbpm.ant.DeployProcessToServerTask.tryFormBasedAuthentication(DeployProcessToServerTask.java:276)
              at org.jbpm.ant.DeployProcessToServerTask.deployProcess(DeployProcessToServerTask.java:196)
              at org.jbpm.ant.DeployProcessToServerTask.deployProcessWithServlet(DeployProcessToServerTask.java:188)
              at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:142)
              at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.deployProcessToServer(SendTestMessage.java:65)
              at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.sendMessage(SendTestMessage.java:41)
              at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.main(SendTestMessage.java:72)


              "salaboy21" wrote:
              My first impresion is that your code have a wrong path to the upload server.. I do not know the SOA platform but i think the correct path is


              /jbpm-console/upload
              


              so try to change this line in your code:

              deployTask.setServerDeployer("/jbpm-console/app/upload");
              

              to
              deployTask.setServerDeployer("/jbpm-console/upload");
              


              if this is not the problem please let me know and we try to solve it together.
              Greetings!


              • 4. Re: deploy a procesee to jboss server using java code
                Feng Qian Newbie

                Thanks!
                Using the method that you said need to set a jbpm runtime to the project in eclipse. But now my project only has jboss esb runtime and cann't set jbpm runtime. How can I get the jbpm runtime location?

                "ziccardi" wrote:
                If you need to deploy a process by code, you can use something like this:

                byte[] parBytes = readFully("yourfile.par");

                JbpmContext ctx = JbpmConfiguration.getInstance().createJbpmContext();
                new DeployProcessCommand(parBytes).execute(ctx);
                ctx.close();

                If you want to deploy a simple xml process definition, you can replace parBytes with a String containing your XML.

                Hope this helps.

                Massimiliano.


                • 6. Re: deploy a procesee to jboss server suing java code
                  Mauricio Salatino Master

                  If you add the jbpm-jpdl-xxx.jar to the dependencies I think you can compile this code.

                  • 7. Re: deploy a procesee to jboss server suing java code
                    Feng Qian Newbie

                    You means jbpm-jpdl.jar? I had added it to the dependencies. But I still get the error:

                    Exception in thread "main" couldn't deploy process archives : null
                    at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:179)
                    at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.deployProcessToServer(SendTestMessage.java:65)
                    at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.sendMessage(SendTestMessage.java:41)
                    at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.main(SendTestMessage.java:72)
                    Caused by: java.lang.NullPointerException
                    at org.jbpm.ant.DeployProcessToServerTask.tryFormBasedAuthentication(DeployProcessToServerTask.java:276)
                    at org.jbpm.ant.DeployProcessToServerTask.deployProcess(DeployProcessToServerTask.java:196)
                    at org.jbpm.ant.DeployProcessToServerTask.deployProcessWithServlet(DeployProcessToServerTask.java:188)
                    at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:142)
                    ... 3 more
                    --- Nested Exception ---
                    java.lang.NullPointerException
                    at org.jbpm.ant.DeployProcessToServerTask.tryFormBasedAuthentication(DeployProcessToServerTask.java:276)
                    at org.jbpm.ant.DeployProcessToServerTask.deployProcess(DeployProcessToServerTask.java:196)
                    at org.jbpm.ant.DeployProcessToServerTask.deployProcessWithServlet(DeployProcessToServerTask.java:188)
                    at org.jbpm.ant.DeployProcessToServerTask.execute(DeployProcessToServerTask.java:142)
                    at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.deployProcessToServer(SendTestMessage.java:65)
                    at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.sendMessage(SendTestMessage.java:41)
                    at org.jboss.soa.esb.samples.quickstarts.bpm_orchestration1.test.SendTestMessage.main(SendTestMessage.java:72)


                    I debug into the codes and found if we use '/jbpm-console/upload', in the tryFormBasedAuthentication() of DeployProcessToServerTask class,
                    Header location = loginFormPost.getResponseHeader("Location");

                    the location == null, so we get the NullPointerException.
                    if we use '/jbpm-console/app/upload',
                    the location is not null, but we will get
                    java.io.FileNotFoundException: http://localhost:8080/jbpm-console/app/upload error.


                    "salaboy21" wrote:
                    If you add the jbpm-jpdl-xxx.jar to the dependencies I think you can compile this code.


                    • 8. Re: deploy a procesee to jboss server suing java code
                      Massimiliano Ziccardi Newbie

                      From your stack trace, it seems to me you are still using the ANT TASK.

                      If you use the code I posted, you won't get ant tasks errors.

                      You just have to :

                      * Configure Hibernate so that it uses your database (hibernate.cfg.xml in your classpath)
                      * Configure JBPM (jbpm.cfg.xml in your classpath)
                      * Put JBPM libraries and Hibernate libraries in your classpath (WEB-INF/lib directory if you are creating a web application).

                      Then use this code:

                      byte[] parBytes = readFully("yourfile.par");
                      
                      JbpmContext ctx = JbpmConfiguration.getInstance().createJbpmContext();
                      new DeployProcessCommand(parBytes).execute(ctx);
                      ctx.close();
                      


                      Hope this helps.

                      • 9. Re: deploy a procesee to jboss server suing java code
                        Amit Shah Newbie

                        The primary issue is that you must be having spaces in the path where you have depoloyed runtime.Mine runtime path was

                         

                        C:\Documents and Settings\129608\jbpm-3.2.8

                         

                        and I changed the same to

                         

                        C:\jbpm-3.2.8 and it worked

                         

                        Refer to known issue

                         

                        https://issues.jboss.org/browse/GPD-385?page=com.atlassian.jira.plugin.ext.subversion%3Asubversion-commits-tabpanel