WSO2代理服务生成错误的响应

时间:2018-05-19 14:39:47

标签: wso2 wso2esb esb proxy-server google-books

我正在使用WSO2企业服务总线构建代理服务。此服务接受XML

<GetBookInfo>
    <isbn>someibnnumberhere</isbn>
</GetBookInfo>

以下是 XML 文件或 实际代理服务

参数代码是

<inSequence>
<log level="full" description="Log SOAP request"/> 
<property xmlns:ns="http://waa.swin.edu.au" 
     name="uri.var.isbn" 
     xpression="//ns:GetBookInfo/isbn" 
     scope="default"
     type="STRING"/>
 <property name="messageType" 
     value="application/json"
     scope="axis2"
     type="STRING"
     description="Transform message format to JSON"/>

发送请求的代码是

<send>
    <endpoint name="GeoLocationProxyService">
        <http method="GET" uri-template="https://www.googleapis.com/books/v1/volumes?q=isbn:{uri.var.isbn}&amp;key=AIzaSyBBJis6L2DK2PROIy2SsFBdgTJohR7GuFg&amp;fields=items(volumeInfo/title,volumeInfo/authors,volumeInfo/publisher,volumeInfo/publishedDate,volumeInfo/industryIdentifiers,saleInfo/country,saleInfo/saleability,volumeInfo/averageRating)" />
    </endpoint>
</send>
</inSequence>

发送和接收响应的代码是

<outSequence>
     <log description="Log returned JSON payload">
        <property name="JSON‐Payload" expression="json-eval($.)"/>
     </log>
     <payloadFactory media-type="xml" description="Generate response data">
        <format>
           <GetGeoLocationResponse xmlns="http://waa.swin.edu.au">
              <title>$1</title>
              <authors>$2</authors>
              <publisher>$3</publisher>
              <publishedDate>$4</publishedDate>
              <type>$5</type>
              <identifier>$6</identifier>
              <country>$7</country>
              <saleability>$8</saleability>
           </GetGeoLocationResponse>
        </format>
        <args>
           <arg evaluator="json" expression="$.items[0].volumeInfo.title"/>
           <arg evaluator="json" expression="$.items[0].volumeInfo.authors"/> 
           <arg evaluator="json" expression="$.items[0].volumeInfo.publisher"/> 
           <arg evaluator="json" expression="$.items[0].volumeInfo.publishedDate"/> 
           <arg evaluator="json" expression="$.items[0].volumeInfo.industryIdentifiers[1].type"/> 
           <arg evaluator="json" expression="$.items[0].volumeInfo.industryIdentifiers[1].identifier"/> 
           <arg evaluator="json" expression="$.items[0].saleInfo.country"/> 
           <arg evaluator="json" expression="$.items[0].saleInfo.saleability"/> 
        </args>
     </payloadFactory>
     <property name="messageType"
        value="application/xml"
        scope="axis2"
        type="STRING"
        description="Transform message format to SOAP"/>
     <send/>
  </outSequence>

此服务创建的响应是一些随机数,但类型相同。这就是我所说的♂️

<GetGeoLocationResponse xmlns="http://waa.swin.edu.au">
   <title>ISBN Review</title>
   <authors>
      <jsonElement>International ISBN Agency</jsonElement>
   </authors>
   <publisher/>
   <publishedDate>1998</publishedDate>
   <type/>
   <identifier/>
   <country>AU</country>
   <saleability>NOT_FOR_SALE</saleability>
</GetGeoLocationResponse>

以上所有丢失的字段都是多个项[i]的结果,其中i:&lt; = 10(我认为)返回包含不同的垃圾/垃圾值。所以,是的,无论是哪个领域都缺失或者他们是错的♂️

如果我通过 浏览器/邮递员

请求相同的服务
{
items: [
    {
        volumeInfo: {
            title: "If At First You Don't Conceive",
            authors: [
                "Liz Ellis"
            ],
            publisher: "Macmillan Publishers Aus.",
            publishedDate: "2018-04-24",
            industryIdentifiers: [
                {
                    type: "ISBN_13",
                    identifier: "9781760780364"
                },
                {
                    type: "ISBN_10",
                    identifier: "1760780367"
                }
            ]
        },
        saleInfo: {
            country: "AU",
            saleability: "FOR_SALE"
        }
    }
    ]
}

1 个答案:

答案 0 :(得分:1)

您可以使用REST_URL_POSTFIX属性,其值附加在端点URL的末尾。

<property name="REST_URL_POSTFIX" expression="fn:concat('?q=isbn:',$ctx:isbn_no,'&amp;key=',$ctx:key)" scope="axis2"/>

然后定义没有查询参数的端点。

<send>
    <endpoint name="GeoLocationProxyService">
        <http method="GET" uri-template="https://www.googleapis.com/books/v1/volumes" />
    </endpoint>
</send>