job scheduling from web dynpro java for ce 7.1 using java scheduler api and ejb3.0 (1)
TRANSCRIPT
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 1/16
ILL BE Job Scheduling from WebDynpro Java for CE 7.1 Using JavaScheduler API and EJB3.0
Appl ies to:
SAP NetWeaver 7.1, Web Dynpro for java, JEE 5, Java Scheduler. For more information, visit the UserInterface Technology homepage.
Summary
A new job scheduler is now available as part of the SAP NetWeaver Application Server, Java EE 5 Edition.
Using EJB 3.0 job is implemented as Message-Driven Bean (MDB), which is invoked using Java MessageService (JMS) technology.
Using scheduler API we can create tasks and set the job parameters through Web Dynpro.
Author : Snehal Kendre
Company: L&T Infotech
Created on: 08 October 2008
Author Bio
Snehal Kendre is an Web Dynpro consultant at L&T Infotech.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 1
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 2/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Table of Contents
Getting started ....................................................................................................................................................3
Scenario .......................................................................................................................................................... 3
Creating an EJB 3.0 project................................................................................................................................3
Developing Job Bean class.............................................................................................................................5
Deploy EAR application project. .....................................................................................................................8
See The Job Definition in Java scheduler....................................................................................................................8
Implementation of Web Dynpro project ..............................................................................................................9
Implementation of SchedulerCompView......................................................................................................................9
Deploy and run Web Dynpro project.............................................................................................................13
Run the Application...........................................................................................................................................13
Task information in Java Scheduler .................................................................................................................14
Successful execution of job........................................................................................................................................14
Related Content................................................................................................................................................15
Disclaimer and Liability Notice..........................................................................................................................16
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 2
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 3/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Getting started
Here we are going to create an EJB 3.0 project that includes a job bean.
The scheduler runtime service provides certain basic services to the job implementation. That is why, theJobBean class cannot implement the onMessage() method, which is the standard business method ofmessage-driven beans. JobBeans have a single business method, the onJob() method. In the JobBeanclass, you must provide an implementation of the onJob() method. The JobBean inherits from anMDBJobImplementation base class which itself provides an implementation of the onMessage() method.
To set the job parameters and schedule we will create a Web Dynpro project
Scenario
We will create a job using job beans which is nothing but a message-driven bean inheritedfrom an MDBJ obI mpl ementat i on base class.
A web Dynpro project will provide basic functionality to schedule a job and to set the job parameters.
Creating an EJB 3.0 project
Open JEE perspective. Create a new EJB project as we_JobEJB
Create an EAR Application project ja_JobEAR
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 3
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 4/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Select the project facets
Add we_JobEJB into ja_JobEAR
Choose the project facets for EJB project
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 4
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 5/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Developing Job Bean class
First add tc~je~scheduler~api~jar as an external jar in build path of we_JobEjb
Create a new message driven bean JobBean
Use javax.jm.queue as JMS destination type
Select MDBJ obI mpl ement at i on as a supercalss for jobbean
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 5
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 6/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
And say finish.
Implementation of ejb-j2ee-engine.xml
Write down the JobBean specific settings in ej b- j 2ee- engi ne. xml
<?xml versi on="1. 0" encodi ng="UTF- 8"?>
<ej b- j 2ee- engi ne
xml ns: xsi ="htt p: / / www. w3. org/ 2001/ XMLSchema- i nstance">
<ent erpr i se- beans>
<ent erpr i se- bean>
<ej b- name> J obBean</ ej b- name>
<j ndi - name> J obBean</ j ndi - name>
<message- props>
<dest i nat i on- name> J obQueue</ dest i nat i on- name>
<connect i on- f act ory- name>
J obQueueFact ory
</ connect i on- f actory- name>
</ message- props>
</ ent er pr i se- bean>
</ ent erpri se- beans>
</ ej b- j 2ee- engi ne>
Create new xml for job information as j ob- def i ni t i ons. xml
< j ob- def i ni t i ons>
< j ob- def i ni t i on name="Schedul eJ ob"
descri pt i on="sampl e j ob for t est i ng">
< j ob- def i ni t i on- paramet er name="User"
data- t ype="St ri ng"
di rect i on="I N"/ >
</ j ob- def i ni t i on> </ j ob- def i ni t i ons>
Implementation of JobBean
/**
*
*/
package com.sap.jobbean;
import java.util.logging.Logger;
import javax.jms.MessageListener;
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 6
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 7/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
import com.sap.scheduler.runtime.JobContext;
import com.sap.scheduler.runtime.JobParameter;
import com.sap.scheduler.runtime.mdb.MDBJobImplementation;
import javax.ejb.MessageDriven;
import javax.ejb.ActivationConfigProperty;
/**
* @author Snehal Kendre
*
*/
@MessageDriven(
//TODO The JMS destination name (mapped name) must correspond to the resource name in the jms-
resources.xml
name="JobBean", mappedName="MyDestination",
activationConfig={@ActivationConfigProperty(
propertyName="messageSelector",
propertyValue="JobDefinition='Schedule_JobBean'"),@ActivationConfigProperty(propertyName="de
stinationType", propertyValue="javax.jms.Queue")})
public class JobBean extends MDBJobImplementation implements MessageListener {
/* (non-Javadoc)
* @see
com.sap.scheduler.runtime.mdb.MDBJobImplementation#onJob(com.sap.scheduler.runtime.JobContext)*/
@Override
public void onJob(JobContext arg0) throws Exception {
// TODO Auto-generated method stub
JobParameter parameter = arg0.getJobParameter("User");
Logger logger = arg0.getLogger();
logger.info("Hi"+parameter+"your job is scheduled");
}
}
Implementation of the application-j2ee-engine.xml from ja_JobEAR
<?xml versi on="1. 0" encodi ng="UTF- 8"?> <appl i cat i on- j 2ee- engi ne xml ns: xsi ="htt p: / / www. w3. org/ 2001/ XMLSchema- i nst ance">
<provi der- name>sap. com</ provi der - name>
<r ef erence r ef erence- t ype="hard">
<r ef erence- t arget pr ovi der- name="sap. com" t ar get- t ype= "ser vi ce">
schedul er~r unt i me
</ r ef er ence- t ar get >
</ r ef erence>
<modul es- addi t i onal >
<modul e>
<ent r y- name>we_J obBean. j ar</ ent r y- name>
<cont ai ner- t ype>schedul er~cont ai ner </ cont ai ner- t ype>
</ modul e>
</ modul es- addi t i onal > </ appl i cat i on- j 2ee- engi ne>
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 7
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 8/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Deploy EAR application project.
Open the server view
Add the EAR application project
And finish it.
See The Job Definition in Java scheduler
We can see our job definition in SAP NetWeaver Administrator.
http://<hostname>:<port>/nwa
Operation Management-> Jobs
Click on Job Definitions
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 8
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 9/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Implementation of Web Dynpro project
Open web Dynpro development perspective and create a new project dp_SchedulerApp.
Create an application.
Create New components as SchedulerComp with window SchedulerWindow and SchedulerCompView.
First add tc~je~scheduler~api~jar as an external jar in build path
Implementation of SchedulerCompView.
Create a New simple type Months
With following Enumerations
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 9
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 10/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Create context for scheduler options as follow
Assign simple type Months to the ctx_va_Month, String type to ctx_va_user and assign Integer to othercontext.
Create a form to take inputs from user. For this use apply template.
Say finish and create a form.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 10
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 11/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Create an action button to submit information to java scheduler.
Apply action button template.
Implement onActionSchedule() as follow
public void onActionSchedule(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent
wdEvent )
{
//@@begin onActionSchedule(ServerEvent)
Scheduler syncscheduler;
try {
InitialContext ctx = new InitialContext();
syncscheduler = (Scheduler)ctx.lookup("scheduler");
JobDefinition syncdef =
syncscheduler.getJobDefinitionByName("Schedule_JobBean");
// SchedulerTaskID taskid = new SchedulerTaskID(2);
wdComponentAPI.getMessageManager().reportSuccess(syncdef.getDescription());
Job syncjob;
java.util.Calendar calendar = java.util.Calendar.getInstance ();
calendar.set(Calendar.YEAR ,
wdContext.currentContextElement().getCtx_va_year());
calendar.set(Calendar.MONTH ,wdContext.currentContextElement().getCtx_va_Month()-1);
calendar.set(Calendar.DAY_OF_MONTH ,
wdContext.currentContextElement().getCtx_va_day());
calendar.set(Calendar.HOUR_OF_DAY ,
wdContext.currentContextElement().getCtx_va_hour());
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 11
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 12/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
calendar.set(Calendar.MINUTE ,
wdContext.currentContextElement().getCtx_va_min());
java.util.Date date = calendar.getTime();
wdComponentAPI.getMessageManager().reportSuccess("your task is scheduled
for date="+ date);
//Create SchedulerTime and pass to it the Calendar instance
SchedulerTime time = new SchedulerTime(date, TimeZone.getDefault ());
//Create RecurringEntry and pass to it SchedulerTime instance
RecurringEntry re = new RecurringEntry(time);
//Create a SchedulerTask for the HelloJob
// set job paramater
JobParameterDefinition user = syncdef.getParameter("User");
JobParameter userparameter = new
JobParameter(user,wdContext.currentContextElement().getCtx_va_user());
SchedulerTask task = new
SchedulerTask(SchedulerTaskID.newID (),syncdef.getJobDefinitionId(),new JobParameter[]
{userparameter},new RecurringEntry[] {re}, new CronEntry[]
{},"Schedule_Job","scheduled by API");
syncscheduler.schedule(task);
//
task.createSchedulerTask(syncdef.getJobDefinitionId(),parm,recs,crons,filters,23,
"synctaskbywd","wd generated task",null);
// syncscheduler.schedule(task);
} catch (Exception e) {
// TODO Auto-generated catch block
wdComponentAPI.getMessageManager().reportException("problem in
scheduler",true);
}
//@@end }
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 12
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 13/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Deploy and run Web Dynpro project
Build project and create its archive
Deploy and run the application
Run the Application
Run the application in browser.
Get the confirmation after scheduling the job.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 13
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 14/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Task information in Java Scheduler
We can see our job definition in SAP NetWeaver Administrator.
http://<hostname>:<port>/nwa
Check the scheduled task in Java Scheduler
Successful execution of job
Check log
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 14
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 15/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
Related Content
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10fed553-0e01-0010-9bb8-ed55659e1236
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8ab5056-0e01-0010-5581-d3e51724ee21
http://help.sap.com/saphelp_nwce10/helpdata/en/44/03d66015ee10b3e10000000a11466f/frameset.htm
For more information, visit the User Interface Technology homepage.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 15
8/17/2019 Job Scheduling From Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0 (1)
http://slidepdf.com/reader/full/job-scheduling-from-web-dynpro-java-for-ce-71-using-java-scheduler-api-and 16/16
ILL BE Job Scheduling from Web Dynpro Java for CE 7.1 Using Java Scheduler API and EJB3.0
SAP DEVELOPER NETWORK | d BUSINESS PROCESS EXPERT COMMUNITY | b
Disclaimer and Liabili ty Notice
This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is notsupported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article orcode sample, including any liability resulting from incompatibility between the content within this document and the materials andservices offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of thisdocument.