Apigee-如何使用Apigee API开发平台使用POST方法发送XML有效负载

Apigee-如何使用Apigee API开发平台使用POST方法发送XML有效负载,post,apigee,payload,Post,Apigee,Payload,我应该使用POST方法访问可公开访问的API()。它接受表单的XML负载 <Customer> <Age>40</Age> <Gender>M</Gender> <Location>IBM</Location> </Customer> 40 M 国际商用机器公司 并返回产品列表。该API在REST客户机中工作并经过测试 我在Apigee API开发平台中所做的工作如下 默认代理

我应该使用POST方法访问可公开访问的API()。它接受表单的XML负载

<Customer>
   <Age>40</Age>
   <Gender>M</Gender>
   <Location>IBM</Location>
</Customer>

40
M
国际商用机器公司
并返回产品列表。该API在REST客户机中工作并经过测试

我在Apigee API开发平台中所做的工作如下

默认代理端点:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Flows>
        <Flow name="default">
            <Request>
                <Step>
                    <Name>AssignCustomerData</Name>
                </Step>
                <Step>
                    <Name>ExecuteProductService</Name>
                </Step>
            </Request>
            <Response>
                <Step>
                    <Name>ParseProductList</Name>
                </Step>
          </Response>
        </Flow>
    </Flows>
    <HTTPProxyConnection>
        <BasePath>/v1/abcinsproductservice</BasePath>
        <VirtualHost>default</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default"/>
</ProxyEndpoint>

分配客户数据
ExecuteProductService
解析产品列表
/v1/abcinsproductservice
违约
AssignCustomerData是AssignMessage策略,它看起来像

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignCustomerData">
    <DisplayName>AssignCustomerData</DisplayName>
    <AssignTo createNew="true" type="request">CustomerData</AssignTo>
  <Set>
    <Payload contentType="text/xml">
      <Customer>
        <Age>40</Age>
        <Gender>M</Gender>
        <Location>IBM</Location>
      </Customer>
    </Payload>
    <Verb>POST</Verb>
  </Set>
</AssignMessage>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="ExecuteProductService">
  <!-- Send the message we just made to the target, and save the result -->
  <Request variable="CustomerData"/>
  <Response>ProductList</Response>
  <HTTPTargetConnection>
    <URL>https://ABCInsuranceCoreApp.ng.bluemix.net/ABCInsurance/ProductService</URL>
  </HTTPTargetConnection>
</ServiceCallout>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="ParseProductList">
    <DisplayName>ParseProductList</DisplayName>
    <FaultRules/>
    <Properties/>
  <VariablePrefix>products</VariablePrefix>
  <XMLPayload>
    <Variable name="name" type="string">
      <XPath>//Products/Product[1]/Name</XPath>
    </Variable>
  </XMLPayload>
</ExtractVariables>

分配客户数据
客户数据
40
M
国际商用机器公司
邮递
ExecuteProductService是一个服务调用,它看起来像

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignCustomerData">
    <DisplayName>AssignCustomerData</DisplayName>
    <AssignTo createNew="true" type="request">CustomerData</AssignTo>
  <Set>
    <Payload contentType="text/xml">
      <Customer>
        <Age>40</Age>
        <Gender>M</Gender>
        <Location>IBM</Location>
      </Customer>
    </Payload>
    <Verb>POST</Verb>
  </Set>
</AssignMessage>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="ExecuteProductService">
  <!-- Send the message we just made to the target, and save the result -->
  <Request variable="CustomerData"/>
  <Response>ProductList</Response>
  <HTTPTargetConnection>
    <URL>https://ABCInsuranceCoreApp.ng.bluemix.net/ABCInsurance/ProductService</URL>
  </HTTPTargetConnection>
</ServiceCallout>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="ParseProductList">
    <DisplayName>ParseProductList</DisplayName>
    <FaultRules/>
    <Properties/>
  <VariablePrefix>products</VariablePrefix>
  <XMLPayload>
    <Variable name="name" type="string">
      <XPath>//Products/Product[1]/Name</XPath>
    </Variable>
  </XMLPayload>
</ExtractVariables>

产品列表
https://ABCInsuranceCoreApp.ng.bluemix.net/ABCInsurance/ProductService
ParseProductList是一个可提取的策略,它看起来像

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignCustomerData">
    <DisplayName>AssignCustomerData</DisplayName>
    <AssignTo createNew="true" type="request">CustomerData</AssignTo>
  <Set>
    <Payload contentType="text/xml">
      <Customer>
        <Age>40</Age>
        <Gender>M</Gender>
        <Location>IBM</Location>
      </Customer>
    </Payload>
    <Verb>POST</Verb>
  </Set>
</AssignMessage>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="ExecuteProductService">
  <!-- Send the message we just made to the target, and save the result -->
  <Request variable="CustomerData"/>
  <Response>ProductList</Response>
  <HTTPTargetConnection>
    <URL>https://ABCInsuranceCoreApp.ng.bluemix.net/ABCInsurance/ProductService</URL>
  </HTTPTargetConnection>
</ServiceCallout>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="ParseProductList">
    <DisplayName>ParseProductList</DisplayName>
    <FaultRules/>
    <Properties/>
  <VariablePrefix>products</VariablePrefix>
  <XMLPayload>
    <Variable name="name" type="string">
      <XPath>//Products/Product[1]/Name</XPath>
    </Variable>
  </XMLPayload>
</ExtractVariables>

解析产品列表
产品
//产品/产品[1]/名称
我认真地按照样品做了,但是安排不起作用。我不知道错误在哪里。 跟踪也不起作用。。 你能帮忙吗

非常感谢
Amitava

我看您需要将源文件添加到您的ExtractVariables策略中,如下所示:

<Source clearPayload="false">ProductList</Source>
ProductList
另外,我很好奇为什么要使用ServiceCallout(而不仅仅是通过TargetEndpoint路由到目标服务)?我在你的ProxyEndpoint中没有看到RouteRule。如果没有RouteRule,您正在创建一个Echo服务器,它将简单地反射进来的任何内容。要阻止这种情况发生,您需要在ExtractVariables策略之后添加RaiseDefault策略以终止调用

或者,也许你只是给我们看了一个片段,还有更多的内容?

依我看

<Step>
                    <Name>ParseProductList</Name>
                </Step>

解析产品列表
应该是一个请求步骤

所以你的代理人变成

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Flows>
        <Flow name="default">
            <Request>
                <Step>
                    <Name>AssignCustomerData</Name>
                </Step>
                <Step>
                    <Name>ExecuteProductService</Name>
                </Step>
                <Step>
                    <Name>ParseProductList</Name>
                </Step>
            </Request>
            <Response/>
        </Flow>
    </Flows>
    <HTTPProxyConnection>
        <BasePath>/v1/abcinsproductservice</BasePath>
        <VirtualHost>default</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default"/>
</ProxyEndpoint>

分配客户数据
ExecuteProductService
解析产品列表
/v1/abcinsproductservice
违约