Re: JSON with XML Stream API/moshi
robertlazarski <[email protected]> Sun, 23 Feb 2025 19:59:59 -1000
| Newsgroups | gmane.text.xml.axis.user |
|---|---|
| Message-ID | <CABpPLBVWR1ULy=XVdeRLJ4avkePwDjd23zGa+jqtC5V4+_DKAQ@mail.gmail.com> |
--00000000000093e380062edd0de8
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I was able to follow your examples with the currency attribute and get some
results but it seems like you have some service.xml and axis2.xml
configurations I am unsure about - could you please post them?
With the service.xml and axis2.xml largely from the spring boot demo I
conjured up with the current state of git master - the one difference is
you are using RequestURIBasedDispatcher instead of the new class
JSONBasedDefaultDispatcher
which works, so I used that too - I am sending this:
{"getPrice":[{"arg0":{"currency":USD,"symbol":IBM}}]}
And getting this response:
{"response":{"local_return":42.0}}
The problem is the skeleton is receiving null values for the currency and
symbol for some reason.
About the MoshiXMLStreamReader question - I don't see that condition being
entered during my debugging.
On Fri, Feb 21, 2025 at 12:52=E2=80=AFAM Stefan Traud <[email protected]=
om>
wrote:
> In between I have also looked into the source of
> org.apache.axis2.json.moshi.MoshiXMLStreamReader and I find
>
> public int getAttributeCount() {
>
> if (isStartElement()) {
>
> return 0; *//* *don't support attributes on tags in JSON convention*
>
> } else {
>
> throw new IllegalStateException("Only valid on START_ELEMENT state");
>
> }
>
> }
>
>
> public QName getAttributeName(int index) {
>
> throw new UnsupportedOperationException("Method is not implemented");
> }
>
> Attributes get ignored (attribute count will be returned as 0). It appear=
s
> that I cannot use the current XML Stream API based approach togehter with
> ADB in my case, at least not without substantial changes in the used
> xml-schemas.
>
>
> Am Mittwoch, 19. Februar 2025 um 09:26:07 MEZ hat Stefan Traud <
> [email protected]> Folgendes geschrieben:
>
>
> I'm attaching 2 debug logs:
>
> - soap.log: processing of the getPrice request using the ADBClient
> from samples.quickstartadb (modified only to set the required currency
> attribute using StockQuoteService.setCurrency). This returns the expec=
ted
> result.
> - json.log: processing of the getPrice request using a post of the
> json message string {"getPrice":{"@currency":"USD","symbol":"IBM"}}
> with content-type application/json and url
> http://localhost:8080/axis2/services/StockQuoteService/getPrice. This
> results in internal server error due to missing required attribute.
>
>
> For your reference, I'm also attaching the modified StockQuoteService.wsd=
l
> from the samples.quickstartadb (adding required attribute 'currency' to t=
he
> getPrice data type).
>
> I also played with various variations of the json message (using
> "currency" instead of "@currency", changing order, or using "_attributes"=
:
> {"currency":"USD"}. This trial-and-error approach does not work.
>
> I also tried what happens if I change the wsdl to require an attribute in
> the getPriceResponse (instead of in the request), as this will use the mo=
shi.JsonFormatter
> to write the output JSON (I hoped to see what convention would be used by
> moshi when producing the json string). However the attribute is simply
> ignored and not included in the response json.
>
> Am Dienstag, 18. Februar 2025 um 16:38:57 MEZ hat robertlazarski <
> [email protected]> Folgendes geschrieben:
>
>
> Could you please paste or attach your logs? That may help me understand
> the problem better. I don't have use cases combining XML and JSON in my o=
wn
> projects but I know the code pretty well and I can probably help.
>
> On Mon, Feb 17, 2025 at 5:23=E2=80=AFAM Stefan Traud <stefan_traud@yahoo.=
com>
> wrote:
>
> Hi Robert
> Using contract first with ADB, I continue to check feasibility to amend
> our existing service with JSON support (based on XML Stream API with mosh=
i).
>
> I'm currently struggling with xml types that include attributes. To
> reproduce the issue I have amended the wsdl in the samples.quickstartadb =
to
> include an attribute in the getPrice element:
>
> <xs:element name=3D"getPrice">
>
> <xs:complexType>
>
> <xs:sequence>
> <xs:element name=3D"symbol"
> nillable=3D"true" type=3D"xs:string" />
>
> </xs:sequence>
> <xs:attribute name=3D"currency"
> type=3D"xs:string" use=3D"required"/>
>
> </xs:complexType>
>
> </xs:element>
>
> My corresponding JSON message should then be something like:
>
> { "getPrice" : {"@currency": "USD", "symbol": "IBM" }}
>
> However the parse method in the GetPrice ADBBean keeps complaining "Requi=
red
> attribute currency is missing"; specifically this call returns null:
>
> reader.getAttributeValue("http://quickstart.samples/xsd", "currency");
>
> (However it works when using SOAP).
>
> Do I need to define attributes differently in the JSON message?
>
>
>
--00000000000093e380062edd0de8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I was able to follow your examples with the currency =
attribute and get some results but it seems like you have some service.xml =
and axis2.xml configurations I am unsure about - could you please post them=
? <br></div><div><br></div><div>With the service.xml and axis2.xml largely =
from the spring boot demo I conjured up with the current state of git maste=
r - the one difference is you are using=C2=A0<span style=3D"font-family:mon=
ospace"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255)">=
RequestURIBasedDispatcher</span></span> instead of the new class <span styl=
e=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);background-colo=
r:rgb(255,255,255)">JSONBasedDefaultDispatcher</span><br></span>which works=
, so I used that too - I am sending this: <br></div><div><br></div><div><sp=
an style=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);backgrou=
nd-color:rgb(255,255,255)">{"getPrice":[{"arg0":{"=
currency":USD,"symbol":IBM}}]}</span><br></span></div><div><=
span style=3D"font-family:monospace"><br></span></div><div><span style=3D"f=
ont-family:monospace">And getting this response: <br></span></div><div><spa=
n style=3D"font-family:monospace"><br></span></div><div><span style=3D"font=
-family:monospace"><span style=3D"color:rgb(0,0,0);background-color:rgb(255=
,255,255)">{"response":{"local_return":42.0}}</span><br=
></span></div><div><span style=3D"font-family:monospace"><br></span></div><=
div><span style=3D"font-family:monospace">The problem is the skeleton is re=
ceiving null values for the currency and symbol for some reason. <br></span=
></div><div><br></div><div>About the <span style=3D"font-family:monospace">=
<span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255)">MoshiXML=
StreamReader question - I don't see that condition being entered during=
my debugging. </span><br></span><br></div></div><br><div class=3D"gmail_qu=
ote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Fe=
b 21, 2025 at 12:52=E2=80=AFAM Stefan Traud <<a href=3D"mailto:stefan_tr=
[email protected]">[email protected]</a>> wrote:<br></div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px soli=
d rgb(204,204,204);padding-left:1ex"><div><div style=3D"font-family:Helveti=
ca Neue,Helvetica,Arial,sans-serif;font-size:13px"><div></div>
<div dir=3D"ltr">In between I have also looked into the source of o=
rg.apache.axis2.json.moshi.MoshiXMLStreamReader and I find</div><div dir=3D=
"ltr"><br></div><div dir=3D"ltr"><div><div style=3D"padding:0px 0px 0px 2px=
"><div style=3D"font-family:Consolas;font-size:10pt"><p style=3D"color:rgb(=
0,0,0);margin:0px"><span style=3D"color:rgb(127,0,85);font-weight:bold">pub=
lic</span> <span style=3D"color:rgb(127,0,85);font-weight:bold">int</span> =
getAttributeCount() {</p><p style=3D"color:rgb(0,0,0);margin:0px"> <=
span style=3D"color:rgb(127,0,85);font-weight:bold">if</span> (isStartEleme=
nt()) {</p><p style=3D"margin:0px"> <span style=3D"color:rgb(127=
,0,85);font-weight:bold">return</span> 0; <font color=3D"#cd232c"><b>//</b>=
</font><span style=3D"color:rgb(63,127,95)"> </span><font color=3D"#cd232c"=
><b>don't support attributes on tags in JSON convention</b></font></p>=
<p style=3D"color:rgb(0,0,0);margin:0px"> } <span style=3D"color:rgb=
(127,0,85);font-weight:bold">else</span> {</p><p style=3D"color:rgb(0,0,0);=
margin:0px"> <span style=3D"color:rgb(127,0,85);font-weight:bold=
">throw</span> <span style=3D"color:rgb(127,0,85);font-weight:bold">new</sp=
an> IllegalStateException(<span style=3D"color:rgb(42,0,255)">"Only va=
lid on START_ELEMENT state"</span>);</p><p style=3D"color:rgb(0,0,0);m=
argin:0px"> }</p><p style=3D"color:rgb(0,0,0);margin:0px"> }</p><=
p style=3D"color:rgb(0,0,0);margin:0px"><br></p><p style=3D"color:rgb(0,0,0=
);margin:0px"> <span style=3D"color:rgb(127,0,85);font-weight:bold">publ=
ic</span> QName getAttributeName(<span style=3D"color:rgb(127,0,85);font-we=
ight:bold">int</span> <span style=3D"color:rgb(106,62,62)">index</span>) {<=
/p><p style=3D"color:rgb(0,0,0);margin:0px"> <span style=3D"color:rg=
b(127,0,85);font-weight:bold">throw</span> <span style=3D"color:rgb(127,0,8=
5);font-weight:bold">new</span> UnsupportedOperationException(<span style=
=3D"color:rgb(42,0,255)">"Method is not implemented"</span>);</p>=
<div style=3D"color:rgb(0,0,0);margin:0px"> }</div><div style=3D"color:r=
gb(0,0,0);margin:0px"><br></div><div style=3D"color:rgb(0,0,0);margin:0px" =
dir=3D"ltr">Attributes get ignored (attribute count will be returned as 0).=
It appears that I cannot use the current XML Stream API based approach tog=
ehter with ADB in my case, at least not without substantial changes in the =
used xml-schemas.</div></div></div></div><br></div><div><br></div>
=20
</div><div id=3D"m_-1352858088099866023yahoo_quoted_0984148450">
<div style=3D"font-family:"Helvetica Neue",Helvetica,=
Arial,sans-serif;font-size:13px;color:rgb(38,40,42)">
=20
<div>
Am Mittwoch, 19. Februar 2025 um 09:26:07 MEZ hat S=
tefan Traud <<a href=3D"mailto:[email protected]" target=3D"_blank"=
>[email protected]</a>> Folgendes geschrieben:
</div>
<div><br></div>
<div><br></div>
=20
=20
<div><div id=3D"m_-1352858088099866023yiv9955715974"><div><=
div style=3D"font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-siz=
e:13px"><div></div>
<div dir=3D"ltr">I'm attaching 2 debug logs:</div><div dir=3D"l=
tr"><ul dir=3D"ltr"><li>soap.log: processing of the getPrice request using =
the ADBClient from samples.quickstartadb (modified only to set the required=
currency attribute using StockQuoteService.setCurrency). This returns the =
expected result.</li><li>json.log: processing of the getPrice request using=
a post of the json message string=C2=A0<span>{"getPrice":{"=
@currency":"USD","symbol":"IBM"}} with c=
ontent-type application/json and url=C2=A0</span><a rel=3D"nofollow noopene=
r noreferrer" shape=3D"rect" href=3D"http://localhost:8080/axis2/services/S=
tockQuoteService/getPrice." target=3D"_blank">http://localhost:8080/axis2/s=
ervices/StockQuoteService/getPrice.</a>=C2=A0This results in internal serve=
r error due to missing required attribute.</li></ul><div><br clear=3D"none"=
></div><div dir=3D"ltr">For your reference, I'm also attaching the modi=
fied StockQuoteService.wsdl from the samples.quickstartadb (adding required=
attribute 'currency' to the getPrice data type).</div><div dir=3D"=
ltr"><br clear=3D"none"></div><div dir=3D"ltr">I also played with various v=
ariations of the json message (using "currency" instead of "=
@currency", changing order, or using "_attributes" : {"=
currency":"USD"}. This trial-and-error approach does not wor=
k.</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">I also t=
ried what happens if I change the wsdl to require an attribute in the getPr=
iceResponse (instead of in the request), as this will use the=C2=A0<span>mo=
shi.JsonFormatter to write the output JSON (I hoped to see what convention =
would be used by moshi when producing the json string). However the attribu=
te is simply ignored and not included in the response json.</span></div></d=
iv><div><br clear=3D"none"></div>
=20
</div><div id=3D"m_-1352858088099866023yiv9955715974yahoo_quoted_02=
01809127">
<div style=3D"font-family:"Helvetica Neue",Helvetica,=
Arial,sans-serif;font-size:13px;color:rgb(38,40,42)">
=20
<div>
Am Dienstag, 18. Februar 2025 um 16:38:57 MEZ hat r=
obertlazarski <<a href=3D"mailto:[email protected]" target=3D"_bl=
ank">[email protected]</a>> Folgendes geschrieben:
</div>
<div><br clear=3D"none"></div>
<div><br clear=3D"none"></div>
=20
=20
<div id=3D"m_-1352858088099866023yiv9955715974yqt48543"><di=
v><div id=3D"m_-1352858088099866023yiv9955715974"><div><div dir=3D"ltr">Cou=
ld you please paste or attach your logs? That may help me understand the pr=
oblem better. I don't have use cases combining XML and JSON in my own p=
rojects but I know the code pretty well and I can probably help. <br clear=
=3D"none"></div><br clear=3D"none"><div id=3D"m_-1352858088099866023yiv9955=
715974yqt01052"><div><div dir=3D"ltr">On Mon, Feb 17, 2025 at 5:23=E2=80=AF=
AM Stefan Traud <<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" =
href=3D"mailto:[email protected]" target=3D"_blank">stefan_traud@yahoo=
.com</a>> wrote:<br clear=3D"none"></div><blockquote style=3D"margin:0px=
0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><di=
v><div style=3D"font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-=
size:13px"><div dir=3D"ltr">Hi Robert</div><div dir=3D"ltr">Using contract =
first with ADB, I continue to check feasibility to amend our existing servi=
ce with JSON support (based on XML Stream API with moshi).</div><div dir=3D=
"ltr"><br clear=3D"none"></div><div dir=3D"ltr">I'm currently strugglin=
g with xml types that include attributes. To reproduce the issue I have ame=
nded the wsdl in the samples.quickstartadb to include an attribute in the g=
etPrice element:</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D=
"ltr"><div><div style=3D"padding:0px 0px 0px 2px"><div style=3D"color:rgb(0=
,0,0);font-family:Consolas;font-size:10pt"><p style=3D"margin:0px"> <span=
style=3D"color:rgb(0,128,128)"><</span><span style=3D"color:rgb(63,127,=
127)">xs:element</span> <span style=3D"color:rgb(127,0,127)">name</span>=3D=
<span style=3D"color:rgb(42,0,255);font-style:italic">"getPrice"<=
/span><span style=3D"color:rgb(0,128,128)">></span></p><p style=3D"margi=
n:0px"> <span style=3D"color:rgb(0,128,128)">=C2=A0=C2=A0=C2=A0=C2=A0<=
;</span><span style=3D"color:rgb(63,127,127)">xs:complexType</span><span st=
yle=3D"color:rgb(0,128,128)">></span></p><p style=3D"margin:0px"> <s=
pan style=3D"color:rgb(0,128,128)">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0<</span><span style=3D"color:rgb(63,127,127)">xs:sequence</span=
><span style=3D"color:rgb(0,128,128)">></span></p><div style=3D"margin:0=
px"><span style=3D"color:rgb(0,128,128)">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<</span><span style=3D"color:rgb(=
63,127,127)">xs:element</span> <span style=3D"color:rgb(127,0,127)">name</s=
pan>=3D<span style=3D"color:rgb(42,0,255);font-style:italic">"symbol&q=
uot;</span>=C2=A0</div><div style=3D"margin:0px"><span style=3D"color:rgb(1=
27,0,127)">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0nillable</span>=3D<span style=3D"color:rgb=
(42,0,255);font-style:italic">"true"=C2=A0</span><span style=3D"f=
ont-size:10pt;color:rgb(127,0,127)">type</span><span style=3D"font-size:10p=
t">=3D</span><span style=3D"font-size:10pt;color:rgb(42,0,255);font-style:i=
talic">"xs:string"</span><span style=3D"font-size:10pt"> </span><=
span style=3D"font-size:10pt;color:rgb(0,128,128)">/></span></div><p sty=
le=3D"margin:0px"> <span style=3D"color:rgb(0,128,128)">=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0</</span><span style=3D"color:rgb(63,12=
7,127)">xs:sequence</span><span style=3D"color:rgb(0,128,128)">></span><=
/p><div style=3D"margin:0px"><span style=3D"color:rgb(0,128,128)">=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<</span><span style=3D"color:rgb(=
63,127,127)">xs:attribute</span> <span style=3D"color:rgb(127,0,127)">name<=
/span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic">"curren=
cy"</span>=C2=A0</div><div style=3D"margin:0px"><span style=3D"color:r=
gb(127,0,127)">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0type</span>=3D<span style=3D"color:rgb(42,0,255);font-style:ita=
lic">"xs:string"</span> <span style=3D"color:rgb(127,0,127)">use<=
/span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic">"requir=
ed"</span><span style=3D"color:rgb(0,128,128)">/></span></div><p st=
yle=3D"margin:0px"> <span style=3D"color:rgb(0,128,128)">=C2=A0=C2=A0=C2=
=A0=C2=A0</</span><span style=3D"color:rgb(63,127,127)">xs:complexType</=
span><span style=3D"color:rgb(0,128,128)">></span></p><p style=3D"margin=
:0px"> <span style=3D"color:rgb(0,128,128)"></</span><span style=3D"co=
lor:rgb(63,127,127)">xs:element</span><span style=3D"color:rgb(0,128,128)">=
></span></p></div></div></div><br clear=3D"none"></div><div dir=3D"ltr">=
My corresponding JSON message should then be something like:</div><div dir=
=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">{ "getPrice" :=
{"@currency": "USD", "symbol": "IBM&quo=
t; }}</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">Howev=
er the parse method in the GetPrice ADBBean keeps complaining "<span><=
span style=3D"padding:0px 0px 0px 2px"><span style=3D"color:rgb(0,0,0);font=
-family:Consolas;font-size:10pt">Required attribute currency is missing</sp=
an></span></span>"; specifically this call returns null:</div><div dir=
=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr"><div><div style=3D"paddi=
ng:0px 0px 0px 2px"><div style=3D"color:rgb(0,0,0);font-family:Consolas;fon=
t-size:10pt"><div style=3D"margin:0px"><span style=3D"color:rgb(106,62,62)"=
>reader</span>.getAttributeValue(<span style=3D"color:rgb(42,0,255)">"=
<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" href=3D"http://quick=
start.samples/xsd" target=3D"_blank">http://quickstart.samples/xsd</a>"=
;</span>, <span style=3D"color:rgb(42,0,255)">"currency"</span>);=
</div><div style=3D"margin:0px"><br clear=3D"none"></div></div></div></div>=
(However it works when using SOAP).</div><div dir=3D"ltr"><br clear=3D"none=
"></div><div dir=3D"ltr">Do I need to define attributes differently in the =
JSON message?</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"lt=
r"><br clear=3D"none"></div></div></div></blockquote></div></div>
</div></div></div></div>
</div>
</div></div></div></div>
</div>
</div></div></blockquote></div>
--00000000000093e380062edd0de8--