用脚本调解员致电调解人

发布于 2025-02-11 15:40:51 字数 1531 浏览 2 评论 0 原文

我正在寻找带有呼叫调解员的API。然后,我想与脚本Medieor一起处理数据,并与响应生成输出。如果我不使用脚本调解员,我的流将起作用。但是,当我想使用脚本Medieor时,我会收到以下错误。

序言中的意外字符'{'(代码123);预期的'<' 在[row,col {col {unknown源}]中:[1,1]

<?xml version="1.0" encoding="UTF-8"?>
<api context="/x" name="x" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence>
            <call>
                <endpoint>
                    <http method="get" uri-template="https://jsonplaceholder.typicode.com/users">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>-1</progressionFactor>
                            <maximumDuration>0</maximumDuration>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </http>
                </endpoint>
            </call>
            <script language="js"><![CDATA[var x = mc.getPayloadJSON();

if  (x.id == "1")
mc.setPayloadJSON('{"s":"success"}');
else 
mc.setPayloadJSON('{"s":"error"}');]]></script>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

预先感谢。

I'm looking for an API with Call Mediator. Then I want to process the data coming with Script Mediaor and generate output with Respond. If I don't use Script Mediator, my stream will work. But when I want to use Script Mediaor I get the following error.

Unexpected character in preface '{' (code 123); expected '<'
in [row,col {unknown source}]: [1,1]

<?xml version="1.0" encoding="UTF-8"?>
<api context="/x" name="x" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence>
            <call>
                <endpoint>
                    <http method="get" uri-template="https://jsonplaceholder.typicode.com/users">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>-1</progressionFactor>
                            <maximumDuration>0</maximumDuration>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </http>
                </endpoint>
            </call>
            <script language="js"><![CDATA[var x = mc.getPayloadJSON();

if  (x.id == "1")
mc.setPayloadJSON('{"s":"success"}');
else 
mc.setPayloadJSON('{"s":"error"}');]]></script>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆一缕阳光ご 2025-02-18 15:40:51

脚本中介器 content-ware 调解器,当您在中介流中添加内容感知的中介器时,将构建消息(二进制消息转换为可读格式)并将其带入该消息中调解流。这通过消息构建者。从您共享的错误片段中,您似乎正在收到JSON消息作为响应。因此,此错误可能有两个原因。

  1. 正如Arunan提到的那样,您的后端可能不会将正确的内容类型作为带有响应的标头发送。
  2. 正确的消息构建器未在传输配置中设置为匹配后端传输的内容类型标头。

如果采用第二种情况,请首先确保为默认的JSON Content-Type Application/json 设置消息构建器,&lt; server_home&gt; /conf/axis2/axis2/axis2.xml << /代码>。如果在那里,请检查您的后端是否正在发送默认内容类型的JSON变体。例如,“应用程序/LD+JSON”等。如果是这种情况,则需要为此内容类型添加新的消息构建器。您可以参考如果您在Mi上,则此文档。如果您在EI上,请参考

更新
检查您的评论后,它看起来像是直接的集成。除上述两个原因外,这可能是后端完全发送错误的响应。您是否正在使用浏览器来测试此API?如果是这样,由于浏览器添加了其他标头,您可能会得到不同的响应。因此,请在呼叫中介之前尝试卸下所有运输标头。请参阅下面。注意&lt; property Action =“ remove” name =“ Transport_headers” scope =“ axis2”/&gt;

<property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
<call>
    <endpoint>
        <http method="get" uri-template="https://jsonplaceholder.typicode.com/users">
            <suspendOnFailure>
                <initialDuration>-1</initialDuration>
                <progressionFactor>-1</progressionFactor>
                <maximumDuration>0</maximumDuration>
            </suspendOnFailure>
            <markForSuspension>
                <retriesBeforeSuspension>0</retriesBeforeSuspension>
            </markForSuspension>
        </http>
    </endpoint>
</call>

The Script Mediator is a content-aware mediator and when you add a content-aware mediator to the mediation flow the message will be built(Binary message converted into a readable format) and brought into the mediation flow. This happens through message builders. From the error snippet you shared, it seems you are receiving a JSON message as a response. So there can be two reasons for this error.

  1. As Arunan mentioned, your backend may not be sending the correct Content-Type as a header with the response.
  2. The correct message builders are not set in the transport configurations to match the Content-Type header the backend is transmitting.

If you take the second case, first make sure a message builder is set for the default JSON content-type application/json in the <SERVER_HOME>/conf/axis2/axis2.xml. If it's there check if your backend is sending a JSON variation of a default content-type. For example "application/ld+json" etc. If that's the case you need to add a new message builder for this content type. You can refer to this document if you are on MI. If you are on EI refer to this.

Update
After checking your comments, it looks like a straightforward integration. Other than the above two reasons this can be the backend altogether sending a wrong response. Are you using the browser to test this API? If so you may be getting a different response due to additional headers added by the browser. Hence please try removing all the transport headers before the call mediator. Refer to the below. Note the <property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>

<property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
<call>
    <endpoint>
        <http method="get" uri-template="https://jsonplaceholder.typicode.com/users">
            <suspendOnFailure>
                <initialDuration>-1</initialDuration>
                <progressionFactor>-1</progressionFactor>
                <maximumDuration>0</maximumDuration>
            </suspendOnFailure>
            <markForSuspension>
                <retriesBeforeSuspension>0</retriesBeforeSuspension>
            </markForSuspension>
        </http>
    </endpoint>
</call>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文