Extract form parameter in Extract Variables policy - apigee

I am trying to extract a form param in an Extract Variables policy without success. request.formparam.grant_type successfully extracts the form parameter value but when I do the following it doesn't work. I don't understand what I am doing wrong I have made the request with the header Content-Type set to application/x-www-form-urlencoded as specified in the documentation but nothing seems to work. I must be doing something really silly but cannot spot what.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
<FormParam name="grant_type"/>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source clearPayload="false">request</Source>
<VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>

Apigee Support helped me out and the following works:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
<FormParam name="grant_type"><Pattern>{grantType}</Pattern></FormParam>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source clearPayload="false">request</Source>
<VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>

You need to provide the variable in which to save the form parameter:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
<FormParam name="grant_type">
<Pattern>{grantType}</Pattern>
</FormParam>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source clearPayload="false">request</Source>
<VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>
Since you have set your VariablePrefix to "apigee", the form parameter grant_type will be saved in the variable apigee.grantType.

Related

xml2::xml_strip_ns() does not work on qualified xml?

I am trying to use R xml2 method xml_strip_ns on a xsd like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Cell" type="Cell_type"/>
<xs:complexType name="Cell_type">
<xs:sequence>
<xs:element name="ID" type="id"/>
...
in order to be able to do xml_find_first(x,'./element') instead of xml_find_first(x,'./xs:element') but apparently strip does not care of working in this situation (it works with the example given in the function help though).
Am I missing something (I am absolutely new to xml so it wouldn't surprise me)?.
Thank you in advance for help,
Luigi

how to collect text data from response apigee

I am using serviceCalloutPolicy to get response from some "xyz" api. The response returned by "xyz" api is text data like "abnfhjdkdhrju784hhkfjhbbhg21g3u2u9fdjkfnfddsnrijirry3784yewrgshbsdjbcjsvnvksdnv" which is neither json nor xml . so how can extract this data into variable. I want to use this data as header in another api call.
You can get the response value by using Extract Variable Policy.
Place it after your Service Callout Policy.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="EVTIB-ExtractValueFromJC">
<DisplayName>EVTIB-ExtractValueFromJC"</DisplayName>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source clearPayload="false">yourJavaCalloutReponseName</Source>
<VariablePrefix>resp.data</VariablePrefix>
<JSONPayload>
<!--- Extract value from Json or XML , for example Json-->
<Variable name="apiRespData">
<JSONPath>$.data</JSONPath>
</Variable>
</JSONPayload>
</ExtractVariables>
And then use variable name to reference the value.

Redirecting to xml with query string in asp.net

I am doing a Response.Redirect to below given xml document with a query string parameter.
Response.Redirect(#"../temp/output.xml?location=newlocation");
What I want is that the value of location attribute for all the product nodes should be replaced with the value I pass in query string parameter. The problem is when I do a response.redirect to xml the c# server code which modifies the xml document does not executes for the obvious reason that xml file does not runs any server code.
Can anyone please suggest a solution for this.
Xml File
<?xml version="1.0" encoding="utf-8"?>
<products xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="products:noNamespaceSchemaLocation">
<store id="BND088412">
<display-name>test</display-name>
</store>
<product location="test">
<length units="minutes">100</length>
<title>Microsoft Excel</title>
</product>
<product location="test">
<length units="minutes">300</length>
<title>Microsoft VBA</title>
</product>
</products>
Thanks & Regards

Caching in Apigee using proxy.basepath

I have created a new API /v1/StatusCache to point to my end point /v1/Status. My goal is to be able to cache the data :
based on the uri
for a particular header
So if user 1 sends request to /v1/StatusCache/1234 and the same user sends request to /v1/StatusCache/5678, I should hit my server instead of getting previously cached result from the first request.
Also we user header (Authorization: Bearer ) in the request so my second goal is that if user 1 with header Authorization: Bearer token1 sends a request to /v1/StatusCache/1234 vs a user 2 with header Authorization: Bearer token2 sends a request to /v1/StatusCache/1234, I should get different results (non cached results)
I have this code for proxypath but it just caches every request for 10 seconds. What am I missing
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="responsecache-1">
<DisplayName>ResponseCache-1</DisplayName>
<FaultRules/>
<Properties/>
<CacheKey>
<Prefix/>
<KeyFragment ref="proxy.pathsuffix" type="string">proxy.pathsuffix</KeyFragment>
</CacheKey>
<Scope>Exclusive</Scope>
<ExpirySettings>
<ExpiryDate/>
<TimeOfDay/>
<TimeoutInSec ref="">10</TimeoutInSec>
</ExpirySettings>
<SkipCacheLookup/>
<SkipCachePopulation/>
</ResponseCache>
My suggestion would be create a variable value combining the header and pathsuffix value (header+pathsuffix) - use this as the key for the response cache.
Try the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="responsecache-1">
<DisplayName>ResponseCache-1</DisplayName>
<FaultRules/>
<Properties/>
<CacheKey>
<Prefix/>
<KeyFragment ref="proxy.pathsuffix" type="string"/>
<KeyFragment ref="request.header.Authorization" type="string"/>
</CacheKey>
<ExpirySettings>
<ExpiryDate/>
<TimeOfDay/>
<TimeoutInSec ref="">60</TimeoutInSec>
</ExpirySettings>
<SkipCacheLookup/>
<SkipCachePopulation/>
</ResponseCache>
I used 60 sec timeout for ease of testing.
This shows an example of proxy.pathsuffix + request.header.Authorization values being a unique cache key. Think of the key now looking like /1234__Bearer token1. The same path suffix and Authorization header value combined are needed to return an entry from cache.
Also, when trying to cache the URI, you may want to try the variable request.uri which includes the querystring-- this can sometimes dictate what the response looks like. If using this, be sure that the querystring does not include unique values like a current timestamp (or at least strip that parameter before using it as a cache key fragment).

Using Web.Config Transforms to Change the "size" element in a log4net "parameter"

I'm working on an ASP.NET project which uses log4net. In the Development environment, I want the size element of the #stackTrace parameter to be set to a higher value than in other environments.
The structure of the log4net.config file is:
<?xml version="1.0"?>
<configuration>
<log4net debug="true">
<appender name="SQLServerAppender" type="log4net.Appender.AdoNetAppender">
<parameter>
<parameterName value="#stackTrace"/>
<dbType value="String"/>
<size value="1000"/>
<layout type="log4net.Layout.RawPropertyLayout">
<key value="stackTrace"/>
</layout>
</parameter>
<!-- More parameters -->
</appender>
</log4net>
</configuration>
I would like to change the value attribute of the size element to 2000.
I tried the following transform file, but it didn't change anything:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<log4net>
<appender name="SQLServerAppender" type="log4net.Appender.AdoNetAppender">
<parameter xdt:Locator="XPath(configuration/log4net/appender[#name='SQLServerAppender']/parameter[parameterName[#value='#stackTrace']])"
xdt:Transform="Remove">
</parameter>
</appender>
</log4net>
</configuration>
The "Remove" was a last resort to try to get something to happen!
What should I do to perform the desired transform? It's not clear to me how to combine xdt:Locator with xdt:Transform in this case.
After the answer by Eric.Y.Fan didn't work, I played around a bit to find out why not.
I first put back the <connectionString> value (I left it out of my post for clarity), and it did work. That proved that the correct <appender> had been found, but that the correct <parameter> was not being found. "Found", or "located". That was a hint.
I looked at the XPath expression, and realized that it was attempting to locate the <parameter> which had a <parameterName> with a value attribute with the value #stackTrace. So I tried using Condition:
<parameter xdt:Locator="Condition([parameterName[#value='#stackTrace']])"
xdt:Transform="Replace">
</parameter>
This worked!
So the final transform is:
<parameter xdt:Locator="Condition([parameterName[#value='#stackTrace']])">
<size value="2000" xdt:Transform="Replace" />
</parameter>
I could be mistaken but I don't think Web.config transforms can be applied to other arbitrary xml files.
For that purpose I usually use SlowCheetah:
http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5
It's a great tool, very easy to use (similar to web.config transforms, but can be applied to anything), and also integrates very well with automated builds and deployments.
Here's a guide from Scott Hanselman:
http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx
Try this:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<log4net>
<appender name="SQLServerAppender" type="log4net.Appender.AdoNetAppender">
<parameter>
<size value="2000" xdt:Locator="XPath(configuration/log4net/appender[#name='SQLServerAppender']/parameter[parameterName[#value='#stackTrace']])" xdt:Transform="SetAttributes"/>
</parameter>
</appender>
</log4net>

Resources