| By Mauro Carniel | Article Rating: |
|
| September 5, 2007 09:15 PM EDT | Reads: |
41,158 |
Configuring an RIA with OpenSwing and Spring
When creating an RIA with an OpenSwing-based GUI, it's possible to use a classic DispatcherServlet
servlet provided with Spring as the unique access point for all HTTP
requests; these requests come from the "ClientUtils.getData()" utility
method provided by OpenSwing that can be used in a client-side
application to generate requests to the server-side application: all
data retrieval classes located in the client-side application will use
this utility method to remotely contact the server-side via the HTTP
protocol.
In any J2EE Web application there must be a defined "WEB-INF/web.xml" file; with Spring this is the first file to configure too. When combining OpenSwing with Spring, a typical web.xml content is like the one described in Listing 1.
As shown in there, a DispatcherServlet servlet class is defined; moreover, other XML files must be defined: they are the other classical files required by Spring: applicationContext.xml and dataAccessContext-....xml
When defining the DispatcherServlet servlet, Spring requires another XML file be created: "xxx-servlet.xml" in which "xxx" is the name of the servlet defined in the web.xml (in our example: "controller"); Listing 2 shows the "controller-servlet.xml" file.
OpenSwing provides two main classes that must be defined in this XML file:
• OpenSwingHandlerMapping
- This job of this class is to get all the requests coming from the
DispatcherServlet: these HTTP requests always contain a serializable
object of the org.openswing.swing.message.send.java.Command
type that contains a server-side bean name to invoke; this bean is a
controller type object recognized by the Spring framework; all
controller type beans in a "controller-servlet.xml" file must be
defined as having as an "id" the "methodName" values stored in the
command object and defined in the client-side layer.
At this point the Spring framework is the only actor: it's possible to define a facade, dao objects, transactions, and any other Spring component. Consequently, it's possible to include any technology that Spring allows to connect: ORM layers (such as Hibernate or iBatis or TopLink or JPA), EJB, etc.
The only constraint to respect is that the value to return to the client-side must be an object that extends org.openswing.swing.message.response.java.Response.
If the client request is generated by a grid control or a lookup then
the return value must be a VOListResponse; if the client request is
generated by a form then the return value must be a VOResponse type as
with any other application based on OpenSwing and not on Spring
(independent of the number of tiers, two or three tiers).
• OpenSwingViewResolver
- This class returns a Response type object to the client side; this
object has been generated in the server-side application and is given
back through HTTP by serializing the object.
So OpenSwingViewResolver doesn't render a Web page. It serializes objects for the client-side application.
It's possible to include any kind of Interceptor object in a Spring configuration as in any application based on Spring. The OpenSwingHandlerMapping class provided by OpenSwing always extracts the command serialized object from the request and stores it as the request's attribute named OpenSwingHandlerMapping. COMMAND_ATTRIBUTE_NAME. In this way the command object is available to all interceptor objects added to the application.
Optionally OpenSwing provides an interceptor class named SessionCheckInterceptor that could be included in "controller-servlet.xml" file: this interceptor checks each HTTP request coming from the client side; SessionCheckInterceptor dispatches requests only if the command object contains a session identifier previously stored in the servlet context (when the client was authenticated); if a command object doesn't contain a session identifier or it contains a session identifier not stored in the servlet context then the request is rejected.
The choice of storing session identifiers in the servlet context instead of in the session context bound to the client derives from the nature of three-tier client/server applications based on the Swing front-end: these applications may be started without a browser (for example, by directly using Java Web Start), so that the traditional means of client session identification (cookies or URL rewriting) can't be applied outside the browser. Consequently, session info bindable to a client must be stored in the servlet context and fetched starting from a client session identifier that must be sent from client to server in each command object.
SessionCheckInterceptor class extracts the client session identifier from the request (through the Command.getSessionId method) and checks in the ServletContext if this identifier is stored. Session identifiers are stored in a HashSet whose attribute name is OpenSwingHandlerMapping. USERS_AUTHENTICATED; if the identifier is stored then the interceptor returns true, otherwise it returns false and gives an org.openswing.swing.message.response. java.ErrorResponse object back to the client.
Resources
• JMatter - http://jmatter.org/
• JGoodies - www.jgoodies.com/
• JDNC - Java Desktop Network Components: https://jdnc.dev.java.net/
• JSR 296 - Swing Application Framework: http://jcp.org/en/jsr/detail?id=296
• JavaDesktop: http://community.java.net/javadesktop/
• OpenSwing Framework: http://oswing.sourceforge.net
• Spring Application Framework: www.springframework.org
• Hibernate Framework: www.hibernate.org/
• iBatis: http://ibatis.apache.org
Published September 5, 2007 Reads 41,158
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Mauro Carniel
Mauro Carniel is an architect at Tecnoinformatica Group. He has more than 9 years of enterprise software development experience utilizing J2EE-based technologies, including JSP, JSF, Swing, EJB. He started focusing more on GUI-based client/server Java applications since 1998. He has a MSc in Information Technology from University of Udine, Italy.
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?






































