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 expected 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.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" :
{"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
moshi.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 own
projects but I know the code pretty well and I can probably help.
On Mon, Feb 17, 2025 at 5:23 AM Stefan Traud <[email protected]> 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 reproduce
the issue I have amended the wsdl in the samples.quickstartadb to include an
attribute in the getPrice element:
<xs:element name="getPrice">
<xs:complexType>
<xs:sequence>
<xs:element name="symbol" nillable="true"
type="xs:string" />
</xs:sequence>
<xs:attribute name="currency" type="xs:string"
use="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 "Required
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?
json.log
Description: Binary data
soap.log
Description: Binary data
StockQuoteService.wsdl
Description: Binary data
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
