Sorry to bring this up again after so long but I've had some time now to play
with this again and I'm still having problems. I am able to form a sensible
looking JSON request containing my namespace and without. In EITHER case the
response from the server comes back with the namespace included:
{"ns:getMostActiveArtistResponse":{"@xmlns":{"ns":"http:\/\/NicksGigs.nsteel.qis.Nickcom.com"},"ns:return":{"$":"The
Cure"}}}
When I then do response.getChildElements(); I get the error "forceExpand:
expected element namespace getMostActiveArtistResponse, found " which then
throws the exception "Element namespace from data source is
http://NicksGigs.nsteel.qis.Nickcom.com, not the expected ".
All I'm doing on my Java client is:
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace ns =
fac.createOMNamespace("http://NicksGigs.nsteel.qis.Nickcom.com","ns2");
OMElement rootElement = fac.createOMElement("getMostActiveArtist", ns);
OMElement response = client.sendReceive(rootElement);
Iterator<OMElement> itr = response.getChildElements();
Which sends the request:
{"ns2:getMostActiveArtist":{"@xmlns":{"ns2":"http:\/\/NicksGigs.nsteel.qis.Nickcom.com"}}}
When tracing through it seems that the badgerfish receiver doesn't have a
correct record of the namespace, should I be setting it somewhere before I
send the request?
Thanks,
Nick
Keithgchapman wrote:
>
> Hi Nick,
>
> I gave this a try and it works for me. In my example scenario I access
> a service which is deployed on a WSO2 Mashup Server [1] on mooshup.com
> (The WSO2 Mashup Server runs on top of Axis2). the service I access is
> the RESTSample [2]. My client is as follows,
>
> ServiceClient serviceClient = new
> ServiceClient(ConfigurationContextFactory.createConfigurationContextFromFileSystem(null,
> "/opt/repo/axis2_default.xml"), null);
> Options options = new Options();
> options.setTo(new
> EndpointReference("http://mooshup.com/services/samples/RESTSample/getWeather"));
> serviceClient.setOptions(options);
> OMElement payload =
> AXIOMUtil.stringToOM("<getWeather><city>col</city></getWeather>");
>
> options.setProperty(Constants.Configuration.MESSAGE_TYPE,"application/json/badgerfish");
> OMElement omElement = serviceClient.sendReceive(payload);
> omElement.serialize(System.out);
>
> The TCPMon traces of the messages are,
> Input
>
> POST /services/samples/RESTSample/getWeather HTTP/1.1
>
> Content-Type: application/json/badgerfish; charset=UTF-8
>
> User-Agent: Axis2
>
> Host: 127.0.0.1
>
> Transfer-Encoding: chunked
>
>
>
> 23
>
> {"getWeather":{"city":{"$":"col"}}}
>
> 0
>
>
> Output
>
> HTTP/1.1 200 OK
>
> Server: Apache-Coyote/1.1
>
> Content-Type: application/json/badgerfish;charset=UTF-8
>
> Transfer-Encoding: chunked
>
> Date: Mon, 01 Sep 2008 14:40:35 GMT
>
>
>
> 73
>
> {"ws:getWeatherResponse":{"@xmlns":{"ws":"http:\/\/services.mashup.wso2.org\/RESTSample?xsd"},"return":{"$":"10"}}}
>
> 0
>
>
> BTW the JavaScript module on the WSO2 Mashup Server [1] up on
> mooshup.com is the one shipped with the 1.4 release of Axis2. And as
> you see it works fine. Can you give this a try please.
>
> Thanks,
> Keith.
>
> [1] http://wso2.org/projects/mashup
> [2] http://mooshup.com/mashup.jsp?author=samples&mashup=RESTSample
>
> On Fri, Aug 29, 2008 at 9:13 PM, Nick Steel
> <[EMAIL PROTECTED]> wrote:
>>
>> 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]
>>
>>
>
>
>
> --
> Keith Chapman
> Senior Software Engineer
> WSO2 Inc.
> Oxygenating the Web Service Platform.
> http://wso2.org/
>
> blog: http://www.keith-chapman.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/Axis2-Java-and-JSON-tp19222439p19609823.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]