Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
abhijeet_mukkawar
Active Contributor

1.

Introduction:

It has always been a bit of struggle when it comes to schedule a NW BPM process that should run at a specific time. Though, in the absence of any external system or job scheduler, we can do it in process modeling as shown in Schedule your NW BPM Process, having a way to schedule it as a job in NWA ->Job Scheduler would give us better control in terms of monitoring all the jobs and related logs.

This can be achieved using message-driven bean (MDB) class where we can code a job definition that in turns calls the web service which can trigger a BPM  process.

The job definition created can then be scheduled as a normal job in NWA -> Job Scheduler to make it run at specific interval.

Prerequisite:

The simple steps required for scheduling the NW BPM process involves a bit of message bean code and a typical BPM process triggered by a Web Service.

Hence, knowledge of J2EE message beans, creating jobs using message bean, basic NW BPM along with NWA access is required.

Scenario:

The scenario is to schedule a process having single automated activity – lets call it Syndicate Records activity - with web service trigger to run at specified interval of time.

Implementation:

1.    1. Create a process with a single automated activity and a web service trigger. Start event maps the output to a similar structured DO. Timer here just produces some delay so we can see the process in Process Repository.

2. Deploy the Process DC and assign provider system to the web service.

2.     3. Next, create an ejb project( here it’s : loc_ejb_syndicatejob) with a build time reference to “tc/je/scheduler/api”.

  

      (For the purpose of keeping the document concise we will not go through every step of creating it. You can find details steps for creating Job bean class at    http://help.sap.com/saphelp_nwce72/helpdata/en/4a/64bbfc49332af4e10000000a42189c/content.htm . It is recommended to go through the steps to know it better as we are not covering it in details).

4. Create a new message bean (here it’s : SyndicateJobBean) with MDMJobImplementation as a superclass. Remove “MessageListener” interface from the  interfaces. The created JobBeans has a single business method, which is onJob() method. The MessageDrivenannotation declares the bean as a message-driven bean. Change the configuration in MessageDriven annotation as below.

The bean class should look like as below:

/**

* Message-Driven Bean implementation class for: SyndicateJobBean

*

*/

@MessageDriven(

            activationConfig = {@ActivationConfigProperty(

                        propertyName="messageSelector",

                        propertyValue="JobDefinition='SyndicateJob'"),

                  @ActivationConfigProperty(

                        propertyName = "destinationType", propertyValue = "javax.jms.Queue"

            ) })

public class SyndicateJobBean extendsMDBJobImplementation {

      

    /**

     * @see MDBJobImplementation#MDBJobImplementation()

     */

    publicSyndicateJobBean() {

        super();

        // TODO Auto-generated constructor stub

  }

     

    public voidonJob(JobContext ctx) {}

      /**

     * @see MessageListener#onMessage(Message)

     */

//    public void onMessage(Message message) {

//        // TODO Auto-generated method stub

//       

//    }

}

In Job Bean class, the onJob() method replaces the onMessage() method, which is the standard business method of message-driven beans. Job Bean  class extends MDBJobImplementation class which provides implementation of the onMessage() method, hence please do not implement onMessage() method in the bean class. Perhaps you can comment it as shown above.

propertyValue="JobDefinition='SyndicateJob' defines 'SyndicateJob' as the name of Job that will appear in  “Job Definition” in NWA. (You can have as many names as you want for the same JobBean Class.)

3.     5. Create a wrapping Enterprise Application (here it's : loc_ear_syndicatejob) to deploy the ejb. At the end, you should have your ejb structure as below

  1. Add "job-definition.xml" file to ejb dc in META-INF which will hold the reference of the job.                                         The ejb structure should look like :  
  2. Also modify the ejb-j2ee-engine.xml of the ejb dc with reference of the SyndicateJobBean class as shown here.
  3. Modify the deployment descriptor of ear dc to refer to ejb jar (you need to build ejb to generate jar) as :
  4. Now get the WSDL URL of the Process DC from NWA -> SOA Management ->  Application and Scenario Communiction -> Single Service Administration.
  5. In the context menu of the EJB DC, choose Import --> Import --> Expand Web services and choose WSDL --> Choose Next. In the WSDL Import Wizard, choose Remote Location/File System and click Next, Enter the URL of the Web service and choose Finish.

      

    Below screen shot shows the EJB DC structure after the WSDL file is imported into it.

  8. Now we have to create the proxy client for the web service. Expand your EJB DC. In the context menu of the imported root WSDL file, choose Web Services   --> Generate Client, keep the slider at “Deploy Client”, ensure that correct EAR application is selected,

   

Choose Next -> Specify JAX-WS customization files and Finish. This will generate the proxy class that will be used to execute the web service.

9. Now implement the onJob() method as shown below to execute the web service.

     public voidonJob(JobContext ctx) {

       

         Logger logger = ctx.getLogger();

         logger.info("Job execution started... ");

       

        try {

        // Create a URL pointer to the WSDL location

        URL wsdlLocation = new URL(<WSDL Url>);

        // Instantiate ProxyClass object with above URL pointer, service name and namespace

        StartJobScheduleProcess_Service serviceWS = newStartJobScheduleProcess_Service(

                           wsdlLocation, newQName(<target namespace of WSDL>,<Service name>));

        // Get the SEI (Service Endpoint Interface) from the above Service Implementaion Object

        // This SEI can be used to execute the method defined in the Web Service

               StartJobScheduleProcess serviceInt = serviceWS.getStartJobScheduleProcessSOAP();

              

        // If the Service demands user authentication, BindingProvider interface to be used to access

    // the protocol with authentication info 

        // and associated context objects for request and response message processing.

             ((BindingProvider) serviceInt).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, <User ID>);

             ((BindingProvider) serviceInt).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, <Password>);

       // Instantiate service parameters and execute the operation

               NewComplexType newComplexType = newNewComplexType();

               newComplexType.setCtxId("1");

               newComplexType.setCtxPrcName("Schedule Job Process");

               serviceInt.newOperation(newComplexType);

              

               logger.info("Job execution completed... ");          

              

         } catch (Exception e) {

       // TODO Auto-generated catch block

                   logger.info("exception in WS call"+ e.getMessage());

               e.printStackTrace();

         }   

    }

    

         Logger class is used to log info and keep track of the execution which also helps in tracing in case anything goes wrong. In our example, we are printing “Job execution started..” and “Job execution completed...” in logs to know successful execution of code.

9.     

        10. Build the EJB and EAR DCs and deploy.

10.    11. Go to NWA - > Operations Management -> Jobs -> Java Scheduler, On Job Definition tab, you can find the above created job i.e. SyndicateJob.

      

11.   12. Create a new task with above – “Syndicate Job” – job, and set its execution time -> Add and Finish.

        

12.   13. You can now see if the job is executed in Jobs tab at spcecified time. You can check the logs tab in details to see if messages are written by the Logger. As both messages are written, the code to execute web services is executed succesfully.

     

14.  14.  Subsequently, check the started process in process repository and its context details to ensure they are same as passed from bean class.

      

         This way we can schedule NW process in central Job Scheduler in NWA.

7 Comments
Labels in this area