Click here to load reader
Upload
trankiet
View
214
Download
1
Embed Size (px)
Citation preview
http://oraclearchworld.wordpress.com/
Integrating Java and Oracle SOA Suite By Kathiravan Udayakumar
As most the readers are aware, Java is widely adopted along language which has wide variety of components available for enterprises to consume. Oracle is thoughtful about this and provided the handful number of features to integrate this language in Oracle SOA Suite.
S.No Component Feature
1 BPEL Java Embedding
2 Mediator Java Callout
3 Business Rules Java Facts
4 B2B Java Callout
Java Embedding in BPEL Java code can be integrated with BPEL using the Oracle BPEL Extension Constructs. This construct helps to write a simple Java code to be used along with BPEL. This feature is very useful to reuse the rich set of Java libraries for various operations to be performed on the data. The screenshot below shows the Java Embedding Activity from Oracle Extension Pane
The screenshot below shows the Java Embedding in BPEL Process.
The screenshot below shows the Java Embedding in BPEL Process
Listing A: Java embedding calling a session bean (EJB) deployed in Weblogic Server along with SOA Suite is shown below
try {
Object. homeObj = lookup("ejb/session/Employee");
Class cls = C1ass.fiorName("com.pcktpub.samples. sessionbean.EmployeeServiceHome") ;
Emp1oyeeServiceHome sa1aryHome = (Emp1oyeeServiceHome) Portab1eRemoteobject.narrow(homeObj ,c1s) ;
if Isa1aryHome == null] {
addAuditTrailEntry("Failed to lookup 'ejb.session.Employee "
+ ". Ensure that the Employee Bean has been Deployed Successfully");
return;
}
Employeefiervice salaryService = sa1aryHome.create();
Element. ssn = (E1ement)getVariah1eData("input", "payload", "/ssn");
int salary = sa1aryService.get.Sa1ary(ssn.getNodeVa1ue());
addAuditTrai1Entry("Salary is: " + salary);
setVariabeData("output" , "payload" , "/tns: salary", new Integer (salary)) ;
} catch (NamingException ne) {
addAuditTrailEntry(ne);
} catch (C1assNotFoundException cnfe) {
addAuditTrailEntry(cnfe);
} catch (CreateException ce) {
addAuditTrailEntry(ce);
} catch (RemoteException ce) {
addAuditTrailEntry(ce);
}
Note: If you are using any custom java class file, it should be available in below path for SOA Runtime to access it. Design time should also have access it from JDeveloper
The following table illustrates the lists of bpelx:exec built-in methods that you can use to read and update scope variables, instance metadata, and audit trails:
S.No Features Function
1 JNDI access Object lookup(String name)
2 Oracle BPEL process manager locator
Locator getLocator()
3 Unique ID associated with each instance
long getInstanceId()
4 Set the title of this BPEL instance
String setTitle(String title)
String getTitle()
5 Status of this instance String setStatus(String status)
String getStatus()
6 Set the composite instance title
void setCompositeInstanceTitle(String title)
7 Set the indexes that can be used for search
void setIndex(int i, String value)
String getIndex(int i)
8 Priority void setPriority(int priority)
intgetPriority()
9 Set and get the creator of the BPEL instance
void setCreator(String creator)
String getCreator()
10 Metadata for generating lists
void setMetadata(String metadata)
String getMetadata()
11 Access preference String getPreference(String key)
12 Add an entry to the audit trail
void addAuditTrailEntry(String message, Object detail)
void addAuditTrailEntry(Throwable t)
13 Access and update variables stored in the scope
Object getVariableData(String name) throws BPELFault
Object getVariableData(String name, String part_Or_Query) throws BPELFault
Object getVariableData(String name, String part, String query)
14 Set variable data void setVariableData(String name, Object value)
void setVariableData(String name, String part, Object value)
void setVariableData(String name, String part, String query, Object value)
Note: It is not recommended implement most of the business logic using Java Embedding. It is recommended to use Java Embedding as a utility to extend the features from Java.
Java Callout in Mediator Additional Messages Processing can be accomplished using Java Callout feature provided by
Mediator. Java class should extend the AbstractJavaCalloutImpl which implements the
oracle.tip.mediator.common.api.IjavaCallout interface. The snapshot below shows the mediator configuration with java callout for post processing of messages.
Listing B: The below code listing contains the custom Mediator callout calls.
package xcom.mediator.callout;
import oracle.tip.mediator.common.api.*;
import oracle.tip.mediator.common.api.AbstractJavaCalloutImpl;
public class mediatorCallout extends AbstractJavaCalloutImpl
{
@Override //Java 1.5 Constructs
public boolean postRouting(CalloutMediatorMessage calloutMediatorMessage1,CalloutMediatorMessage calloutMediatorMessage2,
Throwable throwable) throws MediatorCalloutException
{
System.out.println("Mediator has invoked Java Callout; executing postRouting");
boolean returnValue;
returnValue =super.postRouting(calloutMediatorMessage1, calloutMediatorMessage2,throwable);
return returnValue;
}
}
Java Callout in B2B Oracle B2B Product provides the required features to execute extended functions and operation through Java Callout. Java class can be configured as a transport callout and be associated with Channel. Java class should implement the Callout interface.
Listing C: The below code listing contains the custom B2B Callout.
import java.io.FileInputStream;
import java.util.List;
import java.util.Properties;
import oracle.tip.b2b.callout.Callout;
import oracle.tip.b2b.callout.CalloutContext;
import oracle.tip.b2b.callout.CalloutMessage;
import oracle.tip.b2b.callout.exception.CalloutDomainException;
import oracle.tip.b2b.callout.exception.CalloutSystemException;
import oracle.tip.b2b.domain.B2BParameters;
import oracle.tip.b2b.system.B2BRuntimeException;
import oracle.tip.b2b.system.ErrorKeys;
public class B2BCalloutImplementation implements Callout {
public void execute(CalloutContext calloutContext, List input, List output)
throws CalloutDomainException, CalloutSystemException
{
try
{
System.out.println("B2BCalloutImplementation");
CalloutMessage message = new CalloutMessage();
Properties properties = new Properties();
properties.put("FROM_PARTY", "MarwInc");
properties.put(B2BParameters.TO_PARTY, "Host");
properties.put(B2BParameters.DOCTYPE_NAME, "851");
properties.put(B2BParameters.DOCTYPE_REVISION, "5010X092A1");
message.setParameters(properties);
FileInputStream inStream = new FileInputStream("/in/851.dat");
byte[] content = new byte[inStream.available()];
inStream.read(content);
inStream.close();
message.setBody(content);
output.add(message);
}
catch(Exception e)
{
new B2BRuntimeException(ErrorKeys.B2B_RUNTIME_ERROR, e);
}
}
}