Friday, July 20, 2012

Splitting an array of repeated elements into sub groups based on index in XSL

Splitting an array of repeated elements into sub groups based on index in XSL

Sometimes we may require splitting the array of repeated elements into sub groups based on index in XSL; this blog will explain the approach to do the same.

The below XSLT will select the first two order line items from the list of line items.
The same can be used to select the elements by passing startIndex and endIndex values.

<xsl:stylesheet version="1.0"
                xmlns:xsdLocal="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="startIndex">1</xsl:variable>
<xsl:variable name="endIndex">2</xsl:variable>
  <xsl:template match="/">
    <xsdLocal:orderRequest>
      <xsl:for-each select="/xsdLocal:UserIdRequest/xsdLocal:orderLineItem[(position() >= $startIndex) and (position() &lt;= $endIndex)]">
        <xsdLocal:orderLineItem>
          <xsdLocal:CRMOLIId>
            <xsl:value-of select="xsdLocal:CRMOLIId"/>
          </xsdLocal:CRMOLIId>
          <xsdLocal:parentOrderItemId>
            <xsl:value-of select="xsdLocal:parentOrderItemId"/>
          </xsdLocal:parentOrderItemId>
          <xsdLocal:rootItemId>
            <xsl:value-of select="xsdLocal:rootItemId"/>
          </xsdLocal:rootItemId>
      </xsdLocal:orderLineItem>
      </xsl:for-each>
    </xsdLocal:orderRequest>
  </xsl:template>
</xsl:stylesheet>

Input XML:

<?xml version="1.0" encoding="UTF-8" ?>
<UserIdRequest  xmlns="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement">
  
   <orderLineItem>
      <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
    
   </orderLineItem>
   <orderLineItem>
        <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
   <orderLineItem>
       <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
  
    <orderLineItem>
       <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
  
    <orderLineItem>
       <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
  
    <orderLineItem>
       <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
</UserIdRequest>

Output XML:

<?xml version = '1.0' encoding = 'UTF-8'?>
<xsdLocal:orderRequest xmlns:xsdLocal="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement file:/D:/Albin/DevCodeBase/2012_R5/CRM_EAI_code_deploy/code/CRM61OM/CPFGOM_OrderSplitter/EAI.MSG.OM.125_OrderRequest.xsd">
   <xsdLocal:orderLineItem>
      <xsdLocal:CRMOLIId>CRMOLIId529</xsdLocal:CRMOLIId>
      <xsdLocal:parentOrderItemId>parentOrderItemId530</xsdLocal:parentOrderItemId>
      <xsdLocal:rootItemId>rootItemId531</xsdLocal:rootItemId>
   </xsdLocal:orderLineItem>
   <xsdLocal:orderLineItem>
      <xsdLocal:CRMOLIId>CRMOLIId529</xsdLocal:CRMOLIId>
      <xsdLocal:parentOrderItemId>parentOrderItemId530</xsdLocal:parentOrderItemId>
      <xsdLocal:rootItemId>rootItemId531</xsdLocal:rootItemId>
   </xsdLocal:orderLineItem>
</xsdLocal:orderRequest>


Finding the distinct values of an element in a XSL


Finding the distinct values of an element in a XSL

Sometimes we may have the requirement to identify the distinct elements in the input XML. Key function will help us to identify the distinct elements in the XSL.

The key () function returns a node-set from the document, using the index specified by an <xsl:key> element.

Syntax:

node-set key(string, object)
string - Specifies the name of an xsl:key element
object - A string to search for

The below XSL will find the distinct nextaction1 available in the XML.

TransDistinctNextAction1.xsl

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsdLocal="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement">
  <xsl:key name="orderlines-by-n1" match="/xsdLocal:extendedOrderRequest/xsdLocal:orderLineItem" use="xsdLocal:nextAction1"/>
 
  <xsl:template match="/">
    <xsdLocal:distinctNextActions>
      <xsdLocal:nextAction>
        <xsdLocal:nextAction1>
          <xsl:for-each select="/xsdLocal:extendedOrderRequest/xsdLocal:orderLineItem[generate-id(.) = generate-id( key('orderlines-by-n1', xsdLocal:nextAction1)[1])]">
            <xsdLocal:value>
              <xsl:value-of select="xsdLocal:nextAction1"/>
            </xsdLocal:value>
          </xsl:for-each>
        </xsdLocal:nextAction1>       
      </xsdLocal:nextAction>
    </xsdLocal:distinctNextActions>
  </xsl:template>
</xsl:stylesheet>


  <xsl:key name="orderlines-by-n1" match="/xsdLocal:extendedOrderRequest/xsdLocal:orderLineItem" use="xsdLocal:nextAction1"/>

                      Find the orderLineItems based on the nextaction1

          <xsl:for-each select="/xsdLocal:extendedOrderRequest/xsdLocal:orderLineItem[generate-id(.) = generate-id( key('orderlines-by-n1', xsdLocal:nextAction1)[1])]">

                        Find the unique nextaction1 values from the orderLineItems

Input XML:

