Is it possible to make the Content-Type Value configurable?

Not applicable

We want to make Content-Type value as configurable and store as an entry in KVM Map. And want to call the configurable parameter in the policies like Assign Message policy for setting JSON payload / XML payload as per the requirement. But while doing so, we were getting an error during the deployment of the code. Is it possible to make the Content-Type configurable? Need suggestion on this.

Solved Solved
1 15 693
1 ACCEPTED SOLUTION

Hi @Suranjit Kashyap

Can you try the below code for your requirement.

<Payload contentType="{var}"></Payload>

View solution in original post

15 REPLIES 15

Not applicable

hi @Suranjit Kashyap,

This is very much possible by Assign Message policy. Pl upload the bundle.

Cheers,

cannot upload bundle here as it is project specific. Can you please let me know the process, need to be followed to make the content-type configurable and call the configurable parameter in Assign Message policy?

Not applicable

Add / Set header as applicable as given:

<Header name="Content-Type">{var}</Header>

Thanks!! Setting Header is fine. In my description, I have specifically mentioned while setting payload JSON/XML we need to pass content type. Can we call the config parameter in this? - <Set><Payload contentType={var}></Set>. I have tried this but couldn't deploy the code.

Hi @Suranjit Kashyap

Can you try the below code for your requirement.

<Payload contentType="{var}"></Payload>

@Suranjit Kashyap

Above answer should work, Please find attached proxy that demonstrates same.

contenttypedynamic-rev1-2016-07-14.zip

@GargiTalukdar

while doing so, it is not allowing me to deploy the code and throws an error while deploying the proxy itself.

@Suranjit Kashyap , Error might be somewhere else. Take a look at above proxy i have attached. It demonstrates exactly the answer you are looking for. Are you onPremises / cloud ?

On-Premise

@Suranjit Kashyap , What's the onPremise version ? It might not be available as a feature in older version of onPremises. You need to fallback to approach suggested by @rdoda ,

    <Set>
        <Headers>
      		<Header name="contentType">{contentTypeValue}</Header>
	</Headers>
        <Payload>
          {"name":"foo", "type":"bar"}
	</Payload>
    </set>	

We are using CI tool (Jenkins) to deploy the proxy and there it is failing with the below error: Open quote is expected for attribute "contentType" associated with an element type "Payload" during the execution of install-bundle maven plugin. current version of On-Premise - 4.16.01.01

one more concern regarding the example you showed. Header and Payload is completed different. Header name should be named as Content-Type and <Payload> tag without giving mandatory attribute "contentType" will not work I guess.

@Suranjit Kashyap , Above examples works in cloud. You might need to update your Apigee onPrem version to the latest to verify same.

@Anil Sagar, That might be the case. Thanks!!

@Anil Sagar, I have checked again. calling the configurable variable in <Payload> tag didn't worked for the version I am using 4.16.01.01. But the template provided by you to set the header separately in <Header> tag and calling the configurable value worked for me. Thanks you and everyone for your valuable suggestions.