Sunday, 15 July 2012

calling a secured web service from bpel

Invoking WS-Security compliant Web Services from Oracle BPEL

In last post I have discussed my experience on invoking Web Services using SSL from Oracle BPEL. SSL is a transport level security mechanism; it offers authentication, confidentiality and message integrity. It is one of the proven technologies to secure web applications. Various organizations leverage SSL to protect their web applications.
SOA applications are loosely coupled and composed with multiple services. SOA applications are discoverable from public registries. So securing SOA application is not only securing the transport layer. For a Business Process it might be required to invoke multiple intermediary services. Transport Layer Security can only guarantees security when data is on wires. SOA application security requires a mix of Transport Layer Security and Application-Level Security.
Nowadays many organizations are using Web Services to implement SOA. In Web Services world a lot of specifications are existed to address SOA security needs:
  • WS-Security.
  • WS-Addressing.
  • WS-ReliableMessaging.
  • WS-Policy.
  • WS-SecurityPolicy.
  • SAML.
  • WS-Trust.
  • WS-SecureConversation.
  • WSFederation
In future posts I would discuss all the above mentioned standards in detail.
WS-Security specification provides extensions to the SOAP envelope header used to implement integrity and confidentiality of a message and authenticating the sender. WS-Security specifies how to associate a security token with a SOAP message. WS-Security specification is designed to be extensible. It doesn’t require any specific type of security token.
Oracle SOA Suite supports WS-Security specification. We can handle most of the complex SOA security scenarios using Oracle BPEL Process Manager and Oracle Web Service Manager.
“User Name Token” is a very common scenario to authenticate the web service consumer. It provides a standards-based way to send user credentials so that web services deployed on different platforms can share user credentials. It utilizes a message-based security approach moving credentials outside of the actual operation into SOAP headers without modifying the Web Service contract,
Let’s assume a WS-Security compliant Web Service is deployed on Axis2 and this method contains a method named getPrice(). To interact with this web service, you need to send SOAP messages containing valid WS-security credentials. We can convert any unsecured web service to a secured web service. No need to modify any web service to make it secure. The WS security specification plays with the soap headers rather than modifying the business logic or adding the authentication and authorization logic inside any service. It is the beauty of the WS-Security specification.
To pass security credentials from a BPEL process to another BPEL Process or any other web service it is required to set the following properties on the partner link which is used to invoke a WS Security compliant web service:
wsseHeaders Creates a WS-Security username token. The following values are supported:
  • propagate — If the process has been invoked securely, these credentials are also used for the outbound direction
  • credentials — Passes credentials from the BPEL deployment descriptor(bpel.xml).
wsseUsername The username for the token. It is a required property.
wssePassword The password for the token. It is an optional property.
Now you are ready to create a BPEL process in JDeveloper. Follow the given steps to create a BPEL Process:
  • Create a new BPEL process project named “InvokeWSSecurityCompliantService“ with the Synchronous BPEL Process.

  • Click on next and accept all the defaults and finish the wizard.
  • Right click on the services area and choose “Create Partner Link” from the context menu.
  • Name this partner link “WSSecurityCompliantServicePL”.
  • Browse the WSDL file from the file system. JDeveloper would ask to make a local copy of the external WSDL file and ask to add partner link in the WSDL. Click on “Yes” on both the dialog boxes.
  • Select Partner Link Type, Partner Role and click on the “Property” tab to provide WS security credentials.
  • Click on “Create” and select “wsseHeaders” from the drop down list.
  • You can use either “credentials” or “propagate” based on the requirement. If this BPEL process would be invoked by another process which is passing security credentials then you can use “propagate” to tell BPEL process manager to pass the incoming credentials to the service you are calling. You can use “credentials” as the property value to instruct BPEL Process Manager to read credentials from the deployment descriptor(bpel.xml).
  • Create two new properties “wsseUsername” and “wssePassword” by following the same approach.
  • Add “invoke” activity, name it as “InvokeSecuredWS” and link it with the partner link. Select the operation “getPrice” and create input and output variables.
  • Add 2 assign activities to assign and transform the input and out variables. Final BPEL process will look like the following image:
  • To deploy the BPEL process project on Oracle BPEL Process manager right click on the BPEL Process Project. From the context menu select “Deploy”, choose the appropriate integration server connection from the Deploy menu and select the appropriate domain.
  • Test the BPEL process from the BPEL Console or from any client.
