Thursday, June 28, 2012

Monitoring the JCA Adapter’s through WLST script – Oracle SOA Suite

Monitoring the JCA Adapter’s through WLST script in Oracle SOA Suite:

Sometimes we may need to monitor the runtime performance of the JCA adapters, the monitoring is possible through EM console for limited details, the below WLST script will help us to monitor the required details of the JCA adapter (the scrip should be extended to monitor more details).

The below script can be used for monitoring only the DBAdapter’s and MQAdapter’s; the same can be extended to monitor other JCA Adapters (like FileAdapter) .

Before executing the script change the below condition according to your server name.

if server.getName().strip().startswith('S') | server.getName().strip().startswith('O')

The Adapters are only available in SOA and OSB servers so that I am filtering the other servers  based on the name(AdminServer or MS servers) .The exception will be thrown if we are trying to cd the MBean related to Adapters in others servers.

ResourceAdapterMonitor.py

def monitorDBAdapter(serverName):
    cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/DbAdapter/ComponentRuntimes/DbAdapter/ConnectionPools")
    connectionPools = ls(returnMap='true')
    print '--------------------------------------------------------------------------------------'
    print 'DBAdapter Runtime details for '+ serverName
    print '                                                                                      '
    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'

    print '%10s %13s %15s %18s' % ('Connection Pool', 'State', 'Current', 'Created')
    print '%10s %10s %24s %21s' % ('', '', 'Capacity', 'Connections')
    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'
    for connectionPool in connectionPools:
       if connectionPool!='eis/DB/SOADemo':
          cd('/')
          cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/DbAdapter/ComponentRuntimes/DbAdapter/ConnectionPools/"+str(connectionPool))
          print '%15s %15s %10s %20s' % (cmo.getName(), cmo.getState(), cmo.getCurrentCapacity(), cmo.getConnectionsCreatedTotalCount())

    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'

def monitorMQAdapter(serverName):
    cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/MQSeriesAdapter/ComponentRuntimes/MQSeriesAdapter/ConnectionPools")
    connectionPoolsMQ = ls(returnMap='true')
    print '--------------------------------------------------------------------------------------'
    print 'MQAdapter Runtime details for '+ serverName
    print '                                                                                      '
    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'

    print '%15s %17s %15s %18s' % ('Connection Pool', 'State', 'Current', 'Created')
    print '%15s %15s %24s %21s' % ('', '', 'Capacity', 'Connections')
    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'
    for connectionPoolMQ in connectionPoolsMQ:
          cd('/')
          cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/MQSeriesAdapter/ComponentRuntimes/MQSeriesAdapter/ConnectionPools/")
          cd(connectionPoolMQ)
          print '%15s %20s %10s %20s' % (cmo.getName(), cmo.getState(), cmo.getCurrentCapacity(), cmo.getConnectionsCreatedTotalCount())

    print '                                                                                      '
    print '--------------------------------------------------------------------------------------'


