WSO2 ESB是否支持使用JSON格式的REST到REST?

use*_*779 4 rest json esb wso2 wso2esb

我想使用WSO2 ESB作为网关.我正在使用版本4.0.3我有一些现有的RESTful服务与JSON消息.我知道ESB现在支持REST API.但我仍然找不到WSO2 ESB REST到REST的解决方案.我的意思是所有后端服务都是RESTful的JSON格式.谁能帮我?

Dus*_*wan 7

是的,我们支持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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)