• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to return data from a database table using Apache CXF web service?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Apache CXF (apache-cxf-2.5.0) to create Web Services using bottum up approach (Java first approach). I want to return some data / records (for example username, email) from a database table using web services created by bottum up approach (Java first approach). I can write Java class which returns single response. But I am not able to find way to return a response such as data / records (for example username, email) from a database table. How to do that?

Thanks.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use jdbc/hibernate to get the data from database and pass it as POJO/String response via apache-cxf
 
Wap Rau
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arun Kumar wrote:you can use jdbc/hibernate to get the data from database and pass it as POJO/String response via apache-cxf


Thanks Arun Kumar for your answer. I am new to Web Services. I am having three doubts:

1. If I want to send data as a String data, how to send that from the function (say sendData()) in my Java class as examples on the internet have shown sending only one String as a response?

2. Is it possible/OK to send/return POJO as a response?

3. If I want to send data as POJO, how client which is a Android application can know which type of data is this and retrieve data from POJO?

Thanks.
 
Arun Kumar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answers in-line


1. If I want to send data as a String data, how to send that from the function (say sendData()) in my Java class as examples on the internet have shown sending only one String as a response?
Yes, you can send it (String can have values with some delimiter)

2. Is it possible/OK to send/return POJO as a response?
Yes, you can send POJO.

3. If I want to send data as POJO, how client which is a Android application can know which type of data is this and retrieve data from POJO?
You can use XML to send the data

 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I don't know the size of your service or the system it exists in, but here are some general advise:
- Consider using some method of describing the input and output to/from the service.
The way of describing the data going in and out of the service of course depend on what kind of data it is.
If the service accepts XML, then use an XML schema. For JSON there are some attempts at JSON schema.
Alternatively, a written document of some kind will also suffice.
- When designing the format of the data going in and out of the service, consider what will happen if you need to extend, or in some other way modify, the data.
Perhaps you want to be able to have different versions of one kind of request etc etc.
- Write your code with request and response handling modular and extensible.

Best wishes!
 
Wap Rau
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Arun Kumar, Ivan Krizsan for your answers.

I am creating Apache CXF (apache-cxf-2.5.0) SOAP based Web Services. It creates WSDL from Java class (Java first approach). I have to use SOAP and can't use REST.

I am retrieving data from database using ResultSet. Data is about 5 columns and over 100 rows. Now I want to send this data to Android client. I am thinking of converting ResultSet into ArrayList and sending ArrayList / List object as a response from SOAP Web Service. My problem is - is it possible to send List object as a reponse from SOAP Web Service. If yes, please provide me link to such an examples.

Thank you.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Generally, Java-specific types such as List and Collection should be avoided.
It is better to use plain arrays.
Best wishes!
 
reply
    Bookmark Topic Watch Topic
  • New Topic