Now you are able to invoke WS-Security compliant web services. In next post I would throw some light on BEPL deployment descriptors configuration and preference properties. These properties play a crucial role in customizing BPEL processes as per our requirements.

Sunday, 8 July 2012

soa interview questions

  • 1)Why SOA?      
  •         What are the advantages?
  •         What are the disadvantages?
  • 2)What are the approaches to categorize the existing services in a company?  ------How do we prepare a service portfolio before implementing SOA?
  • 3)What are the different design patterns in SOA?
  •             What are the different types of installation of SOASuite 10g?

  • xml/xsd/wsdl Related

  • What is the difference between concrete and abstract wsdl?
  •             What is the structure of a wsdl?
  •             Difference between Synchronus,One-way,Asynchronus BPEL process wsdls.
  •             What is the significance of targetNamespace in a wsdl.
  •             What is a inline schema?
  •             What is the difference between xsd:import and xsd:include?
  •                   The fundamental difference between include and import is that you must use import to refer to declarations or definitions that are in a different target namespace and you must use include to refer to declarations or definitions that are (or will be) in the same target namespace.
  •             Difference between URI and URL?          

Orchestration == Executeable Process
Web Service Orchestration relates to the execution of specific business processes. WS-BPEL is a language for defining processes that can be executed on an orchestration engine.
Choreography == Multi-party Collaboration
Web Service Choreography relates to describing externally observable interactions between web services. WS-CDL is a language for describing multi-party contracts and is somewhat like an extension of WSDL: WSDL describes web services interfaces, WS-CDL describes collaborations between web services.
  • 8)What is a pick activity?Can I have a pick activity with no onMessage branch?
Go to Developers guide. Answer is no.onMessage branch is mandatory.
  • 9)What are the different message exchange patterns in BPEl?
Go to developers Guide.
  • 10)What is the difference between Async and Sync activity on wsdl level?
two port vs one port funda.Create the two and see the difference.
  • 11)How does pick activity differ from a receive activity?
Pick activity can act as a multiple recieve activity in some business scenarios.If we have two inbound operations and both can trigger the bpel process then we will go with pick activity as we cant have two recieve activity with createInstance box checked.
Go to developer's guide.
  • What is a flowN activity and how does it leverages the flow activity?
Go to developers guide.
  • 13)What are dspMaxThread and a recieverThread properties?Why are they important?
Go to Best Practice Guide
  • 14)How does a async request run in the backend?
Go to Best Practice Guide
  • 15)Explain error handling in BPEL and what is a error handling framework?
Go to Developer's Guide
go to Developers Guide.bpel.xml
  •            What do you mean by non-idempotent activity?Which all activities are non-idempotent by default?
All retriable activities are idempotent by default.If idempotent is set to be false then it is a start of new transaction and in other words a Dehydration point is created.recieve,pick,wait,checkpoint() are non-idempotent by default.
  •            What is the default level of transation in a composite<required|requiredNew>?
