Tuesday, May 29, 2012

Update the Human task payload via JAVA API - Oracle SOA Suite

Update the Human task payload via JAVA API - Oracle SOA Suite:

Oracle SOA Suite provides java API’s to manipulate the Human task data.The below java code will help us to update the Human task payload.

This is the Remote Java client  to get the Workflow service and perform the required operations on the task.

The XPath of the input element will be used to update the payload data.

UpdateWorkflowPayload.java

import java.util.*;
import oracle.bpel.services.workflow.IWorkflowConstants;
import oracle.bpel.services.workflow.client.*;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.repos.*;
import oracle.bpel.services.workflow.task.ITaskService;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;
import org.w3c.dom.Element;
public class UpdateWorkflowPayload {     
   public static void updatePayload()
    {
        List displayColumns = new ArrayList();
        displayColumns.add("TASKNUMBER");
        displayColumns.add("TITLE");
        displayColumns.add("STATE");
        displayColumns.add("CREATOR");
        List optionalInfo = new ArrayList();      
        optionalInfo.add("Comments");
        optionalInfo.add("Payload");      
    try {
              String userid="weblogic";
              String password = "password";       
              String serverUrl ="t3://localhost:8000"; // host:port of the soa server
              Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String> connProperties = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String>();              connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,WorkflowServiceClientFactory.REMOTE_CLIENT);              connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,serverUrl);
              connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");       
              IWorkflowServiceClient wfSvcClient = WorkflowServiceClientFactory.getWorkflowServiceClient(connProperties, null, null);   
              IWorkflowContext ctx = wfSvcClient.getTaskQueryService().authenticate(userid, password.toCharArray(), "jazn.com" );
              ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
              ITaskService taskSvc = wfSvcClient.getTaskService();       
              Predicate statePredicate =new Predicate(TableConstants.WFTASK_STATE_COLUMN,Predicate.OP_EQ,IWorkflowConstants.TASK_STATE_ASSIGNED);
              Predicate compositenamePredicate = new Predicate(TableConstants.COMPONENT_COMPOSITE_NAME_COLUMN,Predicate.OP_EQ,"HumanWorkflow");
              Predicate predicate = new Predicate(statePredicate, Predicate.AND, compositenamePredicate);
            
       
              List tasks =querySvc.queryTasks(ctx, displayColumns, optionalInfo, ITaskQueryService.AssignmentFilter.MY,null, statePredicate, null, 0, 0);
              
              for (int i = 0; i < tasks.size(); i++) {
                       Task task = (Task)tasks.get(i);
                       String taskId = task.getSystemAttributes().getTaskId();                
                       String title = task.getTitle();
                       String state = task.getSystemAttributes().getState();
                       Task currentTask=querySvc.getTaskDetailsById(ctx,taskId);                   
                 
                       Element payload = currentTask.getPayloadAsElement();
                 
                       Map namespacemap = new HashMap();
                       namespacemap.put("ns0", "http://xmlns.oracle.com/bpel/workflow/task");
                                     
                       setPayloadValue(payload,"/ns0:task/ns0:payload/ns0:Name",namespacemap,"Albin Issac");
                       setPayloadValue(payload,"/ns0:task/ns0:payload/ns0:Number",namespacemap,"024");
                       setPayloadValue(payload,"/ns0:task/ns0:payload/ns0:Dep",namespacemap,"I.T");
                       setPayloadValue(payload,"/ns0:task/ns0:payload/ns0:Place",namespacemap,"KAMPLAR");
                 
                       currentTask.setPayloadAsElement(payload);    
                       taskSvc.updateTaskOutcome(ctx, currentTask,"APPROVE"); 
                 
                   }
                         
          } catch (Exception e) {
              e.printStackTrace();
          
          }
    }
  
   public static void setPayloadValue(Element payload,String xpath,Map namespacemap,String value) {
        try {
            XPathUtils.setNodeValue(payload, namespacemap, xpath,value);
        } catch (Exception e) {
        }
    }
   public static void main(String[] args) {
        updatePayload();
    }
}

Saturday, May 26, 2012

Exposing the BPEL process as a Http Service using HTTP Binding Adapter – Oracle SOA Suite

Exposing the BPEL process as a Http Service using HTTP Binding Adapter – Oracle SOA Suite:

By default the BPEL processes can be invoked via SOAP service, sometimes we may need to invoke the service from the HTTP client by using the HTTP methods – GET/POST

The HTTP Binding Adapter will help us to expose the BPEL process as an HTTP Service.

If we are exposing the service as a HTTP service, the marshaling/unmarshaling overhead related to soap can be avoided when the client invoke the service.

Steps to Expose the BPEL process as a HTTP Service:
  • Create a new SOA project with the Composite Template as Empty
  • Open the Composite.xml and Insert HTTP Binding Adapter to Exposed Services section.
  • Configure the Adapter
1.       Select the Interface Option as “Define from operation and schema specified later”
2.       Select the operation type, verb(HTTP Method) and payload type accordingly
3.       Provide the Request/Response Message Schema


 

Friday, May 25, 2012

Updating the BPEL Component preference value from JAVA – Oracle SOA Suite

Updating the BPEL Component preference value from JAVA – Oracle SOA Suite:

Sometimes we may need to update the preference value for the BPEL component in Oracle SOA Suite 11g or Oracle SOA Suite 12c, the below java code will help us to update the preference value.

