问题
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.
Here is my proxy :
<?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>
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>
Postman json request :
{
"name" : "farzam",
"lastname" : "vatanzadeh",
"age" : "1000",
"nested" : {
"id" : "cd12334dasc",
"group" : "asd",
"list" : ["salam"]
}
}
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; }
}
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"
}
}
I'm struggling with this issue for more than 10 days, I would really appreciate WSO2 engineers if they could help me solve it:(
回答1:
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.
来源:https://stackoverflow.com/questions/38321898/wso2-esb-json-missing-quotes-and-brackets-when-using-scheduled-forwarding-messag