File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Architecture: Remoting from a Swing GUI to a Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Architecture: Remoting from a Swing GUI to a Database" Watch "Architecture: Remoting from a Swing GUI to a Database" New topic
Author

Architecture: Remoting from a Swing GUI to a Database

Michael Bradshaw
Greenhorn

Joined: Feb 11, 2011
Posts: 5

Hello,
I am setting up a brand new application using the spring-framework and I was wondering if I could get your comments. I am setting up an application that will need to have a swing client and will be accessible via Java Web Start. (We need to use Swing because we are doing image manipulation on the client side and there are pre-written swing libraries that we will need to access.) The Swing client will generate a lot of data (both text and binary) that will need to be stored remotely on server (in a database and as an external file). Futhermore, the application has multiple users, and users are not allowed to see each other's data. I am planning on setting up a DAO layer using Hibernate. The DAO layer wouldn't have any business logic, and only contain enough information to write to the database. I would then set up a service layer, and in the service layer there would be security logic that would ensure that users could only see data to which they have been assigned. (I was thinking about using spring-security for this, as I have seen annotations that can be used on methods that lock down a particular record a user is trying to access.) For remoting, I was planning on using Spring HTTP invoker. I was planning on making a RESTful interface, but it seems like that would require a lot of DTOs, and a previous post by Mark Spritzler made me rethink about how complicated I was making this application.

I had a few questions:
1) Can you see anything wrong about how I am setting this application up? I'm completely open to any suggestions you may have.
2) Do you recommend HttpInvoker as a good remoting option? I guess this will make this application only compatable with Java, unlike REST? HttpInvoker does binary serialization, correct, and not XML?
3) I understand that HttpInvoker can make it seems like the classes are local to each other. I'm not really sure what is going to happen when I add Hibernate into the mix. Let's say I have an Image java bean that has been initialized by Hibernate, and in the Image class there is a pointer to a Project class. What is going to happen when the client calls image.getProject(), and project hasn't been initialized? Also, let's say the Projects class contains a pointer to a Users list, say, of all the users who have access to the Project. I don't want the client to see this for security reasons. Could you tell me a good way of making this come about? Must I use DTOs, or do you have a better suggestion? I'm trying to get a feel for how my service layer will look.


I read a similar post to my problem here: http://www.coderanch.com/t/465980/Spring/Remoting-Communication-between-swing-client. I really appreciate any advice you can give me, and thanks for tolerating my long post. I'm sorry that I'm asking a lot of questions at once, but this is unfamiliar territory.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

If you want REST, why not use Spring RESTful WebServices on both the client and the server. No need to use HttpInvoker in that case. RestTemplate and @MVC will act in its place.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Michael Bradshaw
Greenhorn

Joined: Feb 11, 2011
Posts: 5

Mark, thanks for your response. REST would be an ideal because we'd like to be able to access our service layer via other languages, and we don't want to be limited to Java. If we use REST, won't we have to use DTOs? First, some of our database classes have sensitive columns that we don't want passed to the client. For example, our users class has a birthdate column that we want to keep private. Second, our hibernate classes have link to other hibernate classes, and I don't see how this would be done in XML. For example, our users class has a link to a Set of Accounts. Thus, it seems like we have to use DTOs. Do you agree?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Michael Bradshaw wrote:Mark, thanks for your response. REST would be an ideal because we'd like to be able to access our service layer via other languages, and we don't want to be limited to Java. If we use REST, won't we have to use DTOs? First, some of our database classes have sensitive columns that we don't want passed to the client. For example, our users class has a birthdate column that we want to keep private. Second, our hibernate classes have link to other hibernate classes, and I don't see how this would be done in XML. For example, our users class has a link to a Set of Accounts. Thus, it seems like we have to use DTOs. Do you agree?


Not necessarily. For instance Jackson(JSON) and JAXB(XML) have annotations you can put in your domain classes to state what you want ignored or allowed. The other great thing about REST is that you aren't responsible for doing the actual conversion or write multiple methods to support all the different representations.

Mark
 
jQuery in Action, 2nd edition
 
subject: Architecture: Remoting from a Swing GUI to a Database