问题
I am trying to use a REST service spit out a JSON output in WSB403 and I have been highly unsuccessful. I followed the steps outlined from the below link.
ESB and JSON
I have added the DynamicResponseModule
and I have it assigned globally.
When I run the REST service normally, I get a XML formatted output as expected, but when I try to add a "response=json
", my service times out and I get the following stacktrace.
Internally the DynamicResponseModule
is supposed to map this responseType
to application/JSON/Badgerfish
and when it does that I get the following stack trace.
java.lang.RuntimeException: Element namespace from data source is http://ws.apache.org/axis2, not the expected at org.apache.axiom.om.impl.llom.OMSourcedElementImpl.forceExpand(OMSourcedElementImpl.java:287) at org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getFirstOMChild(OMSourcedElementImpl.java:867) at org.apache.axiom.om.impl.OMNavigator._getFirstChild(OMNavigator.java:196) at org.apache.axiom.om.impl.OMNavigator.updateNextNode(OMNavigator.java:140) at org.apache.axiom.om.impl.OMNavigator.getNext(OMNavigator.java:112) at org.apache.axiom.om.impl.SwitchingWrapper.updateNextNode(SwitchingWrapper.java:1113) at org.apache.axiom.om.impl.SwitchingWrapper.(SwitchingWrapper.java:235) at org.apache.axiom.om.impl.OMStAXWrapper.(OMStAXWrapper.java:74) at org.apache.axiom.om.impl.llom.OMStAXWrapper.(OMStAXWrapper.java:52) at org.apache.axiom.om.impl.llom.OMContainerHelper.getXMLStreamReader(OMContainerHelper.java:51) at org.apache.axiom.om.impl.llom.OMElementImpl.getXMLStreamReader(OMElementImpl.java:736) at org.apache.axiom.om.impl.llom.OMElementImpl.cloneOMElement(OMElementImpl.java:1038) at org.apache.synapse.util.MessageHelper.cloneSOAPEnvelope(MessageHelper.java:256) at org.apache.synapse.core.axis2.SOAPUtils.convertSOAP11toSOAP12(SOAPUtils.java:95) at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:323) at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:160) at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181) at org.apache.synapse.transport.nhttp.ClientWorker.run(ClientWorker.java:275) at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:173) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) These are the message formatters and builders that I have added to the axis2.xml class="org.apache.axis2.json.JSONOMBuilder"/> class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>
class="org.apache.axis2.json.JSONOMBuilder"/>
class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
class="org.apache.axis2.json.JSONMessageFormatter"/>
Any idea what am I missing here ?
Thanks
Narsi
回答1:
You may inspire from the sample[1]. (Please note that if you want to switch from json to soap11, then you have to set the endpoint format to soap11.)
Use json message builder and formtter in the axis2.xml for the correct content type (e.g. application/json for instance)
[1] http://wso2.org/project/esb/java/4.0.3/docs/samples/advanced_mediation_samples.html#Sample440
来源:https://stackoverflow.com/questions/9605712/wso2-esb-4-0-3-and-json-in-rest-service