aspose file tools*
The moose likes Web Services and the fly likes web services and dbase question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "web services and dbase question..." Watch "web services and dbase question..." New topic
Author

web services and dbase question...

Jay Albano
Greenhorn

Joined: May 07, 2004
Posts: 21
well i have two questions here but i think this belongs to web services as a whole. [i just started learning web service]

am using JAX-WS and is trying to send back a data from a database in XML format.

1. i cant format the XML response properly. i am returning an array now and will be received by the client as an array, this was my first solution since i have a hard time formatting the XML response.

2. is there any other possible way to convert the resultSet to XML format right away? or even for just as an array, especially when working with lists?

currently, what i do is that i fetch the data, get the last row then getRow to specify the size of the array to be returned, then use a loop to contain it to the array. any better idea? thanks in advance!


Trust in the Lord with all thine heart and lean not unto thine own understanding, <br />in all thy ways acknowledge Him and He shall direct thy path.<br /> <br />blue jay´┐Ż
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
In most situations one wouldn't create the XML to be sent, but instead let the WS stack do that. If the method that implements the WS operation has an array as return type that should work fine.

I'd probably iterate through the ResultSet and collect the data in a List, which can then be converted to an array. That way I don't have to care about sizing the array in my code.


Ping & DNS - my free Android networking tools app
Jay Albano
Greenhorn

Joined: May 07, 2004
Posts: 21
i see... ill take that opinion thanks... just a little clarification:

1. just how do you put a resultSet into a list? sorry for asking this but i just dont get it.

2. also, if it is a list, how am i suppose to do this with multi-dimensional arrays?

i am not just so familiar with the list you were talking about. ill have some research on the idea you were talking about while waiting for your reply... thanks for the idea.

EDIT:


If the method that implements the WS operation has an array as return type that should work fine.


i am not so sure if its more like an array, as i see it, its more like a series of <return>...</return> tags with the data inside it, :lol: (if thats how array is implemented in XML that is). also, i haven't tried passing multidimensional though, but ill be having some experiments with it later.

God bless!
[ December 11, 2007: Message edited by: Jay Albano ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
1. just how do you put a resultSet into a list?

By iterating through the ResultSet using next(), and using add() on the List.
2. also, if it is a list, how am i suppose to do this with multi-dimensional arrays?

By using a List that contains List objects, for example. Note, though, that for web services you should use arrays, not collections. Read http://www.ibm.com/developerworks/xml/library/ws-tip-coding.html for more detail.
i am not so sure if its more like an array, as i see it, its more like a series of <return>...</return> tags with the data inside it

I wouldn't worry about what the XML looks like. It's the job of the WS layer to deal with that. Both the service code and the client code should just concern themselves with arrays.
[ December 11, 2007: Message edited by: Ulf Dittmer ]
Jay Albano
Greenhorn

Joined: May 07, 2004
Posts: 21
okay, thanks.

ill try your suggestions about sticking with arrays other than collections. ill give you the feedback right after.

many thanks,
Jay
Jay Albano
Greenhorn

Joined: May 07, 2004
Posts: 21
well, i had tested working with multi-dimensional array as the return string but its still a pain, or is it that i just don't know how.

i just tried returning 2D arrays... the problem with the XML returned is that it would be formatted in this form:

...
<return>
<item></item>
<item></item>
<item></item>
</return>
<return>
<item></item>
<item></item>
<item></item>
</return>
...

the trouble is that it should be accessed by the client application as an array in terms of index... and by doing so, i cannot perform data binding (or is it i just don't know how) in Flex in terms of index.

it could have been easier if only it could return formatted XML like:

...
<return>
<col1></col1>
<col2></col2>
<col3></col3>
</return>
<return>
<col1></col1>
<col2></col2>
<col3></col3>
</return>
...

any idea?
[ December 14, 2007: Message edited by: Jay Albano ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Jay Albano:
and by doing so, i cannot perform data binding (or is it i just don't know how) in Flex in terms of index.


Well, this is the first that you mention that your client is Flex. If in fact this "web service" only exists to provide Flex clients with data then a SOAP web service may not be the optimal solution leading to unnecessary complexity (and performance degradation) in the client.

You may want to consider using a representation other than XML - JSON for example:
Flex + JSON + .Net Sample Application / Tutorial

There are JSON Java libraries that you can use for your data serialization code. Examples:
JSON in Java
StringTree JSON

You could then implement this functionality in a simple servlet or even use Restlet.
  • Design the response data for ease of use by the client
  • Decide how you intend to convey the parameters to the server (as part of the URL, as part of a query string, form encoded, etc.)
  • (Potentially) use the libraries to deserialize the request information for processing.
  • Use the libraries to serialize the result set to the response data


  • JAX-WS and JAXB implementations are good and flexible tools, however this flexibility makes for complex tools. So far I don't see that JAX-WS/JAXB's flexibility is buying you much.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: web services and dbase question...