Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I need to create some Java interfaces to query some database tables and some web services for new framework I'm building. In a previous Java Spring web application, I used Java Beans to handle the results of the query.

In this case, I need to write some interfaces to publish the methods that will be available to end users. I'm a little bit of a newbie in this particular aspect of Java and I was wondering: is it better to allow the end user to see and use the Java beans in JSP, or to hide them using some generic type?

share|improve this question
1  
So you need to expose what queries can be run via a Web Service of some sort? Can you elaborate on how the end user is viewing/interacting with this? Via a web browser or a client piece of software? –  Martijn Verburg Feb 7 '12 at 14:26
    
Web Service replies with an XML. End user will call this api from web application or portlet. –  Andrea Girardi Feb 7 '12 at 14:38
    
That sounds like a job for some kind of WSDL document to me –  AndyBursh Feb 7 '12 at 14:46
1  
Hi Andrea, it's okay and encouraged to ask your question directly instead of asking people for tutorials to answer your question. I've reworded your title to make it clearer what you're looking for: feel free to modify it if I missed the mark. –  user8 Feb 7 '12 at 18:39
    
Thanks Mark for your help. Really appreciate it! –  Andrea Girardi Feb 7 '12 at 22:04
add comment

3 Answers

It's okay to use those Java beans (which I'll call domain objects) to hold the results for a query. Then if you need to return them as a web service, you'll use the service to convert those objects to JSON or the desired format.

share|improve this answer
    
Or XML if JSON doesn't float your boat. –  Martijn Verburg Feb 7 '12 at 19:52
add comment

You sound like you want what is known as a Service Repository or a Service Registry. The following diagram I found on Wikipedia.

enter image description here

I have seen where a Service Repository had its own web service interface where one would request what kinds of web services and where the WSDL's are from a given component. The WSDL specifically will define what operations exist for the given service.

For more information on SOA, see Wikipedia.

share|improve this answer
add comment

I would definitely have them access your beans via interface types, to give you flexibility on the back end. It also provides more complete separation, as your UI code only depends on the interfaces (which can be kept in a separate jar file), not any particular implementation code. Plus, you can re-use front end code more easily. E.g., if you've got an address maintenance page, you can use it for anything that supports the IUpdatableAddress interface, regardless of whether it's a Person, Organization or Event. As long as you don't display or invoke anything that isn't part of the interface, you'll be fine.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.