This update is not a cluster-aware,remember that you must repeat the same process for each managed server of your environment.
Before executing the code change the mbeanName accordingly.

   String mBeanName ="*:*,j2eeType=SCAComposite.SCAComponent,revision=*,SCAComposite=\"Preference\",name=Preference";




import java.util.*;
import javax.management.*;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.remote.*;
import javax.naming.Context;

public class UpdatePreferenceValue {  

    public static MBeanServerConnection getMbeanServerConnection(String host,
                                                                 int port,
                                                                 String userName,
                                                                 String password) throws Exception {
        String jndiroot = "/jndi/";
        MBeanServerConnection m_connection = null;
        try {
            Hashtable jndiProps = new Hashtable();
            jndiProps.put(Context.SECURITY_PRINCIPAL, userName);
            jndiProps.put(Context.SECURITY_CREDENTIALS, password);
            jndiProps.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");

            JMXServiceURL serviceURL =new JMXServiceURL("t3", host, port, jndiroot +"weblogic.management.mbeanservers.runtime");
            JMXConnector m_connector =JMXConnectorFactory.newJMXConnector(serviceURL, jndiProps);
            m_connector.connect();
            m_connection = m_connector.getMBeanServerConnection();

        } catch (Exception e) {

            e.printStackTrace();
        }
        return m_connection;
    }


    private static CompositeDataSupport UpdatePreferenceData(CompositeDataSupport cds,String[] keys,String[] newValues) throws Exception {
        Map<String, Object> items =new HashMap<String, Object>(cds.getCompositeType().keySet().size());

        for (String key : cds.getCompositeType().keySet()) {
            boolean matched = false;
            int i = 0;

            for (; i < keys.length; i++) {
                String searchKey = keys[i];

                if (searchKey.equalsIgnoreCase(key)) {
                    items.put(key, newValues[i]);
                    matched = true;
                    break;
                }
            }       

            if (!matched) {             
                    items.put(key, cds.get(key));
            }
         
        }
    

        return new CompositeDataSupport(cds.getCompositeType(), items);
    }

Monday, May 21, 2012

Using Regular Expressions with Oracle BPEL


Using Regular Expressions with Oracle BPEL:

Sometimes we may have to validate the data based on the Regular Expressions.

xp20:matches() is a function which can be used to compare data with regular expressions. This function returns true when the input matches the given expression.

xp20:matches(intputString, regexPattern)
  • inputString - The input string
  • regexPattern - The regular expression pattern

Validation of numeric fields :

xp20:matches(bpws:getVariableData('inputString'),'^[0-9]*$')=true()

Validation of alpha fields :

xp20:matches(bpws:getVariableData('inputString'),'^[A-Za-z]*$')=true()

Validation for list of values:

xp20:matches(bpws:getVariableData('inputString'),'^(A|B|C|D)$') =true()

The matches function returns true if inputString variable contains any one of these values (A, B, C, and D).

The expression can be replaced with other regular expressions for similar comparisons.

Important date functions in Oracle BPEL


Important date functions in Oracle BPEL:

Format-dateTime:

This function returns the formatted string of dateTime using the format provided.

xp20:format-dateTime(dateTime as string, format as string)
  •   dateTime – The dateTime to be formatted
  •    format – The format for the output
Format String:-

Format Date Time: Year

Example
Expression
2012
[Y0001]
2012
[Y]
12
[Y01]
Two Thousand and Twelve
[YWw]

Format Date Time: Month

 Example
Expression
08
[M01]
8
[M]
VIII
[MI]
August
[MNn]
AUGUST
[MN]
Aug
[MNn,*-3]
AUG
[MN,*-3]

                                      
Format Date Time: Day

Example
Expression
05
[D01]
5
[D]
5
[D1]
31st
[D1o]
Tuesday
[FNn]


Format Date Time: Hour

Example
Expression
3
[h]
9
[H]
08
[H01]

Format Date Time: Minute
Example
Expression
03
[m01]
3
[m]

Format Date Time: Second
Example
Expression
09
[s01]
9
[s]

Format Date Time: Millisecond
Example
Expression
257
[f001]

Format Date Time: AM/PM
Example
Expression
PM
[PN]
Am
[Pn]

Format Date Time: GMT
Example
Expression
GMT+02:00
[z]


Example:-

xp20:format-dateTime(xp20:current-dateTime(),"[D01]/[M01]/[Y0001] [H01]:[m01]:[s01]")

Saturday, May 19, 2012

JAXB Mapping of XML Schema Built-in Data Types

JAXB Mapping of XML Schema Built-in Data Types  


XML Schema Type
Java Data Type
xsd:string
java.lang.String
xsd:integer
java.math.BigInteger
xsd:int
int
xsd.long
long
xsd:short
short
xsd:decimal
java.math.BigDecimal
xsd:float
float
xsd:double
double
xsd:boolean
boolean
xsd:byte
byte
xsd:QName
javax.xml.namespace.QName
xsd:dateTime
java.util.Calendar
xsd:base64Binary
byte[]
xsd:hexBinary
byte[]
xsd:unsignedInt
long
xsd:unsignedShort
int
xsd:unsignedByte
short
xsd:time
java.util.Calendar
xsd:date
java.util.Calendar
xsd:anySimpleType
java.lang.String