格式错误的响应 - 从另一个调用一个ESB REST服务

时间:2013-05-24 12:50:20

标签: rest wso2 wso2esb

我对WSO2 ESB比较陌生, 尝试使用GET参数调用REST Web服务,该参数通过另一个REST API托管在WSO2 ESB上。

这是一个简单的 Web服务(SampleREST),它以XML格式回复欢迎消息, 当我直接调用此服务时;我可以在浏览器上看到正确的响应,如下所示

<Message xmlns="http://ws.apache.org/ns/synapse">WelcomeRanjan</Message>

现在我创建了另一个REST Web服务(InvokeSampleRest),后者又使用参数化GET调用SampleREST Web服务, Invoke WebService Client 返回包含在mediator xml标记和其他格式错误的标记中的XML响应,如下所示

<mediate><<Message xmlns>"http://ws.apache.org/ns/synapse">WelcomeRanjan&lt;/Message></<Message xmlns></mediate>

以下是SampleREST API的代码

<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="SampleREST" context="/SampleRest" hostname="10.203.245.47">
    <resource methods="GET" uri-template="/{str1}">
        <inSequence>
            <header name="To" action="remove"/>
            <property name="RESPONSE" value="true" scope="default" type="STRING"/>
            <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
            <payloadFactory>
                <format>
                    <Message>$1</Message>
                </format>
                <args>
                    <arg expression="get-property('uri.var.str1')"/>
                </args>
            </payloadFactory>
            <log level="full" separator=",">
                <property name="sequence" value="*** Got Request ***"/>
            </log>
            <send/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

InvokeSampleREST代码的代码如下所示(我从这里调用SampleREST服务)

<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="InvokeSampleREST" context="/InvokeSampleREST" hostname="10.203.245.47">
       <resource methods="GET" uri-template="/{str1}">
        <inSequence>
            <log level="full" separator=","/>
            <property name="REST_URL_POSTFIX" expression="fn:concat('/Welcome',get-property('uri.var.str1'))" scope="axis2" type="STRING"/>
            <log level="full">
                <property name="sequence" value="****Message Sent *** "/>
            </log>
            <send>
                <endpoint>
                    <address uri="http://10.203.245.47:8280/SampleRest/"/>
                </endpoint>
            </send>
        </inSequence>
        <outSequence>
            <log level="full" separator=",">
                <property name="out" value="** Ouput of Rest call ***"/>
            </log>
            <property name="ContentType" value="application/xml" scope="axis2" type="STRING"/>
            <send/>
        </outSequence>
        <faultSequence/>
    </resource>
</api>

感谢任何帮助。 谢谢, 兰詹

2 个答案:

答案 0 :(得分:1)

为什么使用两个API?您可以在单个API中设计流程。我的意思是你可以将它们合并在一起 顺便说一句,您需要在后端API中设置contentType属性(即:在SampleREST API中) 因为,当您将响应发送回“InvokeSampleREST”API时,系统不知道传入响应的内容类型,并尝试将其作为文本消息处理。

例如:

 <api name="SampleREST" context="/SampleRest" hostname="localhost">
      <resource methods="GET" uri-template="/{str1}">
         <inSequence>
            <header name="To" action="remove"/>
            <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
            <property name="RESPONSE" value="true" scope="default" type="STRING"/>
            <payloadFactory>
               <format>
                  <Message>$1</Message>
               </format>
               <args>
                  <arg expression="get-property('uri.var.str1')"/>
               </args>
            </payloadFactory>
            <log level="full" separator=",">
               <property name="sequence" value="*** Got Request ***"/>
            </log>
            <property name="Content-Type"
                      value="application/xml"
                      scope="transport"
                      type="STRING"/>
            <send/>
         </inSequence>
         <faultSequence/>
      </resource>

答案 1 :(得分:0)

尝试在InvokeSampleREST API上进行以下更改。

在outSequence中,在&lt; send&gt;之前设置messageType,如下所示:介体。

<property name="messageType" value="application/xml" scope="axis2"/>
相关问题