Wednesday, November 21, 2012

Key, KeyRef and Unique in XSD


xs:key and xs:KeyRef are two XSD elements that defines the association of two elements in a XML document.  It is similar to the primary key and foreign key in the database.  It forces the association constraints between the elements.

xs:unique is XSD element that forces the uniqueness of value of specified XML element or attribute.

Here I will demonstrate the use of these XSD element in the below example.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.toic.com/cdm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="http://www.toic.com/cdm" elementFormDefault="qualified" attributeFormDefault="unqualified">
            <xs:element name="Passengers">
                        <xs:complexType>
                                    <xs:choice maxOccurs="unbounded">
                                                <xs:element name="Passenger" type="tns:PassengerType"/>
                                                <xs:element name="Infant" type="tns:InfantType"/>
                                    </xs:choice>
                        </xs:complexType>
                        <xs:unique name=" PassengerInfantUniqueSequnceNo ">
                                    <xs:selector xpath="tns:Passenger | tns:Infant"/>
                                    <xs:field xpath="@SequenceNo"/>
                        </xs:unique>
                                <xs:unique name="PassengerInfantUniqueID">
                                                <xs:selector xpath="tns:Passenger | tns:Infant"/>
                                                <xs:field xpath="@ID"/>
                                </xs:unique>    
                        <xs:key name="PassengerIdKey">
                                    <xs:selector xpath="tns:Passenger"/>
                                    <xs:field xpath="@ID"/>
                        </xs:key>
                        <xs:key name="InfantIdKey">
                                    <xs:selector xpath="tns:Infant"/>
                                    <xs:field xpath="@ID"/>
                        </xs:key>
                        <xs:keyref name="PassengerAssociationRef" refer="tns:InfantIdKey">
                                    <xs:selector xpath="tns:Passenger"/>
                                    <xs:field xpath="@AssociatedInfantID"/>
                        </xs:keyref>
                        <xs:keyref name="InfantAssociationRef" refer="tns:PassengerIdKey">
                                    <xs:selector xpath="tns:Infant"/>
                                    <xs:field xpath="@AssociatedPassengerID"/>
                        </xs:keyref>
            </xs:element>
            <xs:complexType name="PassengerType">
                        <xs:sequence>
                                    <xs:element name="FullName" type="xs:string"/>
                        </xs:sequence>
                        <xs:attribute name="SequenceNo" type="xs:int" use="required"/>
                        <xs:attribute name="ID" type="xs:int" use="required"/>
                        <xs:attribute name="AssociatedInfantID" type="xs:int"/>
            </xs:complexType>
            <xs:complexType name="InfantType">
                        <xs:sequence>
                                    <xs:element name="FullName" type="xs:string"/>
                        </xs:sequence>
                        <xs:attribute name="SequenceNo" type="xs:int" use="required"/>
                        <xs:attribute name="ID" type="xs:int" use="required"/>
                        <xs:attribute name="AssociatedPassengerID" type="xs:int" use="required"/>
            </xs:complexType>                       
</xs:schema>

 

In this schema a list of passengers (Passengers) is defined and this list consists of Passenger elements and Infant elements. Each item(either Passenger or Infant) in the list has a SequenceNo as an attribute. This SequenceNo needs to be unique within the list.  From the schema this can be achieved by defining xs:unique within Passengers definition.

<xs:unique name="PassengerInfantUniqueKey">
      <xs:selector xpath="tns:Passenger | tns:Infant"/>
     <xs:field xpath="@SequenceNo"/>
</xs:unique>

This definition says the SequenceNo attribute in Passenger and Infant needs to be unique within Passengers list where this unique is defined. Therefore the following XML document is not valid because Infant with ID 2 has the duplicate SequenceNo as one in Passenger with ID 1.

