-
-
Save LCHCAPITALHUMAIN/be30435d7ea0facbdf3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* handles application/json content type requests | |
*/ | |
component { | |
void function configure(){} | |
void function preProcess(event,struct interceptData){ | |
var rc = event.getCollection(); | |
if(isJSONRequest()) | |
{ | |
var jsonString = toString(getHttpRequestData().content); | |
var jsonObject = deserializeJSON( jsonString ); | |
structAppend(rc,jsonObject,true); | |
} | |
} | |
Boolean function isJSONRequest(){ | |
var contentType = getHTTPHeader("Content-Type",""); | |
return find("application/json",contentType) != 0; | |
} | |
function getHTTPHeader(header,defaultValue){ | |
var headers = getHttpRequestData().headers; | |
if( structKeyExists(headers, arguments.header) ){ | |
return headers[arguments.header]; | |
} | |
if( structKeyExists(arguments,"defaultValue") ){ | |
return arguments.defaultValue; | |
} | |
throw(message="Header #arguments.header# not found in HTTP headers",detail="Headers found: #structKeyList(headers)#",type="RequestContext.InvalidHTTPHeader"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment