wood burning stoves 2.0*
The moose likes Web Services and the fly likes Problem with AsyncResult - Axis2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Problem with AsyncResult - Axis2" Watch "Problem with AsyncResult - Axis2" New topic
Author

Problem with AsyncResult - Axis2

Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
The problem is that AsyncResult prints to screen only the last closing tag, not the whole result. For example, the result the service returns is:

<message><record><id>8</id><albumname>Ghost Opera</albumname><date>2007-08-09</date><time>20:23:40</time></record></message>

and AsyncResult "shows" me only </message>.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
The docs for AsyncResult say:
This class holds the results of an asynchronous invocation. The Axis2 engine returns an instance of this class via the Callback.onComplete(AsyncResult) method when the operation completes successfully.

It looks to me like you have to get the result by getting the SOAPEnvelope and extracting various bits from it, not directly from the AsyncResult object.

How are you doing this "AsyncResult prints to screen"?

Bill
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31


My service returns OMElement.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
From the API:

A SOAPBody object contains SOAPBodyElement objects, which have the content for the SOAP body. A SOAPFault object, which carries status and/or error information, is an example of a SOAPBodyElement object.


Why do you expect the toString() method of SOAPBody to recreate the full document?

I think there are some DOM model toolkits which will output the full text content with toString() but it looks like AXIOM is not one.

Bill
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
Thank for your help, but Async Result was not the problem. I solved that but now I have another problem. I am supposed to get data from a database through Axi2 Web Service. How am I supposed to do that? I mean

1. Do I have to serialize the data from the database using StaX?
2. Or its better to use OMDataSource? (For that I haven't found enough info on the web).

3. Or do nothing, special, just get the data with ResultSet, add the RS add text to an OMelement and send it to the client?

So far I have programmed only opt 3 but I get the null word on screen
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
What exactly is the client expecting/needing?

Bill
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
Simple. The Service returns to the client the data of a DB table. Just that. But I have to implement it with Axis2 InOut MEP.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
Simple. The Service returns to the client the data of a DB table.


You misunderstood me - what format is the client expecting?
Apparently this is an Axis2 MEPClient, right? Who is responsible for the client side of this application?

Just to keep things complicated, I got email this morning announcing version 1.3 of Axis2 with major changes!!
Includes this little jewel:
All the asynchronous MessageReceivers have been deprecated


Bill
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
Ha ha. Thank you for the news. My Client is waiting OMElement.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
My Client is waiting OMElement.


Then I dont see any alternative to assembling it from the ResultSet.

Serializing with StaX doesn't make any sense & I dont know a thing about OMDataSource.

So far I have programmed only opt 3 but I get the null word on screen


That doesn't tell us a whole lot - there are plenty of XML methods that return null when beginners expect them to return content. The best resource for understanding this is a table in the JavaDocs for the org.w3c.dom.Node interface. Examine it carefully.

Bill
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
I am posting the source code I have written. I can't stand it anymore. I am a total failure.

Some explanations first. I have a setters, getters bean classof database fields. I have a database class that connects to the database and gets the data, and finally I have the Service class. I am posting the Service and the Database classes.




and my Service Class where I import the Database Class



If you need more explanations, tell it
[ August 16, 2007: Message edited by: Constantinos Grevenitis ]
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
I haven't read the org.w3c.dom.Node yet. I want you to tell me first where I am wrong. This source code returns to the client

id = null
albumname = null
date = null
time = null
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
If you are getting id=null etc that means the bean is not getting set, doesn't it?

If this was my problem I would have System.out.println statements scattered throughout to make sure - for instance - that the method call:
rs.getString("id")
actually gets a reasonable value.

I think you are suffering from the common beginner problem of trying to get it all working at one go. The ancient programmer says to proceed step-wise, making sure that the initial part works before adding the next. That way you wont waste time chasing phantom SOAP problems when the real error is earlier in the data flow.

Bill


Bill
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
I have already done that. I added a public static void main to the database class and another to the service class in order to test if they worked. They both worked fine. I had the results I wanted. But when I had to run the client and use the web service ....boom. Nothing. I am writing the service now. I will test the new service and I will let you know.
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
Hello. I rewrote the service class. I have the same problem. But I have run a test. I realized that when I run the client the service never "enters" the try catch clause, so it never "enters" the database. I believe that the problem might has to do with the org.jdbc.mysql.Driver, because into the aar file that class doesn't exist. So, since it doen't exist the service doesn't know what to with the db. I will check it at home tonight and I will tell you what the results are.

[ August 20, 2007: Message edited by: Constantinos Grevenitis ]
[ August 20, 2007: Message edited by: Constantinos Grevenitis ]
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
Ανάθεμα την τρέλα μου, ήταν τόσο απλό και δεν το σκέφτηκα. These words are greek. No, I am not crazy...yet. I found it. I forgot to add the mysql java connector to the axis2 lib directory. I am a bozo. Now I have another question. The client must receive a SOAPdocument that inside the body you have that.

<results>
<id>1</id><albumname>Eternity</albumname><date>2007-8-21</date><time>23:33:34</time>
<id>2</id><albumname>Dominion</albumname><date>2007-8-22</date><time>23:35:35</time>
...
...
...
<id>10</id><albumname>Ghost Opera</albumname><date>2007--8-25</date><time>20:25:34</time>
</results>

where the text inside the elements is the data from the database. I don't know how to build this. I only get the last record. I know that there is a buildNext() method but I don't know what exactyly is doing. Thanks a priori
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18909
    
    8

Greek, yes, but it starts with "anathema" and that's a word in English too.

Anyway, your JDBC code has several problems. First of all "rs.wasNext()" returns true if the last column that you read returned a null value. There is no point in calling it before you read any columns at all. You seem to think it returns true if the ResultSet has zero records. It doesn't do that at all. Check out the API documentation.

Second, you don't need to call rs.beforeFirst() after you generate the ResultSet, because the cursor is automatically put before the first row anyway. So just remove that too.

And third, the main problem: you only have one DiscographyBean object. For each row of the results you set its properties from that row, replacing whatever was there before. So naturally you end up with the data from the last row. You need to produce a new DiscographyBean object for each row and set its properties from that row. And you need to store all those DiscographyBeans in some kind of a list.
Constantinos Grevenitis
Ranch Hand

Joined: Nov 29, 2006
Posts: 31
Thanks for the help, but the bean is gone now. I re wrote the service class and it's different now. This service was more like a testing service, not the final version. But thanks for the help again.

Yes, one of my problems is that I want to check if the resultset has no records. But I will solve it.

My other problem is with axiom. Now I get the db data and I set them as text to OMElements. There is a buildNext() method but the API says nothing about it. I don't know how exactly it works and I still get the last records. The examples about Axis2 and Axiom are very similar....

The word anathema in greek means a lot of things depenting on how you use it. Greetings from hot Greece. Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with AsyncResult - Axis2