Thursday, April 18, 2013

WPS : Converting XML String to DataObject & DataObject to XMLString

Serializing and Deserializing Business Objects From and To XML Documents in WebSphere Integration Developer


Use BOXMLSerializer and BOXMLDocument interfaces to convert a Business Object to an XML string and vice versa in WebSphere Integration Developer.

Often times you will see a need to convert a given Business Object into an XML string and vice versa. You can serialize and deserialize a Business Object to and from a given XML string by using com.ibm.websphere.bo.BOXMLSerializer and com.ibm.websphere.bo.BOXMLDocument interfaces.

BOXMLSerializer serializer = (BOXMLSerializer)new ServiceManager().
                              locateService(“com/ibm/websphere/bo/BOXMLSerializer”);

Sample Java code to convert a Business Object to an XML String:
Let’s say you have your Business Object stored in a variable ‘inputDataObject’ (of type commonj.sdo.DataObject)

ByteArrayOutputStream outputStream = newByteArrayOutputStream();
serializer.writeDataObject(inputDataObject,inputDataObject.getType().
getURI(),inputDataObject.getType().getName(),outputStream);
String myXMLString = outputStream.toString(“UTF-8”);

“myXMLString” will hold the XML string corresponding to the Data Object “inputDataObject”.

Sample Java code to convert a given XML String to a Business Object:

Let’s say you have the XML string stored in a variable named ‘inputXMLString’ (of type java.lang.String)

BOXMLDocument document = serializer.readXMLDocument(new ByteArrayInputStream
                                            (inputXMLString.getBytes(“UTF-8”)));
commonj.sdo.DataObject myDataObject =document.getDataObject();

“myDataObject” will hold the Business Object corresponding to the XML string “inputXMLString”.

Note: The schema definition (xsd) corresponding to the Business Object that you are trying to convert the XML string into, should be available during runtime.

Wednesday, April 17, 2013

WPS : Common Base Event Infrastructure & Common Base Events

The common event infrastructure or CEI is one of the SOA core components that are a part of WPS.
CEI is available to all the supporting services and service components that are running in the process server environment.All of these supporting services and service components have the ability to generate events that can be handled by CEI and then handled by various clients such as those provided by Tivoli® and WebSphere Business Monitor.


The event definition is being standardized through the OASIS standards body  so that other companies as well as customers can use the same infrastructure to monitor through-out their environments. It provides facilities for the runtime environment to persistently store and retrieve events from different programming environments. This post briefly introduces the basic event-related concepts: Common Event Infrastructure (CEI) Common Base Events (CBE)

Common Event Infrastructure :
In WESB, the CEI is used to provide basic event management services, such as event generation,  transmission, persistence, and consumption. CEI was developed to address industry-wide problems in exchanging events between incompatible systems, many of which employed different event infrastructures, event formats, and data stores.

Common Base Event :
Although CEI provides an infrastructure for event management, it does not define the format of events. This is defined by the Common Base Event specification, which provides a standard XML-based format for
business events, system events, and performance information. Application developers and administrators can use the Common Base Event specification for structuring and developing event types.

Sunday, April 14, 2013

WPS: BOXMLSerializer to validate XML document

XML document validation

XML documents and business objects can be validated using the validation service.
In addition, other services require certain minimum standards or they throw a runtime exception. One of these is BOXMLSerializer.
You can use the BOXMLSerializer to validate XML documents before they are processed by a service request. The BOXMLSerializer validates the structure of XML documents to determine if any of the following types of errors are present:
  • Invalid XML documents, such as those that are missing certain element tags.
  • Not well-formed XML documents, such as those that contain missing closing tags.
  • Documents containing parsing errors, such as errors in entity declaration.
When an error is discovered by the BOXMLSerializer, an exception will be thrown with problem details.
The validation can be performed for import and/or export of XML documents for the following services:
  • HTTP
  • JAXRPC web services
  • JAX-WS web services
  • JMS services
  • MQ services
For the HTTP, JAXRPC, and JAX-WS services, the BOXMLSerializer will generate exceptions in the following manner:
  • Imports –
    1. The SCA component invokes the service.
    2. The service invokes a destination URL.
    3. The destination URL responds with an invalid XML exception.
    4. The service fails with a runtime exception and message.
  • Exports –
    1. The service client invokes the service export.
    2. The service client sends an invalid XML
    3. The export fails for the service and generates an exception and message.