Default is required.

  • 17)What is a XA datasource?How it differs from a non-XA datasource?
  • 18)How a wsdl of inbound jca adapter differs from a outbound one?--create and check.
  • 19)How will you know if a adapter is XA or Non-XA? ---create them and check. Logically they both will implement different classes.
  • 20)What are MCF properties? --- go to developer's guide
  • 21)What all operations can be performed using a file adapter? --create and check
  • 22)What is a syncFileRead operation?Is is a inbound or a outbound operation?Can my process begin with a syncFileRead operation?---Go to developer's Guide.No since it is a outbound operation so you need to invoke it.
  • 23)What all errors can't be handled by a BPEL process?--Best Practices Guide
  • 24)What is a throw activity?---Go to Developer's guide
  • 25)Why do we use a JMS queue?What is the benefit of using it over a simple AQ queue?--maintain JTA transaction capability and to ensure one and only one message delivery.
  • 26)What is getPreference property?How do we set it and what advantage it provides?Explain with a example?--Go to developer's guide
  • 27)How can we make a partner link dynamic?

  • 28)What are the dehydration tables in orabpel|soainfra schema?
  • 29)How do we resubmit a faulted process?---Developers guide
  • 30)How does the server know that a instance is faulted?--Best practice Guide
  • 31)What is a nonBlockingAll property?What is the use of it?
  • 32)In how many ways can a process be deployed?
  • 33)How can we embed or use a java code in BPEL?How can we make a java service a Web-service?What is xml facade?
  • Can we use a File Adapter to get a file without reading its content?---yes.go to developers guide 11g
  • How can we use a file as a trigger file?--go to developers guide 11g
  • XA vs nonXADatasource?

  • ESB
  • 33)When do we use ESB over BPEL?
  • 34)Why ESB is faster than its BPEL counterpart?
  • What is the difference between ESB runtime & Designtime?
  • 35)What is the out of box error handling framework in ESB?
  • 36)How can we get instance ID in ESB?
  • 37)How can we make routing in ESB dynamic?
  • Most of them are discussed in Best Pratices Guide.
  • AIA
  • 38)Why AIA? What is the need of it if SOA is already there?
  • 39)When to go for AIA?
  • 40)What is EBO,EBM,EBS,EBF,ABCs?
  • 41)Can a ABCs be a ESB process?If yes in what scenario?
  • 42)How can we extend a EBM?
  • 43)How can we extend a EBS?
  • 44)How can we extend a ABCs?
  • 45)What is a standard AIA flow?
  • 46)What is the error-handling framework in AIA?

Friday, 6 July 2012

AQ Adapter for Complex Custom Objects

This post would concentrate on creating AQ for consuming custom message structures. The pre-requisites for creating a custom AQ is -
1) Oracle DB 10g – AQ queues are created at DB
2) Admin user credential with sysdba role to grant permission for
normal user (e.g. scott) as in setup_user_grant.sql
3) user credentials for normal user (scott).

Step #1: Granting Permissions to Normal User
Connect tot he oracle DB "sys as sysdba" and run the following script
GRANT CONNECT, RESOURCE to scott;
GRANT EXECUTE ON SYS.DBMS_AQ to scott;
GRANT EXECUTE ON SYS.DBMS_AQADM to scott;
GRANT EXECUTE ON SYS.DBMS_AQIN to scott;
commit;

Step #2: Create Objects (Simple/Complex)
Now log out and re-connect as normal user (scott)
For simple objects like (Student:Roll_Num, Name, Age) run the following >>
create type STUDENT_TYPE as OBJECT (
  ROLL_NUM VARCHAR2(128),
  NAME VARCHAR2(512),
  AGE number
);

For a more complex scenario like >>
Vendor(ID,Name,Equipments (occurs multiple times),Feedback (occurs Multiple Times))

Equipment(ID,Description,Rate)
Feedback(ID,Description)
Create the Types as written below>>
create type Equipment_type is OBJECT
(
id NUMBER,
description VARCHAR(100),
rate NUMBER(10,2)
);

create type Equipment_Arr is VARRAY(50) of Equipment_type;

create type Feedback_type is OBJECT
(
id NUMBER,
description VARCHAR(100)
);

create type Feedback_Arr is VARRAY(50) of Feedback_type;

create type vendor is OBJECT
(
id NUMBER,
name VARCHAR(100),
Equipments Equipment_Arr,
feedback Feedback_Arr
);

Step #3: Create and Start Queue
Here we need to create the table corresponding to object created above and link it with a queue and start the queue.
begin
  dbms_aqadm.create_queue_table('stud_in_table', 'student_type');
  dbms_aqadm.create_queue('stud_in_queue', 'stud_in_table');
  dbms_aqadm.start_queue('stud_in_queue');

  dbms_aqadm.create_queue_table('stud_out_table', 'student_type');
  dbms_aqadm.create_queue('stud_out_queue', 'stud_out_table');
  dbms_aqadm.start_queue('stud_out_queue');
end;


Here we created two queues- in-queue and out-queue, one for reading the contents and another one for writing contents in it. (In case of the complex scenario above, the queue table would be created only for vendor and not for equipment/feedback).
Once this procedure is completed successfully, this AQ can be utilized by BPEL AQ Adapter for enqueuing or dequeuing the object of interest.
The configuration of AQ is not covered in this post you may visit here for a step by step procedure for configuring the AQ Adapter in BPEL.

Thursday, 14 June 2012

