Monday, June 4, 2012

WPS : Mediation Primitive Message Logger

Introduction : We have MessageLogger in Tracing palette. Message Logger writes a copy of the message to a database for future retrieval or audit. You can also create your own custom message log. All or part of the SMO can be written.
Message Logger contains one input, one output and one fail terminal. All message terminal have the same message type.

Properties :
Root : Xpath expression defining portion of SMO to log. Xpath expression can identify any element or portion of the SMO.
default : /body

Transaction mode : It contains two options :: same,new
Same : Commit database update with in the flow transaction  (or) Log the massage to the same file
New : Commit database update immediately using a new transaction. (or) Log the massage to the new file for each message.
default : Same

Logging Type : It contains two options :: Database, Custom
Database : Log the message in the database by using Data source name
Custom : Log the message in fileby using Handler,Formatter,Filter options which are not applicable those are ignorable at runtime.  The file is created in temporary folder : D:\DOCUME~1\user\LOCALS~1\Temp with the file name : MessageLog
default : Database



Data source name : JNDI name of data-source identifying the database. 
default : jdbc/mediation/messageLog

Handler, Formatter, Filter : these options are used for custom logging type. implementation classes are defined by java logging API's. default implementation types are availabe by default. handler is required and formatter and filter is optional.

Literal : {0} to {5} representing following :
{0} Time Stamp : Indicates when the message is logged.
{1} Message ID : Message id from SMO.
{2} Mediation Name : The name of the message logger primitive that logged in the message.
{3} Module Name : The name of the mediation module containing the message logger.
{4} Message : The message specified in the root property
{5} Version : The version of the SMO

WPS : serialisation of XML Dataobject to String and XML string to XML serialized DataObject

Introduction : We required to serialize the the DataObject to XML string and also serialize XML String to DataObject.

imports :
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import com.ibm.websphere.bo.BOXMLDocument;
import com.ibm.websphere.bo.BOXMLSerializer;
import commonj.sdo.DataObject;
import commonj.sdo.Type;
DataObejct to XMLString :


// dataObject is input DataObject
      String xmlSrting = "";
        BOXMLSerializer boXMLSerializer = (com.ibm.websphere.bo.BOXMLSerializer) com.ibm.websphere.sca.ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOXMLSerializer");
      
        Type type = dataObject.getType();
        BOXMLDocument document = boXMLSerializer.createXMLDocument(dataObject,type.getURI(),type.getName());
      
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            boXMLSerializer.writeXMLDocument(document,outputStream);
            return new String(outputStream.toByteArray(),document.getEncoding());
              } catch (UnsupportedEncodingException e) {
            throw e;
        } catch (IOException ex) {
            throw ex;
        }


XMLString to DataObejct :

BOXMLSerializer boXMLSerializer = (com.ibm.websphere.bo.BOXMLSerializer) com.ibm.websphere.sca.ServiceManager.INSTANCE
        .locateService("com/ibm/websphere/bo/BOXMLSerializer");
       
        byte[] bytes = businessObjectXML.getBytes();
        BOXMLDocument document = boXMLSerializer.readXMLDocument(new ByteArrayInputStream(bytes));
        return document.getDataObject();

WPS : Getting the SCA Components and mediation component values by services call in WID

Introduction :  we can able to get SCA component details by using "SCAServices" we can get those details dynamically. Instead of using the custom mediation properties we can get those details by using "MediationServices" class in mediation component dynamically.

Code :
For SCA component :
import com.ibm.wsspi.sibx.mediation.esb.*;
SCAServices scaServices = getSCAServices();
     String moduleName = scaServices.getModuleName();
     String SCAcomponentName = scaServices.getComponentName();

For MEDIATION components :
import com.ibm.wsspi.sibx.mediation.*;
MediationServices mediationServices = getMediationServices();
String mediationPrimitiveName = mediationServices.getMediationName() ;
String mediationPrimitiveDisplyName = mediationServices.getMediationDisplayName();
also we can able to get terminal details like :  input/output terminal name, list of input/output terminals list(if exists)