For the JMS and MQ messaging services, the exceptions are generated in the following manner:
  • Imports –
    1. The import invokes the JMS or MQ service.
    2. The service returns a response.
    3. The service returns an invalid XML exception.
    4. The import fails and generates a message.
  • Exports –
    1. The MQ or JMS client invokes an export.
    2. The client sends invalid XML.
    3. The export fails and generates an exception and message.
You can view the logs for any messages generated by an XML validation exception.

Friday, April 12, 2013

WPS: BO API Specifications


Introduction : While dealing with BO's in Integration designer we may need BO API to deal with BO's to initialize, to get data from bo or to set data to bo for those things we need bo API

Here we will learn bo api along with all it's interfaces and functions in those interfaces.
package : com.ibm.websphere.bo
Interfaces in this package :

  1. BOFactory
  2. BOXSDHelper
  3. BOXMLSerializer
  4. BOTypeMetadata
  5. BOType
  6. BOInstanceValidator
  7. BOXMLDocument
  8. BOEquality
  9. BOEventSummary
  10. BODataObject
  11. BOCopy
  12. BOChangeSummary

1.  BOFactory :  The BOFactory service provides the ability to create business objects and business documents that are represented in memory by the commonj.sdo.DataObject and com.ibm.websphere.bo.BOXMLDocument objects. It contains following method's by using those we can able to create business objects and business documents at runtime.
A. create
     Syntax: commonj.sdo.DataObject create(java.lang.String targetNamespace,
                              java.lang.String complexTypeName)
Creates a DataObject from an XML Schema complex type definition.BOFactory boFactory = (BOFactory) new ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
DataObject customer = boFactory.create("http://MP_SampleModule/Customer", "Customer");
 B. createByElement
     Syntax: commonj.sdo.DataObject createByElement(java.lang.String targetNamesp                              ace,java.lang.String globalElementName)
Creates a DataObject from an XML Schema global element definition.BOFactory boFactory = (BOFactory) new ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
DataObject customer = boFactory.createByElement("http://MP_SampleModule/Customer", "customer");
 C. createByType
     Syntax: commonj.sdo.DataObject createByType(commonj.sdo.Type type)
Creates a DataObject from a commonj.sdo.Type. The Type can be created using the BOType service.BOFactory boFactory = (BOFactory) new ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
BOType boType = (BOType) new ServiceManager().locateService("com/ibm/websphere/bo/BOType");
Type customerType = boType.create("http://MP_SampleModule/Customer", "Customer");
DataObject customer = boFactory.createFromType(customerType);
D. createByMessage
     Syntax: commonj.sdo.DataObject createByMessage(java.lang.String targetNamesp                                 ace,java.lang.String messageName)
Creates a DataObject from a WSDL message definition.BOFactory boFactory = (BOFactory) new ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
DataObject customer = boFactory.createByMessage("http://MP_SampleModule/Customer", "customer");
E. createXMLDocument

Syntax: BOXMLDocument createXMLDocument(java.lang.String targetName                  space,java.lang.String globalElementName)
Creates a BOXMLDocument from an XML Schema global element definition.
BOFactory boFactory = (BOFactory) new ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
BOXMLDocument customerDocument = boFactory.createXMLDocument("http://MP_SampleModule/Customer", "customer");


F .createDataTypeWrapper

     Syntax: commonj.sdo.DataObject createDataTypeWrapper(commonj.sdo.TypedataType,java.lang.Object value)

Creates a DataObject wrapper for a simple data typeBOFactory boFactory = (BOFactory) new ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
BOType boType = (BOType) new ServiceManager().locateService("com/ibm/websphere/bo/BOType");
Type stringType = boType.getType("http://www.w3.org/2001/XMLSchema", "string");
DataObject stringType = boFactory.createDataTypeWrapper(stringType, "foo");


2. BOCopy : The BOCopy interface represents the client programming model interface for the BOCopy service. The BOCopy service provides operations for copying Business Objects.

" We have faced one situation in our project if we manipulate any data from one source data object in snippet activity after that if we are trying to use that same source data object in aother snippets we are unable to get the data from that object. It's reference getting lost. In that situation we are using this
BOCopy.

 A . copy :

Syntax: commonj.sdo.DataObject copy(commonj.sdo.DataObject sourceBusinessObject)
Creates a deep copy of the Business Object.
BOCopy boCopy = (BOCopy) new ServiceManager().locateService("com/ibm/websphere/bo/BOCopy");
DataObject copiedCustomer = boCopy.copy(customer);

B. copyShallow

Syntax: commonj.sdo.DataObject copyShallow(commonj.sdo.DataObject sourceBusinessObject)
Creates a shallow copy of the Business Object.
BOCopy boCopy = (BOCopy) new ServiceManager().locateService("com/ibm/websphere/bo/BOCopy");
DataObject copiedCustomer = boCopy.copyShallow(customer);