<tns:Passengers xmlns:tns="http://www.toic.com/cdm"  instance">
      <tns:Passenger AssociatedInfantID="3" ID="1" SequenceNo="1">
            <tns:FullName>Mark Sean</tns:FullName>
      </tns:Passenger>
      <tns:Passenger ID="2" SequenceNo="2">
            <tns:FullName>John Smith</tns:FullName>
      </tns:Passenger>
      <tns:Infant ID="3" AssociatedPassengerID="1" SequenceNo="1">
            <tns:FullName>Daniel Kemp</tns:FullName>
      </tns:Infant>
</tns:Passengers>

In order to fix this issue we just need to change the value of @SequenceNo in either of two Passengers to a unique value.

 

If you want to keep the association consistency in the list xs:key and xs:keyref can be used to force such consistency.  It is like foreign key referential integrity in RDBMS.   In this example in the list of Passengers one Passenger element may be associated with one Infant element and vice versa.  Such association consistency can achieve by introducing xs:key and xs:keyref elements in Passengers.   In order to do so the first step is to define the Keys and then the KeyRef which will refer the Keys defined before.

As shown below two Keys are defined: one is PassengerIdKey which use the attribute ID in Passenger element as the key and another is InfantIdKey.

<xs:key name="PassengerIdKey">
      <xs:selector xpath="tns:Passenger"/>
      <xs:field xpath="@ID"/>
</xs:key>
 
<xs:key name="InfantIdKey">
      <xs:selector xpath="tns:Infant"/>
      <xs:field xpath="@ID"/>
</xs:key>

Similar to the primary key definition in RDBMS the above definition says we select the attribute @ID in Passenger element as the key: PassengerIdKey and the attribute @ID in Infant element as the key: InfantIdKey.   Of course the key can be also defined base the element field or even a composite key can be defined based on the multiple fields of the element by using more than one xs:field element.

After the keys are defined we can refer these keys by defining keyref.  In the below example keyref PassengerAssociationRef and InfantAssociationRef.   Let us explain this definition by using example PassengerAssociationRef.   It says that the attribute @AssociatedInfantID in element Passenger is used as the keyref and it refers to the key InfantIdKey in Infant.  So the value of attribute AssociatedInfantID should be the same as the value of attribute ID in the associated Infant element.   Otherwise it is not valid against the schema.

<xs:keyref name="PassengerAssociationRef" refer="tns:InfantIdKey">
      <xs:selector xpath="tns:Passenger"/>
      <xs:field xpath="@AssociatedInfantID"/>
</xs:keyref>
 
<xs:keyref name="InfantAssociationRef" refer="tns:PassengerIdKey">
      <xs:selector xpath="tns:Infant"/>
      <xs:field xpath="@AssociatedPassengerID"/>
</xs:keyref>

 

The below is one example of XML document which is not valid against the schema because of the error in the association inconsistency.   The Passenger with ID=1 has the association with one Infant.   From the document this Passenger is supposed to associate with Infant with ID=2.   But actually there is no Infant with ID=2.   If we change AssociateInfantID=”2” in Passenger with ID=”1” to AssociateInfantID=”3” the document becomes valid against the schema.

<tns:Passengers xmlns:tns="http://www.toic.com/cdm">
      <tns:Passenger AssociatedInfantID="2" ID="1" SequenceNo="1">
            <tns:FullName>Mark Sean</tns:FullName>
      </tns:Passenger>
      <tns:Passenger ID="2" SequenceNo="2">
            <tns:FullName>John Smith</tns:FullName>
      </tns:Passenger>
      <tns:Infant ID="3" AssociatedPassengerID="1" SequenceNo="3">
            <tns:FullName>Daniel Kemp</tns:FullName>
      </tns:Infant>
</tns:Passengers>

 

