Unable to use numeric data in KeyFragment while caching response

Hi,

I am using different attributes present in the request payload to form a CacheKey. As long as I include string-values it is working fine. However, when I include a numeric component, I get the following error:

{ "fault": { "faultstring": "java.lang.Long cannot be cast to java.lang.String", "detail": { "errorcode": "Internal Server Error" } } } 
I have tried using the type attribute inside the KeyFragment tag like:
<KeyFragment ref="sales_channel_id" type="Long"/>

, but to no avail.

Solved Solved
0 7 373
1 ACCEPTED SOLUTION

Hi @Mukundha Madhavan, I am parsing the request payload which is in JSON format. This particular attribute is numeric. I could solve the issue by either:

  1. Asking the api consumer to send the numeric value enclosed in double quotes. [I would prefer not to do this, since it's a number and not a string]
  2. Modifying the ExtractVariables policy to read the attribute as a string. [Despite it actually being a numeric field.]
<Variable name="sales_channel_id" type="string">

I have reluctantly used the 2nd approach to resolve my issue as of now. However, it would just be neater, if apigee could use the type attribute in the KeyFragment tag. Thoughts?

View solution in original post

7 REPLIES 7

Hi @Cladius Fernando, I think only strings are supported for Keyfragments, how are you setting the value for the sales_channel_id? I am assuming you are using java callouts to set the variable, can you use just the string values?? [Long.toString() or String.valueOf??]

does it make a difference in your usecase to use long keys vs string keys? internally they are all treated as strings anyways

Thanks,

Hi @Mukundha Madhavan, I am parsing the request payload which is in JSON format. This particular attribute is numeric. I could solve the issue by either:

  1. Asking the api consumer to send the numeric value enclosed in double quotes. [I would prefer not to do this, since it's a number and not a string]
  2. Modifying the ExtractVariables policy to read the attribute as a string. [Despite it actually being a numeric field.]
<Variable name="sales_channel_id" type="string">

I have reluctantly used the 2nd approach to resolve my issue as of now. However, it would just be neater, if apigee could use the type attribute in the KeyFragment tag. Thoughts?

I agree @Cladius Fernando, reasonable usecase - But unfortunately, today, only strings are supported, so you will need to workaround it -like you already did with option 2.

I will forward this feedback to our product team,

Thanks,

Thanks for the response @Mukundha Madhavan. I believe the documentation page for ResponseCache needs to be modified then. It has an example reference section which lists this:

<KeyFragment ref="request.uri" type="string"/>

If strings are the only type supported (as of now), we should remove the type attribute from the above example atleast to avoid potentially misleading developers. What say?

yes @Cladius Fernando,

+ @Floyd Jones, can you pls have a look at this ? Thanks

Thanks! Removed the type attribute. Also added ref specific to that element. http://apigee.com/docs/api-services/reference/response-cache-policy