500-Internal server error when calling external REST endpoint from workflow in OpenIDM 3.x
The purpose of this article is to provide assistance if your call to an external REST endpoint from a workflow in IDM/OpenIDM fails with a 500-Internal server error, where the associated Content-Type is 'application/x-www-form-urlencoded'.
Archived
This article has been archived and is no longer maintained by ForgeRock.
Symptoms
The REST call fails with the following error:
500-Internal server errorWhen the IDM/OpenIDM logging is set to FINEST, you can see that the action is invoked with the correct Content-Type; for example, your logs will show something similar to:
Oct 10, 2014 5:02:36 PM org.forgerock.openidm.external.rest.RestService actionInstance FINE: Action invoked on call with { "content": { "authenticate": { "type": "basic", "user": "admin", "password": "Passw0rd" }, "headers": { "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json" }, "body": "grant_type=client_credentials", "method": "POST", "url": "https://host1.example.com:8080/openam/oauth2/access_token" }, "additionalParameters": { }, "action": "call", "method": "action", "resourceName": "", "fields": [ ] } Oct 10, 2014 5:02:36 PM org.forgerock.openidm.external.rest.RestService setAttributes INFO: Adding header Content-Type: application/x-www-form-urlencodedLater in the log where an attempt is made to execute the request, you can see that the Content-Type has changed to 'application/json':
FINE: Attempt 1 to execute request Oct 10, 2014 5:02:36 PM org.apache.http.impl.conn.DefaultClientConnection sendRequestHeader FINE: Sending request: POST /openam/oauth2/access_token HTTP/1.1 Oct 10, 2014 5:02:36 PM org.apache.http.impl.conn.Wire wire FINE: >> "POST /openam/oauth2/access_token HTTP/1.1[\r][\n]" Oct 10, 2014 5:02:36 PM org.apache.http.impl.conn.Wire wire FINE: >> "Date: Fri, Oct 10, 2014 17:02:36 GMT[\r][\n]" Oct 10, 2014 5:02:36 PM org.apache.http.impl.conn.Wire wire FINE: >> "Content-Type: application/json; charset=UTF-8[\r][\n]"Recent Changes
N/A
Causes
When IDM/OpenIDM makes an external REST call, messages are passed through a client proxy, which may alter the header containing the Content-Type and change it to 'application/json'. Since the Content-Type is no longer correct, the external REST call fails.
Solution
This issue can be resolved by changing the curl command to use the contentType parameter instead of setting the Content-Type via the headers parameter. For example, replace the following parameter in your curl command:
"headers": { "Content-Type": "application/x-www-form-urlencoded" }with:
"contentType" : "application/x-www-form-urlencoded" }See Also
Integrator's Guide › Managing Workflows Over the REST Interface
Related Training
N/A
Related Issue Tracker IDs
N/A