Skip to content

Routes: Http Client

TekMonks edited this page Mar 14, 2019 · 4 revisions

The HTTP Client Route

The HTTP Client route node is used to call HTTP services. Examples are SOAP Web Services, as well as other HTTP artifacts, like a Web Page.

It supports all the HTTP methods like GET, POST, PUT etc.

This node does not parse the parse the incoming data itself and no assumptions are made about the data format. The property message.content contains the read data.

The code block below documents the format for the HTTP client route node.

"route1":{
    "type": "httpclient",
    "dependencies":["route0"],
    "host":"graphical.weather.gov",
    "port":443,
    "isSecure": true,
    "method":"get",
    "path": "",
    "timeout": 180000,
    "headers":["USER-AGENT: JSON_ESB", "ACCEPT: text/html,application/xhtml+xml,application/xml"]
}

The host property is used to point to the HTTP host.

The port is used to indicate the transport port.

isSecure is true for HTTPS calls, else false.

Supported methods are get, post, put and delete.

The path is the path portion of the URL i.e. the path after the host name.

timeout is the HTTP timeout.

headers are the HTTP headers to send to the remote server.

The following is an example of calling a SOAP service, within a REST wrappers, and converting its response to JSON and sending it back as a REST reply i.e. converting a SOAP service to a REST service. The web service used is NOAA National Weather Service to return weather for a location by latitude and longitude.

{
	"flow": {
		"name":"Expose SOAP API as REST",
		"disabled": false,
		"autoGC": false
	},
	"listener": {
		"type":"rest_listener", 
		"isMessageGenerator": true,
		"host": "127.0.0.1",
		"port":9091,
		"url":"/weather",
		"allow_origin": "*",
		"timeout": 120000
	},
	"route0":{
		"type": "js",
		"dependencies":["listener"],
		"js":"flow.route1.path=`/xml/SOAP_server/ndfdXMLclient.php?whichClient=NDFDgen&lat=${message.content.lat}&lon=${message.content.lon}&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&listLat1=&listLon1=&listLat2=&listLon2=&resolutionList=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&listEndPoint1Lat=&listEndPoint1Lon=&listEndPoint2Lat=&listEndPoint2Lon=&zipCodeList=&listZipCodeList=&centerPointLat=&centerPointLon=&distanceLat=&distanceLon=&resolutionSquare=&listCenterPointLat=&listCenterPointLon=&listDistanceLat=&listDistanceLon=&listResolutionSquare=&citiesLevel=&listCitiesLevel=&sector=&gmlListLatLon=&featureType=&requestedTime=&startTime=&endTime=&compType=&propertyName=&product=glance&begin=2004-01-01T00%3A00%3A00&end=2022-09-16T00%3A00%3A00&Unit=e&temp=temp&Submit=Submit`"
	},
	"route1":{
		"type": "httpclient",
		"dependencies":["route0"],
		"host":"graphical.weather.gov",
		"port":443,
		"isSecure": true,
		"method":"get",
		"path": "",
		"timeout": 180000,
		"headers":["USER-AGENT: JSON_ESB", "ACCEPT: text/html,application/xhtml+xml,application/xml"]
	},
	"route2": {
		"type":"xmlparser",
		"dependencies":["route1"]
	},
	"route.error": {
		"type":"js",
		"dependencies":[["listener.error"],["route0.error"],["route1.error"],["route2.error"]],
		"js":"message.content={}; message.content.result=false;"
	},
	"output": {
		"type":"rest_responder",
		"dependencies":[["route2"],["route.error"]]
	},
	"garbagecollector": {
		"type": "simple",
		"dependencies":[["output"],["listener.error"],["route0.error"],["route1.error"],["route2.error"],["output.error"]],
		"isMessageConsumer": true
	}
}