Connected Pawns

February 11, 2013

BizTalk and Rest Example from BizTalk Saturday

Filed under: BizTalk — Tags: , , — mbrimble @ 4:06 pm

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()='<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.

2 Comments »

  1. From: Johann Cooper [DATACOM]
    Sent: Monday, 11 February 2013 6:14 p.m.
    To: Mark Brimble [DATACOM]
    Subject: RE: BizTalk and ReST

    Hi Mark,

    I have downloaded your sample as well as the S. Kumar sample. I copied his pipeline component and the ones in your 3rd party assemblies folder to the BT 2013 pipeline components folder. When I try to build the Pipelines project in your solution I get an error, even though none of the references appear to be broken.
    Nothing I did appeared to work until I opened the properties for the two Datacom.BT.Common.PipelineComponents dlls and chose the unblock option. After I did that I could build the solution.

    I also ran into trouble with S. Kumar’s Remove body pipeline. When I tried to run an input file through the solution that would call on the BroadbandMap.Govt.NZ send port I got the below error.

    There was a failure executing the send pipeline: “BizTalk.RestAdapter.Demo.Pipelines.RemoveBody, BizTalk.RestAdapter.Demo.Pipelines, Version=1.0.0.0, Culture=neutral, PublicKeyToken=98c97ec9324f0fce” Source: “Unknown ” Send Port: “BroadbandMap.Govt.NZ” URI: “http://broadbandmap.govt.nz/api/v1″ Reason: Could not load file or assembly ‘file:///C:\Program Files (x86)\Microsoft BizTalk Server 2013\Pipeline Components\RemoveBody.dll’ or one of its dependencies. The system cannot find the file specified.

    This is strange since the name of the pipeline component assembly is BizTalk.RestAdapter.Demo.PipelineComponents.dll, not RemoveBody.dll. Manually changing the assembly name in S. Kumar’s project to RemoveBody and rebuilding and placing this new file in the pipeline components folder worked around this problem.

    Now I am getting the below error on the BroadbandMap.Govt.NZ send port.

    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 202.160.48.121:80

    It turned out that I had to set the proxy server settings in the send port (this is my on premise VM rather than my cloud VM). Once I did this I successfully got output messages in C:\Temp\BroadbandMap.Govt.NZ\BroadbandMap.Govt.NZ.GetDemandPoint\Out.

    Hope this is the feedback you were after. Well done, this is a cool example on using REST endpoints.

    Cheers
    Johann

    Comment by mbrimble — February 12, 2013 @ 9:59 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Silver is the New Black Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 77 other followers

%d bloggers like this: