Following my unresolved problem with REST last week I tried using JSON and
have had more problems! I followed the guide at http://wso2.org/library/768
and the sample yahoojsonsearch in the axis2 samples. I set the message
builders and formatters in the axis2.xml as instructed. I then firstly
tried to use my existing ADB bindings with the ContentType property set to
"application/json" and when they failed to work I tried constructing the
OMElement myself as in the sample but with no success. Then I tried a
mixture of the two which is the only way I can get a response!
client = new ServiceClient(super.getConfigContext(),
Options options = client.getOptions();
options.setProperty(Constants.Configuration.MESSAGE_TYPE,
"application/json");
client.setTargetEPR(new EndpointReference(endpointUrl));
GetGigsIn getGigsInObj = new GetGigsIn();
getGigsInObj.setParam0(city);
OMElement rootElement = getGigsInObj.getOMElement(GetGigsIn.MY_QNAME, fac);
OMElement response = client.sendReceive(rootElement);
However it throws an exception after during the last line and TCPmon shows
the request and response as:
POST /NicksGigs-war-Axis2/services/GigListingsService HTTP/1.1
Content-Type: application/json; charset=UTF-8
User-Agent: Axis2
Host: 10.4.39.241:8089
Transfer-Encoding: chunked
69
{"ns2:getGigsIn":{"@xmlns":{"ns2":"http:\/\/NicksGigs.nsteel.qis.Nickcom.com"},"param0":{"$":"London"}}}
0
------------------
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 29 Aug 2008 12:22:43 GMT
Connection: close
10c
{"Fault":{"$":"<soapenv:Fault
xmlns:soapenv=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\"><faultcode>soapenv:Server<\/faultcode><faultstring>namespace
mismatch require http:\/\/NicksGigs.nsteel.qis.Nickcom.com found
<\/faultstring><detail \/><\/soapenv:Fault>"}}
0
After tracing through the serverside code I found that the empty namespace
object is created in JSONOMBuilder at Line 52:
OMNamespace ns = new OMNamespaceImpl("", "")
And then only used to create a new OMSourcedElementImpl object at line 111:
return new OMSourcedElementImpl(localName, ns, factory, jsonDataSource);
After which point I dont know what happens to it. If I then set an
expression in Eclipse while debugging to manually set this namespace object
[ns = new OMNamespaceImpl("http://NicksGigs.nsteel.qis.Nickcom.com", "");]
then the server returns a full response but something on the client side
throws this exception:
Caused by: org.apache.axiom.om.OMException:
javax.xml.stream.XMLStreamException: Invalid prefix ns on element ns:return
at
org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
at
org.apache.axiom.om.impl.llom.OMElementImpl.buildNext(OMElementImpl.java:633)
at
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.buildNext(OMSourcedElementImpl.java:847)
at
org.apache.axiom.om.impl.llom.OMElementImpl.getFirstOMChild(OMElementImpl.java:650)
at
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getFirstOMChild(OMSourcedElementImpl.java:839)
at
org.apache.axiom.om.impl.llom.OMElementImpl.getFirstElement(OMElementImpl.java:956)
at
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getFirstElement(OMSourcedElementImpl.java:410)
at
org.apache.axiom.om.impl.llom.OMElementImpl.getChildElements(OMElementImpl.java:332)
at
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getChildElements(OMSourcedElementImpl.java:267)
at
com.qualcomm.qis.nsteel.NicksGigs.ManualJson.getGigsIn(ManualJson.java:69)
... 32 more
Line 69 in ManualJson is:
Iterator<OMElement> itr = response.getChildElements();
Which seems to be throwing an error because the response has not been
properly parsed (response.done=false).
What am i doing wrong here with the namespaces to get both of these
problems?
--
View this message in context:
http://www.nabble.com/Axis2-Java-and-JSON-tp19222439p19222439.html
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]