One thing is needed to note that xs:unique, xs:key and xs:ketref are used in element definition rather than type definition.   And also the uniqueness and association consistency forced by the xs:unique, xs:key and xs:keyref are only effective with the element where these are defined.  Here a modified schema will demonstrate this.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.toic.com/cdm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="http://www.toic.com/cdm" elementFormDefault="qualified" attributeFormDefault="unqualified">
                <xs:element name="Flight">
                                <xs:complexType>
                                                <xs:sequence>
                                                                <xs:element ref="tns:Passengers" maxOccurs="unbounded"/>
                                                </xs:sequence>
                                </xs:complexType>
                                <xs:unique name="PassengerInfantUniqueSequnceNo">
                                                <xs:selector xpath="tns:Passengers/tns:Passenger | tns:Passengers/tns:Infant"/>
                                                <xs:field xpath="@SequenceNo"/>
                                </xs:unique>                    
                </xs:element>
               
                <xs:complexType name="PassengerListType">
                                <xs:choice maxOccurs="unbounded">
                                                                <xs:element name="Passenger" type="tns:PassengerType"/>
                                                                <xs:element name="Infant" type="tns:InfantType"/>
                                </xs:choice>
                                <xs:attribute name="CabinClass" type="xs:string" use="required"/>
                </xs:complexType>
               
                <xs:element name="Passengers" type="tns:PassengerListType">
                                <xs:unique name="PassengerInfantUniqueID">
                                                <xs:selector xpath="tns:Passenger | tns:Infant"/>
                                                <xs:field xpath="@ID"/>
                                </xs:unique>                    
                                <xs:key name="PassengerIdKey">
                                                <xs:selector xpath="tns:Passenger"/>
                                                <xs:field xpath="@ID"/>
                                </xs:key>
                                <xs:key name="InfantIdKey">
                                                <xs:selector xpath="tns:Infant"/>
                                                <xs:field xpath="@ID"/>
                                </xs:key>
                                <xs:keyref name="PassengerAssociationRef" refer="tns:InfantIdKey">
                                                <xs:selector xpath="tns:Passenger"/>
                                                <xs:field xpath="@AssociatedInfantID"/>
                                </xs:keyref>
                                <xs:keyref name="InfantAssociationRef" refer="tns:PassengerIdKey">
                                                <xs:selector xpath="tns:Infant"/>
                                                <xs:field xpath="@AssociatedPassengerID"/>
                                </xs:keyref>
                </xs:element>
                <xs:complexType name="PassengerType">
                                <xs:sequence>
                                                <xs:element name="FullName" type="xs:string"/>
                                </xs:sequence>
                                <xs:attribute name="SequenceNo" type="xs:int" use="required"/>
                                <xs:attribute name="ID" type="xs:int" use="required"/>
                                <xs:attribute name="AssociatedInfantID" type="xs:int"/>
                </xs:complexType>
                <xs:complexType name="InfantType">
                                <xs:sequence>
                                                <xs:element name="FullName" type="xs:string"/>
                                </xs:sequence>
                                <xs:attribute name="SequenceNo" type="xs:int" use="required"/>
                                <xs:attribute name="ID" type="xs:int" use="required"/>
                                <xs:attribute name="AssociatedPassengerID" type="xs:int" use="required"/>
                </xs:complexType>       
                <xs:element name="Infant" type="tns:InfantType">
                                <xs:unique name="InfantIDUnique">
                                                <xs:selector xpath="."></xs:selector>
                                                <xs:field xpath="@ID"></xs:field>
                                </xs:unique>
                </xs:element>
</xs:schema>

 

In this new schema there is new element called: Flight.   Each Flight may have one or more than one list of Passengers.   Now the unique PassengerInfantUniqueSequnceNo is moved to element Flight.   It means that values of @SequenceNo for Passenger or Infant need to be unique within Flight no matter what Passengers list it belongs to.   However the value of @ID just needs to be unique with each Passengers list. 

