You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Nick Steel <ni...@imperial.ac.uk> on 2008/08/29 17:43:34 UTC

Axis2/Java and JSON

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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Axis2/Java and JSON

Posted by Nick Steel <ni...@imperial.ac.uk>.
But the response from the server complains of a namespace mismatch. So isn't
the problem on the server somewhere? And you can see I'm giving it a
namespace in the request so I don't know why it is complaining!

POST /NicksGigs-war-Axis2/services/GigListingsService HTTP/1.1
Content-Type: text/javascript; 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: text/javascript;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 23 Sep 2008 17:37:45 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




Keithgchapman wrote:
> 
> Hi Nick,
> 
> See my comments inline.
> 
> On Tue, Sep 23, 2008 at 4:20 PM, Nick Steel
> <nicholas.steel05@imperial.ac.uk
>> wrote:
> 
>>
>> Just to confuse matters further I realised the reason I could get a
>> response
>> using your code is that it was using the "application/json/badgerfish"
>> MESSAGE_TYPE when in fact in my axis2.xml config my
>> JSONBadgerfishMessageFormatter/JSONBadgerfishOMBuilder are defined as
>> using
>> "text/javascript".  So in fact with your code I was sending plain XML,
>> not
>> JSON.  When I change it to "text/javascript" I get an exception and no
>> output:
>> Caused by: java.lang.IllegalArgumentException: The MessageContext does
>> not
>> have an associated SOAPFault.
> 
> 
> This happens at the client side when a JSON response is a fault. I
> undentified this issue a couple of days ago. We are in the progree of
> discussing this issue on the Axis2-dev list [1]. We should have a
> sollution
> for this soon.
> 
> Thanks,
> Keith.
> 
> 
> [1] http://markmail.org/message/mzlbfvjujfeyeuzd
> 
>>
>>
>> My client code is:
>> ServiceClient client = new
>>
>> ServiceClient(ConfigurationContextFactory.createConfigurationContextFromFileSystem(null,"axis2.xml"),
>> null);
>> Options options = client.getOptions();
>>
>> options.setProperty(Constants.Configuration.MESSAGE_TYPE,"text/javascript");
>> client.setTargetEPR(new
>> EndpointReference("
>> http://mooshup.com/services/samples/RESTSample/getWeather"));
>> try {
>>         OMElement payload =
>> AXIOMUtil.stringToOM("<getWeather><city>col</city></getWeather>");
>>         OMElement omElement = client.sendReceive(payload);
>>        omElement.serialize(System.out);
>> } catch (XMLStreamException e) {
>>        e.printStackTrace();
>> }
>>
>> So I am still very stuck!
>> Nick
>>
>>
>> Nick Steel wrote:
>> >
>> > And yes when I use your code I am able to receive the response from the
>> > weather service without problem. The only difference I can see between
>> the
>> > response from the weather service and my service is that I have
>> ns:return
>> > and you have return, surely that's not the problem?! Otherwise they
>> look
>> > pretty much the same.
>> >
>> > Nick
>> >
>> >
>> > Nick Steel wrote:
>> >>
>> >> 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
>> >>> <ni...@imperial.ac.uk> 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: axis-user-unsubscribe@ws.apache.org
>> >>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>> >>>>
>> >>>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> 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: axis-user-unsubscribe@ws.apache.org
>> >>> For additional commands, e-mail: axis-user-help@ws.apache.org
>> >>>
>> >>>
>> >>>
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Axis2-Java-and-JSON-tp19222439p19625234.html
>> Sent from the Axis - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>>
> 
> 
> -- 
> Keith Chapman
> Senior Software Engineer
> WSO2 Inc.
> Oxygenating the Web Service Platform.
> http://wso2.org/
> 
> blog: http://www.keith-chapman.org
> 
> 

-- 
View this message in context: http://www.nabble.com/Axis2-Java-and-JSON-tp19222439p19633131.html
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Axis2/Java and JSON

Posted by keith chapman <ke...@gmail.com>.
Hi Nick,

See my comments inline.

On Tue, Sep 23, 2008 at 4:20 PM, Nick Steel <nicholas.steel05@imperial.ac.uk
> wrote:

>
> Just to confuse matters further I realised the reason I could get a
> response
> using your code is that it was using the "application/json/badgerfish"
> MESSAGE_TYPE when in fact in my axis2.xml config my
> JSONBadgerfishMessageFormatter/JSONBadgerfishOMBuilder are defined as using
> "text/javascript".  So in fact with your code I was sending plain XML, not
> JSON.  When I change it to "text/javascript" I get an exception and no
> output:
> Caused by: java.lang.IllegalArgumentException: The MessageContext does not
> have an associated SOAPFault.


This happens at the client side when a JSON response is a fault. I
undentified this issue a couple of days ago. We are in the progree of
discussing this issue on the Axis2-dev list [1]. We should have a sollution
for this soon.

Thanks,
Keith.


[1] http://markmail.org/message/mzlbfvjujfeyeuzd

>
>
> My client code is:
> ServiceClient client = new
>
> ServiceClient(ConfigurationContextFactory.createConfigurationContextFromFileSystem(null,"axis2.xml"),
> null);
> Options options = client.getOptions();
>
> options.setProperty(Constants.Configuration.MESSAGE_TYPE,"text/javascript");
> client.setTargetEPR(new
> EndpointReference("
> http://mooshup.com/services/samples/RESTSample/getWeather"));
> try {
>         OMElement payload =
> AXIOMUtil.stringToOM("<getWeather><city>col</city></getWeather>");
>         OMElement omElement = client.sendReceive(payload);
>        omElement.serialize(System.out);
> } catch (XMLStreamException e) {
>        e.printStackTrace();
> }
>
> So I am still very stuck!
> Nick
>
>
> Nick Steel wrote:
> >
> > And yes when I use your code I am able to receive the response from the
> > weather service without problem. The only difference I can see between
> the
> > response from the weather service and my service is that I have ns:return
> > and you have return, surely that's not the problem?! Otherwise they look
> > pretty much the same.
> >
> > Nick
> >
> >
> > Nick Steel wrote:
> >>
> >> 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
> >>> <ni...@imperial.ac.uk> 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: axis-user-unsubscribe@ws.apache.org
> >>>> For additional commands, e-mail: axis-user-help@ws.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> 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: axis-user-unsubscribe@ws.apache.org
> >>> For additional commands, e-mail: axis-user-help@ws.apache.org
> >>>
> >>>
> >>>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Axis2-Java-and-JSON-tp19222439p19625234.html
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Keith Chapman
Senior Software Engineer
WSO2 Inc.
Oxygenating the Web Service Platform.
http://wso2.org/

blog: http://www.keith-chapman.org

Re: Axis2/Java and JSON

Posted by Nick Steel <ni...@imperial.ac.uk>.
Just to confuse matters further I realised the reason I could get a response
using your code is that it was using the "application/json/badgerfish"
MESSAGE_TYPE when in fact in my axis2.xml config my
JSONBadgerfishMessageFormatter/JSONBadgerfishOMBuilder are defined as using
"text/javascript".  So in fact with your code I was sending plain XML, not
JSON.  When I change it to "text/javascript" I get an exception and no
output:
Caused by: java.lang.IllegalArgumentException: The MessageContext does not
have an associated SOAPFault. 

My client code is:
ServiceClient client = new
ServiceClient(ConfigurationContextFactory.createConfigurationContextFromFileSystem(null,"axis2.xml"),
null);
Options options = client.getOptions();
options.setProperty(Constants.Configuration.MESSAGE_TYPE,"text/javascript");
client.setTargetEPR(new
EndpointReference("http://mooshup.com/services/samples/RESTSample/getWeather")); 
try {
	OMElement payload =
AXIOMUtil.stringToOM("<getWeather><city>col</city></getWeather>");
	OMElement omElement = client.sendReceive(payload); 
	omElement.serialize(System.out); 
} catch (XMLStreamException e) {
	e.printStackTrace();
} 

So I am still very stuck!
Nick


Nick Steel wrote:
> 
> And yes when I use your code I am able to receive the response from the
> weather service without problem. The only difference I can see between the
> response from the weather service and my service is that I have ns:return
> and you have return, surely that's not the problem?! Otherwise they look
> pretty much the same.
> 
> Nick
> 
> 
> Nick Steel wrote:
>> 
>> 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
>>> <ni...@imperial.ac.uk> 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: axis-user-unsubscribe@ws.apache.org
>>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>>>
>>>>
>>> 
>>> 
>>> 
>>> -- 
>>> 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: axis-user-unsubscribe@ws.apache.org
>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Axis2-Java-and-JSON-tp19222439p19625234.html
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Axis2/Java and JSON

Posted by Nick Steel <ni...@imperial.ac.uk>.
And yes when I use your code I am able to receive the response from the
weather service without problem. The only difference I can see between the
response from the weather service and my service is that I have ns:return
and you have return, surely that's not the problem?! Otherwise they look
pretty much the same.

Nick


Nick Steel wrote:
> 
> 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
>> <ni...@imperial.ac.uk> 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: axis-user-unsubscribe@ws.apache.org
>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>>
>>>
>> 
>> 
>> 
>> -- 
>> 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: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Axis2-Java-and-JSON-tp19222439p19610303.html
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Axis2/Java and JSON

Posted by Nick Steel <ni...@imperial.ac.uk>.
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
> <ni...@imperial.ac.uk> 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: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>>
> 
> 
> 
> -- 
> 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: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> 

-- 
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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Axis2/Java and JSON

Posted by keith chapman <ke...@gmail.com>.
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
<ni...@imperial.ac.uk> 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: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>



-- 
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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Download site for Service Archive Wizard - Eclipse Plugin and the Code Generator Wizard Eclipse Plugin

Posted by Moni <mo...@yahoo.com>.
Hi all,  I want the Service Archive Wizard - Eclipse Plugin and the Code Generator Wizard Eclipse Plugin.However when I goto the site:http://ws.apache.org/axis2/tools/index.htmland try to download the files in zipped format and try to click on the http or ftp download mirrors, I am getting a Http 404 error.Is there some other site that I should be looking at to download the Service Archive Wizard - Eclipse Plugin and the Code Generator Wizard Eclipse Plugin?Please let me know.Thanks,Monisha 


      

AW: Axis2/Java and JSON

Posted by jo...@gmx.de.
 

Hello,

I have used a combination von FlexJSON and SimpleJSON for my Webservice
under Axis2. My Endpoint looks like this:

public OMElement getCustomer(String id){....}

That runs very fine. To parse the response to the client you only need two
lines of code with FlexJSON.

Thx
Jörn



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(OMSourcedElemen
tImpl.java:847)
	at
org.apache.axiom.om.impl.llom.OMElementImpl.getFirstOMChild(OMElementImpl.ja
va:650)
	at
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getFirstOMChild(OMSourced
ElementImpl.java:839)
	at
org.apache.axiom.om.impl.llom.OMElementImpl.getFirstElement(OMElementImpl.ja
va:956)
	at
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getFirstElement(OMSourced
ElementImpl.java:410)
	at
org.apache.axiom.om.impl.llom.OMElementImpl.getChildElements(OMElementImpl.j
ava:332)
	at
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getChildElements(OMSource
dElementImpl.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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org