I am unable to add Custom Dimensions in Custom Reports using statistics collector and extract variable policy mentioned below.
I have followed all the steps given in tutorial and docs but still I am stuck.
EXTRACT VARIABLE POLICY
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract- Variables-1">
<DisplayName>Extract Variables 1</DisplayName>
<FaultRules/>
<Properties/>
<Source clearPayload="false">response</Source>
<VariablePrefix></VariablePrefix>
<XMLPayload stopPayloadProcessing="false">
<Namespaces>
<Namespace prefix="yweather">http://xml.weather.yahoo.com/ns/rss/1.0</Namespace>
</Namespaces>
<Variable name="weather.location" type="string">
<XPath>/rss/channel/link</XPath>
</Variable>
<Variable name="weather.condition" type="string">
<XPath>/rss/channel/item/yweather:condition/#text</XPath>
</Variable>
<Variable name="weather.forecast_today" type="string">
<XPath>/rss/channel/item/yweather:forecast[1]/#text</XPath>
</Variable>
<Variable name="weather.forecast_tommorow" type="string">
<XPath>/rss/channel/item/yweather:forecast[2]/#text</XPath>
</Variable>
</XMLPayload>
</ExtractVariables>
STATISTICS COLLECTOR POLICY
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="Statistics-Collector-1">
<DisplayName>Statistics Collector 1</DisplayName>
<FaultRules/>
<Properties/>
<Statistics>
<Statistic name="location" ref="weather.location" type="string">Earth</Statistic>
<Statistic name="condition" ref="weather.condition" type="string">Sunny</Statistic>
<Statistic name="forecast_today" ref="weather.forecast_today" type="string">Rainy</Statistic>
<Statistic name="forecast_tomorrow" ref="weather.forecast_tomorrow" type="string">Balmy</Statistic>
</Statistics>
</StatisticsCollector>
Your policies look fine (i.e., it looks like you haven't modified the samples in http://apigee.com/docs/analytics-services/content/analyze-api-message-content-using-custom-analytics), so the problem likely lies in your policy attachment, or, more likely, your deployment. Make sure your proxy is deployed in the expected environment. It can be useful to use the API to do this:
curl -u email:password https://api.enterprise.apigee.com/v1/o/{org_name}/apis/{api_name}/deployments
If your API proxy is deployed properly, please post your ProxyEndpoint configuration, and the request that you are sending to the API proxy and we'll take it from there.
Related
I am trying to prevent requests that contain a json payload with a certain attribute value from hitting my target backend.
For example:
{"status":"pending"}
If the status is "pending", I don't want it to hit my target backend until I see a status of "delivered".
What is the best way to do this?
I have a step in the proxy endpoint preflow that uses a javascript policy to identify the attribute and its value. Now that I know this, how can I prevent the request from hitting the target backend and instead just return a 200 ok to the requester?
As you have the JS to identify the attribute already, now have a policy "Raise-Fault-Attribute" in your preflow after your JS policy.
<Step>
<Condition>(Status is pending) or (Status is null)</Condition>
<Name>Raise-Fault-Attribute</Name>
</Step>
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="Raise-Fault-Attribute">
<DisplayName>Raise Fault Attribute</DisplayName>
<Properties/>
<FaultResponse>
<Set>
<Headers/>
<Payload contentType="text/xml">
....
</Payload>
<StatusCode>500</StatusCode>
<ReasonPhrase>Server Error</ReasonPhrase>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>
`
Hope this helps...
We are trying to use an external SOAP service in our mobile app. We are converting that SOAP service into a GET method REST api using https://apigee.com. But that REST api , is changing our parameter value (which contain some special character like / | and all), when hitting actual SOAP api. How can we stop this encoding/decoding part in Apigee? is their any other free service available there for same purpose ?
REST API GET Request. So you will be sending request parameters in the URL as query parameters. Use the below flow
Use Extract Variables policy to extract query parameter variables
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="true" enabled="true" name="getqueryparams">
<DisplayName>getqueryparams</DisplayName>
<QueryParam name="param1">
<Pattern ignoreCase="true">{param1}</Pattern>
</QueryParam>
<QueryParam name="param2">
<Pattern ignoreCase="true">{param2}</Pattern>
</QueryParam>
<QueryParam name="param3">
<Pattern ignoreCase="true">{param3}</Pattern>
</QueryParam>
<Source>request</Source>
<VariablePrefix>getqueryparams</VariablePrefix>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>
Use Service callout policy to create and send SOAP POST Request
<ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout-1">
<DisplayName>Custom label used in UI</DisplayName>
<Request clearPayload="true" variable="myRequest">
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<Set>
<Headers>
<Header name="Content-Type">text/xml</Header>
<Header name="SOAPAction">http://www.webserviceX.NET/GetWeather</Header>
</Headers>
<Payload contentType="text/xml">
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetWeather xmlns="http://www.webserviceX.NET">
<CityName>{getqueryparams.param1}</CityName>
<CountryName>{getqueryparams.param2}</CountryName>
</GetWeather>
</soap:Body>
</soap:Envelope>
</Payload>
<Verb>POST</Verb>
</Set>
</Request>
<Response>response</Response>
<Timeout>60000</Timeout>
<HTTPTargetConnection>
<URL>http://www.webservicex.com/globalweather.asmx</URL>
</HTTPTargetConnection>
</ServiceCallout>
Use xml to json policy to convert the response xml to JSON in RESPONSE flow
Your service URL: http://superman-prod.apigee.net/service/getService?param1=abc/xyz¶m2=one|two¶m3=omgomgomg
For Apigee API proxy, I need to select a flow based on request parameter. But I also need to remove that parameter before sending the request to the target.
I tried doing this:
<Flow name="SpecialFlow">
<Condition>request.queryparam.specialKey != null</Condition>
<Request>
<Step>
<Name>removeSpecialKey</Name>
</Step>
</Request>
<Response>
<Step><Name>doSpecialStuff</Name></Step>
</Response>
</Flow>
However, since specialKey is removed, the response step doSpecialStuff never gets called. How do I make sure the same flow is used for both request and response in this case?
I remove the parameter like:
context.removeVariable('request.queryparam.specialKey');
Great question and a common scenario. In my proxies I use one of two strategies.
In the first I a saveVars policy right before I head to the target flow, typically as the last step in the preflow request. That policy looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="true" enabled="true" name="assignSaveMessage">
<DisplayName>assignSaveMessage</DisplayName>
<AssignVariable>
<Name>save.request.verb</Name>
<Ref>request.verb</Ref>
</AssignVariable>
<AssignVariable>
<Name>save.request.queryparam.content</Name>
<Ref>request.queryparam.content</Ref>
</AssignVariable>
<AssignVariable>
<Name>save.request.content</Name>
<Ref>request.content</Ref>
</AssignVariable>
<AssignVariable>
<Name>save.request.queryparam.propagation</Name>
<Ref>request.queryparam.propagation</Ref>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
I then execute a restoreVars policy in the first step of postFlow response. This way I can use those variables as conditions. Here is the restore policy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="true" enabled="true" name="assignRestoreMessage">
<DisplayName>assignRestoreMessage</DisplayName>
<AssignVariable>
<Name>request.verb</Name>
<Ref>save.request.verb</Ref>
</AssignVariable>
<AssignVariable>
<Name>request.queryparam.content</Name>
<Ref>save.request.queryparam.content</Ref>
</AssignVariable>
<AssignVariable>
<Name>request.queryparam.propagation</Name>
<Ref>save.request.queryparam.propagation</Ref>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
In your case, you would "stash" your queryparam right before you remove it as a queryparam.
The second approach is to simply assign the request param into another variable, a custom labelled variable that can be accessed throughout the flow. The only concern with this approach is the source of these copied variables is not obvious later flows.
I tried multiple options of publishing custom error message for Quota violation. But I was not able to produce custom error message.
Please provide step by step process to generate custom error message. Thanks!
Create a Raise Fault Policy (but don't attach it to a flow):
<RaiseFault async="false" continueOnError="false" enabled="true" name="Fault-Bad-Quota">
<DisplayName>Fault-Bad-Quota</DisplayName>
<FaultRules/>
<Properties/>
<FaultResponse>
<Set>
<Headers/>
<Payload contentType="text/plain">My Custom Fault for {fault.name}</Payload>
<StatusCode>500</StatusCode>
<ReasonPhrase>Server Error</ReasonPhrase>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>
Add a Conditional Fault to your Proxy configuration
<FaultRules>
<FaultRule name="BadQuota">
<Step>
<Name>Fault-Bad-Quota</Name>
</Step>
<Condition>fault.name = "QuotaViolation"</Condition>
</FaultRule>
</FaultRules>
You can add a global fault policy to your proxy default.xml. If you're using the UI go to the word "default" right under your target.
I am trying to construct an REST service query parameters from an incoming SOAP request, and I need GET mode request(doGet:http://localhost:8888/XMPPService/recieveMsg?accessId=admin&accessSeq=admin&accessPwd=admin).
I use property REST_URL_POSTFIX.
My config is:
<target>
<inSequence>
<property name="REST_URL_POSTFIX" value="?accessId=accessId&accessSeq=accessSeq" scope="axis2" />
<send>
<endpoint>
<address uri="http://localhost:8888/XMPPService/recieveMsg" >
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full" />
<send />
</outSequence>
</target>
<publishWSDL key="XMPPService_wsdl" />
But is also POST mode request, it calls doPost method, not GET mode request.
The receive message is also:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<p:XMPPService xmlns:p="http://iag.sdp.coship.com/xmpp/">
<accessId>admin</accessId>
<accessSeq>admin</accessSeq>
<accessPwd>admin</accessPwd>
</p:XMPPService>
</soapenv:Body>
</soapenv:Envelope>
I'm not clear on what you are trying. From my understanding, you are trying to construct an REST service query parameters from an incoming SOAP request.
If that is the case use REST_URL_POSTFIX property to set the query parameters.
I have written this post which may help you.