The below XML document is valid even though some Passengers have the duplicate IDs within the Flight.

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2008 sp1 (http://www.altova.com)-->
<tns:Flight xsi:schemaLocation="http://www.toic.com/cdm Untitled18.xsd" xmlns:tns="http://www.toic.com/cdm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <tns:Passengers CabinClass="A">
                                <tns:Passenger AssociatedInfantID="3" ID="1" SequenceNo="1">
                                                <tns:FullName>String</tns:FullName>
                                </tns:Passenger>
                                <tns:Passenger ID="2" SequenceNo="2">
                                                <tns:FullName>String</tns:FullName>
                                </tns:Passenger>
                               
                                <tns:Infant ID="3" AssociatedPassengerID="1" SequenceNo="3">
                                                <tns:FullName>String</tns:FullName>
                                </tns:Infant>
                </tns:Passengers>
               
                <tns:Passengers CabinClass="B">
                                <tns:Passenger ID="1" SequenceNo="4">
                                                <tns:FullName>String</tns:FullName>
                                </tns:Passenger>
                                <tns:Passenger ID="2" AssociatedInfantID="3"  SequenceNo="5">
                                                <tns:FullName>String</tns:FullName>
                                </tns:Passenger>
                                <tns:Infant ID="3" AssociatedPassengerID="2" SequenceNo="6">
                                                <tns:FullName>String</tns:FullName>
                                </tns:Infant>                   
                </tns:Passengers>
</tns:Flight>

 

 

Monday, October 22, 2012

Service callout v.s. Route

In Oracle OSB service callout action and route action do the almost same thing: invoke a service synchronously.   But when the fault happens during the invocation how OSB populate the implicit object variables such as: $body, $fault.
Here is one service defined by the interface QueryService.wsdl.  The below lists some scenarios in service callout and rout:

Routing

Service provider returns a SOAP fault.
$body is populated with the fault returned by the provider.

<soapenv:Body xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Fault>
    <faultcode>SYS-0001</faultcode>
    <faultstring>An unknown error has occurred in one of Virgin Australia's systems.</faultstring>
    <detail>
      <isl:fault xmlns:isl="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4" xmlns:cdm="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4/CDM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <cdm:faultCode>concurrentAccessException</cdm:faultCode>
        <cdm:faultString>String</cdm:faultString>
        <cdm:faultActor>String</cdm:faultActor>
        <cdm:detail>
          <cdm:GPELogReference>String</cdm:GPELogReference>
        </cdm:detail>
        <cdm:exception>
          <cdm:code>String</cdm:code>
          <cdm:reason>String</cdm:reason>
          <cdm:actor>String</cdm:actor>
        </cdm:exception>
      </isl:fault>
    </detail>
  </soapenv:Fault>
</soapenv:Body>

$fault is Weblogic error.
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
  <con:errorCode>BEA-380001</con:errorCode>
  <con:reason>Internal Server Error</con:reason>
  <con:location>
    <con:node>Route to RoutingFaultHandlingBusinessService</con:node>
    <con:path>response-pipeline</con:path>
  </con:location>
</con:fault>


Service provide response timeout
$body
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>

$fault
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
  <con:errorCode>BEA-380000</con:errorCode>
  <con:reason>[WliSbTransports:381304]Exception in HttpOutboundMessageContext.RetrieveHttpResponseWork.run: java.net.SocketTimeoutException
java.net.SocketTimeoutException
            at weblogic.net.http.AsyncResponseHandler$MuxableSocketHTTPAsyncResponse$SocketTimeoutNotification.&lt;clinit>(AsyncResponseHandler.java:555)
            at weblogic.net.http.AsyncResponseHandler$MuxableSocketHTTPAsyncResponse.handleTimeout(AsyncResponseHandler.java:400)
            at weblogic.net.http.AsyncResponseHandler$MuxableSocketHTTPAsyncResponse.timeout(AsyncResponseHandler.java:506)
            at weblogic.socket.SocketMuxer$TimerListenerImpl.timerExpired(SocketMuxer.java:1060)
            at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273)
            at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545)
            at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
            at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)</con:reason>
  <con:location>
    <con:node>Route to RoutingFaultHandlingBusinessService</con:node>
    <con:path>response-pipeline</con:path>
  </con:location>
