Tuesday, April 1, 2014

JSON payload for a Fault

We need to generate a JSON output in case of fault. RaiseFault policy is appropriate for the same. Following is an example policy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="invalid_login">
    <FaultResponse>
        <Set>
            <Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
                {
                    "error": "Incorrect login credentials",
                    "source": "API error"
                }
            </Payload>
            <StatusCode>400</StatusCode>
        </Set>
    </FaultResponse>
</RaiseFault>

Why this so different  - please note the variablePrefix, variableSuffix being present even though the content type is application/json and no variables are used. contentType attribute does not have the same impact as in AssignMessage policy. The presence of {} leads to the interpretation of the data between them as variable name. The variablePrefix and variableSuffix change solves the problem.

2 comments:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Apigee, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on Apigee. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: training_maxmunus
    Contact No.-+91-9738507310
    Company Website –http://www.maxmunus.com



    ReplyDelete
  2. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Apigee , kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on TECHNOLOGY. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Sangita Mohanty
    MaxMunus
    E-mail: sangita@maxmunus.com
    Skype id: training_maxmunus
    Ph:(0) 9738075708 / 080 - 41103383
    http://www.maxmunus.com/



    ReplyDelete