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
attributes are not supported.

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 /
Wildfly 32.

See this commit. I created an attribute queue. If the JsonObject as an
attribute would be added to the main queue, it would incorrectly end up as
an Element in the SOAP body generated from JSONHandler.

https://github.com/apache/axis-axis2-java-core/commit/16e832e71ef809ddd85de386b43719575d0a7b7c

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
queue.

With the current code, it will consider JSON with a currency attribute
added invalid because it doesn't read all of it since this Stax streaming
approach needs that JsonObject in the attributes queue.

On Sun, Feb 23, 2025 at 10:42 PM Stefan Traud <stefan_tr...@yahoo.com>
wrote:

> I'm using the services.xml without modification as per
> samples.quickstartadb.resources.META-INF.services.xml. Please see attached.
> Regarding the axis2.xml, I have modified according to the guidelines in Apache
> Axis2 – How to configure Native approach and XML Stream API base approach
> <https://axis.apache.org/docs/json_gson_user_guide.html> for 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="RequestURIOperationDispatcher"
>
> class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
>
> <handler name="JSONMessageHandler"
> class="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:
>
> <handler name="RequestURIBasedDispatcher"
>
> class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
>
> <order phase="Transport"/>
>
> </handler>
>
>
>
> Regarding the moshi.MoshiXMLStreamReader: While I can not see any of the
> unsupported methods being entered during debugging, I can see the
> getAttributeCount method being invoked. This method always returns 0.
>
> Am Montag, 24. Februar 2025 um 07:00:14 MEZ hat robertlazarski <
> robertlazar...@gmail.com> Folgendes geschrieben:
>
>
> 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 AM Stefan Traud <stefan_tr...@yahoo.com>
> 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 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.
>
>
> Am Mittwoch, 19. Februar 2025 um 09:26:07 MEZ hat Stefan Traud <
> stefan_tr...@yahoo.com> 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 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 <
> robertlazar...@gmail.com> 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 <stefan_tr...@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 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?
>
>
>

Reply via email to