</con:fault>

Cannot connect to service provide
$body
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <v4:queryServiceByService xmlns:v4="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4" xmlns:cdm="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4/CDM">
    <v4:service>
      <!--Optional:-->
      <cdm:serviceId>1234</cdm:serviceId>
      <!--Optional:-->
      <cdm:serviceStatus>string</cdm:serviceStatus>
      <!--Optional:-->
      <cdm:location>
        <!--Optional:-->
        <cdm:placeKey>
          <!--Optional:-->
          <cdm:primaryKey>string</cdm:primaryKey>
        </cdm:placeKey>
      </cdm:location>
      <!--Optional:-->
      <cdm:serviceType>string</cdm:serviceType>
      <!--Optional:-->
      <cdm:serviceNotes>
        <!--Zero or more repetitions:-->
        <cdm:serviceNote>
          <!--Optional:-->
          <cdm:note>string</cdm:note>
        </cdm:serviceNote>
      </cdm:serviceNotes>
    </v4:service>
    <v4:type>string</v4:type>
    <v4:customerAccount>
      <!--Optional:-->
      <cdm:accountId>string</cdm:accountId>
    </v4:customerAccount>
  </v4:queryServiceByService>
</soapenv:Body>

$fault
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
  <con:errorCode>BEA-380002</con:errorCode>
  <con:reason>Tried all: '4' addresses, but could not connect over HTTP to server: 'markchen-laptop', port: '8188'</con:reason>
  <con:location>
    <con:node>Route to RoutingFaultHandlingBusinessService</con:node>
    <con:path>request-pipeline</con:path>
  </con:location>
</con:fault>

Service callout

Service provider returns a SOAP fault.

$body

  <v4:queryServiceByService>
    <v4:service>
      <!--Optional:-->
      <cdm:serviceId>4321</cdm:serviceId>
      <!--Optional:-->
      <cdm:serviceStatus>?</cdm:serviceStatus>
      <!--Optional:-->
      <cdm:location>
        <!--Optional:-->
        <cdm:placeKey>
          <!--Optional:-->
          <cdm:primaryKey>?</cdm:primaryKey>
        </cdm:placeKey>
      </cdm:location>
      <!--Optional:-->
      <cdm:serviceType>?</cdm:serviceType>
      <!--Optional:-->
      <cdm:serviceNotes>
        <!--Zero or more repetitions:-->
        <cdm:serviceNote>
          <!--Optional:-->
          <cdm:note>?</cdm:note>
        </cdm:serviceNote>
      </cdm:serviceNotes>
    </v4:service>
    <v4:type>?</v4:type>
    <v4:customerAccount>
      <!--Optional:-->
      <cdm:accountId>?</cdm:accountId>
    </v4:customerAccount>
  </v4:queryServiceByService>
</soapenv:Body>

$fault

<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
  <con:errorCode>BEA-382500</con:errorCode>
  <con:reason>OSB Service Callout action received SOAP Fault response</con:reason>
  <con:details>
    <con1:ReceivedFaultDetail xmlns:con1="http://www.bea.com/wli/sb/stages/transform/config">
      <con1:faultcode>SYS-0001</con1:faultcode>
      <con1:faultstring>An unknown error has occurred in one of Virgin Australia's systems.</con1:faultstring>
      <con1:detail>
        <isl:fault xmlns:isl="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4" xmlns:cdm="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4/CDM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
          <cdm:faultCode>concurrentAccessException</cdm:faultCode>
          <cdm:faultString>String</cdm:faultString>
          <cdm:faultActor>String</cdm:faultActor>
          <cdm:detail>
            <cdm:GPELogReference>String</cdm:GPELogReference>
          </cdm:detail>
          <cdm:exception>
            <cdm:code>String</cdm:code>
            <cdm:reason>String</cdm:reason>
            <cdm:actor>String</cdm:actor>
          </cdm:exception>
        </isl:fault>
      </con1:detail>
      <con1:http-response-code>500</con1:http-response-code>
    </con1:ReceivedFaultDetail>
  </con:details>
  <con:location>
    <con:node>PipelinePairNode1</con:node>
    <con:pipeline>PipelinePairNode1_request</con:pipeline>
    <con:stage>stage1</con:stage>
    <con:path>request-pipeline</con:path>
  </con:location>
