我正在使用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}&key=AIzaSyBBJis6L2DK2PROIy2SsFBdgTJohR7GuFg&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:<=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"
}
}
]
}
可以使用REST_URL_POSTFIX
属性,该属性的值追加在终结点 URL 的末尾。
<property name="REST_URL_POSTFIX" expression="fn:concat('?q=isbn:',$ctx:isbn_no,'&key=',$ctx:key)" scope="axis2"/>
然后定义不带查询参数的终结点。
<send>
<endpoint name="GeoLocationProxyService">
<http method="GET" uri-template="https://www.googleapis.com/books/v1/volumes" />
</endpoint>
</send>