Tuesday 24 January 2012

Oracle SOA Suite 11g – Scheduling the composites using Quartz scheduler

Oracle SOA Suite 11g – Scheduling the composites using Quartz scheduler.

This blog will explain the approach to schedule the composites using the Quartz scheduler.
1. Create the ADF binding to the composite.xml
Open the composite xml
Copy the service section and give a unique name e.g. bpelhelloworld_client_adf and also make sure the ServiceName specified is correct.

Copy the client partnerlink wire and edit the name of the copied wire as adf service name specified in the previous step.

Open the design mode and verify the wires.

2. Create the JOB class that invokes the composite service.
Create the JOB class as shown below to invoke the composite service, change the soa server details and the composite details accordingly.
package javaschedule;
import java.util.Hashtable;
import java.util.UUID;
import java.util.logging.Logger;
import oracle.soa.management.facade.*;
import javax.naming.Context;
import oracle.soa.management.util.*;
import oracle.fabric.common.NormalizedMessage;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
public class BPELHelloWorldJob implements Job {
Logger logger;
public BPELHelloWorldJob() {
logger = Logger.getLogger(this.getClass().getName());
}
public void execute(JobExecutionContext jobExecutionContext) {
try {
System.out.println("initiated");
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL, "t3://soahost:soaport/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxxxxx");
jndiProps.put("dedicated.connection", "true");

Locator locator = null;

String inputPayload ="<ns1:process xmlns:ns1=\"http://xmlns.oracle.com/JavaSchedule/BPELHelloWorld/BPELHelloWorld\"><ns1:input>Albin</ns1:input></ns1:process>";
locator = LocatorFactory.createLocator(jndiProps);
// find composite
Composite composite = locator.lookupComposite("default/BPELHelloWorld!1.0");

System.out.println("Got Composite : "+ composite.toString());

// find exposed service of the composite
Service service = composite.getService("bpelhelloworld_client_adf");
System.out.println("Got serviceName : "+ service.toString());
// make the input request and add this to a operation of the service
NormalizedMessage input = new NormalizedMessageImpl();
// payload is the partname of the process operation
input.getPayload().put("payload",inputPayload);
// process is the operation of the employee service


service.post("process", input);

} catch (Exception e) {
e.printStackTrace();
}
logger.fine("Call HelloWorld BPEL Process Finished");
}
}


3. Create the client that schedule the JOB
Change the cron expression accordingly to change the scheduling period.


package javaschedule;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory;
public class ProcessScheduler {
public ProcessScheduler() {

try {

StdSchedulerFactory schedFact = new StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
System.out.println(sched);
sched.start();
JobDetail jd =new JobDetail("BPEL Hello World Job", "BPEL Job", BPELHelloWorldJob.class);
CronTrigger cronTrigger =new CronTrigger("BPEL Hello World Job", "BPEL Job");
String cronExpr = null;
//every five min
cronExpr ="0 0/5 * * * ?";
cronTrigger.setCronExpression(cronExpr);
sched.scheduleJob(jd, cronTrigger);

} catch (Exception e) {
e.printStackTrace();

}
}
public static void main(String[] args) {
ProcessScheduler cl=new ProcessScheduler ();
System.out.println("Scheduled JOB");
}

}


4. Execute the client – java javaschedule .ProcessScheduler, this will schedule the JOB every 5 minutes to invoke the composite service.

DOWNLOAD SAMPLE

1 comment:

  1. Hi

    Can you please explain how we can schedule service in 10g ? (10.1.1.3)

    Thanks,
    Phani

    ReplyDelete

xslt padding with characters call template for left pad and right pad

  Could a call-template be written that took two parameters ?   a string, and a   number) return the string with empty spaces appended t...