</con:fault>


Service provide response timeout
$body
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <v4:queryServiceByService xmlns:v4="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4" xmlns:cdm="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4/CDM">
    <v4:service>
      <!--Optional:-->
      <cdm:serviceId>1111</cdm:serviceId>
      <!--Optional:-->
      <cdm:serviceStatus>string</cdm:serviceStatus>
      <!--Optional:-->
      <cdm:location>
        <!--Optional:-->
        <cdm:placeKey>
          <!--Optional:-->
          <cdm:primaryKey>string</cdm:primaryKey>
        </cdm:placeKey>
      </cdm:location>
      <!--Optional:-->
      <cdm:serviceType>string</cdm:serviceType>
      <!--Optional:-->
      <cdm:serviceNotes>
        <!--Zero or more repetitions:-->
        <cdm:serviceNote>
          <!--Optional:-->
          <cdm:note>string</cdm:note>
        </cdm:serviceNote>
      </cdm:serviceNotes>
    </v4:service>
    <v4:type>string</v4:type>
    <v4:customerAccount>
      <!--Optional:-->
      <cdm:accountId>string</cdm:accountId>
    </v4:customerAccount>
  </v4:queryServiceByService>
</soapenv:Body>

$fault
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
  <con:errorCode>BEA-380000</con:errorCode>
  <con:reason>[WliSbTransports:381304]Exception in HttpOutboundMessageContext.RetrieveHttpResponseWork.run: java.net.SocketTimeoutException
java.net.SocketTimeoutException
            at weblogic.net.http.AsyncResponseHandler$MuxableSocketHTTPAsyncResponse$SocketTimeoutNotification.&lt;clinit>(AsyncResponseHandler.java:555)
            at weblogic.net.http.AsyncResponseHandler$MuxableSocketHTTPAsyncResponse.handleTimeout(AsyncResponseHandler.java:400)
            at weblogic.net.http.AsyncResponseHandler$MuxableSocketHTTPAsyncResponse.timeout(AsyncResponseHandler.java:506)
            at weblogic.socket.SocketMuxer$TimerListenerImpl.timerExpired(SocketMuxer.java:1060)
            at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273)
            at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545)
            at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
            at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)</con:reason>
  <con:location>
    <con:node>PipelinePairNode1</con:node>
    <con:pipeline>PipelinePairNode1_request</con:pipeline>
    <con:stage>stage1</con:stage>
    <con:path>request-pipeline</con:path>
  </con:location>
</con:fault>

Cannot connect to service provide
$body
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v4="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4" xmlns:cdm="http://com.toic.telecom/ISL/ServiceInventoryManagement/queryServiceByService/V4/CDM">
  <v4:queryServiceByService>
    <v4:service>
      <!--Optional:-->
      <cdm:serviceId>4321</cdm:serviceId>
      <!--Optional:-->
      <cdm:serviceStatus>?</cdm:serviceStatus>
      <!--Optional:-->
      <cdm:location>
        <!--Optional:-->
        <cdm:placeKey>
          <!--Optional:-->
          <cdm:primaryKey>?</cdm:primaryKey>
        </cdm:placeKey>
      </cdm:location>
      <!--Optional:-->
      <cdm:serviceType>?</cdm:serviceType>
      <!--Optional:-->
      <cdm:serviceNotes>
        <!--Zero or more repetitions:-->
        <cdm:serviceNote>
          <!--Optional:-->
          <cdm:note>?</cdm:note>
        </cdm:serviceNote>
      </cdm:serviceNotes>
    </v4:service>
    <v4:type>?</v4:type>
    <v4:customerAccount>
      <!--Optional:-->
      <cdm:accountId>?</cdm:accountId>
    </v4:customerAccount>
  </v4:queryServiceByService>
