Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Calculate Content-Length at Apigee to send to Target

Hi 

I am facing an issue with Content -length with target system , its expecting mandatory to send content-length to get success connection and which Apigee can't calculate in service callout . The service is working fine in Postman since it will send content length by default but Apigee can't calculate buy its own. Do we have any other option other than calculating the payload from java script. ?

niru_25_0-1740595043587.png

 

Hi  @Manisha_Chennu  @shrenikkumar-s  @dchiesa1 

 

Solved Solved
0 3 163
1 ACCEPTED SOLUTION


@niru_25 wrote:

but Apigee can't calculate buy its own.


By the way, what behavior in Apigee are you seeing here?  you wrote that "Apigee can't calculate" the content-length header. Did you actually try this?  Or maybe it is the case that you are assuming it is a problem, if you do not explicitly set the Content-length header?   With the Policy configured the way you showed it, is the upstream system NOT receiving a content-length header?  In my experience when setting the Payload, the content-length header gets set by Apigee and sent to the upstream automatically and implicitly. It does not show in the DebugSession / Trace. But the message received by the target has the content-length header.

Can you provide more information about what you are observing?   Can you share a debugsession showing that?  

View solution in original post

3 REPLIES 3

in JavaScript you can compute the length of the payloadString.

var c = context.getVariable('payloadString');
context.setVariable('lengthOfPayload', c.length);

But what you are describing is strange. Normally Apigee sets this automatically for you when invoking a target.  That's what I see when I use something l Iike this: 

 

<AssignMessage name='AM-Contrived-Payload'>
  <Set>
    <!-- setting the payload. Apigee will automatically set the content-length header -->
    <Payload contentType='text/plain'>{valuehere}-{rnum}</Payload>
  </Set>
</AssignMessage>


@niru_25 wrote:

but Apigee can't calculate buy its own.


By the way, what behavior in Apigee are you seeing here?  you wrote that "Apigee can't calculate" the content-length header. Did you actually try this?  Or maybe it is the case that you are assuming it is a problem, if you do not explicitly set the Content-length header?   With the Policy configured the way you showed it, is the upstream system NOT receiving a content-length header?  In my experience when setting the Payload, the content-length header gets set by Apigee and sent to the upstream automatically and implicitly. It does not show in the DebugSession / Trace. But the message received by the target has the content-length header.

Can you provide more information about what you are observing?   Can you share a debugsession showing that?  

HI,

Sorry for the delay. 

Yes, i tried this in Apigee x . now its working unfortunately i don't have historical debug sessions with me but it was not working in 2 days back as well but somehow its worked. i was developed the code to send the content length explicitly. 

Thanks for your help 

Regards,

Niranjan Reddy