def main():
      #connect(username, password, admurl)
      connect('weblogic','reuters123','t3://<SOA Host>:<SOA Port>)
      servers = cmo.getServers()
      domainRuntime()
      for server in servers:
         cd("/ServerLifeCycleRuntimes/" + server.getName())
         if cmo.getState() == 'RUNNING':  
            if server.getName().strip().startswith('S') | server.getName().strip().startswith('O') :
                 monitorDBAdapter(server.getName())
      for server in servers:
         cd('/')
         cd("/ServerLifeCycleRuntimes/" + server.getName())
         if cmo.getState() == 'RUNNING':  
            if server.getName().strip().startswith('S') | server.getName().strip().startswith('O') :
                 monitorMQAdapter(server.getName())   
      disconnect()
     
main()

Copy the script to the soa server and execute the below command

>   wlst.sh ResourceAdapterMonitor.py

O/P:
--------------------------------------------------------------------------------------
DBAdapter Runtime details for SOA1
--------------------------------------------------------------------------------------
Connection Pool         State         Current            Created
                                                    Capacity          Connections
--------------------------------------------------------------------------------------
  eis/DB/SOA             Running         22               1051
      eis/DB/Test           Running           2                  697
    eis/DB/Test1           Running           1                  130
--------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------
MQAdapter Runtime details for SOA1
------------------------------------------------------------------------------------------------------
Connection Pool                                       State          Current            Created
                                                                                  Capacity           Connections
------------------------------------------------------------------------------------------------------
eis/MQ/MQAdapter                                 Running          0                    0
eis/MQ/MQSeriesAdapterRemote            Running          2                   84
-------------------------------------------------------------------------------------------------------


DOWNLOAD ResourceAdapterMonitor.py

Thursday, June 21, 2012

Support to Retrieve or set a HTTP header in Oracle SOA Suite 11.1.1.5 version


Oracle SOA Suite 11.1.1.6 version provides the support to retrieve or set a HTTP header from BPEL

The same fix has been applied to the version 11.1.1.4 as a patch 12928372 but the patch was not available for the version 11.1.1.5.

Recently oracle has released the patch 12928372 for the version 11.1.1.5 also.

The patch can be downloaded for the metalink by specifying the patch no as 12928372.


 This functionality is working only with the BPEL version 2.0, make sure the BPEL process version is 2.0 when we are trying to implement this functionality.

Friday, June 8, 2012

Could not find registry for application_JBOServiceRegistry while deploying the composite with Oracle ADF-BC adapter


Could not find registry for application_JBOServiceRegistry while deploying the composite with Oracle ADF-BC adapter

When we are invoking the Oracle ADF-BC service from our Oracle SOA Suite composite, we may receive the error
“Could not find registry for applicationname_JBOServiceRegistry”.

The error is due to the wrong registry name used in the ADF-BC adapter configuration also the missing listener entry in the weblogic-application.xml

Follow the below steps to resolve the issue:

Verify the registry name provided in the ADF-BC adapter used in the composite.



The Registry name should be of form <application name>_ JBOServiceRegistry
The application name can be found on the application deployment profile of the ADF-BC application.


Thursday, June 7, 2012

Invoking a ADF-BC service from the SOA Composite – Oracle SOA Suite


Invoking a ADF-BC service from the SOA Composite – Oracle SOA Suite

This blog explains how to create a sample Oracle ADF-BC service and invoke the same from the Oracle SOA Suite composite.

Creating the ADF-BC application: 

This is a simple ADF-BC application to perform the operations on the Employee table.
  • Create the ADF Model Project and name it as EmpModel
 
  • Select the ADF Business Components in the Project Technologies

  •  Right click on the Project -- >Select ADF Business Components -- >Click on Business Components from Tables

Monday, June 4, 2012

Selective tracing for Oracle SOA Suite


Selective tracing for Oracle SOA Suite:

In a production system, setting the trace at a fine-grained level can result in a large amount of output that must be diagnosed. You can alternately use selective tracing that provides a way to get a detailed, on-disk trace selectively (for example, by user name, thereby eliminating trace output for other users).

In Oracle SOA Suite 11g:

Activate the selective tracing:

  • Right-click the domain under WebLogic Domain and choose Logs > Selective Tracing.

Sunday, June 3, 2012

Restrict the access to SOA Composite Service based on the User Role (Authorization to the SOA Composite Service) – Oracle SOA Suite 11g


Restrict the access to SOA Composite Service based on the User Role (Authorization to the SOA Composite Service) – Oracle SOA Suite 11g

Sometimes we may need to restrict the access to the SOA composite service based on the user role.
HTTP basic authentication and an authorization policy can be used to ensure that access is only granted to users who are members of a particular role.

This blog will explain the steps to enable authorization to our composite service. 

Configure the Users and Group:

  • Login to the Weblogic console ('http://<host>:<port>/console')
  • In the left menu select 'Security Realms'
  • Select the realm where you want to create the users and groups.  The default is 'myrealm'
  • At the top select the 'Users and Groups' tab
  • Select User tab and Click 'New' and enter your user name and pwd.  Here am creating the user albin and albin1, create as many users as you want
  • Select ‘Groups’ tab and create a new group.  Here I am creating  ‘IntegrationGroup’
  • Go back to the users and click on  'Albin'
  • Select the 'Groups' tab and add ‘IntegrationGroup’.  The user albin1 will not be part of this group.

Configure the Application Role:

  • Login to EM console
  • Right Click on WebLogic Domain -- >Select Security and Click on Application Roles

  •  Click on 'Create' to configure a new Application Role

Invoking a web service from the composite with HTTP Basic authentication – Oracle SOA Suite

Invoking a web service from the composite with HTTP Basic authentication  – Oracle SOA Suite 11g

Sometimes we may need to invoke the HTTP Basic authentication enabled web service from the  Oracle SOA Suite composite.
This blog will explain the steps to invoke the web service with the HTTP basic authentication enabled.

Configure the credential store:

The credential should be configured in the credential store to invoke the web service with the HTTP Basic authentication enabled.

If the credential store is not configured already then follow the below steps to do the same.
  • Login to EM
  • Right Click on WebLogic Domain - Select Security and Click on Credentials


The same will work in Oracle SOA Suite 12c but the screens will be little different.

oracle_soa_12c_credential_map


  • Click on Create Map

Saturday, June 2, 2012

Enabling the HTTP Basic authentication to the Composite Service (Invoking a composite with HTTP authentication) – Oracle SOA Suite 11g

Enabling the HTTP Basic authentication to the Composite Service (Invoking a composite with HTTP authentication) – Oracle SOA Suite 11g

Sometimes we may need to enable the security like HTTP basic authentication to the composite service, so that the client can securely invoke our services providing the username/password.
This blog will explain the steps to enable HTTP basic authentication to our composite service. 

Configure the Authentication policy to the Composite Service:

  • Open the composite.xml   
  • Right click on the client service and click on Configure WS Polices


  •  Add the security Policy oracle/wss_http_token_service_policy for authentication in the security section.


Tuesday, May 29, 2012

Some handy JSF utility methods

Some handy JSF utility methods:

import java.io.*;
import java.text.*;
import java.util.*;
import javax.faces.application.*;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

import javax.servlet.http.HttpSession;
import oracle.adf.view.faces.model.UploadedFile;


public class JSFUtils {

    private static final String NO_RESOURCE_FOUND = "Missing resource: ";

    /**
       * Method for taking a reference to a JSF binding expression and returning
       * the matching object (or creating it)     
       */
    public static Object resolveExpression(FacesContext ctx,
                                           String expression) {
        Application app = ctx.getApplication();
        ValueBinding bind = app.createValueBinding(expression);
        return bind.getValue(ctx);
    }

    /**
       * Convenience method for resolving a reference to a managed bean by name
       * rather than by expression
       */
    public static Object getManagedBeanValue(FacesContext ctx,
                                             String beanName) {
        StringBuffer buff = new StringBuffer("#{");
        buff.append(beanName);
        buff.append("}");
        return resolveExpression(ctx, buff.toString());
    }

    /**
       * Method for setting a new object into a JSF managed bean
       * Note: will fail silently if the supplied object does
       * not match the type of the managed bean
      */
    public static void setExpressionValue(FacesContext ctx, String expression,
                                          Object newValue) {
        Application app = ctx.getApplication();
        ValueBinding bind = app.createValueBinding(expression);
       
        Class bindClass = bind.getType(ctx);
        if (bindClass.isPrimitive()||bindClass.isInstance(newValue)) {
            bind.setValue(ctx, newValue);
        }
    }

    /**
       * Convenience method for setting the value of a managed bean by name
       * rather than by expression
       */
    public static void setManagedBeanValue(FacesContext ctx, String beanName,
                                           Object newValue) {
        StringBuffer buff = new StringBuffer("#{");
        buff.append(beanName);
        buff.append("}");
        setExpressionValue(ctx, buff.toString(), newValue);
    }


    /**
       * Convenience method for setting Session variables
      */
    public static

    void storeOnSession(FacesContext ctx, String key, Object object) {
        Map sessionState = ctx.getExternalContext().getSessionMap();
        sessionState.put(key, object);
    }

    /**
       * Convenience method for getting Session variables
      */
    public static Object getFromSession(FacesContext ctx, String key) {
        Map sessionState = ctx.getExternalContext().getSessionMap();
        return sessionState.get(key);
    }


    /**
       * Pulls a String resource from the property bundle that
       * is defined under the application &lt;message-bundle&gt; element in
       * the faces config. Respects Locale
       */
    public static String getStringFromBundle(String key) {
        ResourceBundle bundle = getBundle();
        return getStringSafely(bundle, key, null);
    }


    /**
       * Convenience method to construct a <code>FacesMesssage</code>
       * from a defined error key and severity
      */
    public static FacesMessage getMessageFromBundle(String key,
                                                    FacesMessage.Severity severity) {
        ResourceBundle bundle = getBundle();
        String summary = getStringSafely(bundle, key, null);
        String detail = getStringSafely(bundle, key + "_detail", summary);
        FacesMessage message = new FacesMessage(summary, detail);
        message.setSeverity(severity);
        return message;
    }

    /*
       * Internal method to pull out the correct local
       * message bundle
       */

    private static ResourceBundle getBundle() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        UIViewRoot uiRoot = ctx.getViewRoot();
        Locale locale = uiRoot.getLocale();
        ClassLoader ldr = Thread.currentThread().getContextClassLoader();
        return ResourceBundle
        .getBundle(ctx.getApplication().getMessageBundle(), locale, ldr);
    }

    /*
       * Internal method to proxy for resource keys that don't exist
       */

    private static String getStringSafely(ResourceBundle bundle, String key,
                                          String defaultValue) {
        String resource = null;                                         
        try {                                         
            resource = bundle.getString(key);
        }
        catch (MissingResourceException mrex) {
            if (defaultValue != null) {
                resource = defaultValue;
            } else {
                resource = NO_RESOURCE_FOUND + key;
            }
        }
        return resource;
    }
    /**
     *
     * @param msg
     */
    public static void addFacesErrorMessage(String msg) {
        FacesContext ctx = getFacesContext();
        FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR,msg,null);
        ctx.addMessage(getRootViewComponentId(),fm);
      }
      /**
     *
     * @return
     */
    public static FacesContext getFacesContext() {
         return FacesContext.getCurrentInstance();
       }
       /**
     *
     * @return
     */
    public static String getRootViewComponentId() {
         return getFacesContext().getViewRoot().getId();
       } 
       /**
     *
     * @param beanname
     * @return
     */
       public static Object getBeanByName(String beanname) {
           FacesContext ctx = getFacesContext();
           Application app = ctx.getApplication();    
           return app.getVariableResolver().resolveVariable(ctx,beanname);
       }
      
       
     
    public static void  addValuesToSession(String key,String value) {
   
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        session.setAttribute(key, value);
       
    }
   
 
}

