How to extract only content type from request header?. Some time the content type can have additional values. For example -
application/json
application/json; charset=UTF-8
text/xml
text/xml;charset=UTF-16
application/xml;charset=ASCII
& so on..
In all above cases I need only content type (application/json or text/xml).
<ExtractVariables async="false" continueOnError="false" enabled="true" name="EV.ExtractGenericAttributes"> <DisplayName>EV.ExtractGenericAttributes</DisplayName> <Source clearPayload="false">request</Source> <VariablePrefix/> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <Header name="Content-Type"> <Pattern ignoreCase="true">{contentFormat};</Pattern> </Header> </ExtractVariables>
However, it is not setting any value if the Content-Type is just text/xml or application/json.
Solved! Go to Solution.
@Sujnana Rai , Actually issue is your pattern,
Instead of ,
<Pattern ignoreCase="true">{contentFormat};</Pattern>
Use,
<Pattern ignoreCase="true">{contentFormat};{metadata}</Pattern>
Again, above will work only if ; is present in content type header, Ideally it should be,
<Pattern ignoreCase="true">{contentFormat};{metadata}</Pattern> <Pattern ignoreCase="true">{contentFormat}</Pattern>
Where you leverage,
Below should work,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables name="ExtractVariable-ContentType"> <Source>request</Source> <Header name="Content-Type"> <Pattern ignoreCase="true">{contentType};{metadata}</Pattern> <Pattern ignoreCase="true">{contentType}</Pattern> </Header> <VariablePrefix>clientrequest</VariablePrefix> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </ExtractVariables>
Sample proxy attached below,
extracttype-rev3-2016-10-25.zip
Hope it helps, Keep us posted if any.
Hi @Sujnana Rai
I wont set any value if Content-Type is just text/xml or application/json because the pattern you are comparing is {contentFormat}; which both of them lack.
What you can do as alternative is extract whole Content-Type header and fetch only the first part after splitting it by ; operator with javascript callout
I tried by splitting ; operator
<PatternignoreCase="true">{contentFormat};</Pattern> and <Pattern ignoreCase="true">{contentFormat};*</Pattern>
But it fails if Content-Type doesn't have semicolon (;) in it. Ex: application/json or text/xml
@Aswin Segu , Your statement "I wont set any value if Content-Type is just text/xml or application/json because the pattern you are comparing is {contentFormat}; which both of them lack." , Is actually not a valid one. Text inside braces is used to specify the variable into which the extracted pattern value will be saved. See my answer above which should solve OP query.
Hi @Sujnana Rai
string.split(delimiter) method in javascript does not throw error if the delimiter is not in the string.
Cross verify if the string has the content-type value or undefined.
@Nisha Mallesh , Using javascript comes at a cost of performance, Specially when you can achieve same using the oob policies.
@Anil Sagar very true, and I agree with your approach. I have just cleared her concern that there might not be an issue while splitting.
@Sujnana Rai , Actually issue is your pattern,
Instead of ,
<Pattern ignoreCase="true">{contentFormat};</Pattern>
Use,
<Pattern ignoreCase="true">{contentFormat};{metadata}</Pattern>
Again, above will work only if ; is present in content type header, Ideally it should be,
<Pattern ignoreCase="true">{contentFormat};{metadata}</Pattern> <Pattern ignoreCase="true">{contentFormat}</Pattern>
Where you leverage,
Below should work,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables name="ExtractVariable-ContentType"> <Source>request</Source> <Header name="Content-Type"> <Pattern ignoreCase="true">{contentType};{metadata}</Pattern> <Pattern ignoreCase="true">{contentType}</Pattern> </Header> <VariablePrefix>clientrequest</VariablePrefix> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </ExtractVariables>
Sample proxy attached below,
extracttype-rev3-2016-10-25.zip
Hope it helps, Keep us posted if any.