C. copyInto

Syntax: void copyInto(commonj.sdo.DataObject sourceBusinessObject,
              commonj.sdo.DataObject targetBusinessObject,
              java.lang.String targetPropertyPath)
Deprecated. Instead call copy on the source and then set the copy into the destination.
 Replacement code:
        DataObject copyBO = boCopy.copy(sourceBO);
        targetBO.set(path, copyBO);
 End of replacement code.

Creates a deep copy of the source Business Object into the property referenced by the combination of the target Business Object and the target property path parameters.

If the property referenced by the target Business Object and the associated target property path has a cardinality of 1 and has a value, it will be overwritten by the copy operation.
If the property referenced by the target Business Object and the associated target property path has a cardinality of N, the copy operation will result in the copied Business Object being added to the list.

The source Business Object cannot be a Business Graph.

The source Business Object's type must match the type of the property referenced by the target Business Object and the associated target property path.

For example, if the source Business Object consisted of a Customer containing an Address, and the target Business Object consisted of a Company containing a Site containing an Address, the following represent valid ways to copy the source Business Object's address Business Object to the target:

BOCopy boCopy = (BOCopy) new ServiceManager().locateService("com/ibm/websphere/bo/BOCopy");
boCopy.copyInto(addressSource, companyTarget, "site/address");
boCopy.copyInto(addressSource, siteTarget, "address");

D. copyIntoShallow

Syntax: void copyIntoShallow(commonj.sdo.DataObject sourceBusinessObject,
                     commonj.sdo.DataObject targetBusinessObject,
                     java.lang.String targetPropertyPath)
Deprecated. Instead call copy on the source and then set the copy into the destination.
 Replacement code:
        DataObject copyBO = boCopy.copyShallow(sourceBO);
        targetBO.set(path, copyBO);
 End of replacement code.

Creates a shallow copy of the source Business Object into the property referenced by the combination of the target Business Object and the target property path parameters.

If the property referenced by the target Business Object and the target property path has a cardinality of 1 and has a value, it will be overwritten by the copy operation.
If the property referenced by the target Business Object and the target property path has a cardinality of N, the copy operation will result in the copied Business Object being added to the list.

The source Business Object cannot be a Business Graph.

The source Business Object's type must match the type of the property referenced by the target Business Object and the associated property path.

For example, if the source Business Object consisted of a Customer containing an Address, and the target Business Object consisted of a Company containing a Site containing an Address, the following represent valid ways to copy the source Business Object's address Business Object to the target:

BOCopy boCopy = (BOCopy) new ServiceManager().locateService("com/ibm/websphere/bo/BOCopy");
boCopy.copyIntoShallow(addressSource, companyTarget, "site/address");
boCopy.copyIntoShallow(addressSource, siteTarget, "address");

E. copyPropertyInto

Syntax:  void copyPropertyInto(commonj.sdo.DataObject sourceBusinessObject,
                      java.lang.String sourcePropertyPath,
                      commonj.sdo.DataObject targetBusinessObject,
                      java.lang.String targetPropertyPath)
Deprecated. Instead get the property on the source and set on the destination.
 Replacement code:
        Object value = sourceBO.get(sourcePath);
        targetBO.set(targetPath, value);
 End of replacement code.

You may want to special case check for Date type and make a copy of the Date before setting into the destination. Otherwise the same Date object will be in both, and changing one will change the other. The same occurs if it is a List, and the contents of the List are Date objects.
Creates a copy of the simple type property referenced by the source Business Object combined with the source property path into the property referenced by the target Business Object combined with the target property path.

If the simple type property referenced by the target Business Object combined with the target property path has a cardinality of 1 and has a value, it will be overwritten by the copy operation.

If the simple type property referenced by the target Business Object combined with the target property path has a cardinality of N, the copy operation will result in the copied simple type being added to the list.

The property to be copied must be a simple type, and it must have the same type as the property it is being copied into.

For example, if the source Business Object consisted of a Customer containing an Address that contained a street property, and the target Business Object consisted of a Company containing a Site containing an Address that contained a street, the following represent valid ways to copy the street property from the source to the target:

BOCopy boCopy = (BOCopy) new ServiceManager().locateService("com/ibm/websphere/bo/BOCopy");
boCopy.copyPropertyInto(customer, "address/street", company, "site/address/street");
boCopy.copyPropertyInto(address, "street", site, "address/street");
boCopy.copyPropertyInto(addressSource, "street", addressTarget, "street");