Some handy utility methods for XPath

Some handy utility methods for XPath:

import com.collaxa.cube.xml.xpath.SimpleNamespaceContext;
import java.util.*;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.*;
import oracle.bpel.services.common.util.XMLUtil;
import oracle.tip.pc.infra.exception.PCException;

import oracle.xml.xpath.JXPathFactory;
import org.w3c.dom.*;

    public class XPathUtils
{

    public XPathUtils()
    {
    }

    public static NodeList selectNodes(Element pElement, String xpathExpression)
        throws Exception
    {
        XPath xPath = createXPath();
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        NodeList value = (NodeList)xPath.evaluate(xpathExpression, doc, XPathConstants.NODESET);
        return value;
    }

    public static NodeList selectNodes(Element pElement, String xpathExpression, Map prefixNamespaceMapping)
        throws Exception
    {
        XPath xPath = createXPath(prefixNamespaceMapping);
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        NodeList value = (NodeList)xPath.evaluate(xpathExpression, doc, XPathConstants.NODESET);
        return value;
    }

    public static NodeList selectNodes(Element pElement, String xpathExpression, NamespaceContext namespaceContext)
        throws Exception
    {
        XPath xPath = createXPath(namespaceContext);
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        NodeList value = (NodeList)xPath.evaluate(xpathExpression, doc, XPathConstants.NODESET);
        return value;
    }