How to use Logical path with File Adapter in BPEL

I used file adapter in one of my projects and i thought will share some useful information that you can us>e.

Logical Path : BPEL supports the Logical and Physical path. Physical path is nothing but complete path. Logical path will be a relative path.

For defining the logical path you can start with . which denotes the current folder. By default current folder is /somefolder/app/oracle/product/soa/j2ee in oc4j container.

We need to mention this configuration in the bpel.xml file. like below.

{property name="oc4j_soa" type="LogicalDirectory"} ./../../arrowlogs/soa {property}
replace { with < and } with 

Monday, 28 May 2012

Invoking Soa Suite 11g Service from java

Invoking Soa Suite 11g Service from java

In Soa Suite 11g we can not call the composite service directly from java. We need to copy the service in the composite, change its binding to adf and wire this service to the component. All the credits goes to Jay's Blog and Clemens, Great work.

The first step is to open the composite xml and find your service.
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Generated by Oracle SOA Modeler version 1.0 at [8/25/09 3:01 PM]. -->
<composite name="Helloworld"
           revision="1.0"
           label="2009-08-25_15-01-51_078"
           mode="active"
           state="on"
           xmlns="http://xmlns.oracle.com/sca/1.0"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
           xmlns:orawsp="http://schemas.oracle.com/ws/2006/01/policy"
           xmlns:ui="http://xmlns.oracle.com/soa/designer/">
  <import namespace="http://xmlns.oracle.com/HelloWorld/Helloworld/BPELProcess1"
          location="BPELProcess1.wsdl" importType="wsdl"/>
   <service name="bpelprocess1_client_ep" ui:wsdlLocation="BPELProcess1.wsdl">
     <interface.wsdl interface="http://xmlns.oracle.com/HelloWorld/Helloworld/BPELProcess1#wsdl.interface(BPELProcess1)"/>
      <binding.ws port="http://xmlns.oracle.com/HelloWorld/Helloworld/BPELProcess1#wsdl.endpoint(bpelprocess1_client_ep/BPELProcess1_pt)">
      <wsp:PolicyReference URI="oracle/log_policy" orawsp:category="management"
                           orawsp:status="enabled"/>
    </binding.ws>
   </service>

Copy this service and give it a unique name and now we need to add the binding.adf binding to this service instead of the binding.ws
<service name="bpelprocess1_client_ep" ui:wsdlLocation="BPELProcess1.wsdl">
     <interface.wsdl interface="http://xmlns.oracle.com/HelloWorld/Helloworld/BPELProcess1#wsdl.interface(BPELProcess1)"/>
      <binding.ws port="http://xmlns.oracle.com/HelloWorld/Helloworld/BPELProcess1#wsdl.endpoint(bpelprocess1_client_ep/BPELProcess1_pt)">
      <wsp:PolicyReference URI="oracle/log_policy" orawsp:category="management"
                           orawsp:status="enabled"/>
    </binding.ws>
</service>
<service name="ADFBindingService" ui:wsdlLocation="BPELProcess1.wsdl">
     <interface.wsdl interface="http://xmlns.oracle.com/HelloWorld/Helloworld/BPELProcess1#wsdl.interface(BPELProcess1)"/>
    <binding.adf serviceName="{http://xmlns.oracle.com/HelloWorld/Helloworld/BPELProcess1}ADFBindingService"
                 registryName=""/>
</service>

Go back to the design mode and open the new adf binding service and select the same wsdl as your other service ( this will correct the serviceName ) and at last we need to wire the new service to the component