</soapenv:Body>

$fault
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
  <con:errorCode>BEA-382501</con:errorCode>
  <con:reason>OSB Service Callout action received an unrecognized response</con:reason>
  <con:details>
    <con1:UnrecognizedResponseDetail xmlns:con1="http://www.bea.com/wli/sb/stages/transform/config">
      <con1:http-response-code>200</con1:http-response-code>
    </con1:UnrecognizedResponseDetail>
  </con:details>
  <con:location>
    <con:node>PipelinePairNode1</con:node>
    <con:pipeline>PipelinePairNode1_request</con:pipeline>
    <con:stage>stage1</con:stage>
    <con:path>request-pipeline</con:path>
  </con:location>
</con:fault>
  

Wednesday, September 5, 2012

The error using test console of Oracle Service Bus 11g

Recently I was trying to test one proxy service using test console in OSB console I encountered the error after clicking on the Launch Test Console icon.   It shows the error like the below:


I found that one solution for this issue is to check the listen address of the server.  From the console go to the Mydomain --> Environment --> Servers --> AdminServer. Then check the Settings of the AdminServer --> Configuration --> General.   I found that the Listen Adress is empty.  The fix is to enter localhost as the value for Listen Address and save the change as the below:

In order to make this change effective I need to restart the server.    After the server is restarted I can use the test console in OSB console now.
   

Monday, September 3, 2012

How to change jdkhome for Netbeans

After you change your JDK home directory, your installed NetBeans will have the following error when you start it:


You can easily avoid this error occurring by changing the configuration file for NetBeans.
This configuration file: netbeans.config is located in: Your_NetBeans_Installation_Dir\etc.

Open this file and change the item: netbeans_jdkhome to your new JDK home directory as the following example:

netbeans_jdkhome="C:\Java\jdk1.7.0_06" 

Then save the change.   Note that by default this file is set to the security properties without Write attribute so you need to change the security property before you can save your changes.

After the change is saved NetBeans can be started to use the new JDK now.

Thursday, July 26, 2012

Builder Pattern and Template Method Pattern


Builder pattern is one pattern that belongs to the category of Creational Pattern.  It is used to  create the object for the client.  There are some situation where  the object creation is to be done via multiple steps.  Builder pattern comes up for this situations.   With Builder pattern you can have the fine-grained control over the some steps in the creation process.

In the below example to make a policy object it needs several steps: intializePolicy, addProduct and calculateDiscount.  After these three steps one policy objects can be constructed completely.   For different Policy classes you may be able to differentiate the each step creation in the concrete policy maker classes.   Here NZPolicyMaker will make the NZPolicy and AusPolicyMaker will make the AusPolicy.  In each step you can decide what to do based on the requirement for NZPolicy or AustPolicy.

So in short, Builder pattern applies to the situation where one object creation is multiple predefined steps and you can have the control over each steps in concrete Builder based on the requirement.


Template method pattern is another category of design pattern.  It belongs to Behavioural pattern.  This pattern is used to implement one algorithm which is executed in multiple steps and the interface defines the skeleton of the algorithm while the concrete class can implement the steps which vary.

The below is one example of Template method pattern.  The interface FleetCardHandler defines the methods to be used to process the request message from the fleet card.   But different fleet cards need the different processing logic.  These varying logic are implemented in the concrete classes: SUCFleetCardHanlder and TekFleetCardHandler.

From here we can see the similarity between Builder pattern and Template method pattern.  Both these patterns have the predefined steps to perform one process(creation or  algorithm) and these steps can be implemented based on the varying business logic.  Builder and Template Method pattern give you the fine-grained control over the either creation or algorithm.