<?xml version="1.0" encoding="UTF-8" ?>
<extendedOrderRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement">
  
    <orderLineItem>
      <CRMOLIId>CRMOLIId36</CRMOLIId>
      <rootItemId>rootItemId37</rootItemId>
      <parentOrderItemId>parentOrderItemId38</parentOrderItemId>
      <actionCode>actionCode39</actionCode>     
      <nextAction1>nextAction175</nextAction1>     
   </orderLineItem>
   <orderLineItem>
      <CRMOLIId>CRMOLIId36</CRMOLIId>
      <rootItemId>rootItemId37</rootItemId>
      <parentOrderItemId>parentOrderItemId38</parentOrderItemId>
      <actionCode>actionCode39</actionCode>     
      <nextAction1>nextAction175</nextAction1>
   </orderLineItem>
   <orderLineItem>
      <CRMOLIId>CRMOLIId36</CRMOLIId>
      <rootItemId>rootItemId37</rootItemId>
      <parentOrderItemId>parentOrderItemId38</parentOrderItemId>
      <actionCode>actionCode39</actionCode>     
      <nextAction1>nextAction17</nextAction1>
   </orderLineItem>
</extendedOrderRequest>

Output XML:

<?xml version = '1.0' encoding = 'UTF-8'?>
<xsdLocal:distinctNextActions xmlns:xsdLocal="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <xsdLocal:nextAction>
      <xsdLocal:nextAction1>
         <xsdLocal:value>nextAction175</xsdLocal:value>
         <xsdLocal:value>nextAction17</xsdLocal:value>
      </xsdLocal:nextAction1>
   </xsdLocal:nextAction>
</xsdLocal:distinctNextActions>



Java webservice considering the space/newline characters as an element


Java webservice considering the space/newline characters as an element

We have developed a java webservice to convert the xml to fixed length payload; unfortunately it was failing with Class cast Exception.

<faultstring>java.lang.String cannot be cast to javax.xml.bind.JAXBElement</faultstring>

 
After debugging we have identified the parser considering the new line character in the XML payload as the JAXBElement.

 
We tried removing the new line characters and the spaces in the xml payload and it worked fine.



After a long struggle we have identified the root cause.


Wednesday, July 18, 2012

Undeploying SOA Composite while soa-infra is down in Oracle SOA Suite

Undeploying SOA Composite while soa-infra is down in Oracle SOA Suite:

Recently we had an issue with soa-infra start-up, soa-infra application won’t come up due to corrupt composite. 

We have followed the Meta link note 1380835.1 to un-deploy the corrupted composite and bring up the soa-infra application.

Thought of sharing the same here, it may help whoever facing the same issue.

The SOA composites can’t be un-deployed when the soa-infra application. The below steps will help you to un-deploy the SOA composites when the soa-infra application is down.
  • First check the soa logs and identify which composite is causing the problem
  • Download and copy the ShareSoaInfraPartition.ear file to $MWHOME/Oracle_SOA/common/bin
  • Execute $MWHOME/Oracle_SOA/common/bin/wlst.sh
  •  connect()
             Provide username, password and server URL
  • Run the below command to deploy ShareSoaInfraPartition.ear
                 deploy('ShareSoaInfraPartition','ShareSoaInfraPartition.ear',upload='true')
  • Now run the below command by changing the "toLocation" ('/fmw11g/Middleware' is some location path on SOA machine)
   exportMetadata(application='ShareSoaInfraPartition',server='AdminServer',toLocation='/fmw11g/Middleware',docs='/deployed-composites/deployed-composites.xml')
A deployed-composites folder will be created at "toLocation" path with deployed-composites.xml in it
  • Delete the composite which is causing the problem from deployed-composites.xml and save the file
          for example FormatDate composite like below
            <composite-series name="default/FormatDate" default="default/FormatDate!1.0">
                  <composite-revision dn="default/FormatDate!1.0" state="on" mode="active"   location="dc/soa_b8c8782b-776e-42c3-8519-d29fdfb72032">
                 <composite dn="default/FormatDate!1.0*soa_b8c8782b-776e-42c3-8519-d29fdfb72032"  deployedTime="2012-07-11T04:14:47.665-07:00"/>
                </composite-revision>
            </composite-series>
  • Now run the below command by changing the "fromLocation" (this should be the same location as previous)
            importMetadata(application='ShareSoaInfraPartition',server='AdminServer',fromLocation='/fmw11g/fmw1115/Middleware',docs='/deployed-composites/deployed-composites.xml')

 Now bounce your server and the composite will not be deployed by SOA when it comes up and hence that should bring your soa-infra up.

DOWNLOAD ShareSoaInfraPartition.zip


Creating a wlfullclient.jar - Weblogic

Creating a wlfullclient.jar for JDK 1.6 client applications from weblogic server

    Change directories to the server/lib directory.

    cd WL_HOME/server/lib

    Use the following command to create wlfullclient.jar in the server/lib directory:

    java -jar wljarbuilder.jar

    You can now copy and bundle the wlfullclient.jar with client applications.

Creating a wlfullclient5.jar for JDK 1.5 client applications:

    Change directories to the server/lib directory.

    cd WL_HOME/server/lib

    Use the following command to create wlfullclient.jar in the server/lib directory:

    java -jar wljarbuilder.jar -profile wlfullclient5

    You can now copy and bundle the wlfullclient5.jar with client applications.