[英]Does WSO2 ESB support REST to REST with JSON format?
我想使用WSO2 ESB作为网关。 我正在使用版本4.0.3我有一些现有的RESTful服务与JSON消息。 我知道ESB现在支持REST API。 但我仍然找不到WSO2 ESB REST到REST的解决方案。 我的意思是所有后端服务都是RESTful的JSON格式。 谁能帮我?
是的,我们确实支持REST -REST服务,这意味着它在协议切换下进行分类,使用WSO2 ESB,它具有REST API,使您能够处理传入的REST或任何其他格式并进行调解并将它们传递到后端(它不会哪个协议是关键的)
如果您需要访问可能必须使用的表格数据,以下代理允许您将收到的REST消息传输到后端REST服务
<messageFormatter contentType =“application / x-www-form-urlencoded”class =“org.apache.axis2.transport.http.XFormURLEncodedFormatter”/>
<messageBuilder contentType =“application / x-www-form-urlencoded”class =“org.apache.synapse.commons.builders.XFormURLEncodedBuilder”/>
它允许您提取包含REST提交详细信息并根据您的喜好进行任何调解
REST TO REST VIA REST API
<api name="studentSecureAPI" context="/SecureStudentRequest">
<resource methods="POST" uri-template="/student/{name}">
<inSequence>
<property name="REST_URI" expression="fn:substring($axis2:REST_URL_POSTFIX,16,fn:string-length($axis2:REST_URL_POSTFIX))"/>
<property name="AGE" expression="//xformValues//age"/>
<property name="STUDENT" expression="get-property('uri.var.name')"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"/>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<property name="REST_URL_POSTFIX" expression="$ctx:REST_URI" scope="axis2"/>
<payloadFactory>
<format>
<POST>
<age>$1</age>
</POST>
</format>
<args>
<arg expression="$ctx:AGE"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="http://localhost:9764/as/services/RestService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
REST TO REST VIA SIMPLE PROXY :
<proxy name="StudentRequestProxy" transports="https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<property xmlns:ns3="http://org.apache.synapse/xsd" name="Lang" expression="get-property('transport', 'Accept')" scope="default" type="STRING"/>
<log level="custom">
<property name="HTTP_METHOD IS###########" expression="$axis2:HTTP_METHOD"/>
</log>
<switch source="$axis2:HTTP_METHOD">
<case regex="GET">
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
</case>
<case regex="POST">
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
</case>
<default/>
</switch>
<send>
<endpoint>
<address uri="http://localhost:9764/as/services/RestService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
最新的ESB版本(4.8.1)与JSON REST调用完美配合。 尝试关注payloadFactory和property mediators,
<payloadFactory media-type="json">
<format>
{
"name":"$1",
"age":$2
}
</format>
<args>
<arg evaluator="json" expression="$ctx:name"/>
<arg evaluator="json" expression="$ctx:age"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
更多信息可以在这里找到
如果您没有使用任何特定的ESB,您可以查看UltraESB - 这是所有REST方法的示例[http://docs.adroitlogic.org/display/esb/Restful+Proxy+Services]并且有也非常支持JSON
免责声明 - 我是AdroitLogic的创始人兼首席技术官
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.