    public static Object evaluate(Element pElement, String xpathExpression)
        throws Exception
    {
        XPath xPath = createXPath();
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        Object value = xPath.evaluate(xpathExpression, doc, XPathConstants.NODESET);
        return value;
    }

    public static Object evaluate(Element pElement, String xpathExpression, Map prefixNamespaceMapping)
        throws Exception
    {
        XPath xPath = createXPath(prefixNamespaceMapping);
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        Object value = xPath.evaluate(xpathExpression, doc, XPathConstants.NODESET);
        return value;
    }

    public static Object selectSingleNode(Element pElement, String xpathExpression)
        throws Exception
    {
        XPath xPath = createXPath();
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        Node value = (Node)xPath.evaluate(xpathExpression, doc, XPathConstants.NODE);
        return value;
    }

    public static Object selectSingleNode(Element pElement, String xpathExpression, Map prefixNamespaceMapping)
        throws Exception
    {
        XPath xPath = createXPath(prefixNamespaceMapping);
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        Node value = (Node)xPath.evaluate(xpathExpression, doc, XPathConstants.NODE);
        return value;
    }

    public static String valueOf(Element pElement, String xpathExpression)
        throws Exception
    {
        XPath xPath = createXPath();
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
           
        String value = (String)xPath.evaluate(xpathExpression, doc, XPathConstants.STRING);
        return value;
    }

    public static String valueOf(Element pElement, String xpathExpression, Map prefixNamespaceMapping)
        throws Exception
    {
        XPath xPath = createXPath(prefixNamespaceMapping);
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        String value = (String)xPath.evaluate(xpathExpression, doc, XPathConstants.STRING);
        return value;
    }

    public static Number numberValueOf(Element pElement, String xpathExpression)
        throws Exception
    {
        XPath xPath = createXPath();
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        Number nValue = (Number)xPath.evaluate(xpathExpression, doc, XPathConstants.NUMBER);
        return nValue;
    }

    public static Number numberValueOf(Element pElement, String xpathExpression, Map prefixNamespaceMapping)
        throws Exception
    {
        XPath xPath = createXPath(prefixNamespaceMapping);
        Document doc = null;
        if(pElement instanceof Document)
            doc = (Document)pElement;
        else
            doc = pElement != null ? pElement.getOwnerDocument() : null;
        Number nValue = (Number)xPath.evaluate(xpathExpression, doc, XPathConstants.NUMBER);
        return nValue;
    }

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.