Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop SCA composites > Specify bindings in an SCA environment > Configure the SCA JMS binding


Invoke operations using custom operation selectors

If your application cannot use a default JMS binding operation selection or JMS user property operation selection to determine the target operation, you can use a JMS custom operation selector to invoke operations.
Configure the JMS binding for your SCA application.

IBM recommends that your SCA component implementations contain only business logic to improve their portability, such as over other bindings.

To improve portability, use the custom operation selector to hold the JMS-specific logic that handles an incoming JMS Message, enabling the component implementation to focus on binding-neutral business logic.

We can configure a JMS custom operation selector in an SCA composite definition without any changes to the application.

To specify the JMS custom operation selection, add the following operation selection element to the composite definition file:

{http://www.ibm.com/xmlns/prod/websphere/sca/1.0/2007/06}operationSelector.jmsCustom

The custom operation selector must implement the following interface:

package com.ibm.websphere.soa.sca.operationselector.jms.OperationSelector;
import javax.jms.Message;

public interface OperationSelector {
  public String getOperationName(Message msg);
  public WireFormatContext getWireFormatContext();
  public void setWireFormatContext(WireFormatContext ctx);

The interface exposes an instance of javax.jms.Message and enables interaction with the JMS user properties and message body. After doing operation selection, you do not need to use the reset() method to reposition the byte stream cursor for a BytesMessage. The run time automatically resets the cursor in all cases so that the wire format handler is not impacted by the operation selector reading the message first.

If the message body of a BytesMessage is read using any of the read methods available on a BytesMessage, reposition the byte stream to the beginning using the reset() method so that message processors can read the data in the entire message body intended for the targeted operation.

The wire format context is held by an instance of the com.ibm.websphere.soa.sca.wireformat.WireFormatContext class, which is passed with each invocation. The WireFormatContext class provides a java.util.Map interface where you can set property key and value pairs in the context. The WireFormatContext interface also provides several methods to extract useful information about the current context such as component and service names, invocation types, and the ability to mark exceptions. Refer to the Java documentation for the com.ibm.websphere.soa.sca.wireformat.WireFormatContext interface for a complete list of methods.


Procedure

  1. In a composite definition file, configure a custom operation selector.

    Use the operationSelector.jmsCustom element and the class attribute to identify the customer operation selection implementation class. The custom operation selector applies when receiving a request at a service, or a callback at a reference.

    <component name="AccountComponent">
    <implementation.java ...>
    <service name="AccountService">
    <binding.jms>
    <destination ...>
    <response>       ...
    
    </response>       
    <xmlns:fep="http://www.ibm.com/xmlns/prod/websphere/sca/1.0/2007/06"
                    fep:operationSelector.jmsCustom
                    class="com.ibm.test.soa.sca.opsel.SimpleCustomOpSel"/>
    
    </binding.jms>
    </service>
    </component>
    
  2. Write code that implements the JMS custom operation selector class.

    For the SimpleCustomOpSel example class, you can use code such as the following:

    package com.ibm.test.soa.sca.opsel;
    
    import com.ibm.websphere.soa.sca.operationselector.jms.OperationSelector.*;
    import javax.jms.*;
    
    public class SimpleCustomOpSel implements OperationSelector {
    
        private WireFormatContext opSelContext;
    
        @Override
        public String getOperationName(Message msg) {
            String retVal = computeOperationName(msg);
            return retVal;
        }
    
        @Override
        public WireFormatContext getWireFormatContext() {
            return opSelContext;
        }
    
        @Override
        public void setWireFormatContext(WireFormatContext ctx) {
            this.opSelContext = ctx;
        }
    
        /*
         * There is a pre-packaged operationSelector that can do this,      *
    <ts:operationSelector.jmsUser>.
         */
         private String computeOperationName(Message msg) {
             String opName = null;
             Integer val = null;
             try {
                 val = msg.getIntProperty("MyPropertyName");
                 if (val.equals(Integer.valueOf("1"))) {
                     opName = "addOperation";
                 } else if (val.equals(Integer.valueOf("2"))) {
    ...
    


Results

You have configured a custom operation selector.


What to do next

Package the operation selection implementation class with the application. The class must be loadable by an application-level class loader.

Deploy and test the operation selector in your SCA application.
Configure the SCA JMS binding
Invoke operations using JMS binding operation selection
Invoke operations using JMS user property operation selection


Related


Service Component Architecture specifications and APIs

+

Search Tips   |   Advanced Search