{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
0
Question by Vipul Agarwal · Mar 24, 2016 at 06:37 AM · 1.4k Views assign message policyassignmessagexml message

How to generate XML response with the starting XML node describing version and encoding?

Hi All,

I want to mock the error response of a target server, where the response is like:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
	<ErrorCode>2021</ErrorCode>
	<ErrorMessage>Partner with given apikey not authorized to use this operation.</ErrorMessage>
</Error>

I am able to generate the error message except the first line of the message i.e.

<?xml version="1.0" encoding="UTF-8"?>

I am not sure how to do that..Please suggest.

Comment
Add comment Show 2
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Anil Sagar @ Google ♦♦   · Mar 24, 2016 at 07:53 AM 0
Link

Are you using Assign Message policy to set response to above XML ?

avatar image Vipul Agarwal Anil Sagar @ Google ♦♦   · Mar 24, 2016 at 08:29 AM 0
Link

@Anil Sagar: Yes. I am using assign message policy for setting custom error response.

Please suggest the best way to achieve it.

My Assign Message policy is ::

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>Assign Message-1</DisplayName>
    <Properties/>
    <Add>
        <Headers/>
        <QueryParams/>
        <FormParams/>
    </Add>
    <Set>
        <Headers>
            <Header name="Content-Type">text/xml; charset=utf-8</Header>
        </Headers>
        <QueryParams/>
        <FormParams/>
        <!-- <Verb>GET</Verb> -->
        <Payload contentType="test/xml">
            <Error>
                <ErrorCode>2021</ErrorCode>
                <ErrorMessage>Partner with given apikey not authorized to use this operation.</ErrorMessage>
            </Error>
        </Payload>
        <Path/>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

Close

1 Answer

  • Sort: 
avatar image
0
Best Answer

Answer by Anil Sagar @ Google   · Mar 24, 2016 at 10:27 AM

@Vipul Agarwal ,

Seems like Assign Message policy doesn't support raw xml with xml initial tag, but you always have power of Javascript policies. See example below i.e working & proxy attached.

 var errorResponseXml = '<?xml version="1.0" encoding="UTF-8"?><Error><ErrorCode>2021</ErrorCode><ErrorMessage>Partner with given apikey not authorized to use this operation.</ErrorMessage></Error>';
 context.setVariable("errorResponseXml", errorResponseXml);
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>Assign Message-1</DisplayName>
    <Properties/>
    <Add>
        <Headers/>
        <QueryParams/>
        <FormParams/>
    </Add>
    <Set>
        <Headers>
            <Header name="Content-Type">text/xml; charset=utf-8</Header>
        </Headers>
        <QueryParams/>
        <FormParams/>
        <!-- <Verb>GET</Verb> -->
        <Payload contentType="text/xml">{errorResponseXml}</Payload>
        <Path/>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

mockxml-rev1-2016-03-24.zip

screen-shot-2016-03-24-at-35607-pm.png (146.3 kB)
mockxml-rev1-2016-03-24.zip (2.2 kB)
Comment
Add comment Show 1 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vipul Agarwal   · Mar 24, 2016 at 02:03 PM 0
Link

@Anil Sagar: Thanks a lot.

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fetching variable from js policy to assign message policy. 1 Answer

Changing a JSON payload "on the fly" 1 Answer

Adding DOCTYPE tag in request payload using apigee policies 1 Answer

Path suffix not writing variables in new url 1 Answer

Assign Message OR condition check 1 Answer

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges