使用计划的转发消息处理器时,wso2 esb json缺少引号和括号 [英] wso2 esb json missing quotes and brackets when using scheduled forwarding message processor

查看:121
本文介绍了使用计划的转发消息处理器时,wso2 esb json缺少引号和括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过esb和activemq发送json请求时遇到问题,实际上我正在使用代理,并使用其余内容和json内容调用我的代理.这是我的集成流程,我调用一个代理(带有邮递员),然后该代理将请求(带有json内容)发送到一个jms消息存储库,然后,我定义了一个调度的转发消息处理器以使用消息存储库中的消息并将其发送到定义的端点(.net Web API).但问题是带有数字的字符串会自动转换为整数元素:"age":100(我希望它是字符串"age":"100"),另一个问题是json单元素数组更改为json中的字符串属性, "list":["salam"]更改为"list":"salam",似乎有些东西放在括号中,但是如果我发送的数组包含多个元素,则它可以正常工作,但是当我直接从代理发送请求时到我的端点(不使用消息代理),它可以正常工作.(在所有状态下,esb控制台都正确记录了json消息,我认为预定的消息转发处理器正在执行此更改),由于@krishan,我之前曾问过两个问题是我昨天的问题,我更新了axis2.xml文件,并像他说的那样添加了JsonStreamFormatter和JsonStreamBuilder,但没有任何反应.

I have a problem in sending json requests through esb and activemq, actually I'm using a proxy and I call my proxy with rest and json content. Here is my integration flow, I call a proxy (with postman) and the proxy sends the request(with json content) to a jms message store then, I defined a scheduled forwarding message processor to consume messages from message store and send them to a defined endpoint(.net web api). but the problem is strings with numbers automatically get converted as integer elements: "age": 100 ( I want it to be string "age": "100") , another problem is json single elemented array changes to a string attribute in json, "list" : ["salam"] changes to "list" : "salam", it seems something is dropping the brackets but if I send an array with more than one element it works correctly, however when I send the request directly from proxy to my end point (without using message broker) it works correctly.(In all states esb console logs the json message correctly, I think scheduled message forwarding processor is doing this changes), I've asked two questions before, due to @krishan 's answer to my yesterday's question, I updated my axis2.xml file and added JsonStreamFormatter and JsonStreamBuilder like he said, but nothing happened.

这是我的代理人:

<?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse"
       name="myProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="full"/>
         <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
         <property name="OUT_ONLY" value="true"/>
         <property name="messageType" value="application/json" scope="axis2"/>
         <store messageStore="myProxyMS"/>
      </inSequence>
   </target>
   <description/>
</proxy>

我的jms消息存储区:

And my jms message store :

<messageStore name="myProxyMS" class="org.apache.synapse.message.store.impl.jms.JmsStore" xmlns="http://ws.apache.org/ns/synapse">
   <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
   <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
   <parameter name="store.jms.username">admin</parameter>
   <parameter name="store.jms.password">admin</parameter>
   <parameter name="store.jms.JMSSpecVersion">1.1</parameter>
   <parameter name="store.producer.guaranteed.delivery.enable">false</parameter>
   <parameter name="store.failover.message.store.name">InfoGetMobileIndMS</parameter>
</messageStore>

预定的转发消息处理器:

And Scheduled forwarding message processor :

<messageProcessor name="myProxyMP" class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor" targetEndpoint="aspnet" messageStore="myProxyMS" xmlns="http://ws.apache.org/ns/synapse">
   <parameter name="interval">1000</parameter>
   <parameter name="client.retry.interval">1000</parameter>
   <parameter name="max.delivery.attempts">4</parameter>
   <parameter name="is.active">true</parameter>
   <parameter name="max.delivery.drop">Enabled</parameter>
   <parameter name="member.count">1</parameter>
</messageProcessor>

邮递员json请求:

{
    "name" : "farzam",
    "lastname" : "vatanzadeh",
    "age" : "1000",
    "nested" : {
        "id" : "cd12334dasc",
        "group" : "asd",
        "list" : ["salam"]
    }
}

还有我的.NET API

And my .NET api

 [HttpPost]
    [Route("proxy")]
    [Test]
    public HttpResponseMessage Proxy(TempViewModel model)
    {
        return Request.CreateResponse(HttpStatusCode.Accepted);
    }
    public class TempViewModel
    {
        public string name { get; set; }
        public string lastname { get; set; }
        public string age { get; set; }
        public Nested nested { get; set; }
    }
    public class Nested
    {
        public string id { get; set; }
        public string group { get; set; }
        public List<string> list { get; set; }
    }

我定义了一个actionFilter属性来捕获从消息处理器发送到我的api的http发布请求以打开其内容. 我的Json请求变成这样:

I defined an actionFilter attribute to catch http post request sending from message processor to my api to open it's content. my Json request becomes like this:

{
    "name":"farzam",
    "lastname":"vatanzadeh",
    "age":1000,
    "nested":{
        "id":"cd12334dasc",
        "group":"asd",
        "list":"salam"
    }
}

我在这个问题上苦苦挣扎了十多天,如果他们能够帮助我解决问题,我将非常感谢WSO2工程师:(

I'm struggling with this issue for more than 10 days, I would really appreciate WSO2 engineers if they could help me solve it:(

推荐答案

由于在ESB内部使用了STAXON消息格式化程序,因此发生了这种情况.无论如何,我不能依靠这样的说法,即它可以与Sampling消息处理器一起工作.由于转发和采样消息处理器都使用相同的格式化程序.如果在格式化消息时列表中有一个元素,它将显示为一个元素.但是,如果列表中有多个元素,则它将显示为列表.为此,我们已向生产客户发布了补丁.不幸的是,我们不能在这样的公共论坛上发布补丁.如果您需要这样的分辨率,请尝试从WSO2获得生产支持.

This happens due to the STAXON message formatter used inside the ESB. Anyway I can't rely on the claim that this works fine with the Sampling message processor. Since both the forwarding and sampling message processors use the same formatter. If you have one element in the list when it formats the message it will show it as a one element. But if you have multiple elements in the list, then it will be showing as a list. For this we have issued a patch to a production customer. Unfortunately we can not issue patches in public forums like this. Please try to take a production support from WSO2 if you need a resolution like that.

这篇关于使用计划的转发消息处理器时,wso2 esb json缺少引号和括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