Sunday, May 9, 2010

OSB: how to find which service/operation you are in

The $operation variable tells you the operation you are executing. But operation is not unique across all services, so to uniquely identify who you are you must add also the service information.

As reported here

<con:endpoint name="ProxyService$TestUpdateDB$PS$InsertInDbPS" xmlns:con="http://www.bea.com/wli/sb/context">
  <con:service>
    <con:operation>updateCompany</con:operation>
  </con:service>
  <con:transport>
    <con:uri>/TestUpdateDB/PS/InsertInDbPS</con:uri>
    <con:mode>request-response</con:mode>
    <con:qualityOfService>best-effort</con:qualityOfService>
    <con:request xsi:type="http:HttpRequestMetaData" xmlns:http="http://www.bea.com/wli/sb/transports/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <tran:headers xsi:type="http:HttpRequestHeaders" xmlns:tran="http://www.bea.com/wli/sb/transports">
        <http:Content-Type>text/xml; charset=utf-8</http:Content-Type>
        <http:SOAPAction>""</http:SOAPAction>
      </tran:headers>
      <tran:encoding xmlns:tran="http://www.bea.com/wli/sb/transports">utf-8</tran:encoding>
    </con:request>
    <con:response xsi:type="http:HttpResponseMetaData" xmlns:http="http://www.bea.com/wli/sb/transports/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <tran:headers xsi:type="http:HttpResponseHeaders" xmlns:tran="http://www.bea.com/wli/sb/transports">
        <http:Content-Type>text/xml</http:Content-Type>
      </tran:headers>
      <tran:response-code xmlns:tran="http://www.bea.com/wli/sb/transports">0</tran:response-code>
    </con:response>
  </con:transport>
  <con:security>
    <con:transportClient>
      <con:username><anonymous></con:username>
    </con:transportClient>
  </con:security>
</con:endpoint>


there is a $inbound/con:endpoint/con:service variable, but this seems to be always empty :o( (there must a way to assign a value to it...). Theoretically con:service should specify providerName and operation, which sounds interesing, if only it was filled. Reading the docs here http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/context.html#wp1080491 it becomes evident that this applies only to the $outbound variable while publishing... confusing indeed.

The alternative is using $inbound/ctx:transport/ctx:uri, that is the endpoint, which is unique. Better than losing your umbrella, as they say in Bologna.

We also learn that the XSDs MessageContext.xsd of the inbound and outbound elements are in a ORACLE_HOME/osb_10.3/lib/sb-schemas.jar , see here:
http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/context.html#wp1060634


Interesting enough, the Reference.xsd file in the sb-schemas.jar contains a line which causes an error:

xs:import namespace="http://www.bea.com/wli/config/reference"
schemaLocation="Reference.xsd"


just remove it and the error goes away.



This script should return you the URI given the $inbound variable as input:

(:
Pass $inbound as input, it should return you the Service URI
:)


(:: pragma bea:local-element-parameter parameter="$inbound_endpoint1" type="ns0:messagecontext/ns0:inbound-endpoint" location="../../CommonResources/XSD/MessageReporting.xsd" ::)

declare namespace ns0 = "http://www.bea.com/wli/sb/context";
declare namespace xf = "http://tempuri.org/TestUpdateDB/XQuery/getServiceFromInbound/";

declare function xf:getServiceFromInbound($inbound_endpoint1 as element())
as xs:string {
xs:string( data($inbound_endpoint1/ns0:transport/ns0:uri) )
};

declare variable $inbound_endpoint1 as element() external;

xf:getServiceFromInbound($inbound_endpoint1)

No comments: