Edge-orders: Configuration Based Routing

Overview

It's currently necessary to make code changes in edge-orders when integrating with new vendors.  The type query argument informs the edge module where the request is intended for. 

For instance, we have type=GOBI which routes requests to mod-gobi, but if I were to integrate with vendor FOO we'd have to update the edge-order code to route those requests to mod-foo.

Instead it would be great if we could make this configuration driven

Approach

Define mappings, update edge-orders to read these mappings at init time, and use them to route requests based on the "type" query argument.

Example
{
	"typeApiMappings": [{
		"type": "GOBI",
		"method": "POST",
		"pathPattern": "/orders",
		"proxyMethod": "POST",
		"proxyPath": "/gobi/orders"
	}, {
		"type": "FOO",
		"method": "POST",
		"pathPattern": "/orders",
		"proxyMethod": "POST",
		"proxyPath": "/foo/orders"
	}, {
		"type": "GOBI",
		"method": "POST",
		"pathPattern": "/validate",
		"proxyMethod": "POST",
		"proxyPath": "/gobi/validate"
	}, {
		"type": "GOBI",
		"method": "GET",
		"pathPattern": "/validate",
		"proxyMethod": "GET",
		"proxyPath": "/gobi/validate"
	}, {
		"type": "FOO",
		"method": "POST",
		"pathPattern": "/validate",
		"proxyMethod": "POST",
		"proxyPath": "/foo/validate"
	}]
}


Making the "proxyMethod" property optional might help make these mappings less verbose, where the default method used in the proxy request is the same as the original request.

The config file would location would be passed in via the system property, similar to how the secure store properties file is specified (see edge-common)

JIRAs

Other Considerations

  • A formal schema should be defined and used to validate configuration files.
  • Appropriate 4xx responses are returned if a request is made for a type w/o a mapping
  • A sample mapping file should be added to source control for reference, e.g. with the gobi mappings
  • Mappings for non-existent endpoints are ignored - a warning should be logged
  • Errors parsing the mappings should be logged