Re: JSON with XML Stream API/moshi
Stefan Traud <[email protected]> Thu, 13 Mar 2025 14:47:29 +0000 (UTC)
| Newsgroups | gmane.text.xml.axis.user |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_3657944_226670990.1741877249729
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Thanks a lot for looking into this (and apologies for the late response) -=
very much appreciated!
Am Donnerstag, 27. Februar 2025 um 16:38:40 MEZ hat robertlazarski <rob=
[email protected]> Folgendes geschrieben: =20
=20
Thanks for posting your config files, that helped me understand a bit more=
of what you are trying to do as I only use the "native" JSON approach with=
POJO's at my day job. I haven't looked much at the Stax support code using=
the XMLSchema project.
And you were correct in pointing out the comments indicating that attribute=
s are not supported.=20
Anyways, I gave the coding to support attributes a shot but ran out of time=
after getting about 80% the way there - ideally someone with this use case=
can complete the coding though our git repo code requires Tomcat 11 / Wild=
fly 32.=20
See this commit. I created an attribute queue. If the JsonObject as an att=
ribute would be added to the main queue, it would incorrectly end up as an =
Element in the SOAP body generated from JSONHandler.=20
https://github.com/apache/axis-axis2-java-core/commit/16e832e71ef809ddd85de=
386b43719575d0a7b7c
I also created this Jira issue:
https://issues.apache.org/jira/browse/AXIS2-6081
What needs to happen is getAttributeCount() and getAttributeName() need to =
call nextName() and nextValue()
with some type of flag that tells the method to switch to the attribute que=
ue.=C2=A0=20
With the current code, it will consider JSON with a currency attribute adde=
d invalid because it doesn't read all of it since this Stax streaming appro=
ach needs that JsonObject in the attributes queue.=20
On Sun, Feb 23, 2025 at 10:42=E2=80=AFPM Stefan Traud <[email protected]=
om> wrote:
I'm using the services.xml without modification as per samples.quickstarta=
db.resources.META-INF.services.xml. Please see attached. Regarding the axis=
2.xml, I have modified according to the guidelines in=C2=A0Apache Axis2 =E2=
=80=93 How to configure Native approach and XML Stream API base approach=C2=
=A0for the XML Stream API based approach (and replacing occurences of "gson=
" with "moshi"). Please find attached.
In the transport phase, I have added:
<handler name=3D"RequestURIOperationDispatcher"
class=3D"org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
<handler name=3D"JSONMessageHandler"
class=3D"org.apache.axis2.json.moshi.JSONMessageHandler" />
However, I have not modified the RequestURIBasedDispatcher that was already=
there from the axis2-1.8.2 default axis2.xml as follows:
=20
<handler name=3D"RequestURIBasedDispatcher"
class=3D"org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
<order phase=3D"Transport"/>
</handler>
Regarding the moshi.MoshiXMLStreamReader: While I can not see any of the un=
supported methods being entered during debugging, I can see the getAttribut=
eCount method being invoked. This method always returns 0.=C2=A0
Am Montag, 24. Februar 2025 um 07:00:14 MEZ hat robertlazarski <robertl=
[email protected]> Folgendes geschrieben: =20
=20
I was able to follow your examples with the currency attribute and get som=
e results but it seems like you have some service.xml and axis2.xml configu=
rations I am unsure about - could you please post them?=20
With the service.xml and axis2.xml largely from the spring boot demo I conj=
ured up with the current state of git master - the one difference is you ar=
e using=C2=A0RequestURIBasedDispatcher instead of the new class JSONBasedDe=
faultDispatcher
which works, so I used that too - I am sending this:=20
{"getPrice":[{"arg0":{"currency":USD,"symbol":IBM}}]}
And getting this response:=20
{"response":{"local_return":42.0}}
The problem is the skeleton is receiving null values for the currency and s=
ymbol for some reason.=20
About the MoshiXMLStreamReader question - I don't see that condition being =
entered during my debugging.=20
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.mos=
hi.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 appears =
that I cannot use the current XML Stream API based approach togehter with A=
DB in my case, at least not without substantial changes in the used xml-sch=
emas.
Am Mittwoch, 19. Februar 2025 um 09:26:07 MEZ hat Stefan Traud <stefan_=
[email protected]> Folgendes geschrieben: =20
=20
I'm attaching 2 debug logs: =20
- 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.
- json.log: processing of the getPrice request using a post of the json =
message string=C2=A0{"getPrice":{"@currency":"USD","symbol":"IBM"}} with co=
ntent-type application/json and url=C2=A0http://localhost:8080/axis2/servic=
es/StockQuoteService/getPrice.=C2=A0This results in internal server error d=
ue to missing required attribute.
For your reference, I'm also attaching the modified StockQuoteService.wsdl =
from the samples.quickstartadb (adding required attribute 'currency' to the=
getPrice data type).
I also played with various variations of the json message (using "currency"=
instead of "@currency", changing order, or using "_attributes" : {"currenc=
y":"USD"}. This trial-and-error approach does not work.
I also tried what happens if I change the wsdl to require an attribute in t=
he getPriceResponse (instead of in the request), as this will use the=C2=A0=
moshi.JsonFormatter to write the output JSON (I hoped to see what conventio=
n would be used by moshi when producing the json string). However the attri=
bute is simply ignored and not included in the response json.
Am Dienstag, 18. Februar 2025 um 16:38:57 MEZ hat robertlazarski <rober=
[email protected]> Folgendes geschrieben: =20
=20
Could you please paste or attach your logs? That may help me understand th=
e problem 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.=20
On Mon, Feb 17, 2025 at 5:23=E2=80=AFAM Stefan Traud <[email protected]=
m> wrote:
Hi RobertUsing contract first with ADB, I continue to check feasibility to =
amend our existing service with JSON support (based on XML Stream API with =
moshi).
I'm currently struggling with xml types that include attributes. To reprodu=
ce the issue I have amended the wsdl in the samples.quickstartadb to includ=
e an attribute in the getPrice element:
<xs:element name=3D"getPrice">
=C2=A0=C2=A0=C2=A0=C2=A0<xs:complexType>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<xs:sequence>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<xs=
:element name=3D"symbol"=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=A0=C2=A0nillable=3D"true"=C2=A0t=
ype=3D"xs:string" />
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0</xs:sequence>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<xs:attribute name=3D"curre=
ncy"=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=A0type=3D"xs:string" use=3D"required"/>
=C2=A0=C2=A0=C2=A0=C2=A0</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 "Require=
d 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?
=20
=20
=20
------=_Part_3657944_226670990.1741877249729
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head></head><body><div class=3D"ydpe0bf657ayahoo-style-wrap" style=
=3D"font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px=
;"><div></div>
<div dir=3D"ltr" data-setdir=3D"false">Thanks a lot for looking int=
o this (and apologies for the late response) - very much appreciated!</div>=
<div dir=3D"ltr" data-setdir=3D"false"><br></div><div><br></div>
=20
</div><div id=3D"yahoo_quoted_2431688091" class=3D"yahoo_quoted">
<div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
=20
<div>
Am Donnerstag, 27. Februar 2025 um 16:38:40 MEZ hat=
robertlazarski <[email protected]> Folgendes geschrieben:
</div>
<div><br></div>
<div><br></div>
=20
=20
<div><div id=3D"yiv1914504297"><div><div dir=3D"ltr"><div>T=
hanks for posting your config files, that helped me understand a bit more o=
f what you are trying to do as I only use the "native" JSON approach with P=
OJO's at my day job. I haven't looked much at the Stax support code using t=
he XMLSchema project.</div><div><br clear=3D"none"></div><div>And you were =
correct in pointing out the comments indicating that attributes are not sup=
ported. <br clear=3D"none"></div><div><br clear=3D"none"></div><div>Anyways=
, I gave the coding to support attributes a shot but ran out of time after =
getting about 80% the way there - ideally someone with this use case can co=
mplete the coding though our git repo code requires Tomcat 11 / Wildfly 32.=
<br clear=3D"none"></div><div><br clear=3D"none"></div><div> See this comm=
it. I created an attribute queue. If the JsonObject as an attribute would b=
e added to the main queue, it would incorrectly end up as an Element in the=
SOAP body generated from JSONHandler. <br clear=3D"none"></div><div><br cl=
ear=3D"none"></div><div><a rel=3D"nofollow noopener noreferrer" shape=3D"re=
ct" target=3D"_blank" href=3D"https://github.com/apache/axis-axis2-java-cor=
e/commit/16e832e71ef809ddd85de386b43719575d0a7b7c">https://github.com/apach=
e/axis-axis2-java-core/commit/16e832e71ef809ddd85de386b43719575d0a7b7c</a><=
/div><div><br clear=3D"none"></div><div>I also created this Jira issue:</di=
v><div><br clear=3D"none"></div><div><a rel=3D"nofollow noopener noreferrer=
" shape=3D"rect" target=3D"_blank" href=3D"https://issues.apache.org/jira/b=
rowse/AXIS2-6081">https://issues.apache.org/jira/browse/AXIS2-6081</a></div=
><div><br clear=3D"none"></div><div>What needs to happen is getAttributeCou=
nt() and getAttributeName() need to call nextName() and <span style=3D"font=
-family:monospace;"><span style=3D"color:rgb(0,0,0);background-color:rgb(25=
5,255,255);">nextValue()</span><br clear=3D"none"></span>with some type of =
flag that tells the method to switch to the attribute queue. <br clea=
r=3D"none"></div><div><br clear=3D"none"></div><div>With the current code, =
it will consider JSON with a currency attribute added invalid because it do=
esn't read all of it since this Stax streaming approach needs that JsonObje=
ct in the attributes queue. <br clear=3D"none"></div></div><br clear=3D"non=
e"><div id=3D"yiv1914504297yqt42280" class=3D"yiv1914504297yqt7055144266"><=
div class=3D"yiv1914504297gmail_quote"><div dir=3D"ltr" class=3D"yiv1914504=
297gmail_attr">On Sun, Feb 23, 2025 at 10:42=E2=80=AFPM Stefan Traud <<a=
rel=3D"nofollow noopener noreferrer" shape=3D"rect" ymailto=3D"mailto:stef=
[email protected]" target=3D"_blank" href=3D"mailto:[email protected]=
">[email protected]</a>> wrote:<br clear=3D"none"></div><blockquote=
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex;" class=3D"yiv1914504297gmail_quote"><div><div style=3D"fon=
t-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div=
></div>
<div dir=3D"ltr">I'm using the services.xml without modification as=
per samples.quickstartadb.resources.META-INF.services.xml. Please see atta=
ched. Regarding the axis2.xml, I have modified according to the guidelines =
in <span><a rel=3D"nofollow noopener noreferrer" shape=3D"rect" target=
=3D"_blank" href=3D"https://axis.apache.org/docs/json_gson_user_guide.html"=
>Apache Axis2 =E2=80=93 How to configure Native approach and XML Stream API=
base approach</a> for the XML Stream API based approach (and replacin=
g occurences of "gson" with "moshi"). Please find attached.</span></div><di=
v dir=3D"ltr"><span><br clear=3D"none"></span></div><div dir=3D"ltr"><span>=
In the transport phase, I have added:</span></div><div dir=3D"ltr"><span><b=
r clear=3D"none"></span></div><div dir=3D"ltr"><div style=3D"padding:0px 0p=
x 0px 2px;"><div style=3D"color:rgb(0,0,0);font-family:Consolas;font-size:1=
0pt;"><p style=3D"margin:0px;"><span style=3D"color:rgb(0,128,128);"><</=
span><span style=3D"color:rgb(63,127,127);">handler</span> <span style=3D"c=
olor:rgb(127,0,127);">name</span>=3D<span style=3D"color:rgb(42,0,255);font=
-style:italic;">"RequestURIOperationDispatcher"</span></p><p style=3D"margi=
n:0px;"> <span style=3D"color:rgb(127,0,127);">=
class</span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic;">"org.=
apache.axis2.dispatchers.RequestURIOperationDispatcher"</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"color:=
rgb(63,127,127);">handler</span> <span style=3D"color:rgb(127,0,127);">name=
</span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic;">"JSONMessa=
geHandler"</span></p><div style=3D"margin:0px;"><span style=3D"color:rgb(12=
7,0,127);">class</span>=3D<span style=3D"color:rgb(42,0,255);font-style:ita=
lic;">"org.apache.axis2.json.moshi.JSONMessageHandler"</span> <span style=
=3D"color:rgb(0,128,128);">/></span></div></div></div></div><div dir=3D"=
ltr"><br clear=3D"none"></div><div dir=3D"ltr"><br clear=3D"none"></div><di=
v dir=3D"ltr">However, I have not modified the <span style=3D"padding:0px 0=
px 0px 2px;"><span style=3D"font-family:Consolas;font-size:10pt;"><span sty=
le=3D"color:rgb(42,0,255);font-style:italic;">RequestURIBasedDispatcher </s=
pan></span></span>that was already there from the axis2-1.8.2 default axis2=
.xml as follows:</div><div dir=3D"ltr"><span><br clear=3D"none"></span></di=
v><div dir=3D"ltr"><div style=3D"padding:0px 0px 0px 2px;"><div style=3D"co=
lor:rgb(0,0,0);font-family:Consolas;font-size:10pt;"><p dir=3D"ltr" style=
=3D"margin:0px;"> </p><div><div style=3D"padding:0px 0px 0px 2px;"><div sty=
le=3D"color:rgb(0,0,0);font-family:Consolas;font-size:10pt;"><p style=3D"ma=
rgin:0px;"><span style=3D"color:rgb(0,128,128);"><</span><span style=3D"=
color:rgb(63,127,127);background-color:rgb(212,212,212);">handler</span> <s=
pan style=3D"color:rgb(127,0,127);">name</span>=3D<span style=3D"color:rgb(=
42,0,255);font-style:italic;">"RequestURIBasedDispatcher"</span></p><p styl=
e=3D"margin:0px;"> <span style=3D"color:rgb(127,0,127);=
">class</span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic;">"or=
g.apache.axis2.dispatchers.RequestURIBasedDispatcher"</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"color:r=
gb(63,127,127);">order</span> <span style=3D"color:rgb(127,0,127);">phase</=
span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic;">"Transport"<=
/span><span style=3D"color:rgb(0,128,128);">/></span></p><p style=3D"mar=
gin:0px;"> <span style=3D"color:rgb(0,128,128);"></</span><sp=
an style=3D"color:rgb(63,127,127);background-color:rgb(212,212,212);">handl=
er</span><span style=3D"color:rgb(0,128,128);">></span></p></div></div><=
/div><p></p><div style=3D"margin:0px;"><br clear=3D"none"></div></div></div=
></div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr"><span>Reg=
arding the moshi.MoshiXMLStreamReader: While I can not see any of the unsup=
ported methods being entered during debugging, I can see the getAttributeCo=
unt method being invoked. This method always returns 0. </span></div><=
div><br clear=3D"none"></div>
=20
</div><div id=3D"yiv1914504297m_-6451814267192055376m_3835683055986=
474251yahoo_quoted_1177848542">
<div style=3D"font-family:Helvetica, Arial, sans-serif;font-siz=
e:13px;color:rgb(38,40,42);">
=20
<div>
Am Montag, 24. Februar 2025 um 07:00:14 MEZ hat rob=
ertlazarski <<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" ymai=
lto=3D"mailto:[email protected]" target=3D"_blank" href=3D"mailto:ro=
[email protected]">[email protected]</a>> Folgendes geschrie=
ben:
</div>
<div><br clear=3D"none"></div>
<div><br clear=3D"none"></div>
=20
=20
<div><div id=3D"yiv1914504297m_-6451814267192055376m_383568=
3055986474251yiv2506349534"><div><div dir=3D"ltr"><div>I was able to follow=
your examples with the currency attribute and get some results but it seem=
s like you have some service.xml and axis2.xml configurations I am unsure a=
bout - could you please post them? <br clear=3D"none"></div><div><br clear=
=3D"none"></div><div>With the service.xml and axis2.xml largely from the sp=
ring boot demo I conjured up with the current state of git master - the one=
difference is you are using <span style=3D"font-family:monospace;"><s=
pan style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255);">RequestUR=
IBasedDispatcher</span></span> instead of the new class <span style=3D"font=
-family:monospace;"><span style=3D"color:rgb(0,0,0);background-color:rgb(25=
5,255,255);">JSONBasedDefaultDispatcher</span><br clear=3D"none"></span>whi=
ch works, so I used that too - I am sending this: <br clear=3D"none"></div>=
<div><br clear=3D"none"></div><div><span style=3D"font-family:monospace;"><=
span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255);">{"getPri=
ce":[{"arg0":{"currency":USD,"symbol":IBM}}]}</span><br clear=3D"none"></sp=
an></div><div><span style=3D"font-family:monospace;"><br clear=3D"none"></s=
pan></div><div><span style=3D"font-family:monospace;">And getting this resp=
onse: <br clear=3D"none"></span></div><div><span style=3D"font-family:monos=
pace;"><br clear=3D"none"></span></div><div><span style=3D"font-family:mono=
space;"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255);"=
>{"response":{"local_return":42.0}}</span><br clear=3D"none"></span></div><=
div><span style=3D"font-family:monospace;"><br clear=3D"none"></span></div>=
<div><span style=3D"font-family:monospace;">The problem is the skeleton is =
receiving null values for the currency and symbol for some reason. <br clea=
r=3D"none"></span></div><div><br clear=3D"none"></div><div>About the <span =
style=3D"font-family:monospace;"><span style=3D"color:rgb(0,0,0);background=
-color:rgb(255,255,255);">MoshiXMLStreamReader question - I don't see that =
condition being entered during my debugging. </span><br clear=3D"none"></sp=
an><br clear=3D"none"></div></div><br clear=3D"none"><div id=3D"yiv19145042=
97m_-6451814267192055376m_3835683055986474251yiv2506349534yqt77091"><div><d=
iv dir=3D"ltr">On Fri, Feb 21, 2025 at 12:52=E2=80=AFAM Stefan Traud <<a=
rel=3D"nofollow noopener noreferrer" shape=3D"rect" ymailto=3D"mailto:stef=
[email protected]" target=3D"_blank" href=3D"mailto:[email protected]=
">[email protected]</a>> wrote:<br clear=3D"none"></div><blockquote=
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex;"><div><div style=3D"font-family:Helvetica 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 clear=3D"none"></div><div dir=3D"ltr"><div><div style=3D"padding:=
0px 0px 0px 2px;"><div style=3D"font-family:Consolas;font-size:10pt;"><p st=
yle=3D"color:rgb(0,0,0);margin:0px;"><span style=3D"color:rgb(127,0,85);fon=
t-weight:bold;">public</span> <span style=3D"color:rgb(127,0,85);font-weigh=
t:bold;">int</span> getAttributeCount() {</p><p style=3D"color:rgb(0,0,0);m=
argin:0px;"> <span style=3D"color:rgb(127,0,85);font-weight:bold;">i=
f</span> (isStartElement()) {</p><p style=3D"margin:0px;"> <span=
style=3D"color:rgb(127,0,85);font-weight:bold;">return</span> 0; <font col=
or=3D"#cd232c"><b>//</b></font><span style=3D"color:rgb(63,127,95);"> </spa=
n><font color=3D"#cd232c"><b>don't support attributes on tags in JSON conv=
ention</b></font></p><p style=3D"color:rgb(0,0,0);margin:0px;"> } <s=
pan style=3D"color:rgb(127,0,85);font-weight:bold;">else</span> {</p><p sty=
le=3D"color:rgb(0,0,0);margin:0px;"> <span style=3D"color:rgb(12=
7,0,85);font-weight:bold;">throw</span> <span style=3D"color:rgb(127,0,85);=
font-weight:bold;">new</span> IllegalStateException(<span style=3D"color:rg=
b(42,0,255);">"Only valid on START_ELEMENT state"</span>);</p><p style=3D"c=
olor:rgb(0,0,0);margin:0px;"> }</p><p style=3D"color:rgb(0,0,0);marg=
in:0px;"> }</p><p style=3D"color:rgb(0,0,0);margin:0px;"><br clear=3D"no=
ne"></p><p style=3D"color:rgb(0,0,0);margin:0px;"> <span style=3D"color:=
rgb(127,0,85);font-weight:bold;">public</span> QName getAttributeName(<span=
style=3D"color:rgb(127,0,85);font-weight:bold;">int</span> <span style=3D"=
color:rgb(106,62,62);">index</span>) {</p><p style=3D"color:rgb(0,0,0);marg=
in:0px;"> <span style=3D"color:rgb(127,0,85);font-weight:bold;">thro=
w</span> <span style=3D"color:rgb(127,0,85);font-weight:bold;">new</span> U=
nsupportedOperationException(<span style=3D"color:rgb(42,0,255);">"Method i=
s not implemented"</span>);</p><div style=3D"color:rgb(0,0,0);margin:0px;">=
}</div><div style=3D"color:rgb(0,0,0);margin:0px;"><br clear=3D"none"><=
/div><div dir=3D"ltr" style=3D"color:rgb(0,0,0);margin:0px;">Attributes get=
ignored (attribute count will be returned as 0). It appears 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.</div></d=
iv></div></div><br clear=3D"none"></div><div><br clear=3D"none"></div>
=20
</div><div id=3D"yiv1914504297m_-6451814267192055376m_3835683055986=
474251yiv2506349534m_-1352858088099866023yahoo_quoted_0984148450">
<div style=3D"font-family:Helvetica, Arial, sans-serif;font-siz=
e:13px;color:rgb(38,40,42);">
=20
<div>
Am Mittwoch, 19. Februar 2025 um 09:26:07 MEZ hat S=
tefan Traud <<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" ymai=
lto=3D"mailto:[email protected]" target=3D"_blank" href=3D"mailto:stef=
[email protected]">[email protected]</a>> Folgendes geschrieben:
</div>
<div><br clear=3D"none"></div>
<div><br clear=3D"none"></div>
=20
=20
<div><div id=3D"yiv1914504297m_-6451814267192055376m_383568=
3055986474251yiv2506349534m_-1352858088099866023yiv9955715974"><div><div st=
yle=3D"font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:1=
3px;"><div></div>
<div dir=3D"ltr">I'm attaching 2 debug logs:</div><div dir=3D"ltr">=
<ul dir=3D"ltr"><li>soap.log: processing of the getPrice request using the =
ADBClient from samples.quickstartadb (modified only to set the required cur=
rency attribute using StockQuoteService.setCurrency). This returns the expe=
cted result.</li><li>json.log: processing of the getPrice request using a p=
ost of the json message string <span>{"getPrice":{"@currency":"USD","s=
ymbol":"IBM"}} with content-type application/json and url </span><a re=
l=3D"nofollow noopener noreferrer" shape=3D"rect" target=3D"_blank" onclick=
=3D"return window.theMainWindow.showLinkWarning(this)" href=3D"http://local=
host:8080/axis2/services/StockQuoteService/getPrice.">http://localhost:8080=
/axis2/services/StockQuoteService/getPrice.</a> This results in intern=
al server 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=
modified StockQuoteService.wsdl from the samples.quickstartadb (adding req=
uired 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 vari=
ations of the json message (using "currency" instead of "@currency", changi=
ng order, or using "_attributes" : {"currency":"USD"}. This trial-and-error=
approach does not work.</div><div dir=3D"ltr"><br clear=3D"none"></div><di=
v dir=3D"ltr">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 <span>moshi.JsonFormatter to write the output JSON (I hoped t=
o 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.</span></div></div><div><br clear=3D"none"></div>
=20
</div><div id=3D"yiv1914504297m_-6451814267192055376m_3835683055986=
474251yiv2506349534m_-1352858088099866023yiv9955715974yahoo_quoted_02018091=
27">
<div style=3D"font-family:Helvetica, Arial, sans-serif;font-siz=
e:13px;color:rgb(38,40,42);">
=20
<div>
Am Dienstag, 18. Februar 2025 um 16:38:57 MEZ hat r=
obertlazarski <<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" ym=
ailto=3D"mailto:[email protected]" target=3D"_blank" href=3D"mailto:=
[email protected]">[email protected]</a>> Folgendes geschr=
ieben:
</div>
<div><br clear=3D"none"></div>
<div><br clear=3D"none"></div>
=20
=20
<div id=3D"yiv1914504297m_-6451814267192055376m_38356830559=
86474251yiv2506349534m_-1352858088099866023yiv9955715974yqt48543"><div><div=
id=3D"yiv1914504297m_-6451814267192055376m_3835683055986474251yiv250634953=
4m_-1352858088099866023yiv9955715974"><div><div dir=3D"ltr">Could you pleas=
e 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 own projects but I kn=
ow the code pretty well and I can probably help. <br clear=3D"none"></div><=
br clear=3D"none"><div id=3D"yiv1914504297m_-6451814267192055376m_383568305=
5986474251yiv2506349534m_-1352858088099866023yiv9955715974yqt01052"><div><d=
iv dir=3D"ltr">On Mon, Feb 17, 2025 at 5:23=E2=80=AFAM Stefan Traud <<a =
rel=3D"nofollow noopener noreferrer" shape=3D"rect" ymailto=3D"mailto:stefa=
[email protected]" target=3D"_blank" href=3D"mailto:[email protected]"=
>[email protected]</a>> wrote:<br clear=3D"none"></div><blockquote =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa=
dding-left:1ex;"><div><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 service 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 struggling with xml types that include attributes. To reproduce =
the issue I have amended the wsdl in the samples.quickstartadb to include a=
n attribute in the getPrice element:</div><div dir=3D"ltr"><br clear=3D"non=
e"></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;">=09=09=09<span style=3D"color:rgb(0,128,128);"><</span>=
<span style=3D"color:rgb(63,127,127);">xs:element</span> <span style=3D"col=
or:rgb(127,0,127);">name</span>=3D<span style=3D"color:rgb(42,0,255);font-s=
tyle:italic;">"getPrice"</span><span style=3D"color:rgb(0,128,128);">></=
span></p><p style=3D"margin:0px;">=09=09=09=09<span style=3D"color:rgb(0,12=
8,128);"> <</span><span style=3D"color:rgb(63,127=
,127);">xs:complexType</span><span style=3D"color:rgb(0,128,128);">></sp=
an></p><p style=3D"margin:0px;">=09=09=09=09=09<span style=3D"color:rgb(0,1=
28,128);"> <</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:0px;"><span style=3D"colo=
r:rgb(0,128,128);"> &n=
bsp; <</span><span style=3D"color:rgb(63,127,127);">xs:elemen=
t</span> <span style=3D"color:rgb(127,0,127);">name</span>=3D<span style=3D=
"color:rgb(42,0,255);font-style:italic;">"symbol"</span> </div><div st=
yle=3D"margin:0px;"><span style=3D"color:rgb(127,0,127);">  =
; &n=
bsp;nillable</span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic;=
">"true" </span><span style=3D"font-size:10pt;color:rgb(127,0,127);">t=
ype</span><span style=3D"font-size:10pt;">=3D</span><span style=3D"font-siz=
e:10pt;color:rgb(42,0,255);font-style:italic;">"xs:string"</span><span styl=
e=3D"font-size:10pt;"> </span><span style=3D"font-size:10pt;color:rgb(0,128=
,128);">/></span></div><p style=3D"margin:0px;">=09=09=09=09=09<span sty=
le=3D"color:rgb(0,128,128);"> &nbs=
p;</</span><span style=3D"color:rgb(63,127,127);">xs:sequence</span><spa=
n style=3D"color:rgb(0,128,128);">></span></p><div style=3D"margin:0px;"=
><span style=3D"color:rgb(0,128,128);"> =
<</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"c=
olor:rgb(42,0,255);font-style:italic;">"currency"</span> </div><div st=
yle=3D"margin:0px;"><span style=3D"color:rgb(127,0,127);">  =
; type</span>=3D<span =
style=3D"color:rgb(42,0,255);font-style:italic;">"xs:string"</span> <span s=
tyle=3D"color:rgb(127,0,127);">use</span>=3D<span style=3D"color:rgb(42,0,2=
55);font-style:italic;">"required"</span><span style=3D"color:rgb(0,128,128=
);">/></span></div><p style=3D"margin:0px;">=09=09=09=09<span style=3D"c=
olor:rgb(0,128,128);"> </</span><span style=3D"co=
lor:rgb(63,127,127);">xs:complexType</span><span style=3D"color:rgb(0,128,1=
28);">></span></p><p style=3D"margin:0px;">=09=09=09<span style=3D"color=
:rgb(0,128,128);"></</span><span style=3D"color:rgb(63,127,127);">xs:ele=
ment</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 mess=
age should then be something like:</div><div dir=3D"ltr"><br clear=3D"none"=
></div><div dir=3D"ltr">{ "getPrice" : {"@currency": "USD", "symbol": "IBM"=
}}</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">However=
the parse method in the GetPrice ADBBean keeps complaining "<span><span st=
yle=3D"padding:0px 0px 0px 2px;"><span style=3D"color:rgb(0,0,0);font-famil=
y:Consolas;font-size:10pt;">Required attribute currency is missing</span></=
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"padding:0px 0px=
0px 2px;"><div style=3D"color:rgb(0,0,0);font-family:Consolas;font-size:10=
pt;"><div style=3D"margin:0px;"><span style=3D"color:rgb(106,62,62);">reade=
r</span>.getAttributeValue(<span style=3D"color:rgb(42,0,255);">"<a rel=3D"=
nofollow noopener noreferrer" shape=3D"rect" target=3D"_blank" href=3D"http=
://quickstart.samples/xsd">http://quickstart.samples/xsd</a>"</span>, <span=
style=3D"color:rgb(42,0,255);">"currency"</span>);</div><div style=3D"marg=
in: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"ltr"><br clear=3D"none"><=
/div></div></div></blockquote></div></div>
</div></div></div></div>
</div>
</div></div></div></div>
</div>
</div></div></blockquote></div></div>
</div></div></div>
</div>
</div></div></blockquote></div></div>
</div></div></div>
</div>
</div></body></html>
------=_Part_3657944_226670990.1741877249729--