Friday, January 10, 2014

Initiating an OSB Service with Email

Initiating an OSB Service with Email

Email transport will help us to send/receive emails in OSB. Some cases we may required to initiate the external service based on the email in the user inbox.


The Proxy service polls the Mail Inbox for the new messages and invokes the Business service whenever there is a new message in the Inbox.The polling interval can be specified in the Proxy Service configuration.Here i will explain about invoking the service with the XML message received from the email body.

Invoking the service with the XML message received from the email body

Create a XSD message structure that will be used by Proxy Service to receive the message

<?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://xmlns.oracle.com/JEJBSample/EmployeeDetailService/EmployeeDetailService"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="EmployeeRequest">
<complexType>
<sequence>
<element name="empNo" type="string"/>
</sequence>
</complexType>
</element>
</schema>

Create a OSB project and create a Business service that needs to be invoked based on the Email content - Here i am invoking a sample BPEL service with the same XSD structure as input.

Create a Service Account with Static username/password of email user.




Tuesday, January 7, 2014

Exposing a OSB Proxy Service as EJB through JEJB transport

Exposing a OSB Proxy Service as EJB through JEJB transport

The JEJB transport lets you pass Plain Old Java Objects (POJOs) through Oracle Service Bus.To a J2EE client, a JEJB proxy service looks like a stateless session bean. A JEJB proxy service, on receiving the method arguments, passes their XML representation in the pipeline $body variable. POJO arguments are represented as the XML fragment. This XML fragment contains the location of the actual POJO stored in the object repository within the pipeline.

For deployment, Oracle Service Bus automatically packages JEJB proxy services as enterprise archives (EARs) and deploys to weblogic server(OSB Server).


JEJB transport uses the Java Interface to expose as EJB.

Here i will explain exposing the proxy service as EJB and invoking the same through java client by passing/receiving  the java objects and invoking the business service by passing/receiving the XML(Java utility methods will be used to convert Java to XML and XML to Java).The BPEL service invoked will receive the empno and and return back the employee details.

Steps to expose the proxy service as EJB

Create a Java interface that will receive/return the Employee object .

package jejbsample;
public interface EmployeeDetails {
 
    Employee getEmployeeDetails(Employee emp);
}

package jejbsample;
import java.io.Serializable;
public class Employee implements Serializable{
    private String empName;
    private String empNo;
    private String empDept;
    private String empLoc;  
    
    public Employee() {
        super();
    }

    public void setEmpName(String empName) {
        this.empName = empName;
    }
    public String getEmpName() {
        return empName;
    }
    public void setEmpNo(String empNo) {
        this.empNo = empNo;
    }
    public String getEmpNo() {
        return empNo;
    }
    public void setEmpDept(String empDept) {
        this.empDept = empDept;
    }
    public String getEmpDept() {
        return empDept;
    }
    public void setEmpLoc(String empLoc) {
        this.empLoc = empLoc;
    }
    public String getEmpLoc() {
        return empLoc;
    }
}

Create a Utility class that will convert the Java to XML and XML to Java.

package javaxmlconverter;
import java.io.InputStream;
import javax.xml.parsers.*;
import jejbsample.Employee;
import org.apache.xmlbeans.*;
import org.w3c.dom.*;

public class JavaXMLConverter {
    public JavaXMLConverter() {
        super();
    }
    public static String getEmpRequestXML(Employee emp) {       
        return emp.getEmpNo();
    }
    public static Employee getEmpResponseJava(XmlObject xml) throws Exception{
            Employee emp = new Employee();        
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            InputStream inputStream = xml.newInputStream();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(inputStream);           
            String empName=null ;
            String empNo=null;
            String empDept=null;
            String empLoc=null;            
            
            NodeList nList = doc.getElementsByTagName("EmployeeResponse");
            for (int temp = 0; temp < nList.getLength(); temp++) {
                Node nNode = nList.item(temp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element)nNode;
                     empName =eElement.getElementsByTagName("empName").item(0).getTextContent();
                     empNo =eElement.getElementsByTagName("empNo").item(0).getTextContent();
                     empDept =eElement.getElementsByTagName("empDept").item(0).getTextContent();
                     empLoc =eElement.getElementsByTagName("empLoc").item(0).getTextContent();
                   
                }
            }
        emp.setEmpDept(empDept);
        emp.setEmpName(empName);
        emp.setEmpLoc(empLoc);
        emp.setEmpNo(empNo);
        
        return emp;
        }
    }



Tuesday, December 10, 2013

Modifying the Request Headers of a OSB Business Service

Modifying the Request Headers of a OSB Business Service

Sometimes we may required to change the request header values eg. Content-Type and Accept etc for OSB Business Service request dynamically, this post will explain the steps to modify the header values for a Business Service request.

Steps to modify the header values for a Business Service request

Login to sbconsole,Create the session and open the message flow of Proxy Service.


Edit the Route to Business Service and Click on add Request Action



Thursday, December 5, 2013

Dynamic endpoint configuration for OSB Business services

Dynamic endpoint configuration for OSB Business services

Sometimes we may required to change the OSB Business service endpoint dynamically.

Steps to change the Business Service endpoints dynamically

The following are the steps to change the Business Service endpoints dynamically.

Login to sbconsole and create the session.

Open the Proxy Service Message Flow.


Click on the RouteTo_BusinessService and click on Edit Route





Tuesday, November 26, 2013

Creating JCA Adapters with Abstract WSDL - Oracle OSB

Creating JCA Adapters with Abstract WSDL - Oracle OSB

Oracle OSB provides the option to create JCA adapters to connect to different resources through Proxy Services and Business Services.

The JCA adapter needs to be created through JDevelper, JDeveloper creats a Abstract WSDL and a JCA adapter file.


When creating Busines Service through eclipse, eclipse provides the option to generating the service by right clicking the JCA file.

But through OSB console, we will not be able to generate the Business Service with the Abstract WSDL(WSDL Web Service)  because it will not have any binding or service defined.

If we are adding the binding/service to the abstract wsdl and creating the Business servive the following exception will be thrown