Now we only need to call this service from java
package nl.whitehorses.soa.client;
import java.util.Hashtable;
import java.util.UUID;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.Service;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.facade.ComponentInstance;
import oracle.fabric.common.NormalizedMessage;
import oracle.fabric.common.NormalizedMessageImpl;
import oracle.soa.management.util.CompositeInstanceFilter;
import oracle.soa.management.util.ComponentInstanceFilter;
import java.util.Map;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.Element;
import java.io.*;
public class StartProcess {
    public StartProcess() {
        super();
        Hashtable jndiProps = new Hashtable();
        jndiProps.put(Context.PROVIDER_URL, "t3://soaps3.alfa.local:8001/soa-infra");
        jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
        jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
        jndiProps.put(Context.SECURITY_CREDENTIALS, "weblogic1");
        jndiProps.put("dedicated.connection", "true");
        String inputPayload =
        "<process xmlns=\"http://xmlns.oracle.com/HelloWorld/Helloworld/BPELProcess1\">" +
        " <input>hello</input>" +
        "</process>" ;
        Locator locator = null;
        try {
            // connect to the soa server
            locator = LocatorFactory.createLocator(jndiProps);
            String compositeDN = "default/Helloworld!1.0";
            // find composite
            Composite composite = locator.lookupComposite("default/Helloworld!1.0");
            
            System.out.println("Got Composite : "+ composite.toString());
            // find exposed service of the composite
            Service service = composite.getService("ADFBindingService");
            System.out.println("Got serviceName : "+ service.toString());
            // make the input request and add this to a operation of the service
            NormalizedMessage input = new NormalizedMessageImpl();
            String uuid = "uuid:" + UUID.randomUUID();
            input.addProperty(NormalizedMessage.PROPERTY_CONVERSATION_ID,uuid);
            // payload is the partname of the process operation
            input.getPayload().put("payload",inputPayload);
            // process is the operation of the employee service
            NormalizedMessage res = null;
            try {
               res = service.request("process", input);
            } catch(Exception e) {
               e.printStackTrace();
            }
            Map payload = res.getPayload();
            Element element = (Element)payload.get("payload");
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            transformer.setOutputProperty("indent", "yes");
            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(element);
            transformer.transform(source, result);
            System.out.println("Result\n"+sw.toString());
            System.out.println("instances");
            
            
            CompositeInstanceFilter filter = new CompositeInstanceFilter();
            filter.setMinCreationDate(new java.util.Date((System.currentTimeMillis() - 2000000)));
            // get composite instances by filter ..
            List<CompositeInstance> obInstances = composite.getInstances(filter);
            // for each of the returned composite instances..
            for (CompositeInstance instance : obInstances) {
                System.out.println(" DN: " + instance.getCompositeDN() +
                                   " Instance: " + instance.getId() +
                                   " creation-date: " + instance.getCreationDate() +
                                   " state (" + instance.getState() + "): " + getStateAsString(instance.getState())
                                   );
                                  
                // setup a component filter
                ComponentInstanceFilter cInstanceFilter = new ComponentInstanceFilter();
                // get child component instances ..
                List<ComponentInstance> childComponentInstances = instance.getChildComponentInstances(cInstanceFilter);
                // for each child component instance (e.g. a bpel process)
                for (ComponentInstance cInstance : childComponentInstances) {
                    System.out.println(" -> componentinstance: " + cInstance.getComponentName() +
                                       " type: " + cInstance.getServiceEngine().getEngineType() +
                                       " state: " +getStateAsString(cInstance.getState())
                                       );
                    System.out.println("State: "+cInstance.getNormalizedStateAsString() );
                }
            }
  
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private String getStateAsString(int state)
    {
        // note that this is dependent on wheter the composite state is captured or not
        if (state == CompositeInstance.STATE_COMPLETED_SUCCESSFULLY)
            return ("success");
        else if (state == CompositeInstance.STATE_FAULTED)
            return ("faulted");
        else if (state == CompositeInstance.STATE_RECOVERY_REQUIRED)
            return ("recovery required");
        else if (state == CompositeInstance.STATE_RUNNING)
            return ("running");
        else if (state == CompositeInstance.STATE_STALE)
            return ("stale");
        else
            return ("unknown");
    }
    public static void main(String[] args) {
        StartProcess startUnitProcess = new StartProcess();
    }
} /////////////////////////////////////  jars to be downloaded and imported MiddlewareJdev11gR1PS1\jdeveloper\soa\modules\oracle.soa.mgmt_11.1.1\soa-infra-mgmt.jar MiddlewareJdev11gR1PS1\oracle_common\modules\oracle.fabriccommon_11.1.1\fabric-common.jar MiddlewareJdev11gR1PS1\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-client.jar MiddlewareJdev11gR1PS1\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-ext.jar MiddlewareJdev11gR1PS1\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime.jar MiddlewareJdev11gR1PS1\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\oracle-soa-client-api.jar MiddlewareJdev11gR1PS1\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\oracle.soa.fabric.jar ////////////////////////////////////

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...