Comments by Ed (Best viewed with non-IE browser such as FireFox, Mozilla or Chrome) --Ed.

Tuesday Mar 24, 2009

In this blog, we'll show how to get Scheduler BC to trigger a Stateless Session Bean (SLSB) deployed in a Java EE Service Engine.  I'm using GlassFish ESB v2.1 Milestone 1 Installer from here so YMMV if using a different version:

  1. Start a new EJB Module project:

  2. Enter Name and Location of EJB Module:

  3. Select the GlassFish Server and press Finish:

  4. Under the Source Packages node of the project, create a Scheduler WSDL Binding:

  5. Choose the SCHEDULER Binding Type and press Next:

  6. Add a new Simple trigger:

  7. Define the Simple Trigger:

  8. Ensure the appropriate Date Format is selected before pressing Finish:

  9. Under the Source Packages node, create a Web Service from WSDL:

  10. Specify the Name and Location step and browse for the Scheduler Binding WSDL created earlier:

  11. Remember to enter a Package name before pressing Finish:

  12. In the Java editor that appears, implement the method accordingly:

  13. Almost done, save everything and create a Composite Application project:

  14. Key in Project Name and press Finish:

  15. Drag the EJB Module project onto the CASA canvas and do a Build Project and afterwards, should look like this:

  16. Save everything, Deploy the Composite Application project, and you should get similar results:

Tuesday Mar 10, 2009

NOTE, the instructions here have been updated a little for GlassFish ESB v2.1 since its release.

A lot of the demos until this point have illustrated Scheduler BC consuming a BPEL SE, so how 'bout consuming a 'cup of Jo' instead?  POJO that is. 

We'll now show how to have Scheduler BC trigger a POJO SE to execute a Windows (2000, XP, Vista) command that pops up a dialog with some greeting.  Of course, you can adapt this to do more useful things like 'downloading a file from some remote site so that File BC can pick it up and send it to BPEL SE for processing'...but then that'll be work and fun is good!

Prerequisites: Scheduler BC now comes pre-installed with GF ESB v2.1, but you'll need to install POJO SE (installer here).

  1. Create a Java (SE) Application project, keeping the default Main class, although it won't be used here (but it's needed due to a POJO SE project idiosyncrasy):

  2. Right-click the schedpojodemo package and add a New | Other | ESB | POJO for Binding:

  3. Specify that the POJO SE is to work with Scheduler BC by:

  4. Select Next and Add a Simple Trigger:

    The Windows command chosen here in the trigger Message is long so you can copy it from here:

  5. Select Next and Choose Node for the Input Argument Type in the POJO method that will be doing the providing:

  6. Select Finish and in the SchedPojoBinding.java Java editor that shows up, fix the package import warning for Node (answer: org.w3c.dom.Node):

  7. Copy the imports below into the same class, pasting it before the first import statement that's already there:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Level;
                
  8. Copy the code below into the same class, pasting it just above the line that declares "private static final Logger logger":
        private void FireTriggerOperation(String input) {
            List args = new ArrayList();
            if (System.getProperty("os.name").toLowerCase()                 //NOI18N
                    .startsWith("windows")) {                               //NOI18N
                args.add("cmd.exe");                                        //NOI18N
                args.add("/c");                                             //NOI18N
            }
            args.add(input);
            ProcessBuilder procBuilder = new ProcessBuilder(args);
            try {
                Process proc = procBuilder.start();
                StreamEater stdOutEater =
                        new StreamEater(proc.getInputStream(), "StdOut");   //NOI18N
                StreamEater stdErrEater =
                        new StreamEater(proc.getErrorStream(), "StdErr");   //NOI18N
                stdOutEater.start();
                stdErrEater.start();
                int rc = proc.waitFor();
                logger.info("Command \"" + input + "\" exit code: " + rc);  //NOI18N
            } catch (IOException ex) {
                logger.log(Level.SEVERE, "Unknown command? " + input, ex);  //NOI18N
                return;
            } catch (InterruptedException ie) {
                logger.log(Level.WARNING, "Command aborted!");              //NOI18N
            }
        }
    
        private class StreamEater extends Thread {
    
            private BufferedReader rdr;
            private String name;
    
            public StreamEater(InputStream is, String name) {
                super(name + "-Eater");                                     //NOI18N
                rdr = new BufferedReader(new InputStreamReader(is));
                this.name = name;
            }
    
            @Override
            public void run() {
                String line = null;
                try {
                    while ((line = rdr.readLine()) != null) {
                        logger.info(name + "> " + line);                    //NOI18N
                    }
                } catch (IOException ex) {
                    logger.log(Level.SEVERE, "Problem reading " + name, ex);//NOI18N
                }
                try {
                    rdr.close();
                } catch (IOException ex) {
                    // ignore
                }
                rdr = null;
            }
        }
    
        public static void main(String[] args) throws Throwable {
            SchedPojoBinding spb = new SchedPojoBinding();
            spb.FireTriggerOperation("echo MsgBox \"Howdy, all's well!\", " //NOI18N
                    + "0, \"Scheduler POJO Demo\" > C:\\temp\\howdy.vbs & " //NOI18N
                    + "wscript.exe C:\\temp\\howdy.vbs");                   //NOI18N
        }
    
  9. In the FireTriggerOperation(Node inupt) method, add this call:

  10. From here on, it's pretty much mundane...Save this project and create a new Composite Application project
  11. Drag the SchedPojoDemo project into the Service Assembly canvas and do a Build Project
  12. Deploy the CASA project and voila, you got your popup!