How to Pass Content-Length in BeforeOperation Rule for Web Services connector

Hi,

I have configured a web service connector. When I tested the create account operation from postman, content-length is mandatory for creation and that value is dynamic as per the body.

How do we calculate the content-length in sailpoint?

I wrote a beforeOperation rule to add the header as per below code but still it is giving in 411 error code. Please provide me any thoughts.

Map currentBody = requestEndPoint.getBody();

String currentBodyToString = currentBody.toString();

int contentLength = currentBodyToString.getBytes(“UTF-8”).length;

Map currentHeader = requestEndPoint.getHeader();

currentHeader.put(“Content-Length”,String.valueOf(contentLength));

requestEndPoint.setHeader(currentHeader);

return requestEndPoint;

Thank You
Pooja

hi @poojakumari85

I would try below things

  1. Avoid setting Content-Length manually.
    Java HTTP clients (used internally by SailPoint) typically calculate and set this automatically. Manually setting it can conflict with internal behavior.
  2. Ensure body is a raw JSON string, not a Map.
    If you’re using:

Map currentBody = requestEndPoint.getBody();
Convert it to a JSON string using a library like Gson:


import com.google.gson.Gson;

Gson gson = new Gson();

String jsonBody = gson.toJson(currentBody);

requestEndPoint.setBody(jsonBody);
  1. Remove manual Content-Length header :
Map headers = requestEndPoint.getHeader();

headers.remove("Content-Length");

requestEndPoint.setHeader(headers);
4. Ensure Content-Type is set correctly :
headers.put("Content-Type", "application/json");