BizTalk and Rest Example from BizTalk Saturday

Posted: February 11, 2013  |  Categories: BizTalk Uncategorized

This is one of my demonstrations from BizTalk Saturday at Auckland on 9/02/2013. This event was organised by Bill Chestnut and Nikolai Blackie.

BizTalk 2013 Hands On Day - 03 REST

I was asked if you could use the same ReST send adapter and dynamically send different ReSTful requests. For example can we use a send adapter to send two GETS that use the  base URI of http://broadbandmap.govt.nz/api/v1 i.e

http://broadbandmap.govt.nz/api/v1/DemandCategory/7

http://broadbandmap.govt.nz/api/v1/DemandPoint/14

As it happens I had a demonstration that showed one way of doing this. This demo sends a request to ReSTful service to get a list of Broadband demand points and then the details each Broadband demand point is subsequently retrieved from another ReSTful service that has the same base url.  I configured a send port as shown below that had two different operations for the two ReSTful requests.

<BtsHttpUrlMapping>

<Operation Name=”GetDemandCategory” Method=”GET” Url=”DemandCategory/{id}”/>

<Operation Name=”GetDemandPoint” Method=”GET” Url=”DemandPoint/{id}”/>

</BtsHttpUrlMapping>

image

The variable mapping was configured to use id context property with a name space of https://Datacom.BT.RestDEmo.ExternalSchemas.Broadbandmap_Govt_NZPropertySchema. The two schemas that reference this property schema for GetDemandCategory and GetDemandPoint are respectively.

clip_image002clip_image002[6]

The send pipeline is configured to use the Saravana Kumar’s RemoveBody custom pipeline and the receive pipeline uses a custom pipeline.  The custom receive pipeline  adds a namespace to the response from the ReST service and stamps the message with a BTS.Operation = GetDemaondPoint.

imageimage

The send adapter subscribes to messages from the message box using these filters. The first filter subscribes to the initial request to get the Demand Point list and the second filter subscribes to the DemandPoints that are split from the  list response..

image

 

A receive port and receive location was created to with a file adapter to initiate the ReST request. The receive pipeline dissembles the message as XML and then promotes BTS.Operation = GetDemandCategory.

imageimage

 

<ns0:Broadbandmap_Govt_NZ xmlns:ns0=”http://Datacom.BT.RestDEmo.ExternalSchemas.Broadbandmap_Govt_NZ”>
<id>14</id>
</ns0:Broadbandmap_Govt_NZ>

If the message above is submitted to the receive location , then it is submitted to the message box,  the BroadbandMap.Govt.NZ send port subscribes to the message and  a request like “GET http://broadbandmap.govt.nz/api/v1/DemandCategory/14 HTTP/1.1” is sent. The response is

<?xml version=”1.0″ encoding=”UTF-8″?>
<DemandCategory href=”
http://broadbandmap.govt.nz/api/v1/DemandCategory/14.xml”>
<Title>Professional, Scientific and Technical Services</Title>
<ImportedTitle>Professional, Scientific and Technical Services</ImportedTitle>
<ParentID>4</ParentID>
<ID>14</ID>
<Parent linktype=”has_one” href=”
http://broadbandmap.govt.nz/api/v1/DemandCategory/4.xml” id=”4″></Parent>
<Points linktype=”has_many” href=”
http://broadbandmap.govt.nz/api/v1/DemandCategory/14/Points.xml”>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3938.xml” id=”3938″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3943.xml” id=”3943″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3944.xml” id=”3944″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3954.xml” id=”3954″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3957.xml” id=”3957″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3959.xml” id=”3959″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3960.xml” id=”3960″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3965.xml” id=”3965″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/3967.xml” id=”3967″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/33207.xml” id=”33207″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/33208.xml” id=”33208″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6950.xml” id=”6950″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6954.xml” id=”6954″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6959.xml” id=”6959″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6961.xml” id=”6961″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6962.xml” id=”6962″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6963.xml” id=”6963″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6966.xml” id=”6966″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6970.xml” id=”6970″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/6977.xml” id=”6977″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/7961.xml” id=”7961″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9944.xml” id=”9944″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9948.xml” id=”9948″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9950.xml” id=”9950″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9953.xml” id=”9953″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9954.xml” id=”9954″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9958.xml” id=”9958″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9962.xml” id=”9962″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9963.xml” id=”9963″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9964.xml” id=”9964″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9966.xml” id=”9966″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9968.xml” id=”9968″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9970.xml” id=”9970″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9976.xml” id=”9976″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/9984.xml” id=”9984″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/10966.xml” id=”10966″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/11256.xml” id=”11256″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/11271.xml” id=”11271″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/11268.xml” id=”11268″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/11267.xml” id=”11267″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/11264.xml” id=”11264″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/11263.xml” id=”11263″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/11331.xml” id=”11331″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/11329.xml” id=”11329″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/12490.xml” id=”12490″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/12520.xml” id=”12520″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34294.xml” id=”34294″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34293.xml” id=”34293″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34285.xml” id=”34285″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34282.xml” id=”34282″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34278.xml” id=”34278″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34277.xml” id=”34277″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34265.xml” id=”34265″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34126.xml” id=”34126″></DemandPoint>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34213.xml” id=”34213″></DemandPoint>
</Points>
</DemandCategory>

