Hi,
According to this [1], you can't use JSON with RPCMessageReceiver.
I modified JSONBadgerfishBuilder to handle this case by converting
JSON/Badgerfish explicitly to SOAP:
public OMElement processDocument(InputStream inputStream, String contentType,
MessageContext messageContext) throws
AxisFault {
....
AbstractXMLInputFactory inputFactory = createFactory();
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(
new JSONTokener(IOUtils.toString(reader)));
OMNodeEx document = (OMNodeEx) new
StAXOMBuilder(xmlReader).getDocumentElement();
//removing parent
document.setParent(null);
//wrapping document with envelope
SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
SOAPBody body = soapEnvelope.getBody();
body.addChild(document);
soapEnvelope.build();
...
}
[1] http://isurues.wordpress.com/2009/10/06/how-to-use-axis2-json/
From: Charles Galpin [mailto:[email protected]]
Sent: Wednesday, September 28, 2011 4:06 PM
To: [email protected]
Subject: Re: [AXIS2] Problem: Sending JSON messages to a SOAP Web service using
Axis2
On a related note, can anyone tell me how to compose a request to a service
using a plain http request or from javascript to invoke the json formatter? I
tried this with the JSONMessageFormatter/JSONOMBuilder but can't seem to get
the contentType sent in the request to trigger the formatter. This is on a
service method with no arguments.
thanks,
charles
On Sep 28, 2011, at 3:58 AM, Hans De Clercq wrote:
I'm trying to alter this so I can send JSON messages instead of xml.
What have I done? :
- in axis2.xml : added
[CODE] <messageFormatters>
<messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
<!-- more message formatters -->
</messageFormatters>
<messageBuilders>
<messageBuilder contentType="application/json"
class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>
<!-- more message builders -->
</messageBuilders>[/CODE]