if you temporarily change the receive pipeline on the BroadbandMap.Govt.NZ send port to an XML receive pipeline and create a file send port with a subscription BTS.messageType = DemandCategory then this message will be written to this file location.

if the receive pipeline on the BroadbandMap.Govt.NZ send port is Rcv_broadMap_govt_NZ_DemandPoint the message is stamped with a namespace of http://Datacom.BT.RestDEmo.ExternalSchemas.BroadbandMap_Govt_NZ_DemandCategory , de-batched into individual DemandPoint messages (shown below) and then stamped with BTS.Operation = DemandPoint . The message of type http://Datacom.BT.RestDEmo.ExternalSchemas.BroadbandMap_Govt_NZ_DemandCategory#DemandCategory is an envelope with a body xpath of =”/*[local-name()=’DemandCategory’ and namespace-uri()=’http://Datacom.BT.RestDEmo.ExternalSchemas.BroadbandMap_Govt_NZ_DemandCategory’]/*[local-name()=’Points’ and namespace-uri()=’http://Datacom.BT.RestDEmo.ExternalSchemas.BroadbandMap_Govt_NZ_DemandCategory’]” .

<DemandPoint href=”http://broadbandmap.govt.nz/api/v1/DemandPoint/34265.xml” id=”34265″ xmlns=”http://Datacom.BT.RestDEmo.ExternalSchemas.BroadbandMap_Govt_NZ_DemandCategory”></DemandPoint>

These messages are once again submitted to the message box. The BroadbandMap.Govt.NZ send port once again subscribes to these messages using the second filter and ReST request like “GET http://broadbandmap.govt.nz/api/v1/DemandPoint/34265 HTTP/1.1”. The responses contain the individual Demand Point details. The BroadbandMap.Govt.NZ.GetDemandPointResponse_FILE send port with a fliter of  BTS.MessageType == http://Datacom.BT.RestDEmo.ExternalSchemas.BroadbandMap_Govt_NZ_DemandCategory#DemandPoint  And Datacom.BT.RestDEmo.ExternalSchemas.DPID Exists writes these message to the file system e.g.

<?xml version=”1.0″ encoding=”UTF-8″?>
<DemandPoint href=”
http://broadbandmap.govt.nz/api/v1/DemandPoint/34265.xml”>
<OrganisationTitle>The Techno Geek</OrganisationTitle>
<StreetNumber>17</StreetNumber>
<Street>Sholson St</Street>
<Suburb>Putaruru</Suburb>
<City></City>
<PostalCode>3411</PostalCode>
<Region>Waikato</Region>
<Country>NZ</Country>
<Phone>021735745</Phone>
<Mobile>021735745</Mobile>
<Point x=”175.786527″ y=”-38.0549402″ srid=”” /><ExternalIdentifier></ExternalIdentifier>
<MeshBlock></MeshBlock>
<ImportID></ImportID>
<CategoryID>14</CategoryID>
<OwnerID>677</OwnerID>
<ID>34265</ID>
<Category linktype=”has_one” href=”
http://broadbandmap.govt.nz/api/v1/DemandCategory/14.xml” id=”14″></Category>
</DemandPoint>

 

The source code  and installation package for this example can be downloaded from REST Demo.zip  . You must be using BizTalk 2013 beta, have Saravana Kumar’s RemoveBody custom pipeline installed and have the ESB toolkit installed.

BizTalk360
BizTalk Server

Over 500+ customers across
30+ countries depend on BizTalk360

Learn More
Serverless360
Azure

Manage and monitor serverless
components effortlessly

Learn More
Atomicscope
Business Users

Monitor your Business Activity in iPaaS
or Hybrid integration solutions

Learn More

Back to Top